以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  修改数据的代码,这样用会不会出问题?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=88740)

--  作者:yancheng
--  发布时间:2016/8/8 19:02:00
--  修改数据的代码,这样用会不会出问题?

入库明细表中,DataColChanged 中写入


If e.DataCol.Name = "定额编码" Then
    Dim cmd As New SQLCommand
    Dim dt As DataTable
    cmd.C
    Dim dr As DataRow = e.DataRow
    cmd.CommandText = "SELE CT * Fro m {材料} Where [定额编码] = \'" & dr("定额编码") & "\'"
    dt = cmd.ExecuteReader()
    If dt.DataRows.Count > 0 Then
        dr("入库单价") = dt.DataRows(0)("成本价")
    Else
        dr("入库单价") = Nothing
    End If

这个代码,这样写是为了输入时,自动从:材料表,提取原料已经输入了的:成本价,避免重复录入同样的价格。
但是,如果我为了测试,或为了批量修改一些数据,我执行了:入库明细表,定额编码,列的,重置。这样是不是这个代码还是要执行,把我已经录入的:入库单价,改成:材料表中的成本价。这样就错了。
有没有什么办法调整一下这个代码。让我既能输入时,利用材料表的已录入价格,又避免我重置 :入库明细-定额编码列时,不改数据 ?

--  作者:yancheng
--  发布时间:2016/8/8 19:08:00
--  
如果 加一个,审核,的判断是不是就行了?如下:
If e.DataCol.Name = "定额编码" Then
    Dim cmd As New SQLCommand
    Dim dt As DataTable
    cmd.C
    Dim dr As DataRow = e.DataRow
    If dr.IsNull("审核")=True Then
        cmd.CommandText = "SELE CT * Fro m {材料} Where [定额编码] = \'" & dr("定额编码") & "\'"
        dt = cmd.ExecuteReader()
        If dt.DataRows.Count > 0 Then
            dr("入库单价") = dt.DataRows(0)("成本价")
        Else
            dr("入库单价") = Nothing
        End If
    End If
End If

我现在好怕重置列,我感觉好像之前重置了,它就是自动改我的数据了。请问老师,修改数据 的代码,应该注意哪些方面?
[此贴子已经被作者于2016/8/8 19:08:19编辑过]

--  作者:大红袍
--  发布时间:2016/8/8 20:15:00
--  

 如果单价为空值,就取,否则,就不修改。

 

 你要理清逻辑才行啊

 

If e.DataCol.Name = "定额编码" Then

    If e.DataRow.IsNull("入库单价") Then

 

    End If

End If


--  作者:yancheng
--  发布时间:2016/8/8 21:21:00
--  
嗯。懂了。谢谢老师