Пример #1
0
 /// <summary>
 /// Event handler for the click event of the Add menuítem of the Customer menu.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mnuCustomerAdd_Click(object sender, EventArgs e)
 {
     // create and show the new instance of the CustomerForm
     CustomerForm frmCustomer = new CustomerForm("Add New Customer");
     //if the user clicks OK on the customerform then call the UpdateCusomerList()
     //to update the listbox
     if (frmCustomer.ShowDialog() == DialogResult.OK)
     {
         customerMngr.AddCustomer(frmCustomer.CustomerData);
         UpdateCustomerList();
     }
 }
Пример #2
0
        /// <summary>
        /// Event handler for teh click event of Change menuitme of the Customer Menu.
        /// If list box is not empty then allow the user to change details of the customer
        /// at the selected index, else call showError() method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mnuCustomerChange_Click(object sender, EventArgs e)
        {
            //perform the update if the list box is not empty
            if (lstCustomerDetails.Items.Count != 0)
            {
                CustomerForm frmCustomer = new CustomerForm("Change Customer Details");

                int index = lstCustomerDetails.SelectedIndex;
                //if index is not selected then show error, otherwise continue
                if (index != -1)
                {
                    frmCustomer.CustomerData = new Customer(customerMngr.GetCustomer(index).ContactData);
                }
                else
                {
                    MessageBox.Show("Please select an index", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //if the user clicks on the Ok button of the customerForm then continue with the updation
                if (frmCustomer.ShowDialog() == DialogResult.OK)
                {
                    customerMngr.ChangeCustomer(frmCustomer.CustomerData.ContactData, lstCustomerDetails.SelectedIndex);
                    UpdateCustomerList();
                }
            }
            else
            {
                //if list box is empty, show error
                ShowError();
                return;
            }
        }