我对我一直试图弄清楚的一个问题感到困惑。这是我面临的问题。我有两个类:CustomerFind.vb 和 CreateInvoice.vb。用户单击搜索按钮以打开另一个最顶部的表单,当用户搜索该客户时,结果将显示在 DataGridView 中。用户然后为客户选择该行,然后单击“确定”。我需要将该CustomersID 从(CustomerFind.vb) 发送到--> (CreateInvoice.vb)。一旦我在 CreateInvoice 中拥有该变量,我需要使用该变量传递给一个函数以获取该客户详细信息的表格...请参阅下面的内容...
这将打开 CustomerFind.vb 表单...
Private Sub btnFindCustomer_Click(sender As System.Object, e As System.EventArgs) Handles btnFindCustomer.Click
Dim findCustomer As New CustomerFind
findCustomer.ShowDialog()
End Sub
一旦用户选择了他们的客户,变量就会传递给另一个类......
Public Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
Dim intCustomerID As Integer = dgvSearchResults.SelectedRows(0).Cells(0).Value
CreateInvoice.CreateNewInvoice(intCustomerID)
End Sub
这是来自 CreateInvoice.vb 的子,我也正在传递变量...
Public Shared Sub CreateNewInvoice(ByVal intCustomerID As Integer)
'Datatable to hold returned results'
Dim oTable As DataTable
'Get the data that we need for the customer'
oTable = CustomerHelper.GetCustomer(intCustomerID)
txtFirstName.Text = IIf(oTable.Rows(0).Item("First_Name") Is DBNull.Value, "NA", oTable.Rows(0).Item("First_Name")))
txtLastName.Text = IIf(oTable.Rows(0).Item("Last_Name") Is DBNull.Value, "NA", oTable.Rows(0).Item("Last_Name"))
txtCity.Text = IIf(oTable.Rows(0).Item("City") Is DBNull.Value, "NA", oTable.Rows(0).Item("City"))
cboState.SelectedValue = IIf(oTable.Rows(0).Item("State") Is DBNull.Value, "NA", oTable.Rows(0).Item("State"))
txtAddress.Text = IIf(oTable.Rows(0).Item("Address") Is DBNull.Value, "NA", oTable.Rows(0).Item("Address"))
txtZipCode.Text = IIf(oTable.Rows(0).Item("Zip_Code") Is DBNull.Value, "NA", oTable.Rows(0).Item("Zip_Code"))
txtEmail.Text = IIf(oTable.Rows(0).Item("Email") Is DBNull.Value, "NA", oTable.Rows(0).Item("email"))
txtHomePhone.Text = IIf(oTable.Rows(0).Item("Home_Phone") Is DBNull.Value, "NA", oTable.Rows(0).Item("Home_Phone"))
txtCellPhone.Text = IIf(oTable.Rows(0).Item("Cell_Phone") Is DBNull.Value, "NA", oTable.Rows(0).Item("Cell_Phone"))
txtMiddleInitial.Text = IIf(oTable.Rows(0).Item("Middle_Initial") Is DBNull.Value, "NA", oTable.Rows(0).Item("Middle_Initial"))
End Sub
问题在于这里。所有的文本字段都不能从共享方法中引用一个类的实例成员......我需要从返回的表中填写这些字段。
我不确定我在这里错过了什么,也许我只是累了......
谢谢!