0

我对我一直试图弄清楚的一个问题感到困惑。这是我面临的问题。我有两个类: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

问题在于这里。所有的文本字段都不能从共享方法中引用一个类的实例成员......我需要从返回的表中填写这些字段。

我不确定我在这里错过了什么,也许我只是累了......

谢谢!

4

2 回答 2

1

我不明白您的期望,但我认为您可能需要这个(将 CustomerId 从 CustomerFind.vb 传递到 CreateInvoice.vb)。为此,您可以使用以下内容:

创建一个不可见的标签并将 CustomerId 分配给 CustomerFind.vb 中的标签,例如

  inlabel.Text=""+CustomerId 

在 CreateInvoice.vb

   Dim id as Integer
   id=CustomerFind.inlabel.text

现在您可以使用 CustomerId

于 2013-01-24T06:06:29.670 回答
0

自从我进行任何表单开发以来已经有一段时间了,但是您不想做类似的事情:

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
    Dim invoiceDlg as New CreateInvoice

    ' new field in you invoice class
    invoiceDlg.CustomerID = intCustomerID
    ' set up text fields in your dialog init function instead of CreateNewInvoice()
    invoiceDlg.ShowDialog();
End Sub
于 2013-01-24T06:11:50.790 回答