Esempio n. 1
0
        /// <summary>
        /// When a row is activated, the Change button is activated.
        /// When it is clicked, the customer manager is called to replace the customer.
        /// with another one.
        /// </summary>
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count == 1)
            {
                int index = listView1.SelectedIndices[0];
                if (index < _customerManager.Count)
                {
                    var aCustomer = _customerManager.GetCustomer(index);
                    var aContact  = aCustomer.Contact;
                    var itsID     = aCustomer.Id;


                    ContactForm  dlg          = new ContactForm(aCustomer.Contact);
                    Contact      b            = dlg.WorkContact;
                    DialogResult dialogResult = dlg.ShowDialog();

                    if (dialogResult == DialogResult.OK)
                    {
                        var changedCustomer = new Customer(b, aCustomer.Id);
                        //showTheContact(dlg);  // Activate to show a dialog box
                        _customerManager.ChangeCustomer(changedCustomer, index);
                        UpdateTable();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// edit customer if selected in list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEditCustomer_Click(object sender, EventArgs e)
        {
            int index = lstCustomers.SelectedIndex; //index of selected customer in listbox

            //check if index is out of range, ie if no customer is selected
            if (!customerManagerObj.CheckIndex(index))
            {
                MessageBox.Show("Please select a customer in the customer list.");
            }
            else
            {
                //get customer from customer manager
                Contact c = customerManagerObj.GetCustomer(index).ContactData;
                //create an instance of Contactform with title as parameter
                ContactForm contactFormObj = new ContactForm("Edit a customer");

                contactFormObj.ContactData = new Contact(c);

                if (contactFormObj.ShowDialog() == DialogResult.OK)
                {
                    customerManagerObj.EditCustomer(contactFormObj.ContactData, index); //add the edited customer object

                    UpdateGui();                                                        //update customer list
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// add customer to customer list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            //create an instance of Contactform with title as parameter
            ContactForm contactFormObj = new ContactForm("Add a new customer");

            if (contactFormObj.ShowDialog() == DialogResult.OK)
            {
                customerManagerObj.AddCustomer(contactFormObj.ContactData); //add the new customer object

                UpdateGui();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// When Add is clicked, a ContactForm is created and called.
        ///
        /// </summary>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Contact      aContact     = new Contact();
            ContactForm  dlg          = new ContactForm(aContact);
            DialogResult dialogResult = dlg.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                //showTheContact(dlg);  // Activate to show a dialog box
                _customerManager.AddCustomer(dlg.WorkContact);
                UpdateTable();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Add new customer
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var contactForm = new ContactForm();

            var answer = contactForm.ShowDialog();

            if (answer == DialogResult.OK)
            {
                _customerManager.Add(new Customer(contactForm.Contact));
            }

            UpdateGUI();
        }
Esempio n. 6
0
        /// <summary>
        /// This method calls when user click on the button btnEdit and user changes information of a cunstomer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, EventArgs e)
        {
            int index = listBox.SelectedIndex;

            if (index != -1)
            {
                ContactForm frmContact = new ContactForm("Change Costumer");
                frmContact.ContactData = customerMng.GetCustomer(index).ContactData;
                if (frmContact.ShowDialog() == DialogResult.OK)
                {
                    customerMng.ChangeCustomer(frmContact.ContactData, index);
                    UpdateGui();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Edit contact
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void btnChange_Click(object sender, EventArgs e)
        {
            var index = lstCustomerRegistry.SelectedIndex;

            if (_customerManager.CheckIndex(index))
            {
                var contactForm = new ContactForm(_customerManager.GetAt(index).Contact);

                var answer = contactForm.ShowDialog();
                if (answer == DialogResult.OK)
                {
                    _customerManager.ReplaceAt(index, contactForm.Contact);
                }
                UpdateGUI();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// This method calls when user click on button btnClick and user adds a new costumer info.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ContactForm frmContact = new ContactForm("Add New Costumer");
            int         index      = listBox.SelectedIndex;

            if (index != -1)
            {
                frmContact.ContactData = customerMng.GetCustomer(index).ContactData;
            }
            if (frmContact.ShowDialog() == DialogResult.OK)
            {
                customerMng.AddCustomer(frmContact.ContactData);
                frmContact.ContactData = new Contact();
                UpdateGui();
            }
        }