以文本方式查看主题

-  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=190778)

--  作者:dahai
--  发布时间:2024/3/2 21:20:00
--  无法保存行
我用的是阿里云sql数据库,在datacolchanged代码如下

If e.DataCol.Name = "创建日期" Then
    If e.DataRow.IsNull("创建日期") Then
        e.DataRow("退货单编号") = Nothing
    Else
        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 = "TC" & Format(d, "yyyyMM") 
        If e.DataRow("退货单编号").StartsWith(bh) = False Then
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.SQLCompute("Max(退货单编号)", "创建日期 >= \'" & fd & "\' And 创建日期 <= \'" & ld & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
            If max > "" Then 
                idx = CInt(max.Substring(8, 4)) + 1 
            Else
                idx = 1 
            End If
            e.DataRow("退货单编号") = bh & Format(idx, "0000")
        End If
    End If
    e.DataRow.save()
End If

新增行后,并不会自动保存,我不清楚问题出在哪里,请专家帮忙看一下问题出在哪,谢谢!


--  作者:有点蓝
--  发布时间:2024/3/3 20:08:00
--  
新增行后,输入"创建日期"才会保存的
--  作者:dahai
--  发布时间:2024/3/4 10:37:00
--  回复:(有点蓝)新增行后,输入"创建日期"才会保存的...
datarowadding 设置了 e.datarow("创建日期") = date.today 并且也自动生成了编号,程序上e.datarow.save()是在datarowadding和datacolchanged之后的。所以我觉得应该可以自动保存才对。
--  作者:有点蓝
--  发布时间:2024/3/4 11:05:00
--  
datarowadding 事件改为放到datarowadded事件
--  作者:dahai
--  发布时间:2024/3/4 13:55:00
--  回复:(有点蓝)datarowadding 事件改为放到dat...
谢谢版主,问题解决了。看了帮助文件datarowadding 和 datarowadded的区别,我还是不太理解,帮助文件中,自动生成编号的例子,为什么不在 datarowadded中自动生成日期,而使用datarowadding
--  作者:有点蓝
--  发布时间:2024/3/4 14:09:00
--  
帮助不需要触发事件。datarowadding的时候,行还没有添加到表格,不会触发datacolchanged事件