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
if (customerframe.ShowDialog() == DialogResult.OK) //if button OK is clicked then value will be inserted
{
listviewitem = new ListViewItem("1");
listviewitem.SubItems.Add(customerframe.firstName);
listviewitem.SubItems.Add(customerframe.lastName);
listviewitem.SubItems.Add(customerframe.zipcode);
//there will be more here later
this.listView1.Items.Add();
Form2
private void btnOk_Click(object sender, EventArgs e)
{
MainForm main = new MainForm();
contact.FirstName = tbFirstName.Text;
firstName = contact.FirstName;
contact.LastName = tbLastName.Text;
lastName = contact.LastName;
//there will be more code here later as well
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
You should use events to inform smth about change of object’s state