private void Submit(bool isActive = true) { var product = new Product(); var productTypeObject = new ProductType { Id = productType.Where(x => x.Name.Equals(cmbCategory.Text)).Select(x => x.Id).FirstOrDefault() }; var user = new User { Id = 1 }; // TO DO : implement user audit product.Id = selectedProductId; product.Name = txtName.Text; product.ProductType = productTypeObject; product.Description = txtDescription.Text; product.Rate = string.IsNullOrEmpty(txtRate.Text) ? 0 : decimal.Parse(txtRate.Text); product.Qty = 0; // TO DO : implement based on ask product.Added_Date = DateTime.Now; product.Added_By = user; product.IsActive = isActive; var bLl = new ProductsBll(); bLl.SaveOrUpdate(product, db); ReloadForm(); }
public bool Update(ProductsBll p) { //create a boolean variable and set its initial value to false bool isSuccess = false; //Create SQL Connection for DAtabase SqlConnection conn = new SqlConnection(_myconnstrng); try { //SQL Query to Update Data in dAtabase String sql = "UPDATE tbl_products SET name=@name, category=@category, description=@description, rate=@rate, added_date=@added_date, added_by=@added_by WHERE id=@id"; //Create SQL Cmmand to pass the value to query SqlCommand cmd = new SqlCommand(sql, conn); //Passing the values using parameters and cmd cmd.Parameters.AddWithValue("@name", p.Name); cmd.Parameters.AddWithValue("@category", p.Category); cmd.Parameters.AddWithValue("@description", p.Description); cmd.Parameters.AddWithValue("@rate", p.Rate); cmd.Parameters.AddWithValue("@qty", p.Qty); cmd.Parameters.AddWithValue("@added_date", p.AddedDate); cmd.Parameters.AddWithValue("@added_by", p.AddedBy); cmd.Parameters.AddWithValue("@id", p.Id); //Open the Database connection conn.Open(); //Create Int Variable to check if the query is executed successfully or not int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the value of rows will be greater than 0 else it will be less than zero if (rows > 0) { //Query ExecutedSuccessfully isSuccess = true; } else { //Failed to Execute Query isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
//还原 protected void Unnamed3_Click(object sender, EventArgs e) { //当前点击按钮,获取传过来的ID LinkButton lb = (LinkButton)sender; int id = BasePage.GetRequestId(lb.CommandArgument); bool b = new ProductsBll().Update1(datatable, "IsDel", "0", id.ToString()); if (b) { BasePage.JscriptPrint(Page, "还原成功!", "Products.aspx?ac=del&mid=" + mid + "&Tid=" + cid + "&language=" + Language); } }
public bool Insert(ProductsBll p) { //Creating Boolean Variable and set its default value to false bool isSuccess = false; //Sql Connection for DAtabase SqlConnection conn = new SqlConnection(_myconnstrng); try { //SQL Query to insert product into database String sql = "INSERT INTO tbl_products (name, category, description, rate, qty, added_date, added_by) VALUES (@name, @category, @description, @rate, @qty, @added_date, @added_by)"; //Creating SQL Command to pass the values SqlCommand cmd = new SqlCommand(sql, conn); //Passign the values through parameters cmd.Parameters.AddWithValue("@name", p.Name); cmd.Parameters.AddWithValue("@category", p.Category); cmd.Parameters.AddWithValue("@description", p.Description); cmd.Parameters.AddWithValue("@rate", p.Rate); cmd.Parameters.AddWithValue("@qty", p.Qty); cmd.Parameters.AddWithValue("@added_date", p.AddedDate); cmd.Parameters.AddWithValue("@added_by", p.AddedBy); //Opening the Database connection conn.Open(); int rows = cmd.ExecuteNonQuery(); //If the query is executed successfully then the value of rows will be greater than 0 else it will be less than 0 if (rows > 0) { //Query Executed Successfully isSuccess = true; } else { //FAiled to Execute Query isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
//放入回收站 protected void Unnamed1_Click(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; string delid = lb.CommandArgument; int id = BasePage.GetRequestId(delid); bool b = new ProductsBll().Update1(datatable, "IsDel", "1", id.ToString()); if (b) { BasePage.JscriptPrint(Page, "删除成功!", "Article.aspx?mid=" + mid + "&Tid=" + tid + "&language=" + Language); } }
public bool Delete(ProductsBll p) { //Create Boolean Variable and Set its default value to false bool isSuccess = false; //SQL Connection for DB connection SqlConnection conn = new SqlConnection(_myconnstrng); try { //Write Query Product from DAtabase String sql = "DELETE FROM tbl_products WHERE id=@id"; //Sql Command to Pass the Value SqlCommand cmd = new SqlCommand(sql, conn); //Passing the values using cmd cmd.Parameters.AddWithValue("@id", p.Id); //Open Database Connection conn.Open(); int rows = cmd.ExecuteNonQuery(); //If the query is executed successfullly then the value of rows will be greated than 0 else it will be less than 0 if (rows > 0) { //Query Executed Successfully isSuccess = true; } else { //Failed to Execute Query isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public ProductsBll GetProductsForTransaction(string keyword) { //Create an object of productsBLL and return it ProductsBll p = new ProductsBll(); //SqlConnection SqlConnection conn = new SqlConnection(_myconnstrng); //Datatable to store data temporarily DataTable dt = new DataTable(); try { //Write the Query to Get the detaisl string sql = "SELECT name, rate, qty FROM tbl_products WHERE id LIKE '%" + keyword + "%' OR name LIKE '%" + keyword + "%'"; //Create Sql Data Adapter to Execute the query SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); //Open DAtabase Connection conn.Open(); //Pass the value from adapter to dt adapter.Fill(dt); //If we have any values on dt then set the values to productsBLL if (dt.Rows.Count > 0) { p.Name = dt.Rows[0]["name"].ToString(); p.Rate = decimal.Parse(dt.Rows[0]["rate"].ToString()); p.Qty = decimal.Parse(dt.Rows[0]["qty"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Close Database Connection conn.Close(); } return(p); }
//刷新 protected void Unnamed4_Click(object sender, EventArgs e) { //当前点击按钮,获取传过来的ID LinkButton lb = (LinkButton)sender; int id = BasePage.GetRequestId(lb.CommandArgument); bool b = new ProductsBll().Updatezd(datatable, "EditDate='" + BasePage.formatDateTime(DateTime.Now.ToString()) + "'", id); Response.Write(DateTime.Now); if (Request.UrlReferrer != null) { ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); } if (b) { BasePage.JscriptPrint(Page, "刷新成功!", ViewState["UrlReferrer"].ToString()); } }
public ProductsBll GetProductIdFromName(string productName) { //First Create an Object of DeaCust BLL and REturn it ProductsBll p = new ProductsBll(); //SQL Conection here SqlConnection conn = new SqlConnection(_myconnstrng); //Data TAble to Holdthe data temporarily DataTable dt = new DataTable(); try { //SQL Query to Get id based on Name string sql = "SELECT id FROM tbl_products WHERE name='" + productName + "'"; //Create the SQL Data Adapter to Execute the Query SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); conn.Open(); //Passing the CAlue from Adapter to DAtatable adapter.Fill(dt); if (dt.Rows.Count > 0) { //Pass the value from dt to DeaCustBLL dc p.Id = int.Parse(dt.Rows[0]["id"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(p); }
public ActionResult AddProduct(Product model, HttpPostedFileBase ProductPic) { int id; if (!ModelState.IsValid) { using (var db = new ElectroSterkDbContext()) { model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); return(View(model)); } } using (var db = new ElectroSterkDbContext()) { if (db.Products.Any(x => x.Name == model.Name)) { model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); ModelState.AddModelError("", "This product is already exist"); return(View(model)); } } using (var db = new ElectroSterkDbContext()) { var category = db.Categories.FirstOrDefault(x => x.Id == model.CategoryId); var newProduct = new Product() { Name = model.Name, Description = model.Description, Price = model.Price, CategoryId = model.CategoryId, CategoryName = category.Name }; ProductsBll.Add(newProduct); id = newProduct.Id; } TempData["Msg"] = "The product has been aded"; var mainDir = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\"))); var tempPath1 = Path.Combine(mainDir.ToString(), "Products"); var tempPath2 = Path.Combine(mainDir.ToString(), "Products\\" + id.ToString()); var tempPath3 = Path.Combine(mainDir.ToString(), "Products\\" + id.ToString() + "\\Thumbs"); var tempPath4 = Path.Combine(mainDir.ToString(), "Products\\" + id.ToString() + "\\Gallery"); var tempPath5 = Path.Combine(mainDir.ToString(), "Products\\" + id.ToString() + "\\Gallery\\Thumbs"); if (!Directory.Exists(tempPath1)) { Directory.CreateDirectory(tempPath1); } if (!Directory.Exists(tempPath2)) { Directory.CreateDirectory(tempPath2); } if (!Directory.Exists(tempPath3)) { Directory.CreateDirectory(tempPath3); } if (!Directory.Exists(tempPath4)) { Directory.CreateDirectory(tempPath4); } if (!Directory.Exists(tempPath5)) { Directory.CreateDirectory(tempPath5); } if (ProductPic != null && ProductPic.ContentLength > 0) { var ext = ProductPic.ContentType.ToLower(); if (ext != "image/jpg" && ext != "image/jpeg" && ext != "image/gif" && ext != "image/pjpeg" && ext != "image/x-png" && ext != "image/png") { using (var db = new ElectroSterkDbContext()) { model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); ModelState.AddModelError("", "Invalid Image!"); return(View(model)); } } var image = ProductPic.FileName; using (var db = new ElectroSterkDbContext()) { var productForChangeName = db.Products.FirstOrDefault(x => x.Id == id); productForChangeName.ImageName = image; db.SaveChanges(); } var path = string.Format("{0}\\{1}", tempPath2, image); var path1 = string.Format("{0}\\{1}", tempPath3, image); ProductPic.SaveAs(path); WebImage img = new WebImage(ProductPic.InputStream); img.Resize(200, 200); img.Save(path1); } return(RedirectToAction("AddProduct")); }
public ActionResult AddProduct() { return(View(ProductsBll.Get())); }
//添加修改 protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Request.Form["txtTid"]) || string.IsNullOrEmpty(txtTitle.Text)) { BasePage.Alertback("标题名称和所属栏目不能为空"); return; } ProductsModel pm = new ProductsModel(); pm.Languagen = int.Parse(Drlanguage.SelectedValue); pm.Title = txtTitle.Text.Trim(); int ctid = BasePage.GetRequestId(Request.Form["txtTid"]); pm.Tid = ctid; pm.PicUrl = txtPicUrl.Text; pm.BigPhoto = txtBigPhoto.Text; pm.Contents = txtcontents.Text; pm.Contents2 = txtcontents2.Text; pm.Contents3 = txtcontents3.Text; pm.IsRecommend = txtRecommend.Checked ? 1 : 0; pm.IsNew = txtNew.Checked ? 1 : 0; pm.IsPopular = txtPopular.Checked ? 1 : 0; pm.IsSpecial = txtIsSpecial.Checked ? "1" : "0"; if (!String.IsNullOrEmpty(txtAddDate.Text)) { pm.AddDate = DateTime.Parse(txtAddDate.Text); } else { pm.AddDate = DateTime.Now; } pm.Px = BasePage.GetRequestId(txtpx.Text); pm.Hits = BasePage.GetRequestId(txtHits.Text); if (!string.IsNullOrEmpty(txtPrice.Text)) { pm.Price = decimal.Parse(txtPrice.Text); } else { pm.Price = 0; } if (!String.IsNullOrEmpty(txtPriceMarket.Text)) { pm.PriceMarket = decimal.Parse(txtPriceMarket.Text); } else { pm.PriceMarket = 0; } pm.ProducerName = txtProducerName.Text; pm.ProModel = txtProModel.Text; pm.ProSpecificat = txtProSpecificat.Text; pm.Unit = txtUnit.Text; pm.TitleColor = colortxt.Value; if (!String.IsNullOrEmpty(txtTotalNum.Text)) { pm.TotalNum = int.Parse(txtTotalNum.Text); } else { pm.TotalNum = 0; } pm.Comment = BasePage.GetRequestId(ddlComment.SelectedValue); pm.Intro = txtIntro.Text; if (!String.IsNullOrEmpty(txtseotitle.Text.Trim())) { pm.SeoTitle = txtseotitle.Text; } else { pm.SeoTitle = txtTitle.Text; } pm.SeoKeyWord = txtKeyWord.Text; pm.SeoDescription = txtDescription.Text; pm.EditDate = DateTime.Now; pm.Inputer = Cookies.GetCookie("User_Name"); pm.FilesUrl = filesurl.Text; //if (BasePage.ArrayExist(Cookies.GetCookie("ModelPower"), "ms" + mid)) //{ // pm.Verific = 1; //} //else //{ // pm.Verific = 0; //} pm.Verific = 0; pm.ShopId = BasePage.GetRequestId(txtcompanyid.Value); pm.id = id; //扩展字段 string _sql = ""; int modeexists = new CommonBll().GetRecordCount("GL_ModelField", "FieldOnOff=0 and Modeid=" + mid); if (modeexists > 0) { string[] _atype = Request.Params.GetValues("hideFieldType"); //类型 string[] _atitle = Request.Params.GetValues("hideFieldTitle"); // string[] _bcontents = Request.Params.GetValues("txtFieldContent"); if (_atitle != null && _bcontents != null && _atype != null) { for (int i = 0; i < _atitle.Length; i++) { string vv = "'" + _bcontents[i] + "'"; if (_atype[i].ToString() == "1") { //数值 vv = _bcontents[i]; } if (String.IsNullOrEmpty(_sql)) { _sql += _atitle[i] + "=" + vv; } else { _sql += "," + _atitle[i] + "=" + vv; } } } } //将公司名存进cookies,方便下次添加 Cookies.SaveCookie("company", txtcompany.Text, 0); Cookies.SaveCookie("companyId", txtcompanyid.Value, 0); //更新相册 if (id == 0) { int i = new ProductsBll().Add(datatable, pm); if (i > 0) { //更新自定义 if (modeexists > 0) { bool bb = new ProductsBll().Updatezd(datatable, _sql, i); } UpateAlbum(i); BasePage.JscriptPrint(Page, "添加成功!" + txtcompanyid.Value, "Products.aspx?mid=" + mid + "&cid=" + ctid + "&language=" + BasePage.GetRequestId(Language)); } } else { bool b = new ProductsBll().Update(datatable, pm); if (b) { //更新自定义 if (modeexists > 0) { bool bb = new ProductsBll().Updatezd(datatable, _sql, id); } UpateAlbum(id); BasePage.JscriptPrint(Page, "修改成功!", hiddenbackurl.Value.ToString()); } } }
protected void GetData() { //绑定数据 if (id != 0) { ProductsModel pm = new ProductsBll().GetModel(datatable, id); //根据语言重新绑定栏目 // ClassTreeBind(0, "请选择所属类别", mid, this.txtTid, "ClassType=0 and Languagen=" + pm.Languagen); txtTid.Text = new ClassBll().GetClassSelect(0, "请选择所属类别", mid, "txtTid", "ClassType=0 and Languagen=" + pm.Languagen + "", pm.Tid.ToString(), "required input-control select-control"); txtTitle.Text = pm.Title; if (pm.IsRecommend == 1) { txtRecommend.Checked = true; } if (pm.IsPopular == 1) { txtPopular.Checked = true; } if (pm.IsNew == 1) { txtNew.Checked = true; } if (pm.IsSpecial == "1") { txtIsSpecial.Checked = true; } txtPicUrl.Text = pm.PicUrl; txtBigPhoto.Text = pm.BigPhoto; txtcontents.Text = pm.Contents; txtcontents2.Text = pm.Contents2; txtcontents3.Text = pm.Contents3; txtAddDate.Text = BasePage.formatDateTime(pm.AddDate.ToString()); txtpx.Text = pm.Px.ToString(); txtHits.Text = pm.Hits.ToString(); txtPrice.Text = pm.Price.ToString(); txtPriceMarket.Text = pm.PriceMarket.ToString(); txtProModel.Text = pm.ProModel; txtProSpecificat.Text = pm.ProSpecificat; txtProducerName.Text = pm.ProducerName; txtUnit.Text = pm.Unit; txtTotalNum.Text = pm.TotalNum.ToString(); ddlComment.SelectedValue = pm.Comment.ToString(); txtIntro.Text = pm.Intro; txtseotitle.Text = pm.SeoTitle; txtKeyWord.Text = pm.SeoKeyWord; txtDescription.Text = pm.SeoDescription; filesurl.Text = pm.FilesUrl; colortxt.Value = pm.TitleColor; Button1.Text = "确认修改"; Drlanguage.SelectedValue = pm.Languagen.ToString(); Drlanguage.Enabled = false; txtcompanyid.Value = pm.ShopId.ToString(); //将公司id转名称显示 txtcompany.Text = new CommonBll().GetTitle("gl_shop", "Company", BasePage.GetRequestId(pm.ShopId.ToString())); //相册 Repeater1.DataSource = new CommonBll().GetList("", "GL_Album", "ModelId=" + mid + " and ParentId=" + id, "id asc"); Repeater1.DataBind(); if (Request.UrlReferrer != null) { ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); hiddenbackurl.Value = ViewState["UrlReferrer"].ToString(); } } }
//批量 protected void Button3_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(articleid.Text)) { string allid = articleid.Text; string radiobutton = Request.Form["radiobutton"]; if (Request.UrlReferrer != null) { ViewState["UrlReferrer"] = Request.UrlReferrer.ToString(); } if (String.IsNullOrEmpty(radiobutton)) { BasePage.Alertback(Page, "请选择要批量处理的选项"); return; } // allid = allid.Substring(0, allid.Length - 1);//去掉最后一个, ProductsBll ArticleBll = new ProductsBll(); if (radiobutton == "1") { if (!String.IsNullOrEmpty(changclass.SelectedValue)) { bool b = ArticleBll.Update1(datatable, "Tid", changclass.SelectedValue, allid); if (b) { BasePage.JscriptPrint(Page, "批量处理成功!", ViewState["UrlReferrer"].ToString()); } } else { BasePage.Alertback(Page, "请选择要移动到的新栏目"); return; } } if (radiobutton == "2") { if (!String.IsNullOrEmpty(ddlsx.SelectedValue)) { string ddlsx1 = ddlsx.SelectedValue; bool b = false; if (ddlsx1 == "0")//设为推荐 { b = ArticleBll.Update1(datatable, "IsRecommend", "1", allid); } else if (ddlsx1 == "1") { b = ArticleBll.Update1(datatable, "IsRecommend", "0", allid); } else if (ddlsx1 == "2")//设为热卖 { b = ArticleBll.Update1(datatable, "IsPopular", "1", allid); } else if (ddlsx1 == "3") { b = ArticleBll.Update1(datatable, "IsPopular", "0", allid); } else if (ddlsx1 == "4")//设为最新 { b = ArticleBll.Update1(datatable, "IsNew", "1", allid); } else if (ddlsx1 == "5")//取消最新 { b = ArticleBll.Update1(datatable, "IsNew", "0", allid); } else if (ddlsx1 == "6")//设为特价 { b = ArticleBll.Update1(datatable, "IsSpecial", "1", allid); } else if (ddlsx1 == "7")//取消特价 { b = ArticleBll.Update1(datatable, "IsSpecial", "0", allid); } if (b) { BasePage.JscriptPrint(Page, "批量处理成功!", ViewState["UrlReferrer"].ToString()); return; } } else { BasePage.Alertback(Page, "请选择要操作的属性值"); return; } } if (radiobutton == "3") { //放入回收站 bool b = ArticleBll.Update1(datatable, "IsDel", "1", allid); if (b) { BasePage.JscriptPrint(Page, "成功放入回收站!", ViewState["UrlReferrer"].ToString()); } } if (radiobutton == "6") { if (!String.IsNullOrEmpty(txthits.Text.Trim())) { bool b = ArticleBll.Update1(datatable, "Hits", txthits.Text.Trim(), allid); if (b) { BasePage.JscriptPrint(Page, "批量操作成功!", ViewState["UrlReferrer"].ToString()); } } else { BasePage.Alertback(Page, "请输入浏览次数,且仅能为数字"); return; } } if (radiobutton == "7") { if (!String.IsNullOrEmpty(txteditdata.Text.Trim())) { bool b = ArticleBll.Update1(datatable, "EditDate", txteditdata.Text.Trim(), allid); if (b) { BasePage.JscriptPrint(Page, "批量操作成功!", ViewState["UrlReferrer"].ToString()); } } else { BasePage.Alertback(Page, "请输入最后修改时间"); return; } } if (radiobutton == "8") { bool b = new CommonBll().DeleteList(datatable, allid); if (b) { BasePage.JscriptPrint(Page, "彻底删除成功!", ViewState["UrlReferrer"].ToString()); } } } else { BasePage.Alertback(Page, "请先选择要操作的选项ID"); return; } }
public ProductsController() { ProductsBll = new ProductsBll(); }