private IEnumerable<ListViewItem> GetVideoByStatus() { var booking = new Booking(database); var videolist = booking.GetVideo().ToList(); var genrelist = booking.GetGenre().ToList(); var result = from video in videolist join genre in genrelist on video.GenreId equals genre.Id where (video.IsRented == false) select new ListViewItem(new string[] { video.Id.ToString(), video.Name, genre.Name, video.DaysToBeRent.ToString() }); return result; }
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 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 cboVideoVideo_SelectedIndexChanged(object sender, EventArgs e) { var booking = new Booking(database); var video = (Video)cboVideoVideo.SelectedItem; var genre = booking.GetGenre().First(g => g.Id.Equals(video.GenreId)); cboVideoGenre.SelectedItem = genre; cboVideoVideo.DisplayMember = "Name"; nmrDaysToBeRent.Value = Convert.ToDecimal(video.DaysToBeRent); txtVideoName.Text = video.Name; }
private void FillAvailableVideoList() { var booking = new Booking(database); var videolist = booking.GetVideo().ToList(); var genrelist = booking.GetGenre().ToList(); var result = from video in videolist join genre in genrelist on video.GenreId equals genre.Id where (video.IsRented == false) select new ListViewItem(new string[] { video.Id.ToString(), video.Name, genre.Name, video.DaysToBeRent.ToString() }); lvwVideoStatus.Items.Clear(); lvwVideoStatus.Items.AddRange(result.ToArray()); }
private void btnVideoDelete_Click(object sender, EventArgs e) { string video = txtVideoName.Text; if (string.IsNullOrWhiteSpace(video)) { MessageBox.Show("Please select Video from list.", "Error Message"); txtVideoName.Clear(); txtVideoName.Focus(); } else { try { var booking = new Booking(database); var result = booking.DeleteVideo((Video)cboVideoVideo.SelectedItem); if (result) { cboVideoVideo.DataSource = booking.GetVideo().ToList(); cboVideoVideo.DisplayMember = "Name"; txtVideoName.Clear(); cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; FillAvailableVideoList(); } else { MessageBox.Show("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 btnVideoUpdate_Click(object sender, EventArgs e) { var video = txtVideoName.Text; if (string.IsNullOrWhiteSpace(video)|| (nmrDaysToBeRent.Value == 0)) { MessageBox.Show("Please enter valid Video name.", "Error Message"); txtVideoName.Clear(); txtVideoName.Focus(); } else { try { var booking = new Booking(database); var result = booking.UpdateVideo(((Video)cboVideoVideo.SelectedItem).Id, ((Genre) cboVideoGenre.SelectedItem).Id, txtVideoName.Text, Convert.ToInt16(nmrDaysToBeRent.Value)); if (result) { cboVideoVideo.DataSource = booking.GetVideo().ToList(); cboVideoVideo.DisplayMember = "Name"; txtVideoName.Clear(); cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; //cboVideoGenre.SelectedText= ((Video)cboVideoVideo.SelectedItem).GenreId FillBookingList(); FillAvailableVideoList(); } } catch (VideoRentalException ex) { MessageBox.Show(String.Format("Error occured: {0} is not updated succesfully", ex.Item.Name)); } catch (Exception ex) { MessageBox.Show(string.Format("Error Occoured: {0}", ex.Message)); } } }
private void btnGenreUpdate_Click(object sender, EventArgs e) { var genre = txtGenreName.Text; if (string.IsNullOrWhiteSpace(genre) || genre.Any(Char.IsDigit)) { MessageBox.Show("Please enter valid Genre name.", "Error Message"); txtGenreName.Clear(); txtGenreName.Focus(); } else { try { var booking = new Booking(database); var result = booking.UpdateGenre(((Genre)cboGenreGenre.SelectedItem).Id, txtGenreName.Text); if (result) { cboGenreGenre.DataSource = booking.GetGenre().ToList(); cboGenreGenre.DisplayMember = "Name"; txtGenreName.Clear(); cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; FillBookingList(); FillAvailableVideoList(); } else { MessageBox.Show(String.Format("Error occured: {0} is not updated succesfully",((Genre)cboGenreGenre.SelectedItem).Name)); } } catch (VideoRentalException ex) { MessageBox.Show(String.Format("Error occured: {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)); } }
private void cboVideoVideo_SelectedIndexChanged(object sender, EventArgs e) { try { var booking = new Booking(DbManager); var video = (Video) cboVideoVideo.SelectedItem; var genre = booking.GetGenre().First(g => g.Id.Equals(video.GenreId)); cboVideoGenre.SelectedIndex = cboVideoGenre.FindString(genre.Name); nmrDaysToBeRent.Value = Convert.ToDecimal(video.DaysToBeRent); txtVideoName.Text = video.Name; } catch (VideoRentalException ex) { MessageBox.Show(String.Format("Error occured: {0} is not updated succesfully", ex.Item.Name)); } catch (Exception ex) { MessageBox.Show(string.Format("Error Occoured: {0}", ex.Message)); } }
private void btnGenreAdd_Click(object sender, EventArgs e) { try { string genre = txtGenreName.Text; if (string.IsNullOrWhiteSpace(genre) || genre.Any(Char.IsDigit)) { MessageBox.Show("Please enter valid Genre name.", "Error Message"); txtGenreName.Clear(); txtGenreName.Focus(); } else { var booking = new Booking(DbManager); var result = booking.AddGenre(new Genre() {Name = txtGenreName.Text}); if (result) { cboGenreGenre.DataSource = booking.GetGenre(); cboGenreGenre.DisplayMember = "Name"; txtGenreName.Clear(); cboVideoGenre.DataSource = booking.GetGenre(); cboVideoGenre.DisplayMember = "Name"; MessageBox.Show(txtGenreName.Text + " genre added successfully."); } else { MessageBox.Show(txtGenreName.Text + " genre already exists."); } } } 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 btnGenereDelete_Click(object sender, EventArgs e) { try { string genre = txtGenreName.Text; if (string.IsNullOrWhiteSpace(genre)) { MessageBox.Show("Please select Genre name from list.", "Error Message"); txtGenreName.Clear(); txtGenreName.Focus(); } else { var booking = new Booking(DbManager); var result = booking.DeleteGenre((Genre) cboGenreGenre.SelectedItem); if (result) { cboGenreGenre.DataSource = booking.GetGenre().ToList(); cboGenreGenre.DisplayMember = "Name"; txtGenreName.Clear(); cboVideoGenre.DataSource = booking.GetGenre().ToList(); cboVideoGenre.DisplayMember = "Name"; MessageBox.Show("Deletion succesfull."); } else { MessageBox.Show("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)); } }