在BeforeOpenFile事件之中:
'文件协作相关代码
If user.Group="管理员" Then
Dim str_FileName As String =e.FileName
str_FileName=str_FileName.TrimStart("//")
Dim str_path="\\172.16.11.5\pm文件\test\" & str_FileName
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "S elect 编辑者 From {文件协作表} Where [_Identify] = " & e.DataRow("_Identify")
Dim nm As String = cmd.ExecuteScalar
'msgbox(nm)
If nm>"" And e.DataRow("编辑者") = User.Name Then '如果编辑者不为空 且 编辑者是当前用户,则退出此事件
e.Cancel=True
Return
Else If nm > "" And e.DataRow("编辑者")<>User.Name Then '如果查询的编辑者字段不为空,且编辑者字段不是当前用户
MessageBox.show(nm & "正在编辑此行,你不能同时编辑!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel=True '禁止文件管理器打开附件
'Else If nm= "" Then
' MessageBox.show("此行可能已经被删除,无法编辑!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else If nm = "" And e.DataRow.RowState <> DataRowState.Added '如果等于当前编辑者的记录没有查询到 且 当前行不是新增行,则把当前编辑者插入进去
Dim exp As String = "编辑者 Is Null And [_Identify] = " & e.DataRow("_Identify")
cmd.C
cmd.CommandText = "U pdate {文件协作表} Set 编辑者 = '" & User.Name & "' Where " & exp
If cmd.ExecuteNonQuery = 1 Then '如果在数据库中字段成功写入编辑者
e.DataRow("编辑者") = User.Name '在显示的表中也改一下
'以下为打开附件列中的附件
If e.DataCol.Name = "附件" Then '如果鼠标操作的是附件列
If vars("ls").ContainsKey(e.DataRow("_identify")) Then '如果vars("ls")字典包含 当前列的 序列号
Vars("ls")(e.DataRow("_identify")) = system.Diagnostics.Process.Start(str_path)
Else '如果不包含
Vars("ls").add(e.DataRow("_identify"),system.Diagnostics.Process.Start(str_path))
End If
'msgbox(1)
e.Cancel = True '取消系统默认的打开文件操作,因为前面已经编码打开了 '成功也要取消打开文件,下面的失败也要取消,因为已经用代码打开了,不再需要文件管理器自动打开
End If
End If
End If
End If '如果当前用户是管理员