以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  职员档案已使用部门,部门档案不能再增加下级  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=63794)

--  作者:blsu33
--  发布时间:2015/1/28 22:03:00
--  职员档案已使用部门,部门档案不能再增加下级
有点甜老师,
      有两个档案,部门档案和职员档案
      部门档案怎么达到,职员档案中已使用了该部门,部门档案不能增加二级,已经使用了递归的函数
部门档案的befor add datarow怎么写代码(没有e参数) 类似如下  

Select Case e.DataCol.Name                                                                                        
    Case "编码名称"
        Dim dr As DataRow
        dr = DataTables("职员档案").Find("部门名称 = \'" & e.DataRow & "\'")
            If dr IsNot Nothing Then
                MessageBox.Show("已职员档案中使用,不能增加下级","提示")
                e.Cancel = True
            End If
      Case "编码规则"
        Dim dr As DataRow
        dr= DataTables("职员档案").Find("部门编码 = \'" & e.DataRow & "\'")
            If dr IsNot Nothing Then
                MessageBox.Show("已职员档案中使用,不能增加下级","提示")
                e.Cancel = True
            End If
End Select                                                                                                                                                                                                                                                                              
[此贴子已经被作者于2015-1-28 22:10:46编辑过]

--  作者:有点甜
--  发布时间:2015/1/28 22:10:00
--  

 肯定不应该beforeAddDataRow事件处理。

 

 因为你这个时候,你还没有填入部门名称,怎么知道是否被使用了?

 

 去Datacolchanged事件处理。


--  作者:blsu33
--  发布时间:2015/1/28 22:32:00
--  
Datacolchanged现在的代码,跪求老师帮忙改下

Select Case e.DataCol.Name                                                                                                \'更改编码规则的重新定义开始
    Case "编码规则"
        If e.NewValue IsNot Nothing Then
            Dim dr As DataRow = DataTables("分类编码方案").Find("基础档案名称 = \'" & e.DataTable.Name & "\'")
            If dr IsNot Nothing Then
                Dim sum As Integer
                For i As Integer = 0 To dr("编码规则").Length - 1
                    sum += val(dr("编码规则")(i))
                    If e.NewValue.length = sum Then
                        e.DataRow("编码级次") = dr("编码级次")(i)
                        Exit For
                    End If
                Next
            End If
        End If
End Select                                                                                                \'更改编码规则的重新定义结束


If e.DataCol.Name = "编码规则" AndAlso e.NewValue <> Nothing Then                                            \'更改编码规则的是否末级的重新定义开始
    Dim fdr As DataRow = DataTables("分类编码方案").Find("基础档案名称 = \'" & e.DataTable.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
            e.DataRow("是否末级") = (fdr("字符数") = e.NewValue.length)\'我加的
            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 e.DataTable.Find("编码规则 = \'" & str & "\'") Is Nothing Then
                        MessageBox.Show("缺少上级科目:" & str,"提示",MessageBoxButtons.OK)
                        e.Cancel = True
                        e.DataRow("是否末级")=False
                        Exit For
                    Else If e.OldValue = str Then
                        MessageBox.Show("缺少上级科目:" & str,"提示",MessageBoxButtons.OK)
                        e.Cancel = True
                        Exit For
                    End If
                Else If count = e.NewValue.length  Then
                    If i = fdr("编码规则").length - 1 Then
                        e.DataRow("是否末级") = True
                        e.DataTable.ReplaceFor("是否末级", False, "编码规则 = \'" & prev & "\'")
                    Else
                        Dim filter As String = "编码规则 <> \'" & str & "\' and 编码规则 like \'" & str & "*\'"
                        If  e.DataTable.Find(filter) Is Nothing Then
                            e.DataRow("是否末级") = True
                            filter = "编码规则 = \'" & prev & "\'"
                            e.DataTable.ReplaceFor("是否末级", False, filter)
                        Else
                            e.DataRow("是否末级") = False
                        End If
                        
                        Exit For
                    End If
                End If
                prev = str
            Next
        End If
    End If
End If   

                                                                                                         \'更改编码规则的是否末级的重新定义结束

--  作者:有点甜
--  发布时间:2015/1/28 22:35:00
--  
  以前给你写过了啊。在Datacolchanging 或者 Datacolchanged,加入1楼的代码啊。
--  作者:blsu33
--  发布时间:2015/1/28 22:47:00
--  
1楼代码只是解决了一级科目不允许增加,如下例子:
部门档案使用正则 编码为2+2

  01 财务部  在职员档案中已使用 
  现在的问题是,01 财务部已经在职员档案中使用,那么,不允许部门档案再增加01财务部下的部门0101 出纳,是这个意思。

--  作者:有点甜
--  发布时间:2015/1/28 22:50:00
--  

  用like就行啊。

 

dr = DataTables("职员档案").Find("部门名称 like \'" & e.DataRow("部门名称") & "%\'")