Exemple #1
0
        private void btnCustomersAdd_Click(object sender, EventArgs e)
        {
            string fname = txtCustomersFName.Text;
            string lname = txtCustomersLName.Text;

            if (string.IsNullOrWhiteSpace(fname) || (string.IsNullOrWhiteSpace(lname)))
            {
                MessageBox.Show("Please enter full customer name.", "Error Message");
                txtCustomersFName.Focus();
            }
            else
            {
                try
                {
                    var booking = new Booking(DbManager);

                    var result =
                        booking.AddCustomer(new Customer()
                            {
                                FirstName = txtCustomersFName.Text,
                                LastName = txtCustomersLName.Text
                            });

                    if (result)
                    {
                        cboCustomersName.DataSource = booking.GetCustomer().ToList();
                        cboCustomersName.DisplayMember = "Name";
                        txtCustomersFName.Clear();
                        txtCustomersLName.Clear();

                        cboRentCustomerName.DataSource = booking.GetCustomer().ToList();
                        cboRentCustomerName.DisplayMember = "Name";

                        MessageBox.Show("Successfully Added.");
                    }
                    else
                    {
                        MessageBox.Show("Name could not be added.");
                    }
                }
                catch (VideoRentalException ex)
                {
                    MessageBox.Show(String.Format("Error occured: {0} is not added succesfully", ex.Item.Name));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Error Occoured:  {0}", ex.Message));
                }
            }
        }