以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 自动编号 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=147988) |
|
-- 作者:lisangyu -- 发布时间:2020/3/28 15:12:00 -- 自动编号 蓝总:您好! If
e.DataCol.Name = "日期"
Then If
e.DataRow.IsNull("日期") Thene.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 = Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月. If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符 Dim max As String Dim idx As Integer max = e.DataTable.Compute("Max(编号)","日期 > = #" & fd & "# And 日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号 If max > "" Then \'如果存在最大编号 idx = CInt(max.Substring(7,3)) + 1 \'获得最大编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If e.DataRow("编号") = bh & "-" & Format(idx,"000") End If End If End
If 1、为什么我发起3条记录的编号都是一样的,202003-001? 2、Sqltable生成的表中的时间是不是不能带上datatime效果?
|
|
-- 作者:有点蓝 -- 发布时间:2020/3/28 16:05:00 -- 请不要发重复的问题 2、可以
|
|
-- 作者:lisangyu -- 发布时间:2020/3/29 13:12:00 -- 1、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 = Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月. If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符 Dim max As String Dim idx As Integer max = e.DataTable.Compute("Max(编号)","填报日期 >= #" & fd & "# And 填报日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号 If max > "" Then \'如果存在最大编号 idx = CInt(max.Substring(bh.length,3)) + 1 \'获得最大编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If e.DataRow("编号") = bh & "-" & Format(idx,"000") End If End If End If 填报了好几次申请,自动生成的编号全部为:202003-001,没有变化递增,是不是主键列的问题? 2、 SQLtable 生成的用户数据操作记录副本表,时间不带datatime效果,主表中的时间为datatime格式。如果把副本表换成normal类型,生成的副本表时间带datatime效果。
|
|
-- 作者:2900819580 -- 发布时间:2020/3/29 14:00:00 -- idx = CInt(max.Substring(bh.length + 1,3)) + 1 \'
|
|
-- 作者:lisangyu -- 发布时间:2020/3/29 19:59:00 -- 这个怎么理解?我上面的代码是根据帮助里改的,不该出错,不清楚为什么不递增?麻烦指导下,谢谢 [此贴子已经被作者于2020/3/29 20:00:09编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2020/3/29 22:16:00 -- 1、自己调试一下就明白了 max = e.DataTable.Compute("Max(编号)","填报日期 >= #" & fd & "# And 填报日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号 msgbox(max.Substring(bh.length,3)) ‘结果应该是【-00】 msgbox(max.Substring(bh.length+1,3)) If max > "" Then \'如果存在最大编号 idx = CInt(max.Substring(bh.length+1,3)) + 1 \'获得最大编号的后三位顺序号,并加1 Else idx = 1 \'否则顺序号等于1 End If 2、参考:http://www.foxtable.com/webhelp/topics/1611.htm,加载表之后再设置
|
|
-- 作者:zcgmxf -- 发布时间:2020/3/29 22:23:00 -- e.DataRow("编号") = bh & "-" & Format(idx,"000") 增加后要保存 e.DataRow.Save()
|
|
-- 作者:有点蓝 -- 发布时间:2020/3/29 22:55:00 -- 以下是引用zcgmxf在2020/3/29 22:23:00的发言:
使用sqlCompute才需要保存
e.DataRow("编号") = bh & "-" & Format(idx,"000") 增加后要保存 e.DataRow.Save()
|
|
-- 作者:lisangyu -- 发布时间:2020/3/29 23:42:00 -- 蓝总: 我改成
|
|
-- 作者:有点蓝 -- 发布时间:2020/3/30 8:47:00 -- 自动填充是怎么做的?什么事件? |