private string GetWhere() { string where = ""; string query = Request.Url.Query; if ((!MemberName.Equals("")) || MemberName != null) { where += "&MemberName=" + BLL.Util.EscapeString(MemberName); } if ((!MemberCode.Equals("")) || MemberCode != null) { where += "&MemberCode=" + BLL.Util.EscapeString(MemberCode); } if ((!CustId.Equals("")) || CustId != null) { where += "&CustId=" + BLL.Util.EscapeString(CustId); } where += "&nmc=1&random=" + (new Random()).Next().ToString(); return(where); }
//Rent movie implementation here private void buttonRentMovie_Click(object sender, EventArgs e) { try { string CustId, MovieId, IssueDate, ReturnDate; int totalDays = 0; int temp = 0; int TotalRent = 0; CustId = cbCust.SelectedValue.ToString(); MovieId = cbMovi.SelectedValue.ToString(); IssueDate = dtissue.Value.ToShortDateString(); ReturnDate = dtReturn.Value.ToShortDateString(); if (CustId.Equals("") || CustId == null) { MessageBox.Show("Please select a customer", "Alert"); } else if (MovieId.Equals("") || MovieId == null) { MessageBox.Show("Please select a movie", "Alert"); } else if (DateTime.Parse(IssueDate) > DateTime.Parse(ReturnDate)) { MessageBox.Show("Issue date can not be greater than retun date", "Alert"); } else if (IssueDate == ReturnDate) { totalDays = 1; temp = CalculateMovieRentCost(int.Parse(MovieId)); // Getting rent amount for that movie TotalRent = totalDays * temp; // Calculate the Total Rent of issue movie } else { totalDays = Convert.ToInt32((DateTime.Parse(ReturnDate) - DateTime.Parse(IssueDate)).TotalDays); temp = CalculateMovieRentCost(int.Parse(MovieId)); // Getting rent amount for that movie TotalRent = totalDays * temp; // Calculate the Total Rent of issue movie } SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString; con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "RentMovie"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@MovieID", MovieId); cmd.Parameters.AddWithValue("@CustID", CustId); cmd.Parameters.AddWithValue("@RentDate", IssueDate); cmd.Parameters.AddWithValue("@ReturnDate", ReturnDate); cmd.Parameters.AddWithValue("@TotalRent", TotalRent); bool result = cmd.ExecuteNonQuery() > 0; if (result) { BindRentMovieGrid(); //method calling to Bind Grid for all rental movies MessageBox.Show("Movie rented successfully!"); } else { MessageBox.Show("Failed to rent this movie"); } cmd.Dispose(); con.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }