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)); } } }
private void btnCustomersDelete_Click(object sender, EventArgs e) { string customerName = txtCustomersFName.Text+txtCustomersLName; if (string.IsNullOrWhiteSpace(customerName)) { MessageBox.Show("Please select Customer name from list.", "Error Message"); txtCustomersFName.Clear(); txtCustomersLName.Clear(); txtCustomersFName.Focus(); } else { try { var booking = new Booking(database); var result = booking.DeleteCustomer((Customer)cboCustomersName.SelectedItem); if (result) { cboCustomersName.DataSource = booking.GetCustomer().ToList(); cboCustomersName.DisplayMember = "Name"; txtCustomersFName.Clear(); txtCustomersLName.Clear(); cboRentCustomerName.DataSource = booking.GetCustomer().ToList(); cboRentCustomerName.DisplayMember = "Name"; } else { MessageBox.Show("Customer deletion not succesfull."); } } catch (VideoRentalException ex) { MessageBox.Show(String.Format("Error occured: {0} is not deleted succesfully", ex.Item.Name)); } catch (Exception ex) { MessageBox.Show(string.Format("Error Occoured: {0}", ex.Message)); } } }
private void Form1_Load(object sender, EventArgs e) { var booking = new Booking(database); cboGenreGenre.DataSource = booking.GetGenre().ToList(); cboGenreGenre.DisplayMember = "Name"; cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; cboVideoVideo.DataSource = booking.GetVideo().ToList(); cboVideoVideo.DisplayMember = "Name"; cboCustomersName.DataSource = booking.GetCustomer().ToList(); cboCustomersName.DisplayMember = "Name"; cboRentCustomerName.DataSource= booking.GetCustomer().ToList(); cboRentCustomerName.DisplayMember = "Name"; FillAvailableVideoList(); }
private void FillBookingList() { var booking = new Booking(database); var bookingList = booking.GetBookingList(); var videolist = booking.GetVideo(); var genrelist = booking.GetGenre(); var customerlist = booking.GetCustomer(); var result = from bklist in bookingList join vdo in videolist on bklist.VideoId equals vdo.Id join cust in customerlist on bklist.CustomerId equals cust.Id join gnr in genrelist on vdo.GenreId equals gnr.Id select new ListViewItem(new VideoBooking() { Id= bklist.Id, CustomerName= cust.Name, VideoName = vdo.Name, GenreName = gnr.Name, RentDate = bklist.RentDate, ReturnDate = bklist.ReturnDate, Cost = bklist.Cost }.ToArray()); lvwBookings.Items.Clear(); lvwBookings.Items.AddRange(result.ToArray()); }
private void btnCustomersUpdate_Click(object sender, EventArgs e) { string customerName = txtCustomersFName.Text + txtCustomersLName; if (string.IsNullOrWhiteSpace(txtCustomersFName.Text) || customerName.Any(Char.IsDigit)) { MessageBox.Show("Please enter valid Customer name.", "Error Message"); txtCustomersFName.Clear(); txtCustomersLName.Clear(); txtCustomersFName.Focus(); } else { try { var booking = new Booking(database); var result = booking.UpdateCustomer(((Customer) cboCustomersName.SelectedItem).Id, txtCustomersFName.Text, txtCustomersLName.Text); if (result) { cboCustomersName.DataSource = booking.GetCustomer().ToList(); cboCustomersName.DisplayMember = "Name"; txtCustomersFName.Clear(); txtCustomersLName.Clear(); cboRentCustomerName.DataSource = booking.GetCustomer().ToList(); cboRentCustomerName.DisplayMember = "Name"; FillBookingList(); } else { MessageBox.Show("Update not successfull: Customer already exists.", "Error Message"); } } catch (VideoRentalException ex) { MessageBox.Show(String.Format("Error occured: Customar {0} is not updated succesfully", ex.Item.Name)); } catch (Exception ex) { MessageBox.Show(string.Format("Error Occoured: {0}", ex.Message)); } } }
private void Form1_Load(object sender, EventArgs e) { try { tabControl1.SelectTab(2); var booking = new Booking(DbManager); cboGenreGenre.DataSource = booking.GetGenre().ToList(); cboGenreGenre.DisplayMember = "Name"; cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; cboVideoVideo.DataSource = booking.GetVideo().ToList(); cboVideoVideo.DisplayMember = "Name"; cboCustomersName.DataSource = booking.GetCustomer().ToList(); cboCustomersName.DisplayMember = "Name"; cboRentCustomerName.DataSource = booking.GetCustomer().ToList(); cboRentCustomerName.DisplayMember = "Name"; FillAvailableVideoList(); FillBookingList(); } catch (Exception ex) { MessageBox.Show(string.Format("Error Occoured: {0}", ex.Message)); } }