Exemple #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (isValid())
         {
             var customer = new Customer(txtFirstname.Text);
             customer.lastName     = txtLastName.Text;
             customer.phoneNumber  = mskTelephoneNumber.Text;
             customer.eMail        = txtEmail.Text;
             customer.age          = (int)nupAge.Value;
             customer.genderIsMale = rbtMale.Checked;
             PersistenceCustomer.getInstance().Insert(customer);
             InsertGrid(customer);
             ClearForm();
         }
     }
     catch (MyException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #2
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (dgvCustomer.SelectedRows.Count == 0)
            {
                return;
            }

            var customer = (ICustomer)dgvCustomer.SelectedRows[0].Tag;

            if (customer == null)
            {
                return;
            }

            if (MessageBox.Show(string.Format("Do you want to delete the customer {0}?", customer.name), "Remove", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    PersistenceCustomer.getInstance().Delete(customer);
                    dgvCustomer.Rows.Remove(dgvCustomer.SelectedRows[0]);
                }
                catch (MyException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemple #3
0
        private void CarForm_Load(object sender, EventArgs e)
        {
            var customers = PersistenceCustomer.getInstance().GetAll().OrderBy(x => x.name);

            foreach (var customer in customers)
            {
                InsertGrid(customer);
            }
        }