If e.Form.Controls("ComboBox1").Value = Nothing Then
MessageBox.Show("请选择供应商")
Return
End If
Dim t As Table = e.Form.controls("table1").Table
For Each r As Row In t.rows
For Each c As Col In t.cols
If r.IsNull(c.name) Then
MessageBox.Show(r.index+1 & "行 " & c.name & " 列为空")
Return
End If
Next
Next
Dim Cols1() As String = {"产品名称","型号规格","单位","单价"}
Dim Cols2() As String = {"产品名称","型号规格","单位","单价"}
Dim idxs As String = "-1,"
Dim ls_add As new List(Of Row)
Dim dic As new Dictionary(of Row, DataRow)
For i As Integer = 0 To t.Rows.count-1
Dim dr1 As Row = t.Rows(i)
Dim dr2 As DataRow = DataTables("材料表").find("供应商 = '" & e.Form.Controls("ComboBox1").text & "' and 产品名称 = '" & dr1("产品名称") & "' and 型号规格 = '" & dr1("型号规格") & "'")
If dr2 Is Nothing Then
ls_add.add(dr1)
Else
dic.Add(dr1, dr2)
End If
Next
If dic.count > 0 Then
Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式1")
cs1.backcolor = Color.red
cs1.Forecolor = Color.white
For Each key As Row In dic.Keys
t.Grid.SetCellStyle(key.Index+1, 4, cs1)
Next
Dim Result As DialogResult
Result = MessageBox.Show("是否替换", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
For Each key As Row In dic.Keys
Dim dr2 = dic(key)
dr2("供应商")=e.Form.Controls("ComboBox1").text
For i As Integer = 0 To Cols1.Length-1
dr2(Cols2(i))=key(Cols1(i))
Next
Dim c = t.Grid.GetCellRange(key.Index+1, 4)
c.Style = Nothing
Next
For Each r As Row In ls_add
Dim dr2 = DataTables("材料表").AddNew()
dr2("供应商")=e.Form.Controls("ComboBox1").text
For i As Integer = 0 To Cols1.Length-1
dr2(Cols2(i))=r(Cols1(i))
Next
Next
End If
t.DataTable.DataRows.Clear
Else
For Each r As Row In ls_add
Dim dr2 = DataTables("材料表").AddNew()
dr2("供应商")=e.Form.Controls("ComboBox1").text
For i As Integer = 0 To Cols1.Length-1
dr2(Cols2(i))=r(Cols1(i))
Next
Next
t.DataTable.DataRows.Clear
End If