簡體   English   中英

不包含發票定義?

[英]does not contain definition for invoice?

我正在嘗試將數據從表單1傳輸到表單2,但是即使我在項目中添加了Invoice.cs類,它也會引發錯誤。

拋出錯誤:

'System.Windows.Forms.Form'不包含'Invoice'的定義,找不到擴展方法'Invoice'接受類型為'System.Windows.Forms.Form'的第一個參數(您是否缺少using指令或裝配參考?)

表格1

private void button5_Click(object sender, EventArgs e)
    {
        Form InvoiceSystem = new Form();
        if (InvoiceSystem == null)
        {
            Invoice invoice = new Invoice();
            invoice.id = Convert.ToInt16(textId.Text);
            invoice.nameItem = textNameiTem.Text;
            invoice.priceItem = Convert.ToDouble(textPrice.Text);
            invoice.qty = Convert.ToInt16(textQty.Text);
            invoice.amount = Convert.ToDouble(textAmount.Text);
            invoice.date = Convert.ToInt16(textDate.Text);
            invoice.invoiceNo = Convert.ToInt16(textInvoice.Text);
            InvoiceSystem.Invoice = invoice;
            InvoiceSystem.Show();
        }
    }

表格2

  public partial class InvoiceSystem : Form
        {
            public Invoice Invoice
            {
              set
        {
            textId.Text = value.id.ToString();
            textitem.Text = value.nameItem;
            textPrice.Text = value.priceItem.ToString();
            textQty.Text = value.qty.ToString();
            textAmt.Text = value.amount.ToString();
            textdate.Text = value.date.ToString();
            textInvoiceNo.Text = value.invoiceNo.ToString();
        }
    }

在Invoice.cs類中

public class Invoice
{
    public int id {get;set;}
    public string nameItem { get; set; }
    public double priceItem{get;set;}
    public int qty { get; set; }
    public double amount { get; set; }
    public int date { get; set; }
    public int invoiceNo { get; set; }
}

您已將變量聲明為Form

Form InvoiceSystem = new Form();

Form本身沒有任何自定義項。 它是框架中所有形式的基類。 您的自定義類是InvoiceSystem ,您已將其作為一種特定的形式進行制作。 使用:

InvoiceSystem invoiceSystem = new InvoiceSystem();

(還要注意,我將變量名設置為小寫。因此,您還需要更新引用該變量的其他代碼行。不要使用與您的類相同的名稱來命名變量。這引起混淆。)


還要注意,您的if語句是多余的:

Form InvoiceSystem = new Form();
if (InvoiceSystem == null)
//...

前一行直接實例化了變量。 因此該變量在下一行永遠不會null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM