protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteRecord") { if (e.CommandArgument != null) { ProductBAL balProduct = new ProductBAL(); ProductENT entProduct = new ProductENT(); #region Delete image from folder entProduct = balProduct.SelectByPK(Convert.ToInt32(e.CommandArgument.ToString())); FileInfo path = new FileInfo(Server.MapPath(entProduct.ProductImage.Value.ToString())); path.Delete(); #endregion Delete image from folder if (balProduct.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim()))) { FillProductGridView(); } else { lblMessage.Text = balProduct.Message; divMessage.Visible = true; } } } }
private void FillProductDetails(Int32 ProductID) { ProductENT entProduct = new ProductENT(); ProductBAL balProduct = new ProductBAL(); entProduct = balProduct.SelectByPK(ProductID); if (!entProduct.Equals(null)) { imgProduct.ImageUrl = entProduct.ProductImage.Value.ToString(); lblProductName.Text = entProduct.ProductName.Value.ToString(); lblPrice.Text = entProduct.Price.Value.ToString(); lblDescription.Text = entProduct.Description.Value.ToString(); if (Request.QueryString["CategoryName"] == "T-shirt") { divTshirt.Visible = true; } else if (Request.QueryString["CategoryName"] == "Calendar") { divCalendar.Visible = true; } else if (Request.QueryString["CategoryName"] == "Canvas") { divCanvas.Visible = true; } } }
private void FillControls(SqlInt32 ProductID) { ProductBAL balProduct = new ProductBAL(); ProductENT entProduct = new ProductENT(); entProduct = balProduct.SelectByPK(ProductID); if (!entProduct.CategoryID.IsNull) { ddlCategoryID.SelectedValue = entProduct.CategoryID.Value.ToString(); } if (!entProduct.ProductName.IsNull) { txtProductName.Text = entProduct.ProductName.Value.ToString(); } if (!entProduct.Description.IsNull) { txtDescription.Text = entProduct.Description.Value.ToString(); } if (!entProduct.Price.IsNull) { txtPrice.Text = entProduct.Price.Value.ToString(); } }
public ProductENT SelectByPK(SqlInt32 ProductID) { using (SqlConnection objConnection = new SqlConnection(ConnectionString)) { using (SqlCommand objcmd = objConnection.CreateCommand()) { try { objConnection.Open(); #region Prepare Command objcmd.CommandType = CommandType.StoredProcedure; objcmd.CommandText = "PR_Product_SelectByPK"; objcmd.Parameters.AddWithValue("@ProductID", ProductID.ToString()); #endregion Prepare Command #region ReadData And SetData ProductENT entProduct = new ProductENT(); using (SqlDataReader objSDR = objcmd.ExecuteReader()) { while (objSDR.Read()) { if (!objSDR["ProductName"].Equals(DBNull.Value)) { entProduct.ProductName = Convert.ToString(objSDR["ProductName"]); } } } return(entProduct); #endregion ReadData And SetData } catch (SqlException Sqlex) { Message = Sqlex.Message.ToString(); return(null); } catch (Exception ex) { Message = ex.Message.ToString(); return(null); } finally { if (objConnection.State == ConnectionState.Open) { objConnection.Close(); } } } } }
private void LoadControls(SqlInt32 ProductID) { ProductENT entProduct = new ProductENT(); ProductBAL balProduct = new ProductBAL(); entProduct = balProduct.SelectByPK(ProductID); if (!entProduct.ProductName.IsNull) { txtProductName.Text = entProduct.ProductName.Value.ToString(); } }
public Boolean Update(ProductENT entProduct) { ProductDAL dalProduct = new ProductDAL(); if (dalProduct.Update(entProduct)) { return(true); } else { Message = dalProduct.Message; return(false); } }
public Boolean Insert(ProductENT entProduct) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Product_Insert"; objCmd.Parameters.Add("@ProductID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; objCmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = entProduct.CategoryID; objCmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = entProduct.ProductName; objCmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = entProduct.Description; objCmd.Parameters.Add("@Price", SqlDbType.Int).Value = entProduct.Price; objCmd.Parameters.Add("@ProductImage", SqlDbType.VarChar).Value = entProduct.ProductImage; #endregion prepare Command objCmd.ExecuteNonQuery(); if (objCmd.Parameters["@ProductID"] != null) { entProduct.ProductID = Convert.ToInt32(objCmd.Parameters["@ProductID"].Value); } return(true); } catch (SqlException sqlex) { Message = sqlex.InnerException.Message; return(false); } catch (Exception ex) { Message = ex.InnerException.Message; return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
public Boolean Update(ProductENT entProduct) { ProductDAL ProductDAL = new ProductDAL(); if (ProductDAL.Update(entProduct)) { return(true); } else { this.Message = ProductDAL.Message; return(false); } }
public Boolean Update(ProductENT entProduct) { using (SqlConnection objConnection = new SqlConnection(ConnectionString)) { using (SqlCommand objcmd = objConnection.CreateCommand()) { try { objConnection.Open(); #region Prepare Command objcmd.CommandType = CommandType.StoredProcedure; objcmd.CommandText = "PR_Product_UpdateByPK"; objcmd.Parameters.AddWithValue("@ProductID", entProduct.ProductID); objcmd.Parameters.AddWithValue("@ProductName", entProduct.ProductName); objcmd.Parameters.AddWithValue("@UserID", entProduct.UserID); #endregion Prepare Command #region ReadData And SetData objcmd.ExecuteNonQuery(); return(true); #endregion ReadData And SetData } catch (SqlException Sqlex) { Message = Sqlex.Message.ToString(); return(false); } catch (Exception ex) { Message = ex.Message.ToString(); return(false); } finally { if (objConnection.State == ConnectionState.Open) { objConnection.Close(); } } } } }
public Boolean Update(ProductENT entProduct) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Product_Update"; objCmd.Parameters.AddWithValue("@ProductID", entProduct.ProductID); objCmd.Parameters.AddWithValue("@CategoryID", entProduct.CategoryID); objCmd.Parameters.AddWithValue("@ProductName", entProduct.ProductName); objCmd.Parameters.AddWithValue("@Description", entProduct.Description); objCmd.Parameters.AddWithValue("@Price", entProduct.Price); objCmd.Parameters.AddWithValue("@ProductImage", entProduct.ProductImage); #endregion prepare Command objCmd.ExecuteNonQuery(); return(true); } catch (SqlException sqlex) { Message = sqlex.InnerException.Message; return(false); } catch (Exception ex) { Message = ex.InnerException.Message; return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
protected void btnSave_Click(object sender, EventArgs e) { #region ServerSide Validation #endregion ServerSide Validations ProductENT entProduct = new ProductENT(); ProductBAL balProduct = new ProductBAL(); #region Gather Data if (txtProductName.Text.Trim() != String.Empty) { entProduct.ProductName = txtProductName.Text.Trim(); } entProduct.CreationDate = DateTime.Now; entProduct.UserID = Convert.ToInt32(Session["UserID"]); if (Request.QueryString["ProductID"] == null) { balProduct.Insert(entProduct); lblMessage.Text = "Data Insert SuccessFully"; ClearControl(); } else { entProduct.ProductID = Convert.ToInt32(Request.QueryString["ProductID"]); balProduct.Update(entProduct); Response.Redirect("~/AdminPanel/Product/ProductList.aspx"); } #endregion Gather Data }
public ProductENT SelectByPK(SqlInt32 ProductID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Product_SelectByPK"; objCmd.Parameters.AddWithValue("@ProductID", ProductID); #endregion prepare Command #region ReadData and Set Controls ProductENT entProduct = new ProductENT(); using (SqlDataReader objSDR = objCmd.ExecuteReader()) { while (objSDR.Read()) { if (!objSDR["ProductID"].Equals(DBNull.Value)) { entProduct.ProductID = Convert.ToInt32(objSDR["ProductID"]); } if (!objSDR["CategoryID"].Equals(DBNull.Value)) { entProduct.CategoryID = Convert.ToInt32(objSDR["CategoryID"]); } if (!objSDR["ProductName"].Equals(DBNull.Value)) { entProduct.ProductName = Convert.ToString(objSDR["ProductName"]); } if (!objSDR["Description"].Equals(DBNull.Value)) { entProduct.Description = Convert.ToString(objSDR["Description"]); } if (!objSDR["Price"].Equals(DBNull.Value)) { entProduct.Price = Convert.ToInt32(objSDR["Price"]); } if (!objSDR["ProductImage"].Equals(DBNull.Value)) { entProduct.ProductImage = Convert.ToString(objSDR["ProductImage"]); } } } return(entProduct); #endregion ReadData and Set Controls } catch (SqlException sqlex) { Message = sqlex.InnerException.Message; return(null); } catch (Exception ex) { Message = ex.InnerException.Message; return(null); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
protected void btnAdd_Click(object sender, EventArgs e) { #region ServerSide Validation String strErrorMessage = ""; if (ddlCategoryID.SelectedIndex <= 0) { strErrorMessage += "Select Category<br/>"; } if (txtProductName.Text == "") { strErrorMessage += "Enter Product Name<br/>"; } if (txtDescription.Text == "") { strErrorMessage += "Enter Description<br/>"; } if (txtPrice.Text == "") { strErrorMessage += "Enter Price<br/>"; } if (strErrorMessage != "") { lblMessage.Text = strErrorMessage; divMessage.Visible = true; } #endregion ServerSide Validation #region Collect FormData ProductENT entProduct = new ProductENT(); if (ddlCategoryID.SelectedIndex != 0) { entProduct.CategoryID = Convert.ToInt32(ddlCategoryID.SelectedValue); } if (txtProductName.Text != "") { entProduct.ProductName = txtProductName.Text.Trim(); } if (txtDescription.Text != "") { entProduct.Description = txtDescription.Text.Trim(); } if (txtPrice.Text != "") { entProduct.Price = Convert.ToInt32(txtPrice.Text.Trim()); } #region Upload File if (fuProductImage.HasFile) { string strPath = "~/ProductImage/"; if (ddlCategoryID.SelectedItem.ToString() == "Calendar") { strPath += "Calendar/"; } if (ddlCategoryID.SelectedItem.ToString() == "T-shirt") { strPath += "T-shirt/"; } if (ddlCategoryID.SelectedItem.ToString() == "Canvas") { strPath += "Canvas/"; } string strPhysicalPath = Server.MapPath(strPath) + fuProductImage.FileName; fuProductImage.SaveAs(strPhysicalPath); entProduct.ProductImage = strPath + fuProductImage.FileName; } else { lblMessage.Text = "Select File"; divMessage.Visible = true; } #endregion Upload File #endregion Collect FormData ProductBAL balProduct = new ProductBAL(); if (Request.QueryString["ProductID"] == null) { if (balProduct.Insert(entProduct)) { ClearControls(); lblMessage.Text = "Add Successfully"; divMessage.Visible = true; } else { lblMessage.Text = balProduct.Message; divMessage.Visible = true; } } else { entProduct.ProductID = Convert.ToInt32(Request.QueryString["ProductID"]); if (balProduct.Update(entProduct)) { ClearControls(); Response.Redirect("~/AdminPanel/Product/ProductList.aspx"); } else { lblMessage.Text = balProduct.Message; divMessage.Visible = true; } } }