以文本方式查看主题

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

--  作者:ruan
--  发布时间:2011/8/29 12:44:00
--  增加行 提示错误怎么回事
 

BeforeConnectOuterDataSource

 

If e.name = "编号" Then

    e.C & e.ProjectPath & "编号.mdb;Persist Security Info=False"

End if

 

AfterOpenProject

 

Tables("订单").Sort = "编号"

 

计划管理

 

表事件

 

订单_DataColChanged

 

If e.DataCol.Name = "编号" Then

    If e.DataRow.GetChildRows("关联").Count = 0 Then

        Dim dr As DataRow = DataTables("关联").DataRows.AddNew()

        dr("编号") = e.newvalue

    End If

End If

 

订单_BeforeSaveDataRow

 

Dim dr As DataRow = e.DataRow

Dim pf As String

If dr.RowState <> DataRowState.Added Then \'如果不是新增行

    Return \'那么返回

ElseIf dr.IsNull("日期") Then \'如果没有输入日期

    e.Cancel = True \'取消保存此行

    MessageBox.Show("必须输入日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

    Return

Else

    pf = Format(dr("日期"),"yyMM") \'否则获得编号的前缀,两位年,两位月

End If

Dim cmd1 As New SQLCommand

Dim cmd2 As New SQLCommand

Dim Key As Integer

cmd1.C \'设置数据源名称

cmd2.C

cmd1.commandText = "Select Count(*) From [编号] Where [前缀] = \'" & pf & "\'"

If cmd1.ExecuteScalar = 0 Then \'如果编号表不存在前缀的行,那么增加一行

    cmd1.commandtext = "Insert Into 编号 (前缀, 顺序号) Values(\'" & pf & "\',1)"

    cmd1.ExecuteNonQuery

End If

cmd1.commandText = "Select [顺序号] From [编号] Where [前缀] = \'" & pf & "\'"

Do

    Key = cmd1.ExecuteScalar() \'从后台获得顺序号

    cmd2.commandText = "Update [编号] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [前缀] = \'" & pf & "\'"

    If cmd2.ExecuteNonQuery() > 0 Then \'更新顺序号

        Exit Do \'更新成功则退出循环

    End If

Loop

e.DataRow("编号") = pf & "-" & Format(Key,"0000")

 

订单_DataRowAdding

 

\'生成临时编号

Static Index As Integer = 99999

e.DataRow("编号") = Format(Date.Today(),"yyMM") & "-" & Index

Index = Index - 1

 

 

 

 

 

 


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

--  作者:lihe60
--  发布时间:2011/8/29 13:18:00
--  

纸上不谈兵。


--  作者:狐狸爸爸
--  发布时间:2011/8/29 13:59:00
--  
传文件上上来测试看看。
--  作者:mr725
--  发布时间:2011/8/29 16:40:00
--  

订单_DataColChanged

 

If e.DataCol.Name = "编号" Then

    If e.DataRow.GetChildRows("关联").Count = 0 Then

        Dim dr As DataRow = DataTables("关联").DataRows.AddNew()

        dr("编号") = e.newvalue           \' 也许是这里的问题···

    End If

End If