以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  【紧急求助】为什么用“_indentify”做编号为什么还会出现重复?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=48246)

--  作者:xvkewen
--  发布时间:2014/3/25 22:08:00
--  【紧急求助】为什么用“_indentify”做编号为什么还会出现重复?
以下代码是在BeforeSavedatarow事件中,用于自动编号,可为什么还会出现重复现象呢?“_idnetify”不是从不会重复的吗?怎么才能解决?因为系统在公司里运行,实例拿不出来;

对了,补充一下,在单机上操作没有问题,但在网络操作才会出现重复现象,同时使用用户数约150个;一般只会重复两个,偶尔会出现3个;如下图;

图片点击可在新窗口打开查看此主题相关图片如下:123.jpg
图片点击可在新窗口打开查看


此外,我用input.show(currenttable.current("_identify")来验证当前行的编号时发现很多的编号居然与show出来的结果不同;太意外了;

BeforeSavedatarow事件全部代码:

Dim yh As DataRow = DataTables("User_info").Find("User_Name = \'" & _username & "\'" ) \'获取当前用户信息
e.DataTable.DeleteFor("[Customer] Is Null and [Style_No] is null and [size] is null and [color] is null and [Follow_QA] = \'" & yh("FullName") & "\'") \'删除无效行
Dim dr1 As DataRow = DataTables("scheduling").Find("([排单顺序] Is Null or [Sewing_Team] Is Null or [sample_state] Is Null ) And [Follow_QA] = \'" & yh("FullName") & "\'") \' 找出当前用户出办日期为空,车缝组别,样办状态的办单;
Dim i As Integer = Tables("scheduling").Findrow("([排单顺序] Is Null or [Sewing_Team] Is Null or [sample_state] Is Null ) and [Follow_QA] = \'" & yh("FullName") & "\'")  \'找出当前用户出办日期为空的办单行的位置;
If e.DataRow.RowState <> DataRowState.Added And e.DataRow.RowState <> DataRowState.Modified  Then
    Return
End If
If dr1 Is Nothing Then    \'如果没有找到当前用户出办日期为空的办单,则保存当前排期,并给出新的内部办单号
    \'**************************设定办单号为自动编号*******************************
    If e.DataRow.IsNull("Inside_SRS") Then
        Dim d As Date = e.DataRow("input_date")
        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,"yyMM") \'生成编号的前6位,4位年,2位月.
        Dim bh1 As String ="BR" & bh
        If e.DataRow("Inside_SRS").StartsWith(bh) = False \'如果编号的前6位不符
            Dim idx As Integer = e.DataRow("_Identify")
            
            e.DataRow("Inside_SRS") = bh1 & "-" & Format(idx,"000000")
        End If
    End If
Else  \'否则需要补充【出办日期】与【车缝组别】才能保存,如果【样办状态】为空将会出现无法加载的情况
    msgbox("办单号:" & dr1("SRS_No") & ",款号: " & dr1("Style_No") & "的【出办日期】,【样办状态】及【车缝组别】不能为空,请补充完毕后重新保存;")
    e.Cancel = True
    Tables("scheduling").Position = i
End If

--  作者:有点甜
--  发布时间:2014/3/25 22:16:00
--  

你这样不重复才奇怪,BeforeSavedatarow执行的时候, _Identify还是临时值,保存之后才会生成真正的值。

例如原来99行,两个用户分别增加1行,_Identify都是99(包括BeforeSavedatarow执行时),只有保存之后,一个是99,一个是100。


--  作者:xvkewen
--  发布时间:2014/3/25 22:25:00
--  
那应该怎么办呢?又没有aftersavedatarow事件,难道要放到Aftersaveproject事件中?
--  作者:jspta
--  发布时间:2014/3/25 22:46:00
--  
学习网络编号这一章节即可解决。你这种方法只能是单机
--  作者:有点甜
--  发布时间:2014/3/25 22:51:00
--  
可以自己做个保存按钮,保存前用一个集合收集所有新增行,保存行遍历此集合,逐行生成编码,然后再保存一下。
--  作者:xvkewen
--  发布时间:2014/3/25 22:56:00
--  
用"_identify"列做编号也要这么麻烦吗?
--  作者:有点甜
--  发布时间:2014/3/25 23:06:00
--  

你是在编程哦,这算什么麻烦的:

 

Dim drs As new List(of DataRow)
For Each dr As DataRow In DataTables("xxx").DataRows
   If dr.RowState = DataRowState.Added Then
        drs.Add(dr)
    End If
Next
DataTables.Save()
For Each dr As DataRow In drs
   dr("编号") = .......
Next

 DataTables.Save()


--  作者:xvkewen
--  发布时间:2014/3/25 23:50:00
--  
好吧,就先这样改了。 但有没有更好点办法呢?
--  作者:Bin
--  发布时间:2014/3/26 8:28:00
--  
采用帮助的网络编号方式


--  作者:xvkewen
--  发布时间:2014/3/26 11:37:00
--  
我楼上的案例也是用的网络编号中的一种较为简单的做法,只是帮助中没有具体说明怎么使用identity做网络编号?需要注意些什么?