Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string message         = "";
            string video_title     = textVideoTitle.Text.Trim();
            string genre           = textGenre.Text.Trim();
            string year_of_release = textYear.Text.Trim();
            int    hours           = (int)numericHour.Value;
            int    minutes         = (int)numericMinute.Value;

            if (Checks.checkEmpty(video_title) || Checks.checkEmpty(genre) || Checks.checkEmpty(year_of_release))
            {
                message = "Please Fill All Boxes";
            }
            else if (!Checks.checkNumber(year_of_release))
            {
                message = "Please Enter Number in Year of Release";
            }
            else
            {
                int year        = int.Parse(year_of_release);
                int rental_cost = 5;
                if (year < DateTime.Now.Year - 5)
                {
                    rental_cost = 2;
                }
                if (btnSave.Text.Contains("Add"))
                {
                    if (common.AddVideo(video_title, year, genre, hours, minutes, rental_cost))
                    {
                        textRentalCost.Text = rental_cost.ToString();
                        message             = "Video Details is Saved";
                        LoadDatabase();
                    }
                    else
                    {
                        message = "Video Details does not Saved";
                    }
                }
                else if (btnSave.Text.Contains("Update"))
                {
                    string videoid = textVideoID.Text.Trim();
                    if (Checks.checkNumber(videoid))
                    {
                        int vid = int.Parse(videoid);
                        if (common.UpdateVideo(vid, video_title, year, genre, hours, minutes, rental_cost))
                        {
                            message = "Record is Updated";
                            LoadDatabase();
                        }
                        else
                        {
                            message = "Record in not Updated";
                        }
                    }
                    textVideoID.Text  = textVideoTitle.Text = textGenre.Text = textYear.Text = textRentalCost.Text = "";;
                    numericHour.Value = numericMinute.Value = 0;
                    btnSave.Text      = "Add New Video";
                    btnDelete.Enabled = false;
                }
                else
                {
                    message = "Invalid Operation";
                }
            }
            MessageBox.Show(message);
        }