startedit事件调换一下位置,Syscmd.Row.Load()会导致数据保存且不会触发保存事件
If e.Row("编辑者") = User.Name Then '如果编辑者是当前用户
Return
End If
Dim cmd As New SQLCommand
cmd.ConnectionName = "仓管系统"
Dim id As Integer = e.Row("_Identify")
cmd.CommandText = "Select 用户名 From {入库表} Where [_Identify] = " & id
Dim nm As String = cmd.ExecuteScalar
If nm <> User.Name Then
Syscmd.Row.Load()
End If
Dim cmd2 As New SQLCommand
Dim exp2 As String = "编辑者 Is Null And [_Identify] = " & e.Row("_Identify")
cmd2.ConnectionName = "仓管系统"
cmd2.CommandText = "Update {入库表} Set 编辑者 = '" & User.Name & "' Where " & exp2
If cmd2.ExecuteNonQuery = 1 Then
e.Row("编辑者") = User.Name
Else
cmd2.CommandText = "Select 编辑者 From {入库表} Where [_Identify] = " & e.Row("_Identify")
Dim nm2 As String = cmd2.ExecuteScalar
If nm2 > "" Then
MessageBox.show(nm2 & "正在编辑此行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
MessageBox.show("此行可能已经被删除,无法编辑!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
e.Cancel = True '取消编辑
End If