以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  编号不能归1,请大神帮忙修改一下  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=90319)

--  作者:zoyong
--  发布时间:2016/9/9 15:07:00
--  编号不能归1,请大神帮忙修改一下
      现代码如下:


Dim m As Integer
 m = DataTables("出纳记帐").DataRows.Count-1
DataTables("出纳记帐").datarows(m)("年月")=DataTables("出纳记帐").datarows(m-1)("年月")
DataTables("出纳记帐").datarows(m)("编号")=DataTables("出纳记帐").datarows(m-1)("编号")+1
Dim d As Date = Date.Today
DataTables("出纳记帐").datarows(m)("日")=d.day


图片点击可在新窗口打开查看此主题相关图片如下:搜狗截图16年09月09日1458_1.png
图片点击可在新窗口打开查看

理想效果为下边的右侧

图片点击可在新窗口打开查看此主题相关图片如下:搜狗截图16年09月09日1505_2.png
图片点击可在新窗口打开查看






[此贴子已经被作者于2016/9/9 15:25:03编辑过]

--  作者:有点蓝
--  发布时间:2016/9/9 15:18:00
--  
贴出创建编号的代码


--  作者:zoyong
--  发布时间:2016/9/9 15:25:00
--  
Dim m As Integer
 m = DataTables("出纳记帐").DataRows.Count-1
DataTables("出纳记帐").datarows(m)("年月")=DataTables("出纳记帐").datarows(m-1)("年月")
DataTables("出纳记帐").datarows(m)("编号")=DataTables("出纳记帐").datarows(m-1)("编号")+1
Dim d As Date = Date.Today
DataTables("出纳记帐").datarows(m)("日")=d.day

--  作者:有点蓝
--  发布时间:2016/9/9 15:33:00
--  
参考2楼例子,"出纳记帐"DataColChanged的代码

If
 e.DataCol.Name = "年月" Then
    If e.DataRow.IsNull(
"
年月"Then
        e.DataRow(
"
编号") = Nothing
    Else

        
Dim bh As String = e.DataRow("年月") \'生成编号的前6位,4位年,2位月.
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","
年月 = \'" & bh "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = Format(idx,"000")
        End If
    End 
If

End
 If
--  作者:zoyong
--  发布时间:2016/9/9 15:45:00
--  
.NET Framework 版本:2.0.50727.5485
Foxtable 版本:2016.7.29.1
错误所在事件:表,出纳记帐,DataColChanged
详细错误信息:
调用的目标发生了异常。
未找到类型“Integer”的公共成员“StartsWith”。


--  作者:有点蓝
--  发布时间:2016/9/9 15:49:00
--  
If e.DataCol.Name = "年月" Then
    If e.DataRow.IsNull("年月") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = e.DataRow("年月") \'生成编号的前6位,4位年,2位月.
        Dim max As String
        Dim idx As Integer
        max = e.DataTable.Compute("Max(编号)","年月 = \'" & bh & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
        If max > "" Then \'如果存在最大编号
            idx = CInt(max) + 1 \'获得最大编号的后三位顺序号,并加1
        Else
            idx = 1 \'否则顺序号等于1
        End If
        e.DataRow("编号") = Format(idx,"000")
    End If
End If