-- 作者:大红袍
-- 发布时间:2015/6/29 17:14:00
--
Functions.Execute("datacol",DataTables("部门档案"),e)
----------------
Dim dt As DataTable=args(0) Dim e As object = args(1) Dim dt1 As DataTable= DataTables("编码规则") Dim dc As DataCol = e.DataCol If dc.Name = "部门编码" AndAlso e.newValue <> Nothing Then Dim fdr As DataRow = dt1.Find("数据表名 = \'" & dt.Name & "\'") If fdr IsNot Nothing Then Dim reg As new System.Text.RegularExpressions.Regex(fdr("正则")) If reg.Ismatch(e.newValue) = False Then e.Cancel = True Else Dim count As Integer = 0 Dim prev As String = "" For i As Integer = 0 To fdr("编码规则").length - 1 count += val(fdr("编码规则").chars(i)) Dim str As String = e.newValue.Substring(0, count) If count < e.Newvalue.length Then If dt.Find("部门编码 = \'" & str & "\'") Is Nothing Then msgbox("缺少:" & str) e.Cancel = True Exit For End If Else If count = e.newvalue.length Then If i = fdr("编码规则").length - 1 Then dt.DataRows(0)("是否末级") = True dt.ReplaceFor("是否末级", False, "部门编码 = \'" & prev & "\'") Else Dim filter As String = "部门编码 <> \'" & str & "\' and 部门编码 like \'" & str & "*\'" If dt.Find(filter) Is Nothing Then dt.DataRows(0)("是否末级") = True filter = "部门编码 = \'" & prev & "\'" dt.ReplaceFor("是否末级", False, filter) Else dt.DataRows(0)("是否末级") = False End If Exit For End If End If prev = str Next End If End If End If Dim dt As DataTable=args(0) Dim e As object = args(1) Dim dt1 As DataTable= DataTables("编码规则") Dim dc As DataCol = e.DataCol If dc.Name = "部门编码" AndAlso e.newValue <> Nothing Then Dim fdr As DataRow = dt1.Find("数据表名 = \'" & dt.Name & "\'") If fdr IsNot Nothing Then Dim reg As new System.Text.RegularExpressions.Regex(fdr("正则")) If reg.Ismatch(e.newValue) = False Then e.Cancel = True Else Dim count As Integer = 0 Dim prev As String = "" For i As Integer = 0 To fdr("编码规则").length - 1 count += val(fdr("编码规则").chars(i)) Dim str As String = e.newValue.Substring(0, count) If count < e.Newvalue.length Then If dt.Find("部门编码 = \'" & str & "\'") Is Nothing Then msgbox("缺少:" & str) e.Cancel = True Exit For End If Else If count = e.newvalue.length Then If i = fdr("编码规则").length - 1 Then dt.DataRows(0)("是否末级") = True dt.ReplaceFor("是否末级", False, "部门编码 = \'" & prev & "\'") Else Dim filter As String = "部门编码 <> \'" & str & "\' and 部门编码 like \'" & str & "*\'" If dt.Find(filter) Is Nothing Then dt.DataRows(0)("是否末级") = True filter = "部门编码 = \'" & prev & "\'" dt.ReplaceFor("是否末级", False, filter) Else dt.DataRows(0)("是否末级") = False End If Exit For End If End If prev = str Next End If End If End If
|