Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:26:13+00:00 2026-05-28T14:26:13+00:00

I want my program to know that a new customer has been added i

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:26:14+00:00Added an answer on May 28, 2026 at 2:26 pm

    You should use events to inform smth about change of object’s state

    class Form1
      : Form
    {
      private CustomerManager manager;
    
      public Form1()
      {
        ...
    
        manager = new CustomerManager();
        manager.CustomerAdded += OnCustomerAdded;
    
        ...
      }
    
      private void OnCustomerAdded(object source, CustomerEventArgs eventArgs)
      {
        var listviewitem = new ListViewItem(eventArgs.Customer.FirstName);
        listviewitem.SubItems.Add(eventArgs.Customer.LastName);
    
        this.listView1.Items.Add(listviewitem);
      }
    }
    
    class CustomerEventArgs
      : EventArgs
    {
      public readonly Customer Customer;
    
      public CustomerEventArgs(Customer customer)
      {
        Customer = customer;
      }
    }
    
    class Customer
    {
      public string FirstName{get;set;}
      public string LastName{get;set;}
    }
    
    class CustomerManager
    {
      private List<Customer> list = new List<Customer>();
    
      public event EventHandler<CustomerEventArgs> CustomerAdded;
      private void OnCustomerAdded(Customer customer)
      {
         var handler = CustomerAdded;
         if(handler != null)
         {
           handler(this, new CustomerEvenetArgs(customer));
         }
      }
    
      public event EventHandler<CustomerEventArgs> CustomerDeleted;
      private void OnCustomerDeleted(Customer customer)
      {
         var handler = CustomerDeleted;
         if(handler != null)
         {
           handler(this, new CustomerEvenetArgs(customer));
         }
      }
    
      public int Count
      {
         get
         {
           return list.Count;
         }
      }
    
      public bool AddCustomer(Customer customer)
      {
        if(list.Any(c => c.FirstName == customer.FirstName && c.LastName == customer.LastName))
        {
          return false;
        }
    
        list.Add(customer);
        OnCustomerAdded(customer);
        return true;
      }
    
      public bool DeleteCustomer(Customer customer)
      {
        var currentCustomer = list.FirstOrDefault(c => c.FirstName == customer.FirstName && c.LastName == customer.LastName);
        if(currentCustomer != null)
        {
           list.Remove(currentCustomer);
           OnCustomerDeleted(currentCustomer);
           return true;
        }
    
        return false;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there're stdout/in/err for a program and I want to redirect a
I just want to know if there is a program that can convert an
I want to know how I can make a Java program where an unknown
I want my program always know all of the mountpoints. After a quick google
In my C program I want to know if my executable is run in
For about a year I have been thinking about writing a program that writes
Got a task to make a program that registers animals and the object is
I have a program that I want to use google maps for. The problem
I want to make a simple program. Don't really care what it does, actually.
i know that node.js is relativity new.. so i hope that someone here can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.