Ejemplo n.º 1
0
        // Delete button click event handler
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int index = lstCustomers.SelectedIndex;

            // if index is not equal to -1
            //   determine customer indicated by index
            //   create message asking if user is sure to delete
            //       indicated customer
            //   display message in dialog box with yes/no buttons
            //   if dialog box yes button is selected
            //       remove the indicated customer
            //       save updated customers list to CustomerDB
            //       fill customer list box
            if (index != -1)
            {
                Customer customer = customers[index];
                string   message  = "Are you sure you want to delete" +
                                    customer.FirstName + " " + customer.LastName + "?";
                DialogResult dialog = MessageBox.Show(message, "Confirm Delete",
                                                      MessageBoxButtons.YesNo);
                // nested if
                if (dialog == DialogResult.Yes)
                {
                    customers.Remove(customer);
                    CustomerDB.SaveCustomers(customers);
                    FillCustomerListBox();
                }
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer addCustomerForm = new frmAddCustomer();
            Customer       customer        = addCustomerForm.GetNewCustomer();

            if (customer != null)
            {
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
Ejemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)                  // When the user clicks the add button, give them a form to fill out to create a new customer
        {
            frmAddCustomer newCustomerForm = new frmAddCustomer();             // Create the form
            Customer       customer        = newCustomerForm.GetNewCustomer(); // Get the information from the form

            if (customer != null)
            {
                customers.Add(customer);                // Create, save, and show the new customer
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer newAddCustomerForm = new frmAddCustomer();                // create new instance of AddCustomer form
            Customer       customer           = newAddCustomerForm.GetNewCustomer(); // get data for new customer

            if (customer != null)                                                    // check if customer object is null
            {
                customers.Add(customer);                                             // add new customer
                CustomerDB.SaveCustomers(customers);                                 // save customers list
                FillCustomerListBox();                                               // call method to refresh customer list box
            }
        }
Ejemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer addCustomerForm = new frmAddCustomer();
            Customer       customer        = addCustomerForm.GetCustomer();

            if (customer != null)
            {
                MessageBox.Show(customer.GetDisplayText("\t"));
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
Ejemplo n.º 6
0
        // Step 11.
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // create a new instance of the Add Customer form
            frmAddCustomer newAddCustomerForm = new frmAddCustomer();
            Customer       customer           = newAddCustomerForm.GetNewCustomer();

            if (customer != null)
            {
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer frmAddCustomer = new frmAddCustomer();
            Customer       customer       = frmAddCustomer.GetNewCustomer();

            if (customer.FirstName != ""
                & customer.LastName != ""
                & customer.Email != "")
            {
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
Ejemplo n.º 8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer newCustomerForm = new frmAddCustomer();
            Customer       customer        = newCustomerForm.GetNewCustomer();

            // if customer is not null
            //   add customer to customers list
            //   save customers list to CustomerDB
            //   fill customer list box
            if (customer != null)
            {
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int i = lstCustomers.SelectedIndex;

            if (i != -1)
            {
                Customer     customer = customers[i];
                string       message  = "Are you sure you want to delete" + customer.FirstName + " " + customer.LastName + "?";
                DialogResult button   = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo);
                if (button == DialogResult.Yes)
                {
                    customers.Remove(customer);
                    CustomerDB.SaveCustomers(customers);
                    FillCustomerListBox();
                }
            }
        }
Ejemplo n.º 10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer frm = new frmAddCustomer();
            Customer       c   = frm.GetNewCustomer();

            if (c != null)
            {
                customers.Add(c);
                CustomerDB.SaveCustomers(customers);
            }

            lstCustomers.Items.Clear();
            foreach (Customer cx in customers)
            {
                lstCustomers.Items.Add(cx);
            }
        }
Ejemplo n.º 11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddCustomer newCustomerForm = new frmAddCustomer();
            Customer       customer        = newCustomerForm.GetNewCustomer();

            /* If customer object returned not null
             *      add new customer to array list
             *      save list to CustomerDB
             *      refresh customer list box
             */

            if (customer != null)
            {
                customers.Add(customer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int i = lstCustomers.SelectedIndex;                                                              // create & set variable to selected customer in list

            if (i != -1)                                                                                     // check if a customer has been selected
            {
                Customer customer = customers[i];                                                            // create & set variable for selected customer
                string   message  = "Are you sure you want to delete "
                                    + customer.FirstName + " " + customer.LastName + "?";                    // create delete confirmation message
                DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2); // display confirmation to delete
                if (button == DialogResult.Yes)                                                              // check if user confirmed deletion
                {
                    customers.Remove(customer);                                                              // remove selected customer from list
                    CustomerDB.SaveCustomers(customers);                                                     // save updated customers list
                    FillCustomerListBox();                                                                   // call method to refresh customer list box
                }
            }
        }
Ejemplo n.º 13
0
        private void btnDelete_Click(object sender, EventArgs e)        // When the user clicks the delete button with a customer selected, ask if they are sure, then if they say yes, delete it
        {
            int i = lstCustomers.SelectedIndex;

            if (i != -1)
            {
                Customer customer = customers[i];           // Get the customer they clicked
                string   message  = "Are you sure you want to delete "
                                    + customer.FirstName + " " + customer.LastName + "?";
                DialogResult button =
                    MessageBox.Show(message, "Confirm Delete",
                                    MessageBoxButtons.YesNo);
                if (button == DialogResult.Yes)             // Delete the customer if they say yes
                {
                    customers.Remove(customer);
                    CustomerDB.SaveCustomers(customers);
                    FillCustomerListBox();
                }
            }
        }
Ejemplo n.º 14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            /* Confirm delete operation?
             *      Removes customer from customers
             *      Save list
             *      Refresh list box
             */

            int      index       = lstCustomers.SelectedIndex;
            Customer delCustomer = customers[index];

            // Confirms whether or not user wants to delete a customer
            DialogResult button =
                MessageBox.Show("Are you sure you want to delete this customer?", "Delete Customer",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            // If user confirms, removes customer at index, saves list, refreshes listbox
            if (button == DialogResult.Yes)
            {
                customers.Remove(delCustomer);
                CustomerDB.SaveCustomers(customers);
                FillCustomerListBox();
            }
        }
Ejemplo n.º 15
0
 public void Save() => CustomerDB.SaveCustomers(this);
Ejemplo n.º 16
0
 public void Save()
 {
     CustomerDB.SaveCustomers(customers);
 }