以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]通过代码增加Var变量(在5楼)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=12927)

--  作者:yyzlxc
--  发布时间:2011/9/20 21:39:00
--  [求助]通过代码增加Var变量(在5楼)

原代码是当去向为空时,归还日期为系统日期,现在想改成取自设备目录表、设备管理窗口、DateTimePicker1控件的值,代码应该如何修改,请各位老师指教,谢谢!!(附原代码)

 

Select Case  e.DataCol.Name
    Case "去向"
        If e.DataRow.IsNull("去向") And  e.DataRow.IsNull("使用单位") Then
            e.DataRow("归还日期")=Nothing
        Else
            Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = \'" & e.DataRow("设备编号") & "\'")
            If e.DataRow.IsNull("去向") Then
                e.DataRow("归还日期") = Date.Today
                If dr IsNot Nothing Then
                    dr("使用单位") = e.DataRow("使用单位")
                End If
            Else
                dr("使用单位") = e.DataRow("产权单位")
            End If
        End If
End Select

[此贴子已经被作者于2011-9-21 9:15:19编辑过]

--  作者:程兴刚
--  发布时间:2011/9/20 21:43:00
--  

您需要通过全局变量来实现,因为别的表的那个窗口在本代码执行时没有打开吧?

 

先用全局变量保存DateTimePicker1的值再引用就ok了!

[此贴子已经被作者于2011-9-20 21:44:54编辑过]

--  作者:yyzlxc
--  发布时间:2011/9/20 21:50:00
--  

谢谢程老师的回复,全局变量我没有做过,请程老师帮助指教一下,谢谢了。

 

 


[此贴子已经被作者于2011-9-20 23:23:51编辑过]

--  作者:yyzlxc
--  发布时间:2011/9/20 23:23:00
--  

在原代码中加了一条,达到所需效果,在这里再次谢谢程老师!!

 

If e.DataRow.IsNull("去向") And  e.DataRow.IsNull("使用单位") Then
    e.DataRow("归还日期")=Nothing
Else
    Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = \'" & e.DataRow("设备编号") & "\'")
    Dim mydate As Date = Forms("设备管理").Controls("DateTimePicker1").Text
    If e.DataRow.IsNull("去向") Then
        e.DataRow("归还日期") = mydate
        If dr IsNot Nothing Then
            dr("使用单位") = e.DataRow("使用单位")
        End If
    Else
        dr("使用单位") = e.DataRow("产权单位")
    End If
End If
End Select


--  作者:yyzlxc
--  发布时间:2011/9/21 9:14:00
--  

通过代码增加Var变量

将设备目录表、设备管理窗口、DateTimePicker1控件的值与全局变量mydate关联,代码应该如何写?放在哪个事件里?请各位老师指教。谢谢!!


--  作者:狐狸爸爸
--  发布时间:2011/9/21 11:12:00
--  

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