Dim t As Table = Tables("备份")
Dim d1 As String = "201401"
Dim d2 As String = "201402"
Dim cls() As String = {"职务_评定", "职称", "学科", "工资", "奖金", "合计"}
Dim delCount As Integer = 0
Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.grid.Styles.Add("cs1")
Dim cs2 As C1.Win.C1FlexGrid.CellStyle = t.grid.Styles.Add("cs2")
Dim cs3 As C1.Win.C1FlexGrid.CellStyle = t.grid.Styles.Add("cs3")
Dim cs4 As C1.Win.C1FlexGrid.CellStyle = t.grid.Styles.Add("cs4")
cs1.backcolor = Color.red
cs2.backcolor = Color.blue
cs3.backcolor = Color.green
cs4.backcolor = Color.yellow
Dim filter1 As String = "年月 = '" & d1 & "'"
Dim filter2 As String = "年月 = '" & d2 & "'"
t.Filter = filter1 & " or " & filter2
t.Sort = "姓名,年月"
Dim r1, r2 As Row
Dim i As Integer = 0
Do While i < t.Rows.Count - 1
r1 = t.Rows(i)
r2 = t.Rows(i+1)
If r1("姓名") = r2("姓名") Then '对比
Dim changed As Boolean = False
For Each c As String In cls
If r1(c) <> r2(c) Then
t.Grid.SetCellStyle(i+t.HeaderRows,t.Cols(c).Index+1,cs4)
t.Grid.SetCellStyle(i+t.HeaderRows+1,t.Cols(c).Index+1,cs3)
changed = True
End If
Next
If changed = False Then
r1.Delete
r2.Delete
delcount += 2
Else
i += 2
End If
Else
If r1("年月") = d1 Then '减少
For j As Integer = 2 To t.Cols.Count - 1
t.Grid.SetCellStyle(i+t.HeaderRows,j+1,cs2)
Next
Else If r1("年月") = d2 Then '新增
For j As Integer = 2 To t.Cols.Count - 1
t.Grid.SetCellStyle(i+t.HeaderRows,j+1,cs1)
Next
End If
i += 1
End If
Loop
If t.Rows.Count > 1 Then
r1 = t.Rows(t.Rows.Count-2)
r2 = t.Rows(t.Rows.Count-1)
If r1("姓名") = r2("姓名") Then '对比
For Each c As String In cls
If r1(c) <> r2(c) Then
t.Grid.SetCellStyle(t.Rows.Count+t.HeaderRows-2,t.Cols(c).Index+1,cs4)
t.Grid.SetCellStyle(t.Rows.Count+t.HeaderRows-1,t.Cols(c).Index+1,cs3)
End If
Next
End If
Else If t.Rows.count > 0 Then
r2 = t.Rows(t.Rows.Count-1)
If r2("年月") = d1 Then '减少
For j As Integer = 2 To t.Cols.Count - 1
t.Grid.SetCellStyle(t.Rows.count+t.HeaderRows-1,j+1,cs2)
Next
Else If r2("年月") = d2 Then '新增
For j As Integer = 2 To t.Cols.Count - 1
t.Grid.SetCellStyle(t.Rows.Count+t.HeaderRows-1,j+1,cs1)
Next
End If
End If