Example #1
0
 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;
 }
Example #2
0
        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());
        }
Example #3
0
        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();
        }
Example #4
0
 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());
 }
Example #5
0
        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));
                }

            }
        }
Example #6
0
        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));
                }
            }
        }
Example #7
0
        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));
            }
        }
Example #8
0
        private void btnVideoAdd_Click(object sender, EventArgs e)
        {
            string video = txtVideoName.Text;
            if (string.IsNullOrWhiteSpace(video) || (nmrDaysToBeRent.Value == 0))
            {
                MessageBox.Show(string.Format("Please enter valid Video name or Number of days to be rented.", "Error Message"));
                txtVideoName.Focus();
            }
            else
            {
                try
                {
                    var booking = new Booking(DbManager);

                    var result =
                        booking.AddVideo(new Video()
                        {
                             GenreId = ((Genre)cboVideoGenre.SelectedItem).Id,
                             Name = txtVideoName.Text,
                             DaysToBeRent = Convert.ToInt16(nmrDaysToBeRent.Value)
                        });
                    if (result)
                    {
                        cboVideoVideo.DataSource = booking.GetVideo().ToList();
                        cboVideoVideo.DisplayMember = "Name";
                        txtVideoName.Clear();

                        FillBookingList();
                        FillAvailableVideoList();

                        MessageBox.Show("Successfully Added.");
                    }
                    else
                    {
                        MessageBox.Show(txtVideoName.Text + " video 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));
                }
            }
        }