以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  自动增加行问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=148536)

--  作者:13775189031
--  发布时间:2020/4/9 16:23:00
--  自动增加行问题
增加行后信息显示不全,是什么原因?是和其他代码有冲突?
增加行没有问题,但生成的行中只有“合同性质_一单一招”和"工作联系单编号",“生产令号”、“协作内容”、“合同类别”都生成不过去
Select Case e.DataCol.name
    Case "合同签订"
        If e.newvalue = False Then
            DataTables("外协作合同台账").DeleteFor("工作联系单编号=\'" & e.DataRow("工作联系单编号") & "\'")
        Else
            Dim ndr As Row = Tables("外协作合同台账").AddNew
            ndr("工作联系单编号") = e.DataRow("工作联系单编号")
            ndr("生产令号") = e.DataRow("生产令号")
            ndr("协作内容") = e.DataRow("协作内容")
            ndr("合同性质_年度合同") = e.DataRow("合同性质_年度合同")
            ndr("合同性质_一单一招") = e.DataRow("合同性质_一单一招")
            ndr("合同类别") = e.DataRow("合同类别")
            ndr.Move(0)
        End If
End Select

Select Case e.DataCol.Name
    Case "生产令号","协作内容","合同类别"
        Dim Filter As String = "[工作联系单编号] = \'" & e.DataRow("工作联系单编号") & "\'"
        Dim drs As List(Of DataRow) = DataTables("外协作合同台账").Select(Filter)
        For Each dr4 As DataRow In drs
            dr4(e.DataCol.Name) = e.NewValue
        Next
End Select

--  作者:有点蓝
--  发布时间:2020/4/9 16:37:00
--  
Select Case e.DataCol.Name
    Case "生产令号","协作内容","合同类别","合同性质_一单一招","合同性质_年度合同"
……

--  作者:13775189031
--  发布时间:2020/4/10 8:19:00
--  
还是一样!
--  作者:13775189031
--  发布时间:2020/4/10 8:21:00
--  
我试了一下,把“生产令号”复制黏贴到“外协合同台账”中,然后切换到其他表格,再切换回来,“生产令号”又变成空白了,应该是这个问题导致的,是什么原因?
--  作者:有点蓝
--  发布时间:2020/4/10 9:06:00
--  
“生产令号”是表达式列?检查项目事件,比如MainTableChanged
--  作者:13775189031
--  发布时间:2020/4/10 10:47:00
--  
生产令号都是数据列,查出来问题出在这段代码上,删掉这句代码就没问题,是什么原因呢?

If MainTable.Name = "外协作合同台账" Then
    DataTables("外协作合同台账").DataCols("协作合同编号").RaiseDataColChanged()
End If


--  作者:有点蓝
--  发布时间:2020/4/10 11:01:00
--  
"外协作合同台账"的datacolchanged事件全部发上来看看
--  作者:13775189031
--  发布时间:2020/4/10 12:28:00
--  
协作合同台账
If e.DataCol.Name = "协作合同编号" Then
    If e.NewValue Is Nothing Then
        e.DataRow("生产令号") = Nothing
        e.DataRow("合同类别") = Nothing
        e.DataRow("协作内容") = Nothing
        Dim dr4 As DataRow
        dr4 = DataTables("外协工作联系单").Find("[工作联系单编号] = \'" & e.NewValue & "\'")
        If dr4 IsNot Nothing
            e.DataRow("生产令号") = dr4("生产令号")
            e.DataRow("合同类别") = dr4("合同类别")
            e.DataRow("协作内容") = dr4("协作内容")
        End If
    End If
End If

If e.DataCol.Name = "协作合同编号" Then
    Dim Filter As String = "[协作合同编号] = \'" & e.NewValue & "\'"
    e.DataRow("累计结算数量") = val(DataTables("外协作结算清单").Compute("Sum(结算数量)", Filter))
End If

If e.DataCol.Name = "协作合同编号" Then
    Dim Filter As String = "[协作合同编号] = \'" & e.NewValue & "\'"
    e.DataRow("累计结算金额") = val(DataTables("外协作结算清单").Compute("Sum(结算金额)", Filter))
End If

If e.DataCol.Name = "合同类别" Then
    If e.NewValue Is Nothing Then
        e.DataRow("合同类别代号") = Nothing
    Else
        Dim dr2 As DataRow
        dr2 = DataTables("外协合同类别代号").Find("[合同类别] = \'" & e.NewValue & "\'")
        If dr2 IsNot Nothing
            e.DataRow("合同类别代号") = dr2("代号")
        End If
    End If
End If

Dim dr1 As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "合同签订日期"
        If e.DataRow.IsNull("合同签订日期") Then
            dr1("年度") = Nothing
        Else
            dr1("年度") = Left(e.DataRow("合同签订日期") ,4)
        End If
End Select

Select e.DataCol.Name
    Case "年度","合同类别代号"
        If e.DataRow.IsNull("年度") OrElse e.DataRow.IsNull("合同类别代号") Then
            e.DataRow("协作合同编号") = Nothing
        Else
            Dim bh As String = e.DataRow("年度") & "-" & e.DataRow("合同类别代号") & "-"
            If e.DataRow("协作合同编号").StartsWith(bh) = False \'如果报告单编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "年度 = \'"& e.DataRow("年度") & "\'And 合同类别代号 = \'"& e.DataRow("合同类别代号") & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(协作合同编号)",flt) \'取得该月的相同部门代号的最大报告单编号
                If max > "" Then \'如果存在最大报告单编号
                    idx = CInt(max.Substring(8,4)) + 1 \'获得最大报告单编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("协作合同编号") = bh & Format(idx,"0000")
            End If
        End If
End Select

If e.DataCol.Name = "生产令号" Then \'如果内容发生变动的是品名列
    If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空
        e.DataRow("内部合同编号") = Nothing
        e.DataRow("项目名称") = Nothing
    Else
        Dim dr3 As DataRow
        dr3 = DataTables("生产令号").Find("[生产令号] = \'" & e.NewValue & "\'")
        If dr3 IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing
            e.DataRow("内部合同编号") = dr3("内部合同编号")
            e.DataRow("项目名称") = dr3("项目名称")
        End If
    End If
End If



--  作者:13775189031
--  发布时间:2020/4/10 12:29:00
--  
协作工作联系单
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "生产令号"
        If dr.IsNull("生产令号") Then
            dr("编制日期") = Nothing
        Else
            dr("编制日期") = Date.today
        End If
End Select

If e.DataCol.Name = "生产令号" Then \'如果内容发生变动的是品名列
    If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空
        e.DataRow("项目名称") = Nothing
    Else
        Dim dr3 As DataRow
        dr3 = DataTables("生产令号").Find("[生产令号] = \'" & e.NewValue & "\'")
        If dr3 IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing
            e.DataRow("项目名称") = dr3("项目名称")
        End If
    End If
End If

Dim dr1 As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "编制日期"
        If e.DataRow.IsNull("编制日期") Then
            dr1("年度") = Nothing
        Else
            dr1("年度") = Left(e.DataRow("编制日期") ,4)
        End If
End Select

If e.DataCol.Name = "编制日期" OrElse e.DataCol.Name = "合同性质_一单一招" OrElse e.DataCol.Name = "合同性质_年度合同" Then
    If e.DataRow.IsNull("编制日期") Then
        e.DataRow("工作联系单编号") = Nothing
    Else
        If e.DataRow("合同性质_一单一招") = True Then
            Dim d As Date = e.DataRow("编制日期")
            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 = "WX-" & Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.
            If e.DataRow("工作联系单编号").StartsWith(bh) = False \'如果编号的前6位不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(工作联系单编号)","工作联系单编号 like \'" & bh & "%\' and 编制日期 >= #" & fd & "# And 编制日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(10,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("工作联系单编号") =bh & "-" & Format(idx,"000")
                e.DataRow.Save
            End If
        ElseIf e.DataRow("合同性质_年度合同") = True Then
            Dim d As Date = e.DataRow("编制日期")
            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 = "ND-" &Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.
            If e.DataRow("工作联系单编号").StartsWith(bh) = False \'如果编号的前6位不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(工作联系单编号)","工作联系单编号 like \'" & bh & "%\' and 编制日期 >= #" & fd & "# And 编制日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(10,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("工作联系单编号") = bh & "-" & Format(idx,"000")
                e.DataRow.Save
            End If
        End If
    End If
End If

Select Case e.DataCol.Name
    Case "结算"
        If e.DataRow("结算") = True Then
            Dim dr3 As Row = Tables("外协作结算清单").AddNew()
            dr3("结算日期") = Date.today
            dr3("协作合同编号") = e.DataRow("协作合同编号")
            dr3("生产令号") = e.DataRow("生产令号")
            dr3("项目名称") = e.DataRow("项目名称")
            dr3("协作内容") = e.DataRow("协作内容")
            dr3.Move(0)
        End If
End Select

Select Case e.DataCol.Name
    Case "合同签订","生产令号","协作内容","合同类别","合同性质_一单一招"
        If e.DataRow("合同签订") = False OrElse e.DataRow.IsNull("生产令号") = True OrElse e.DataRow.IsNull("协作内容") = True OrElse e.DataRow.IsNull("合同类别") = True OrElse e.DataRow("合同性质_一单一招") = False Then
            DataTables("外协作合同台账").DeleteFor("工作联系单编号=\'" & e.DataRow("工作联系单编号") & "\'")
        Else
            Dim ndr As Row = Tables("外协作合同台账").AddNew
            ndr("工作联系单编号") = e.DataRow("工作联系单编号")
            ndr("生产令号") = e.DataRow("生产令号")
            ndr("协作内容") = e.DataRow("协作内容")
            ndr("合同性质_一单一招") = e.DataRow("合同性质_一单一招")
            ndr("合同类别") = e.DataRow("合同类别")
            ndr.Move(0)
        End If
End Select

Select Case e.DataCol.Name
    Case "生产令号","协作内容","合同类别"
        Dim Filter As String = "[工作联系单编号] = \'" & e.DataRow("工作联系单编号") & "\'"
        Dim drs As List(Of DataRow) = DataTables("外协作合同台账").Select(Filter)
        For Each dr4 As DataRow In drs
            dr4(e.DataCol.Name) = e.NewValue
        Next
End Select

--  作者:有点蓝
--  发布时间:2020/4/10 13:56:00
--  
6楼diamond会触发协作合同台账这些代码。然后会从"外协工作联系单"取数据覆盖"生产令号",应该是"外协工作联系单"这个编号的"生产令号"没有数据吧。
If e.DataCol.Name = "协作合同编号" Then
    If e.NewValue Is Nothing Then
        e.DataRow("生产令号") = Nothing
        e.DataRow("合同类别") = Nothing
        e.DataRow("协作内容") = Nothing
        Dim dr4 As DataRow
        dr4 = DataTables("外协工作联系单").Find("[工作联系单编号] = \'" & e.NewValue & "\'")
        If dr4 IsNot Nothing
            e.DataRow("生产令号") = dr4("生产令号")
            e.DataRow("合同类别") = dr4("合同类别")
            e.DataRow("协作内容") = dr4("协作内容")
        End If
    End If
End If