Protected Sub MainGrdvDataBinding()
Dim ds_MainBills As DataSet, i As Integer
Dim j As Integer = 0 '數量的總計
Dim k As Integer = 0 '總重量的總計
Dim l As Integer = 0 '木架數總計
Dim m As Integer = 0 '木架費總計
Dim n As Decimal = 0 '金額總計
Dim dt As DataTable
Dim DetailRow As DataRow
Try
con_brmis = Css2DataAccess.GetConnection(Nothing, "css2")
ds_MainBills = Css2DataAccess.ExecuteDataset(con_brmis, CommandType.Text, Session("Sql_Main"))
dt = ds_MainBills.Tables(0).Columns.Add.Table
For i = 0 To dt.Rows.Count - 2
If dt.Rows(i)("box_num") Then
j += dt.Rows(i)("box_num")
k += dt.Rows(i)("total_weight")
l += dt.Rows(i)("shelft_num")
m += dt.Rows(i)("shelft_fee")
n += dt.Rows(i)("total_fee")
End If
Next
DetailRow = dt.NewRow
DetailRow("traffic_comp_name") = "总计"
DetailRow("box_num") = j
DetailRow("total_weight") = k
DetailRow("shelft_num") = l
DetailRow("shelft_fee") = m
DetailRow("total_fee") = n
dt.Rows.Add(DetailRow)
Main_grdv.DataSource = dt
Main_grdv.DataBind()
With Main_grdv
For i = 0 To .Rows.Count - 2
If .Rows(i).Cells(16).Text = "1" Then
.Rows(i).Cells(16).Text = "正常发货"
ElseIf .Rows(i).Cells(16).Text = "2" Then
.Rows(i).Cells(16).Text = "补货"
End If
Next
.Rows(i).Cells(2).Visible = False
.Rows(i).Cells(4).Visible = False
.Rows(i).Cells(5).Visible = False
.Rows(i).Cells(3).ColumnSpan = 4
End With
If ds_MainBills.Tables(0).Rows.Count = 0 Then
ErrorMsg.Text = Resources.CommonLan.Msg_NotFound
Else
MainBills_pnl.Visible = True
End If
'合并相同取货单的行
Call gvRender()
ds_MainBills = Nothing
Catch ex As Exception
ErrorMsg.Text = ex.Message
Finally
con_brmis.Close()
End Try
End Sub
'合并相同取货单的行
Private Sub gvRender()
Dim i As Integer, j As Integer
If Main_grdv.Rows.Count <= 1 Then
Return
End If
'由行开始循环
For i = Main_grdv.Rows.Count - 2 To 0 Step -1
Dim oldTr As TableRow = Main_grdv.Rows(i)
Dim newTr As TableRow = Main_grdv.Rows(i + 1)
If oldTr.Cells(2).Text = newTr.Cells(2).Text And oldTr.Cells(4).Text = newTr.Cells(4).Text And oldTr.Cells(7).Text = newTr.Cells(7).Text Then
'由列开始循环 Main_grdv.Columns.Count - 3 到 Main_grdv.Columns.Count - 1 列则为不合并的列
For j = 0 To Main_grdv.Columns.Count - 4
'Main_grdv.Rows(r).Cells(j).RowSpan = rowspan
If newTr.Cells(j).RowSpan < 2 Then
oldTr.Cells(j).RowSpan = 2
Else
oldTr.Cells(j).RowSpan = newTr.Cells(j).RowSpan + 1
oldTr.Cells(j).VerticalAlign = VerticalAlign.Middle
End If
newTr.Cells(j).Visible = False
Next
Else
End If
Next
End Sub