简体   繁体   English

不包含发票定义?

[英]does not contain definition for invoice?

I'm trying to data transfer from form 1 to form 2 But it throw error even i have add the Invoice.cs class in my project. 我正在尝试将数据从表单1传输到表单2,但是即使我在项目中添加了Invoice.cs类,它也会引发错误。

Throw error: 抛出错误:

'System.Windows.Forms.Form' does not contain a definition for 'Invoice' and no extension method 'Invoice' accepting a first argument of type 'System.Windows.Forms.Form' could be found (are you missing a using directive or an assembly reference?) 'System.Windows.Forms.Form'不包含'Invoice'的定义,找不到扩展方法'Invoice'接受类型为'System.Windows.Forms.Form'的第一个参数(您是否缺少using指令或装配参考?)

Form 1 表格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();
        }
    }

Form 2 表格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();
        }
    }

In Invoice.cs class 在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; }
}

You've declared your variable as a Form : 您已将变量声明为Form

Form InvoiceSystem = new Form();

Form itself doesn't have any of your customizations. Form本身没有任何自定义项。 It's the base class for all forms, built into the framework. 它是框架中所有形式的基类。 Your custom class is InvoiceSystem , which you've made as a specific kind of form. 您的自定义类是InvoiceSystem ,您已将其作为一种特定的形式进行制作。 Use that: 使用:

InvoiceSystem invoiceSystem = new InvoiceSystem();

(Note also that I made the variable name lowercase. So you'll need to update the other lines of code which reference that variable as well. Don't name variables with the same names as your classes. It will lead to confusion.) (还要注意,我将变量名设置为小写。因此,您还需要更新引用该变量的其他代码行。不要使用与您的类相同的名称来命名变量。这引起混淆。)


Also note that your if statement is superfluous: 还要注意,您的if语句是多余的:

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

The immediate preceding line instantiated the variable. 前一行直接实例化了变量。 So that variable will never be null on that next line. 因此该变量在下一行永远不会null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM