将客户添加到程序中 [英] Adding customer into program

查看:45
本文介绍了将客户添加到程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的程序知道已添加新客户,但我不知道如何在CustomerManager类和Form类之间建立链接,我已经完成了所需的代码,请看这里

表格1

I want my program to know that a new customer has been added i dont kow how to make the links between my CustomerManager class and my Form classes, I have already done the code which is needed, look here

Form 1

public MainForm()
      {
          InitializeComponent();


          lvwColumnSorter = new ListViewColumnSorter();
          this.listView1.ListViewItemSorter = lvwColumnSorter;

          manager = new CustomerManager();
          manager.CustomerAdded += onCustomerAdded;


      }


Form1


Form1

if (customerframe.ShowDialog() == DialogResult.OK)                 {
    CustomerFiles.Contact contact = customerframe.GetContact();
    CustomerFiles.Address address = customerframe.GetAddress();

    listviewitem = new ListViewItem(contact.FirstName);
    listviewitem.SubItems.Add(contact.LastName);
    listviewitem.SubItems.Add(address.ZipCode);

    this.listView1.Items.Add(listviewitem);
}



Form2




Form2


internal CustomerFiles.Contact GetContact()
      {
          CustomerFiles.Contact contact = new CustomerFiles.Contact();
          CustomerFiles.Address address = new CustomerFiles.Address();
          contact.FirstName = tbFirstName.Text;
          contact.LastName = tbLastName.Text;
          contact.PhoneData = new CustomerFiles.Phone(tbCellPhone.Text);
          contact.PhoneData = new CustomerFiles.Phone(tbHomePhone.Text);

          return contact;

      }
      internal CustomerFiles.Address GetAddress()
      {
          address.City = tbCity.Text;
          address.Street = tbStreet.Text;
          address.ZipCode = tbZipCode.Text;
          address.country = cbCountry.Text;

          return address;
      }


CustomerManager类


CustomerManager class

class CustomerManager 
    { 
        private Customer CustomerIN; 
        private List<Customer> customers = new List<Customer>(); 
        private int nrOfCustomers; 
        private int id = 100; 
 
        public CustomerManager() 
        { 
          throw new System.NotImplementedException(); 
        } 
 
        public int Count 
        { 
            get 
            { 
              return nrOfCustomers; 
            } 
            set 
            { 
                foreach (Customer customer in customers) 
                    nrOfCustomers++; 
            } 
        } 
 
        public int GetNewID 
        { 
            get 
            { 
                return id; 
            } 
            set 
            { 
            } 
        } 
 
        public bool AddCustomer() 
        { 
                if (customers != null) 
                { 
                     foreach (Customer customer in customers) 
                     { 
                    customers.Add(customer); 
                    CustomerIN.ID = id++; 
                     } 
                    return true; 
                } 
                else return false; 
            } 
 
        public bool ChangeCustomer() 
        { 
            throw new System.NotImplementedException(); 
        } 
 
        public bool DeleteCustomer() 
        { 
            if (customers != null) 
            { 
                foreach (Customer customer in customers) 
                { 
                    customers.Remove(customer); 
                } 
                return true; 
            } 
            else return false; 
        } 
 
        public Customer GetCustomer() 
        { 
            throw new System.NotImplementedException(); 
        } 
 
        public void TestValues() 
        { 
            throw new System.NotImplementedException(); 
        } 
    } 
} 





我希望上面的类与程序中的表单进行交互,因为我认为我的代码非常混乱.我应该怎么做





I want the class above to interact with my forms in my program, because i think i have done my code very messy. How should i do

推荐答案

您需要返回一到两个步骤,并尝试确定要执行的操作:目前,您有一个您无法实例化的CustomerManager(因为它将立即引发NotImplementedException),以及一堆无法调用的方法,因此尚未进行测试.
您正在为尚未创建的事件添加处理程序,并且不引发事件.
您引用的是CustomerIN,但从未给它赋值.

我怀疑您已从某处复制了此文件,并添加了其余内容,这是您的家庭作业,但您希望我们为您做.这不会发生.

首先,使代码达到无错误编译的地步,并且在尝试运行它时不会引发任何异常.
然后考虑一下您要实现的目标以及如何实现目标.

然后回来询问具体问题.
You need to go back a step or two, and try to work out what you are trying to do: At the moment, you have a CustomerManager that you can''t instantiate (because it will immediately throw a NotImplementedException), and a bunch of methods you can''t call and thus haven''t tested as a result.
You are adding a handler for an event you haven''t created, and don''t raise.
You are referencing CustomerIN, but you never give it a value.

I suspect that you have copied this from somewhere, and it your homework to add the rest, but you want us to do it for you. Which is not going to happen.

First, get your code to the point where it compiles without errors, and throws no exceptions when you try to run it.
Then think about what you are trying to achieve, and how you want to achieve it.

Then come back and ask about specific problems.


这篇关于将客户添加到程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆