-- 作者:cd_tdh
-- 发布时间:2022/9/19 9:35:00
-- 变量赋值问题
此主题相关图片如下:222.jpg
老师,请教一下:我有个窗口,如上图:
1、供货方名称控件:
Enter事件代码如下:
Dim r As Row = Tables("委托支付管理").Current If r IsNot Nothing Then \'如果找到的话 e.Sender.ComboList = DataTables("采购合同管理").SQLGetComboListString("供货方名称 + \',\' + 供货方账号 + \',\' + 供货方开户银行","[项目名称] = \'" & r("项目名称") & "\'") End If
ValueChanged事件代码如下:
Dim cmb As WinForm.ComboBox = e.Form.Controls("ComboBox6") Dim cmb1 As WinForm.TextBox = e.Form.Controls("TextBox6") Dim cmb2 As WinForm.TextBox = e.Form.Controls("TextBox10") Dim Multi As String = cmb.text Dim Values() As String Values = Multi.split(",") If Values.Length > 1 Tables("委托支付管理").Current("供货方名称")=Values(0) Tables("委托支付管理").Current("供货方账号")=Values(1) Tables("委托支付管理").Current("供货方开户银行")=Values(2) End If
2、付款方户名控件
Enter事件代码如下:
e.Sender.ComboList = DataTables("委托支付管理").sqlGetComboListString("付款方户名 + \',\' + 付款方账号 + \',\' + 付款方开户银行")
ValueChanged事件代码如下:
Dim cmb As WinForm.ComboBox = e.Form.Controls("ComboBox4") Dim cmb1 As WinForm.TextBox = e.Form.Controls("TextBox1") Dim cmb2 As WinForm.TextBox = e.Form.Controls("TextBox03") Dim Multi As String = cmb.text Dim Values() As String Values = Multi.split(",") If Values.Length > 1 Tables("委托支付管理").Current("付款方户名")=Values(0) Tables("委托支付管理").Current("付款方账号")=Values(1) Tables("委托支付管理").Current("付款方开户银行")=Values(2) End If
问题:我先选择供货方名称,然后在选择付款方户名时,付款方的账号和付款方开户银行会替换掉前面已经选择的:供货方账号、供货方开户银行,是哪儿问题呢?
|
-- 作者:cd_tdh
-- 发布时间:2022/9/19 10:18:00
--
控件事件没有其他代码了,控件绑定了表格,表事件DataColChanged代码只有这个:
If e.DataCol.Name = "项目名称" Then Dim nms()As String = {"合同编码","所属机构","合同金额"} If e.NewValue Is Nothing Then For Each nm As String In nms e.DataRow(nm)= Nothing Next Else Dim c md As New SQLCommand Dim dt As DataTable cmd.C cmd.C ommandText = "S ELECT DISTINCT 合同编码,所属机构,项目名称,合同金额 From {合同签订} where [项目名称]= \'" & e.NewValue & "\'" dt = cmd.ExecuteReader() If dt.datarows.count > 0 Dim dr As DataRow = dt.datarows(0) For Each nm As String In nms e.DataRow(nm)= dr(nm) Next End If End If End If
If e.DataRow("付款金额") >= "30000" Then If e.DataCol.Name = "供货方名称" OrElse e.DataCol.Name = "付款金额" Then Dim nms()As String = {"供货方账号","供货方开户银行"} If e.NewValue Is Nothing Then For Each nm As String In nms e.DataRow(nm)= Nothing Next Else If e.DataRow("供货方名称") <> Nothing Then Dim c md As New SQLCommand Dim dt As DataTable cmd.C \'cmd.C ommandText = "S ELECT DISTINCT 供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\'" cmd.C ommandText = "S ELECT DISTINCT 项目名称,供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\' and [项目名称] = \'" & e.DataRow("项目名称") & "\'" dt = cmd.ExecuteReader() If dt.datarows.count > 0 Then Dim dr As DataRow = dt.datarows(0) For Each nm As String In nms e.DataRow(nm)= dr(nm) Next e.DataRow("是否签订采购合同") = True Else e.DataRow("供货方名称") = Nothing e.DataRow("是否签订采购合同") = False MessageBox.Show("该供应商还未签订供应合同,不能办理委托支付事宜!","提示",MessageBoxButtons.OK,MessageBoxIcon.None) Return End If End If End If End If Else Dim nmw()As String = {"供货方账号","供货方开户银行"} Dim c md As New SQLCommand Dim dt As DataTable cmd.C \'cmd.C ommandText = "S ELECT DISTINCT 供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\'" cmd.C ommandText = "S ELECT DISTINCT 项目名称,供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\' and [项目名称] = \'" & e.DataRow("项目名称") & "\'" dt = cmd.ExecuteReader() If dt.datarows.count > 0 Then Dim dr As DataRow = dt.datarows(0) For Each nm As String In nmw e.DataRow(nm)= dr(nm) Next e.DataRow("是否签订采购合同") = True End If End If 而且只有一个项目会有这种情况,其他项目没这样的情况
[此贴子已经被作者于2022/9/19 10:19:11编辑过]
|
-- 作者:cd_tdh
-- 发布时间:2022/9/19 10:53:00
--
这一段代码注释掉就没问题,但是没想明白为什么只有这一个项目名称会出现这种情况
If e.DataRow("付款金额") >= "30000" Then If e.DataCol.Name = "供货方名称" OrElse e.DataCol.Name = "付款金额" Then Dim nms()As String = {"供货方账号","供货方开户银行"} If e.NewValue Is Nothing Then For Each nm As String In nms e.DataRow(nm)= Nothing Next Else If e.DataRow("供货方名称") <> Nothing Then Dim c md As New SQLCommand Dim dt As DataTable cmd.C \'cmd.C ommandText = "S ELECT DISTINCT 供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\'" cmd.C ommandText = "S ELECT DISTINCT 项目名称,供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\' and [项目名称] = \'" & e.DataRow("项目名称") & "\'" dt = cmd.ExecuteReader() If dt.datarows.count > 0 Then Dim dr As DataRow = dt.datarows(0) For Each nm As String In nms e.DataRow(nm)= dr(nm) Next e.DataRow("是否签订采购合同") = True Else e.DataRow("供货方名称") = Nothing e.DataRow("是否签订采购合同") = False MessageBox.Show("该供应商还未签订供应合同,不能办理委托支付事宜!","提示",MessageBoxButtons.OK,MessageBoxIcon.None) Return End If End If End If End If Else Dim nmw()As String = {"供货方账号","供货方开户银行"} Dim c md As New SQLCommand Dim dt As DataTable cmd.C \'cmd.C ommandText = "S ELECT DISTINCT 供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\'" cmd.C ommandText = "S ELECT DISTINCT 项目名称,供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\' and [项目名称] = \'" & e.DataRow("项目名称") & "\'" dt = cmd.ExecuteReader() If dt.datarows.count > 0 Then Dim dr As DataRow = dt.datarows(0) For Each nm As String In nmw e.DataRow(nm)= dr(nm) Next e.DataRow("是否签订采购合同") = True End If End If
|
-- 作者:有点蓝
-- 发布时间:2022/9/19 11:05:00
--
调试跟踪每一行代码执行的结果
msgbox("付款金额=" & e.DataRow("付款金额") ) If e.DataRow("付款金额") >= "30000" Then msgbox("触发的列名=" & e.DataCol.Name ) If e.DataCol.Name = "供货方名称" OrElse e.DataCol.Name = "付款金额" Then Dim nms()As String = {"供货方账号","供货方开户银行"} msgbox("触发的列数据=" & e.NewValue ) If e.NewValue Is Nothing Then For Each nm As String In nms e.DataRow(nm)= Nothing Next Else msgbox(其它调试自行写.....) If e.DataRow("供货方名称") <> Nothing Then Dim c md As New SQLCommand msgbox(其它调试自行写....) …… Else Dim nmw()As String = {"供货方账号","供货方开户银行"} Dim c md As New SQLCommand Dim dt As DataTable cmd.C \'cmd.C ommandText = "S ELECT DISTINCT 供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\'" cmd.C ommandText = "S ELECT DISTINCT 项目名称,供货方名称,供货方账号,供货方开户银行 From {采购合同管理} where [供货方名称]= \'" & e.NewValue & "\' and [项目名称] = \'" & e.DataRow("项目名称") & "\'" dt = cmd.ExecuteReader()
msgbox("dt.datarows.count=" & dt.datarows.count ) If dt.datarows.count > 0 Then Dim dr As DataRow = dt.datarows(0) For Each nm As String In nmw msgbox("nm=" & nm & “,赋值=” & dr(nm)) e.DataRow(nm)= dr(nm) Next e.DataRow("是否签订采购合同") = True End If End If
|