以文本方式查看主题

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

--  作者:红颜
--  发布时间:2013/3/10 21:29:00
--  [求助]内部表后台自动编号代码不执行?

If e.DataCol.Name = "RQ" Then
    If e.DataRow.IsNull("RQ") Then
        e.DataRow("BH") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd") 

        If e.DataRow("BH").StartsWith(bh) = False \'如果编号的前8位不符           
            Dim idx As Integer
            Dim max As String
            max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") \'取得该天的最大编号
            If max > "" And e.DataRow("RQ") = Vars("ksrq") Then \'如果存在最大编号并且日期等于变量的日期
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                If max = "" And e.DataRow("RQ") = Vars("ksrq") Then\'如果不存在最大编号而日期等于变量的日期

                    idx = CInt(Vars("ksrq").Substring(9,3)) + 1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("BH") = bh & "-" & Format(idx,"000")
            End If
        End If
    End If
End If

 

红色部分为修改的地方

[此贴子已经被作者于2013-3-10 21:30:07编辑过]

--  作者:双轨制
--  发布时间:2013/3/10 21:33:00
--  

用messagebox显示一下某些变量的值或条件表达式,这样就可以知道代码是否执行,没有执行,是不是条件不符,条件不符,是不是变量的值不对。

http://www.foxtable.com/help/topics/1485.htm

 


--  作者:红颜
--  发布时间:2013/3/10 21:39:00
--  
以下是引用双轨制在2013-3-10 21:33:00的发言:

用messagebox显示一下某些变量的值或条件表达式,这样就可以知道代码是否执行,没有执行,是不是条件不符,条件不符,是不是变量的值不对。

http://www.foxtable.com/help/topics/1485.htm

 

测试过了,变量的值正确,可能是代码有问题,但没有任何提示。


--  作者:红颜
--  发布时间:2013/3/10 22:49:00
--  

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bm As String = Format(e.DataRow("RQ"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("编号").StartsWith(bm) = False \'如果编号的前8位不符
            Dim idx As Integer
            Dim max As String
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "#") \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1
            End If                           \'获得最大编号的后三位顺序号,并加1
            If max = "" And vars("zdbh") > "" Then 如果最大编号不存在,而变量的值存在,引用变量
                idx = CInt(Vars("zdbh").Substring(9,3)) + 1在变量的基础上加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bm & "-" & Format(idx,"000")
        End If
    End If
End If

 

 

测试的结果是后三位总是:001

重新修改了代码,还是有问题,但看不出问题在哪?


--  作者:红颜
--  发布时间:2013/3/11 14:50:00
--  
以下是引用muhua在2013-3-11 8:21:00的发言:

If max > "" Then \'如果存在最大编号
    idx = CInt(max.Substring(9,3)) + 1

else

If max = "" And vars("zdbh") > "" Then 如果最大编号不存在,而变量的值存在,引用变量
    idx = CInt(Vars("zdbh").Substring(9,3)) + 1在变量的基础上加1
Else
    idx = 1 \'否则顺序号等于1
End If

 

End If \'获得最大编号的后三位顺序号,并加1

 

If e.DataCol.Name = "RQ" Then
    If e.DataRow.IsNull("RQ") Then
        e.DataRow("BH") = Nothing
    Else
        Dim bm As String = Format(e.DataRow("RQ"),"yyyymmdd") \'取得编号的8位前缀
        If e.DataRow("BH").StartsWith(bm) = False
            Dim idx As Integer
            Dim max As String
            max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") \'取得该天的最大编号
            If max > "" Then
                idx = CInt(max.Substring(9,3)) + 1
            Else
                If max = "" And vars("zdbh") > "" Then
                    idx = CInt(Vars("zdbh").Substring(9,3)) + 1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("BH") = bm & "-" & Format(idx,"000")
            End If
        End If
    End If
End If

 

上面是完整代码。

空表新增行时,第一行编号正确,可以取得变量的值。

第二行不能自动计算总是:001,下面代码好像不参与计算

max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") \'取得该天的最大编号
            If max > "" Then
                idx = CInt(max.Substring(9,3)) + 1
            Else


--  作者:狐狸爸爸
--  发布时间:2013/3/11 15:33:00
--  

代码逻辑有问题,应该这样:

 

If e.DataCol.Name = "RQ" Then
    If e.DataRow.IsNull("RQ") Then
        e.DataRow("BH") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd")
        If e.DataRow("BH").StartsWith(bh) = False \'如果编号的前8位不符
            Dim idx As Integer
            Dim max As String
            If  e.DataRow("RQ") = Vars("ksrq") Then \'如果存在最大编号并且日期等于变量的日期
                max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") \'取得该天的最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                If max > ""  Then \'如果不存在最大编号而日期等于变量的日期
                    idx = CInt(Vars("ksrq").Substring(9,3)) + 1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("BH") = bh & "-" & Format(idx,"000")
            End If
        End If
    End If
End If

 


--  作者:红颜
--  发布时间:2013/3/11 20:07:00
--  
以下是引用狐狸爸爸在2013-3-11 15:33:00的发言:

代码逻辑有问题,应该这样:

 

If e.DataCol.Name = "RQ" Then
    If e.DataRow.IsNull("RQ") Then
        e.DataRow("BH") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd")
        If e.DataRow("BH").StartsWith(bh) = False \'如果编号的前8位不符
            Dim idx As Integer
            Dim max As String
            If  e.DataRow("RQ") = Vars("ksrq") Then \'如果存在最大编号并且日期等于变量的日期
                max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") \'取得该天的最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                If max > ""  Then \'如果不存在最大编号而日期等于变量的日期
                    idx = CInt(Vars("ksrq").Substring(9,3)) + 1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("BH") = bh & "-" & Format(idx,"000")
            End If
        End If
    End If
End If

 

老总,代码不成功。开始我用“最大日期变量”来判断编号,现在直接用“最大编号变量”来判断取值。

代码如下:

If e.DataCol.Name = "RQ" Then
    If e.DataRow.IsNull("RQ") Then
        e.DataRow("BH") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd")
        If e.DataRow("BH").StartsWith(bh) = False
            Dim idx As Integer
            Dim max As String
            max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#")
            If max > "" Then如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1
                If max = "" And Vars("zdbh")>"" Then 如果不存在最大编号,但Vars("zdbh") 变量存在
                    idx = CInt(Vars("zdbh").Substring(9,3)) + 1
                Else  如果两者都不存在
                    idx = 1
                End If
                e.DataRow("BH") = bh & "-" & Format(idx,"000")
            End If
        End If
    End If
End If

 

问题是根本不生成编号。

[此贴子已经被作者于2013-3-11 20:37:05编辑过]

--  作者:双轨制
--  发布时间:2013/3/11 22:52:00
--  

自己用MessageBox逐行分析就行。

没有例子,谁也没办法帮你分析,只能说个大概。

最好是做个简单的例子,更好是自己分析,逻辑在这里,看看到执行到了哪一步,没有往下执行的原因是什么。


--  作者:红颜
--  发布时间:2013/3/14 16:23:00
--  

项目已上传

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:收费2013.3.12.zip

 

门诊收费窗口添加按钮,编号不能正确生成,最大编号已经显示
表中编号不能自动生成

[此贴子已经被作者于2013-3-14 17:24:55编辑过]

--  作者:红颜
--  发布时间:2013/3/15 14:13:00
--  
谢谢!谢谢!