http://foxtable.com/bbs/dispbbs.asp?boardid=2&Id=145239,看4楼实例Select e.DataCol.Name
Case "日期"
If e.DataRow.IsNull("日期") Then
e.DataRow("编号") = Nothing
Else
Dim dr As DataRow = DataTables("号表").Find("编号 is not null and 表名='订单'", "编号")
If dr IsNot Nothing Then
e.DataRow("编号") = dr("编号")
dr.Delete
DataTables("号表").save
Else
Dim rt As String = QQClient.SendWait(":f" & e.DataTable.Name & "f:")
e.DataRow("编号") = rt
End If
End If
Case "编号"
If e.NewValue Is Nothing AndAlso e.OldValue IsNot Nothing Then
Dim dr1 As DataRow = DataTables("号表").Find("表名 ='订单' and 编号 ='" & e.OldValue & "'")
If dr1 Is Nothing Then
dr1 = DataTables("号表").AddNew
dr1("表名") = "订单"
dr1("编号") = e.OldValue
dr1.save
End If
End If
End Select
问题一:日期列的值的改变,没触编号列生成编号的值?
问题二:红代码,没报错,也没执行,无法实现回收使用
的编号,如果有旧编号用旧编号,没旧编号,新生成编号,跨月,旧编号不能用,只能新编号
问题1:我浿试需要单击编号,才生成,后续会在窗口上文本框来显示,每次操作,都要单击编号,那很不友好问题2:旧编号没有回收再利用。
[此贴子已经被作者于2024/7/26 10:36:11编辑过]
Dim db = HySq-l.DataBaseFactory.CreateDatabase("编号用户测试库")
'不重复编号上传用,这里的用法比较简单,没有做复杂的编号规则处理'
Public Class BizCodeBuilder
Private _bizcode As DataTable '直接把编号表取出到内存'
Private _codelock As New Object
Public Sub New(sjy As String)
Dim Sql = "selec-t * from {uSysBizCode}" '执行SQL
Dim dt As system.data.DataTable = db.ExecuteDataSet(Sq-l).Tables(0)
dt.TableName = "uSysBizCode"
_bizcode = Functions.Execute("Cmd_GetDataTable", sjy, sq-l, True)
End Sub
Public Function GetNextCode(s_name As String,Optional s_prefix As String = Nothing) As String
SyncLock _codelock '使用锁处理并发
Dim dr As DataRow = _bizcode.Find(CExp("BizName='{0}'", s_name))
If dr Is Nothing Then
'建议先在编号表中维护好需要产生编号的表,不用默认生成的编号规则'
dr = _bizcode.AddNew()
dr("BizName") = s_name
dr("MaxValue") = 1
If String.IsNullOrEmpty(s_prefix) Then s_prefix = Date.now.ToString("mmss") & "BH"
dr("Prefix") = s_prefix
dr("Mark") = "yyyyMMdd"
dr("MarkValue") = Date.Today.ToString("yyyyMMdd")
dr("Length") = 4
Else
'这里的处理规则是按时间进行重新编号,至于是按年,月还是日,在掩码中体现'
If dr("MarkValue") <> Date.Today.ToString(dr("Mark")) Then
dr("MaxValue") = 1
dr("MarkValue") = Date.Today.ToString(dr("Mark"))
Else
dr("MaxValue") = dr("MaxValue") + 1
End If
End If
dr.Save()
Return dr("Prefix") & dr("MarkValue") & Format(dr("MaxValue"),"0000") '顺序号只取4位'
End SyncLock
End Function
End Class
上面代码报错:
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:项目,AfterOpenProject
详细错误信息:
FROM 子句语法错误。
'AfterOpenProject里的代码
_BizCodeBuilder = New BizCodeBuilder("")
Forms("窗口1").open
如何解决?
'不重复编号上传用,这里的用法比较简单,没有做复杂的编号规则处理'
Public Class BizCodeBuilder
Private _codelock As New Object
Public Sub New()
End Sub
Public Function GetNextCode(s_name As String, Optional s_prefix As String = Nothing) As String
SyncLock _codelock '使用锁处理并发
Dim db = HySql.DataBaseFactory.CreateDatabase("编号用户测试库")
Dim Sql As String = CExp("select * from uSysBizCode where BizName='{0}'", s_name) '执行SQL
Dim dt As system.data.DataTable = db.ExecuteDataSet(Sql).Tables(0)
Dim dr As system.data.DataRow
If dt.Rows.count = 0 Then
dr = dt.NewRow()
dr("BizName") = s_name
dr("MaxValue") = 1
If String.IsNullOrEmpty(s_prefix) Then s_prefix = Date.now.ToString("mmss") & "BH"
dr("Prefix") = s_prefix
dr("Mark") = "yyyyMMdd"
dr("MarkValue") = Date.Today.ToString("yyyyMMdd")
dr("Length") = 4
dt.Rows.Add(dr)
Else
dr = dt.Rows(0)
'这里的处理规则是按时间进行重新编号,至于是按年,月还是日,在掩码中体现'
If dr("MarkValue") <> Date.Today.ToString(dr("Mark")) Then
dr("MaxValue") = 1
dr("MarkValue") = Date.Today.ToString(dr("Mark"))
Else
dr("MaxValue") = dr("MaxValue") + 1
End If
End If
db.UpdateDataTable(dt)
Return dr("Prefix") & dr("MarkValue") & Format(dr("MaxValue"), "0000") '顺序号只取4位'
End SyncLock
End Function
End Class
[此贴子已经被作者于2024/7/26 15:55:38编辑过]