CutRecord_BeforeAddDataRow
For Each dr As DataRow In
e.DataTable.DataRows
If dr.RowState = DataRowState.Added Then
MessageBox.Show("请先保存或撤销当前行,才能新增!","【裁剪记录单】提示",
MessageBoxButtons.OK ,MessageBoxIcon.Information)
e.Cancel = True
End If
Next
CutRecord_DataRowAdded
Dim d As Date = Date.Today
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer =
Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1)
'获得该月的第一天
Dim ld As Date = New
Date(y,m,Days) '获得该月的最后一天
Dim bh As String ="CUT"
& Format(d,"yyMM") '生成编号的前6位,4位年,2位月.
If
e.DataRow("CutRecordID").StartsWith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max =
e.DataTable.Compute("Max(CutRecordID)","CutDate >= #"
& fd & "# And CutDate <= #" & ld & "#")
'取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(8,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("CutRecordID") = bh
& "-" & Format(idx,"000")
End If
CutRecord_BeforeSaveDataRow
Dim dr As DataRow = e.DataRow
If dr.RowState <>
DataRowState.Added Then '如果不是新增行
Return '那么返回
Else
'==========
Dim CCutRecordID As String
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Select
[CutRecordID] From {CutRecord} Where [CutRecordID] = '" &
e.DataRow("CutRecordID") & "'"
CCutRecordID = cmd.ExecuteScalar()
'==========
If CCutRecordID IsNot Nothing Then
Dim d As Date = Date.Today
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
Dim bh As String ="CUT" &
Format(d,"yyMM") '生成编号的前6位,4位年,2位月.
Dim max As String
Dim idx As Integer
cmd.CommandText = "Select
Max([CutRecordID]) From {CutRecord} Where CutDate >= '" & fd &
"' And CutDate <= '" & ld & "'"
max = cmd.ExecuteScalar() '取得该月的最大编号
' MessageBox.Show("max" &
max)
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(8,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("CutRecordID") = bh
& "-" & Format(idx,"000")
End If
'==========
End If