示例#1
0
        //Add New Movie here
        private void btnAddMOvie_Click_1(object sender, EventArgs e)
        {
            try
            {
                string Title, Rent, Year, Rating, Genre;
                Title  = txtTitle.Text.Trim();
                Rent   = txtRentedCost.Text.Trim();
                Rating = txtRating.Text.Trim();
                Year   = txtYear.Text.Trim();
                Genre  = txtGenre.Text.Trim();

                if (Title.Equals(""))
                {
                    MessageBox.Show("Movie title is required!");
                }
                else if (Year.Equals(""))
                {
                    MessageBox.Show("Movie released year is required!");
                }

                else if (Genre.Equals(""))
                {
                    MessageBox.Show("Movie genre is required!");
                }
                else if (Rent.Equals(""))
                {
                    MessageBox.Show("Movie rent cost is required!");
                }

                else if (Rating.Equals(""))
                {
                    MessageBox.Show("Movie rating is required!");
                }

                else
                {
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                    con.Open();
                    SqlCommand cmd = new SqlCommand();

                    cmd.CommandText = "insert into movies values(@Title,@Year,@Rent,@Genre,@Rating)";
                    cmd.Connection  = con;

                    cmd.Parameters.Add(new SqlParameter("@Title", Title));
                    cmd.Parameters.Add(new SqlParameter("@Rent", Rent));
                    cmd.Parameters.Add(new SqlParameter("@Genre", Genre));
                    cmd.Parameters.Add(new SqlParameter("@Year", Year));
                    cmd.Parameters.Add(new SqlParameter("@Rating", Rating));
                    bool result = cmd.ExecuteNonQuery() > 0;
                    if (result)
                    {
                        BindGridMovies(); // method calling to Bind Grid Movies
                        MessageBox.Show("Movie Info Saved!", "Alert");

                        txtTitle.Text      = "";
                        txtYear.Text       = "";
                        txtRating.Text     = "";
                        txtGenre.Text      = "";
                        txtRentedCost.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Movie Info NOT Saved!", "Alert");
                    }
                    cmd.Dispose();
                    con.Dispose();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
示例#2
0
        //Update movie Info
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string Title, Rent, Year, Rating, Genre;
                Title  = txtTitle.Text.Trim();
                Rent   = txtRentedCost.Text.Trim();
                Rating = txtRating.Text.Trim();
                Year   = txtYear.Text.Trim();
                Genre  = txtGenre.Text.Trim();
                string movieId = tbxMovieID.Text.Trim();
                if (Title.Equals(""))
                {
                    MessageBox.Show("Movie title is required!");
                }
                else if (Year.Equals(""))
                {
                    MessageBox.Show("Movie released year is required!");
                }

                else if (Genre.Equals(""))
                {
                    MessageBox.Show("Movie genre is required!");
                }
                else if (Rent.Equals(""))
                {
                    MessageBox.Show("Movie rent cost is required!");
                }

                else if (Rating.Equals(""))
                {
                    MessageBox.Show("Movie rating is required!");
                }

                else
                {
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                    con.Open();
                    SqlCommand cmd = new SqlCommand();

                    cmd.CommandText = "UpdateMovieInfo";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@movieid", movieId));
                    cmd.Parameters.Add(new SqlParameter("@title", Title));
                    cmd.Parameters.Add(new SqlParameter("@rent", Rent));
                    cmd.Parameters.Add(new SqlParameter("@genre", Genre));
                    cmd.Parameters.Add(new SqlParameter("@year", Year));
                    cmd.Parameters.Add(new SqlParameter("@rating", Rating));
                    bool result = cmd.ExecuteNonQuery() > 0;
                    if (result)
                    {
                        BindGridMovies(); // method calling to Bind Grid Movies
                        MessageBox.Show("Movie Info updated!", "Alert");
                        tbxCustomerID.Text = "";
                        txtTitle.Text      = "";
                        txtYear.Text       = "";
                        txtRating.Text     = "";
                        txtGenre.Text      = "";
                        txtRentedCost.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Movie Info NOT Updated!", "Alert");
                    }
                    cmd.Dispose();
                    con.Dispose();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }