public void SaveProduct() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.cateogries where d.CategoryName == ExistingCategoriesCombo.GetItemText(ExistingCategoriesCombo.SelectedItem) select new { CategoryID = d.CategoryID }).SingleOrDefault(); string productname; string productdescription; if (ProductNameField.Text.Length > 0) { productname = ProductNameField.Text; productdescription = ProductDescriptionField.Text; Model.product p = new Model.product(); p.ProductName = ProductNameField.Text; p.ProductDescription = productdescription; p.CategoryID = query.CategoryID; p.ImageFileName = Path.GetFileName(filename); p.Barcode = SetBarcodeField.Text; db.products.Add(p); db.SaveChanges(); MessageBox.Show("New Product '" + productname + "' has been added in the system."); clearFields(); } else { } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update gm_dt_product_type set "); strSql.Append("name=@name,"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.add_time; parameters[2].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into gm_dt_product_type("); strSql.Append("name,add_time)"); strSql.Append(" values ("); strSql.Append("@name,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.name; parameters[1].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private bool DoEdit(int _id) { try { BLL.product bll = new BLL.product(); Model.product model = bll.GetModel(_id); model.title = txtTitle.Text; model.category = Convert.ToInt32(ddlCategoryId.SelectedValue); model.sort = Convert.ToInt32(txtSort.Text); model.city = txtCity.Text; model.lat = txtLat.Text; model.lon = txtLon.Text; model.addr = txtAddr.Text; model.cont = txtCont.Text; model.add_time = Convert.ToDateTime(txtAddTime.Text); model.pass_time = Convert.ToDateTime(txtPassTime.Text); if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改产品信息:" + model.title); //记录日志 return(true); } } catch { return(false); } return(false); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">Model.product</param> /// <returns>True or False</returns> public bool Update(Model.product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [" + databaseprefix + "product] set "); strSql.Append("category=@category,"); strSql.Append("title=@title,"); strSql.Append("img=@img,"); strSql.Append("cont=@cont,"); strSql.Append("lat=@lat,"); strSql.Append("lon=@lon,"); strSql.Append("city=@city,"); strSql.Append("addr=@addr,"); strSql.Append("user_id=@user_id,"); strSql.Append("status=@status,"); strSql.Append("pass_time=@pass_time,"); strSql.Append("add_time=@add_time,"); strSql.Append("sort=@sort"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@category", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@img", SqlDbType.NVarChar, 200), new SqlParameter("@cont", SqlDbType.NText), new SqlParameter("@lat", SqlDbType.NVarChar, 30), new SqlParameter("@lon", SqlDbType.NVarChar, 30), new SqlParameter("@city", SqlDbType.NVarChar, 50), new SqlParameter("@addr", SqlDbType.NVarChar, 200), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@pass_time", SqlDbType.DateTime), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@sort", SqlDbType.Int), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.category; parameters[1].Value = model.title; parameters[2].Value = model.img; parameters[3].Value = model.cont; parameters[4].Value = model.lat; parameters[5].Value = model.lon; parameters[6].Value = model.city; parameters[7].Value = model.addr; parameters[8].Value = model.user_id; parameters[9].Value = model.status; parameters[10].Value = model.pass_time; parameters[11].Value = model.add_time; parameters[12].Value = model.sort; parameters[13].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } return(false); }
public SqlDataReader readpro(Model.product myorder) { StringBuilder sql = new StringBuilder(); sql.Append("select * from product where _id=@id"); SqlParameter[] par = { new SqlParameter("@id", SqlDbType.Int, 4) }; par[0].Value = myorder.id; return(Common.DbHelperSQL.ExecuteReader(sql.ToString(), par)); }
// public DataSet drpo(Model.product aa) { StringBuilder sql = new StringBuilder(); sql.Append("select * from product where _id=@id"); SqlParameter[] par = { new SqlParameter("@id", SqlDbType.Int, 4) }; par[0].Value = aa.id; return(Common.DbHelperSQL.Query(sql.ToString(), par)); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">Model.product</param> /// <returns>ID</returns> public int Add(Model.product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [" + databaseprefix + "product]("); strSql.Append("category,title,img,cont,lat,lon,city,addr,user_id,status,pass_time,add_time,sort"); strSql.Append(") values("); strSql.Append("@category,@title,@img,@cont,@lat,@lon,@city,@addr,@user_id,@status,@pass_time,@add_time,@sort)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@category", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@img", SqlDbType.NVarChar, 200), new SqlParameter("@cont", SqlDbType.NText), new SqlParameter("@lat", SqlDbType.NVarChar, 30), new SqlParameter("@lon", SqlDbType.NVarChar, 30), new SqlParameter("@city", SqlDbType.NVarChar, 50), new SqlParameter("@addr", SqlDbType.NVarChar, 200), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@pass_time", SqlDbType.DateTime), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@sort", SqlDbType.Int, 4) }; parameters[0].Value = model.category; parameters[1].Value = model.title; parameters[2].Value = model.img; parameters[3].Value = model.cont; parameters[4].Value = model.lat; parameters[5].Value = model.lon; parameters[6].Value = model.city; parameters[7].Value = model.addr; parameters[8].Value = model.user_id; parameters[9].Value = model.status; parameters[10].Value = model.pass_time; parameters[11].Value = model.add_time; parameters[12].Value = model.sort; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (null != obj) { return(Convert.ToInt32(obj)); } else { return(0); } }
private bool DoEdit(int _id) { bool result = true; BLL.product bll = new BLL.product(); Model.product model = bll.GetModel(_id); model.name = txtName.Text.Trim(); if (!bll.Update(model)) { result = false; } return(result); }
private bool DoAdd() { bool result = true; Model.product model = new Model.product(); BLL.product bll = new BLL.product(); model.name = txtName.Text.Trim(); model.add_time = DateTime.Now; if (bll.Add(model) < 1) { result = false; } return(result); }
public int Insert(Model.product mym) { StringBuilder sql = new StringBuilder(); sql.Append("insert into product"); sql.Append(" values ("); sql.Append("@title,@cateid,@marketprice,@localprice,@content,@posttime,@weight,@ischeap,@isrecommend,@top,@procount,@imageid"); sql.Append(")"); SqlParameter[] par = { new SqlParameter("@title", SqlDbType.VarChar, 50), new SqlParameter("@cateid", SqlDbType.Int, 4), new SqlParameter("@marketprice", SqlDbType.Money, 32), new SqlParameter("@localprice", SqlDbType.Money, 32), new SqlParameter("@content", SqlDbType.VarChar, 0), new SqlParameter("@posttime", SqlDbType.VarChar, 50), new SqlParameter("@weight", SqlDbType.VarChar, 50), new SqlParameter("@ischeap", SqlDbType.Int, 4), new SqlParameter("@isrecommend", SqlDbType.Int, 4), new SqlParameter("@top", SqlDbType.Int, 4), new SqlParameter("@procount", SqlDbType.Int, 5), new SqlParameter("@imageid", SqlDbType.VarChar, 50), }; par[0].Value = mym.title; par[1].Value = mym.cateid; par[2].Value = mym.marketprice; par[3].Value = mym.localprice; par[4].Value = mym.content; par[5].Value = mym.posttime; par[6].Value = mym.weight; par[7].Value = mym.ischeap; par[8].Value = mym.isrecomment; par[9].Value = mym.top; par[10].Value = mym.procount; par[11].Value = mym.imageid; return(Common.DbHelperSQL.ExecuteSql(sql.ToString(), par)); }
public string select_imageid(Model.product mym) { StringBuilder sql = new StringBuilder(); sql.Append(" select _imageid from product "); sql.Append(" where product._id=@id "); SqlParameter[] par = { new SqlParameter("@id", SqlDbType.Int, 4) }; par[0].Value = mym.id; return((string)Common.DbHelperSQL.GetSingle(sql.ToString(), par)); }
public int delete_id(Model.product mym) { StringBuilder sql = new StringBuilder(); sql.Append(" delete from product "); sql.Append(" where _id=@id "); SqlParameter[] par = { new SqlParameter("@id", SqlDbType.Int, 4) }; par[0].Value = mym.id; return(Common.DbHelperSQL.ExecuteSql(sql.ToString(), par)); }
/// <summary> /// Call to Shopify api for get one product details based on product id. /// </summary> /// <param name="apiKey">pass apiKey used login in Shopify main portal</param> /// <param name="password">password used login in Shopify main portal</param> /// <param name="storeUrl">pass storeUrl created for the store Shopify main portal</param> /// <returns>Return a product based on product id, available on Shopify</returns> public static TrekWoAProductsPortal.Model.product GetProduct(string apiKey, string password, string storeUrl, string fullUrl = null) { TrekWoAProductsPortal.Model.product product = null; try { dynamic shopifyProductSelected = new Shopify.Api(apiKey, password, storeUrl, fullUrl); var IsProductSelected = shopifyProductSelected.Products(); if (IsProductSelected != null) { product = new Model.product() { id = Convert.ToString(IsProductSelected.product.id), title = IsProductSelected.product.title }; } } catch (Exception ex) { } return(product); }
protected void Button1_Click(object sender, EventArgs e) { Tool.UpFile up = new UpFile(); Tool.UpFile t = new Tool.UpFile(); Model.product product = new Model.product() { product_name = Name.Text, product_intro = intro.Text, product_imageurl = up.upFileName(this.Img, "../img/product/"), product_content = content.Text, product_price = int.Parse(price.Text) }; _ = BackStages.Add <Model.product> .AddPro(product) > 0 ? Tool.Tool.Alert("True") : Tool.Tool.Alert("False"); try { Response.Redirect(Session["Web_Url"].ToString()); } catch (Exception exception) { Process p = new Process(); //设置要启动的应用程序 p.StartInfo.FileName = "cmd.exe"; p.StartInfo.RedirectStandardInput = true; //输出信息 p.StartInfo.RedirectStandardOutput = true; // 输出错误 p.StartInfo.RedirectStandardError = true; //不显示程序窗口 p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; //启动程序 p.Start(); p.StandardInput.WriteLine(exception); p.StandardInput.AutoFlush = true; Console.WriteLine(); Response.Redirect("product.aspx"); } }
/// <summary> /// 组合成对象实体 /// </summary> /// <param name="row">一行数据</param> /// <returns>Model.product</returns> private Model.product DataRowToModel(DataRow row) { Model.product model = new Model.product(); if (row != null) { if (null != row["id"] && "" != row["id"].ToString()) { model.id = int.Parse(row["id"].ToString()); } if (null != row["category"] && "" != row["category"].ToString()) { model.category = int.Parse(row["category"].ToString()); } if (null != row["title"]) { model.title = row["title"].ToString(); } if (null != row["img"]) { model.img = row["img"].ToString(); } if (null != row["cont"]) { model.cont = row["cont"].ToString(); } if (null != row["lat"]) { model.lat = row["lat"].ToString(); } if (null != row["lon"]) { model.lon = row["lon"].ToString(); } if (null != row["city"]) { model.city = row["city"].ToString(); } if (null != row["addr"]) { model.addr = row["addr"].ToString(); } if (null != row["user_id"] && "" != row["user_id"].ToString()) { model.user_id = int.Parse(row["user_id"].ToString()); } if (null != row["status"] && "" != row["status"].ToString()) { model.status = int.Parse(row["status"].ToString()); } if (null != row["pass_time"] && "" != row["pass_time"].ToString()) { model.pass_time = DateTime.Parse(row["pass_time"].ToString()); } if (null != row["add_time"] && "" != row["add_time"].ToString()) { model.add_time = DateTime.Parse(row["add_time"].ToString()); } if (null != row["sort"] && "" != row["sort"].ToString()) { model.sort = int.Parse(row["sort"].ToString()); } } return(model); }
public int insert(Model.product mym) { DAL.product dal = new DAL.product(); return(dal.Insert(mym)); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">Model.product</param> /// <returns>True Or False</returns> public bool Update(Model.product model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">Model.product</param> /// <returns>ID</returns> public int Add(Model.product model) { return(dal.Add(model)); }
public int SaveProduct() { using (var db = new POSApplication.Model.posdbEntities()) { string selectedCategory = CategoryList.GetItemText(CategoryList.SelectedItem); string selectedSupplier = SuppliersList.GetItemText(SuppliersList.SelectedItem); string path = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = System.IO.Path.GetDirectoryName(path); if (selectedCategory.Length > 0) { var query = (from d in db.categories where d.CategoryName == selectedCategory select new { CategoryID = d.CategoryID }).SingleOrDefault(); var supp = (from d in db.suppliers where d.SupplierName == selectedSupplier select new { SupplierID = d.SupplierID }).SingleOrDefault(); if (ProductNameField.Text.Length > 0) { if (selectedProductName == null) { Model.product p = new Model.product(); p.ProductName = ProductNameField.Text; p.ProductDescription = ProductDescriptionField.Text; p.CategoryID = query.CategoryID; if (supp != null) { p.SupplierID = supp.SupplierID; } else { p.SupplierID = 0; } p.ImageFileName = Path.GetFileName(filename); p.Barcode = ProductBarcodeField.Text; p.WarrantyPeriodYears = WarrantyField.Text; p.GuaranteePeriodYears = GuaranteeField.Text; p.ProductCode = ProductCodeField.Text; p.ProductSize = SizeField.Text; p.ProductWeight = WeightField.Text; p.ProductColor = ColorField.Text; p.ProductWidth = WidthField.Text; p.ProductHeight = HeightField.Text; db.products.Add(p); db.SaveChanges(); //adding the same product in inventory with sum quantity 0 /////////////////////////////////////////////////////////////////////////// var existprd = (from ep in db.products where ep.ProductName == p.ProductName && ep.CategoryID == p.CategoryID && ep.ProductCode == p.ProductCode select new { ProductID = ep.ProductID } ).SingleOrDefault(); if (existprd != null) { POSApplication.Model.inventory inv = new POSApplication.Model.inventory(); inv.ProductID = existprd.ProductID; inv.Quantity = 0; inv.PackingTypeID = 0; inv.PurchasePrice = 0; inv.SalePrice = 0; inv.PurchaseDate = null; inv.SaleDate = null; inv.CreateDt = DateTime.Now; inv.UpdateDt = null; inv.SumQuantity = 0; db.inventories.Add(inv); db.SaveChanges(); } /////////////////////////////////////////////////////////////////////////// if (filename != null) { string destfile = System.IO.Path.Combine(path + "\\images", filename); string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"); destfile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\" + Path.GetFileName(filename)); //MessageBox.Show(destfile); var dir = new System.IO.DirectoryInfo(ImagesDirectory); //foreach (var file in dir.EnumerateFiles(Path.GetFileNameWithoutExtension(filename))) //{ // file.Delete(); //} try { //File.Copy(filename.Replace("\\\\","\\"), destfile, true); File.Copy(filename, destfile, true); } catch (Exception e) { MessageBox.Show(e.ToString()); } //Model.AppConfig.imagefile = destfile; //FileStream fs = new FileStream(Model.AppConfig.imagefile, System.IO.FileMode.Open, System.IO.FileAccess.Read); //ProductImage.Image = Image.FromStream(fs); //fs.Close(); } MessageBox.Show("New Product '" + ProductNameField.Text + "' has been added in the system."); clearFields(); loadCategories(); return(1); } else { Model.product p = (from x in db.products where x.ProductName == selectedProductName select x).First(); p.ProductName = ProductNameField.Text; p.ProductDescription = ProductDescriptionField.Text; p.CategoryID = query.CategoryID; if (supp != null) { p.SupplierID = supp.SupplierID; } else { p.SupplierID = 0; } if (ProductImage.Image != null) { p.ImageFileName = Path.GetFileName(filename); } else { p.ImageFileName = null; } p.Barcode = ProductBarcodeField.Text; p.WarrantyPeriodYears = WarrantyField.Text; p.GuaranteePeriodYears = GuaranteeField.Text; p.ProductCode = ProductCodeField.Text; p.ProductSize = SizeField.Text; p.ProductWeight = WeightField.Text; p.ProductColor = ColorField.Text; p.ProductWidth = WidthField.Text; p.ProductHeight = HeightField.Text; db.SaveChanges(); if (filename != null) { string destfile = System.IO.Path.Combine(path + "\\images", filename); string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"); destfile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\" + Path.GetFileName(filename)); //MessageBox.Show(destfile); var dir = new System.IO.DirectoryInfo(ImagesDirectory); //foreach (var file in dir.EnumerateFiles(Path.GetFileNameWithoutExtension(filename))) //{ // file.Delete(); //} try { //File.Copy(filename.Replace("\\\\","\\"), destfile, true); File.Copy(filename, destfile, true); } catch (Exception e) { MessageBox.Show(e.ToString()); } //Model.AppConfig.imagefile = destfile; //FileStream fs = new FileStream(Model.AppConfig.imagefile, System.IO.FileMode.Open, System.IO.FileAccess.Read); //ProductImage.Image = Image.FromStream(fs); //fs.Close(); //return 1; } else { } MessageBox.Show("Product '" + selectedProductName + "' has been updated."); clearFields(); return(1); } } else { MessageBox.Show("Enter name for the new Product."); return(0); } } else { MessageBox.Show("Select a Category for the new Product."); return(0); } } }
public int update(Model.product mym) { string sql = "update product set _product_name='" + mym.title + "',_cateid=" + mym.cateid + ",_market_price='" + mym.marketprice + "',_local_price='" + mym.localprice + "',_describe='" + mym.content + "',_product_weight=" + mym.weight + ",_price_state=" + mym.ischeap + ",_special_offer=" + mym.isrecomment + ",_top=" + mym.top + ",_product_count=" + mym.procount + " where _id =" + mym.id + " "; return(Common.DbHelperSQL.ExecuteSql(sql)); }
public SqlDataReader drim(Model.product aa) { DAL.product dalpdd = new DAL.product(); return(dalpdd.drima(aa)); }
public DataSet select_title(Model.product mym) { string sql = "select * from product where _product_name like '%" + mym.title + "%'"; return(Common.DbHelperSQL.Query(sql)); }
// public DataSet drpo(Model.product aa) { DAL.product dalp = new DAL.product(); return(dalp.drpo(aa)); }
public SqlDataReader drpr(Model.product aa) { DAL.product dalps = new DAL.product(); return(dalps.drpr(aa)); }
public int update(Model.product mym) { DAL.product dal = new DAL.product(); return(dal.update(mym)); }
public string select_imageid(Model.product mym) { DAL.product dal = new DAL.product(); return(dal.select_imageid(mym)); }
public DataSet select_title(Model.product mym) { DAL.product dal = new DAL.product(); return(dal.select_title(mym)); }
public int delete_id(Model.product mym) { DAL.product dal = new DAL.product(); return(dal.delete_id(mym)); }
private void ShowInfo(int _id) { BLL.product bll = new BLL.product(); Model.product model = bll.GetModel(_id); txtName.Text = model.name; }