private void buttonDelete_Click(object sender, EventArgs e)
        {
            Customer customer = customerVM.GetDisplayedCustomer();

            CustomerInfoRepository.DeleteCustomer(customer);
            customerVM.Customers           = CustomerInfoRepository.GetAllCustomers();
            listBoxCustomers.DataSource    = customerVM.Customers;
            listBoxCustomers.DisplayMember = "CustomerCode";
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                Customer customer = customerVM.GetDisplayedCustomer();
                int      rowsAffected;
                bool     success;

                if (!isNew)
                {
                    rowsAffected = CustomerValidation.UpdateCustomer(customer, out success);
                }
                else
                {
                    rowsAffected = CustomerValidation.NewCustomer(customer, out success);
                }

                if (rowsAffected > 0)
                {
                    customerVM.Customers           = CustomerInfoRepository.GetAllCustomers();
                    listBoxCustomers.DataSource    = customerVM.Customers;
                    listBoxCustomers.DisplayMember = "CustomerCode";
                }

                // Validation for ErrorProviders
                if (!success)
                {
                    ErrorList errors = CustomerValidation.Errors;

                    errorProvider.SetError(textBoxCompanyCode, errors.CompanyCodeErrorMessage);
                    errorProvider.SetError(textBoxName, errors.CompanyNameErrorMessage);
                    errorProvider.SetError(textBoxFirstAddress, errors.FirstAddressErrorMessage);
                    errorProvider.SetError(textBoxProvince, errors.ProvinceErrorMessage);
                    errorProvider.SetError(textBoxPostalCode, errors.PostalCodeErrorMessage);
                    errorProvider.SetError(textBoxYTDSales, errors.YTDSalesErrorMessage);
                }
                else
                {
                    isNew = false;
                    errorProvider.SetError(textBoxCompanyCode, string.Empty);
                    errorProvider.SetError(textBoxName, string.Empty);
                    errorProvider.SetError(textBoxFirstAddress, string.Empty);
                    errorProvider.SetError(textBoxProvince, string.Empty);
                    errorProvider.SetError(textBoxPostalCode, string.Empty);
                    errorProvider.SetError(textBoxYTDSales, string.Empty);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     try
     {
         customerVM           = new CustomerViewModel();
         customerVM.Customers = CustomerInfoRepository.GetAllCustomers();
         setBindings();
         isNew = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }