示例#1
0
        private int AddVideo()
        {
            try
            {
                string errMsg = String.Empty;
                if (IsNumeric(txtVideosName.Text))
                {
                    errMsg = " video name can not contain numbers" + Environment.NewLine;
                }
                if (txtVideosName.TextLength == 0)
                {
                    errMsg += "Incorrect video name" + Environment.NewLine;
                }
                if (cboVideosGenre.SelectedIndex < 0)   //Any genre selected
                {
                    errMsg += "No genre is selected." + Environment.NewLine;
                }

                if (numVideosDays.Value < 1)    //Enough days selected
                {
                    errMsg += "Too few rental days selected." + Environment.NewLine;
                }
                if (txtVideosName.TextLength == 0 || IsNumeric(txtVideosName.Text) ||
                    cboVideosGenre.SelectedIndex < 0 || numVideosDays.Value < 1)
                {
                    MessageBox.Show(errMsg);
                    return(-1);
                }
                var video = new Video()
                {
                    GenreId    = ((ComboClass)cboVideosGenre.SelectedItem).Id,
                    Name       = txtVideosName.Text,
                    RentalDays = (int)numVideosDays.Value
                };
                booking.AddVideo(video);
                FillVideos();
                FillAvailbaleVideos();
                txtVideosName.Text = String.Empty;

                return(cboVideosVideo.Items.Count - 1);
            }
            catch (VideoRentalException ex)
            {
                MessageBox.Show(ex.Message);
                return(Int32.MinValue);
            }
            catch
            {
                return(-1);
            }
        }