private bool CheckExists(string code, int?id, int?companyId, bool isName) { try { T_Product obj = null; if (!isName) { obj = db.T_Product.FirstOrDefault(x => !x.IsDeleted && x.CompanyId == companyId && x.Code.Trim().ToUpper().Equals(code) && x.Id != id); } else { obj = db.T_Product.FirstOrDefault(x => !x.IsDeleted && x.CompanyId == companyId && x.Name.Trim().ToUpper().Equals(code) && x.Id != id); } if (obj == null) { return(false); } return(true); } catch (Exception ex) { throw ex; } }
protected override void FormLoad() { CRMServiceClient client = new CRMServiceClient(); var customerlst = client.getCustomerList(); foreach (var customer in customerlst) { cmb_cst.Properties.Items.Add(customer.customername); } cmb_cst.Properties.Tag = customerlst; if (formmode == frmmodetype.edit) { m_product = client.getProductbyId(m_pid); setData(); List<T_Crafts> craftlst = new List<T_Crafts>(client.getProductCraft(m_pid)); gccraft.DataSource = craftlst; } else if (formmode == frmmodetype.delete) { m_product = client.getProductbyId(m_pid); setData(); List<T_Crafts> craftlst = new List<T_Crafts>(client.getProductCraft(m_pid)); gccraft.DataSource = craftlst; } }
protected override void FormLoad() { var customerlst = m_client.getCustomerList(); foreach (var customer in customerlst) { cmb_cst.Properties.Items.Add(customer.customername); } cmb_cst.Properties.Tag = customerlst; if (formmode == frmmodetype.edit) { m_product = m_client.getProductbyId(m_pid); setData(); List <T_Crafts> craftlst = m_client.getProductCraft(m_pid); gccraft.DataSource = craftlst; } else if (formmode == frmmodetype.delete) { m_product = m_client.getProductbyId(m_pid); setData(); List <T_Crafts> craftlst = m_client.getProductCraft(m_pid); gccraft.DataSource = craftlst; } base.FormLoad(); }
public ActionResult DisableForm(string F_Id) { T_Product t_Product = ProductBLL.GetForm(F_Id); t_Product.F_Enable_Mark = 0; ProductBLL.SubmitForm(t_Product); return(Success("操作成功")); }
protected override void AddObject() { m_product = new T_Product(); getData(); m_client.AddNewProduct(m_product); saveCraft(); base.AddObject(); }
public bool AddNewProduct(T_Product product) { using (MEMSContext db = new MEMSContext()) { db.T_Product.Add(product); return(db.SaveChanges() > 0 ? true : false); } }
protected override void AddObject() { CRMServiceClient client = new CRMServiceClient(); m_product = new T_Product(); getData(); client.AddNewProduct(m_product); base.AddObject(); }
public bool UpdateProduct(T_Product product) { using (MEMSContext db = new MEMSContext()) { db.Entry(product).State = EntityState.Modified; return(db.SaveChanges() > 0 ? true : false); } }
bool checkPermis(T_Product obj, int actionUser, bool isOwner) { if (isOwner) { return(true); } return(obj.CreatedUser == actionUser); }
public async Task <object> SaveProduct(T_Product model) { object data = await T_Customer_BLL.SaveProduct(model); return(Ok(new { statusCode = 200, result = data })); }
public bool UpdateProduct(T_Product product) { try { ph = new ProductHelper(); return(ph.UpdateProduct(product)); } catch (Exception ex) { throw ex; } }
public void AddTest() { T_Product model = new T_Product { Name = "aaaa", Manufactor = "qwe", Mobile = "12345678901", FK_Variety = Guid.Parse("012FA116-F518-4CF4-91B9-EF5200C3388A"), Region = "asd", Remark = "" }; _bll.Add(model); }
public ActionResult AddProduct(T_Product product, HttpPostedFileBase file) { string picture = null; if (file != null) { picture = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/ProductImages/"), picture); file.SaveAs(path); } product.ProductImage = picture; product.CreatedDate = DateTime.Now; _unitywrok.GetRepositoryInstance <T_Product>().Add(product); return(RedirectToAction("Product")); }
public ActionResult UpdateData(HttpPostedFileBase file) { DataTable dataTable = ExcelHelper.ImportToDataTable(file.InputStream); List <T_Product> list = new List <T_Product>(); foreach (DataRow dr in dataTable.Rows) { T_Product t_Product = new T_Product(); t_Product.F_Name = dr["名称"].ToString().Trim(); t_Product.F_Code = dr["编码"].ToString().Trim(); t_Product.F_Spec = dr["规格"].ToString().Trim(); t_Product.F_Unit = dr["单位"].ToString().Trim(); t_Product.F_Enable_Mark = 1; list.Add(t_Product); } ProductBLL.InsertFormBatch(list); return(Success("操作成功")); }
public ActionResult EditProduct(T_Product product, HttpPostedFileBase file) { string picture = null; if (file != null) { picture = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/ProductImages/"), picture); file.SaveAs(path); } product.ProductImage = file != null ? picture : product.ProductImage; //if we want to this file Dont to change soo above line to be used as rafered same code in EditProuct to Starting method product.ModifiedDate = DateTime.Now; _unitywrok.GetRepositoryInstance <T_Product>().Update(product); return(RedirectToAction("Product")); }
public static List <T_Product> convertToProduct(List <ProductModel> pmList) { List <T_Product> productList = new List <T_Product>(); foreach (ProductModel pm in pmList) { T_Product newProduct = new T_Product(); newProduct.id = pm.id; newProduct.companyName = pm.companyName; newProduct.name = pm.name; newProduct.price = pm.price; newProduct.date = pm.date; newProduct.discount = pm.discount; newProduct.keyword = pm.keyword; productList.Add(newProduct); } return(productList); }
public bool UpdateData(string F_Id, DataTable totalTable) { DataTable bomTable = new DataTable(); bomTable.Columns.Add("零件编码", typeof(System.String)); bomTable.Columns.Add("零件数量", typeof(System.Int32)); List <T_Product> productList = new ProductBLL().GetList(); List <T_Part> partList = new PartBLL().GetList(); T_Product t_product = new T_Product(); //判断产品,添加产品 if (productList.Where(x => x.F_Name == totalTable.Rows[1]["Column2"].ToString()).ToList().Count == 0) { if (productList.Where(x => x.F_Code == totalTable.Rows[2]["Column2"].ToString()).ToList().Count == 0) { //添加产品 try { if (!string.IsNullOrEmpty(totalTable.Rows[1]["Column2"].ToString())) { t_product.F_Name = totalTable.Rows[1]["Column2"].ToString(); } else { throw new Exception("产品名称不能为空,请检查"); } } catch (Exception) { throw new Exception("产品名称异常,请检查"); } try { if (!string.IsNullOrEmpty(totalTable.Rows[2]["Column2"].ToString())) { t_product.F_Code = totalTable.Rows[2]["Column2"].ToString(); } else { throw new Exception("产品编码不能为空,请检查"); } } catch (Exception) { throw new Exception("产品编码异常,请检查"); } t_product.F_Create_By = ManageProvider.Provider.Current().User.F_Account; t_product.F_Create_Time = DateTime.Now; } else { throw new Exception("产品编码重复,请检查"); } } //添加零件,分解出bom详情table for (int i = 5; i < totalTable.Rows.Count; i++) { DataRow dr = bomTable.NewRow(); try { if (!string.IsNullOrEmpty(totalTable.Rows[i]["Column2"].ToString())) { if (partList.Select(x => x.F_Code.PadRight(12, '0') == totalTable.Rows[i]["Column2"].ToString().PadRight(12, '0')).ToList().Count > 0) { dr["零件编码"] = totalTable.Rows[i]["Column2"].ToString().PadRight(12, '0'); } else { throw new Exception("数据源第" + Convert.ToInt32(i + 2) + "行零件编码不存在,请检查"); } } else { throw new Exception("数据源第" + Convert.ToInt32(i + 2) + "行零件编码为空,请检查"); } } catch (Exception) { throw new Exception("数据源第" + Convert.ToInt32(i + 2) + "行零件编码异常,请检查"); } try { if (!string.IsNullOrEmpty(totalTable.Rows[i]["Column5"].ToString())) { dr["零件数量"] = int.Parse(totalTable.Rows[i]["Column5"].ToString()); } else { throw new Exception("数据源第" + Convert.ToInt32(i + 2) + "行零件数量为空,请检查"); } } catch (Exception) { throw new Exception("数据源第" + Convert.ToInt32(i + 2) + "行零件数量异常,请检查"); } bomTable.Rows.Add(dr);//添加零件临时表 } List <T_Bom_Detail> insertBomDetailList = new List <T_Bom_Detail>(); var query = from t in bomTable.AsEnumerable() group t by new { t1 = t.Field <string>("零件编码") } into m select new { pob = m.Key.t1, rowcount = m.Count() }; int j = 0; foreach (var q in query) { j++; if (q.rowcount > 1) { throw new Exception("数据源第" + Convert.ToInt32(j + 6) + "行零件编码有重复,请检查"); } }//验证导入Excel是否存在重复编码 //int InsertId = new Repository<T_Bom_Detail>().FindCountBySql("SELECT ISNULL(MAX(F_ID), 0) + 1 FROM T_BOM_DETAIL"); for (int i = 0; i < bomTable.Rows.Count; i++) { T_Bom_Detail t_Bom_Detail = new T_Bom_Detail(); t_Bom_Detail.F_Num = int.Parse(bomTable.Rows[i]["零件数量"].ToString()); t_Bom_Detail.F_Part_Code = bomTable.Rows[i]["零件编码"].ToString(); t_Bom_Detail.F_Bom_Id = F_Id; t_Bom_Detail.F_Enable_Mark = 1; t_Bom_Detail.F_Create_Time = DateTime.Now; t_Bom_Detail.F_Create_By = ManageProvider.Provider.Current().User.F_Account; insertBomDetailList.Add(t_Bom_Detail); //InsertId++; } using (var isOpenTrans = new Repository <T_Bom_Detail>().BeginTrans()) { try { if (t_product.F_Code != null && t_product.F_Name != null) { new RepositoryFactory <T_Product>().SubmitForm(t_product, isOpenTrans); //添加产品 } new BomDetailBLL().Modify(F_Id, isOpenTrans); //修改详情 new BomDetailBLL().InsertFormBatch(insertBomDetailList, isOpenTrans); //批量插入bom详情 new Repository <T_Bom_Detail>().Commit(); return(true); } catch (Exception) { new Repository <T_Bom_Detail>().Rollback(); throw; } finally { new Repository <T_Bom_Detail>().Close(); } } }
public ActionResult SubmitForm(T_Product t_Product) { ProductBLL.SubmitForm(t_Product); return(Success("操作成功")); }
public ResponseBase InsertOrUpdate(ProductModel model) { try { using (db = new IEDEntities()) { var result = new ResponseBase(); if (CheckExists(model.Name.Trim().ToUpper(), model.Id, model.CompanyId, true)) { result.IsSuccess = false; result.Errors.Add(new Error() { MemberName = "Insert Product Type", Message = "Tên Sản Phẩm này đã tồn tại. Vui lòng chọn lại Tên khác !." }); return(result); } else { //if (!string.IsNullOrEmpty(model.Code)) //{ // if (CheckExists(model.Code.Trim().ToUpper(), model.Id, model.CompanyId , false)) // { // result.IsSuccess = false; // result.Errors.Add(new Error() { MemberName = "Insert Product Type", Message = "Mã Sản Phẩm này đã tồn tại. Vui lòng chọn lại Tên khác !." }); // return result; // } //} T_Product obj; if (model.Id == 0) { obj = new T_Product(); Parse.CopyObject(model, ref obj); obj.CreatedDate = DateTime.Now; obj.CreatedUser = model.ActionUser; db.T_Product.Add(obj); } else { obj = db.T_Product.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id); if (obj == null) { result.IsSuccess = false; result.Errors.Add(new Error() { MemberName = "Update Product Type", Message = "Loại Sản Phẩm bạn đang thao tác đã bị xóa hoặc không tồn tại. Vui lòng kiểm tra lại !." }); return(result); } else { obj.CompanyId = model.CompanyId; obj.Name = model.Name; obj.Code = model.Code; obj.CustomerId = model.CustomerId; obj.Description = model.Description; obj.UpdatedUser = model.ActionUser; obj.UpdatedDate = DateTime.Now; // cap nhat ben phan tich mat hang var commoAna = db.T_CommodityAnalysis.Where(x => !x.IsDeleted && x.ObjectId == obj.Id && x.ObjectType == (int)eObjectType.isCommodity); if (commoAna != null && commoAna.Count() > 0) { foreach (var item in commoAna) { item.Name = model.Name; item.UpdatedUser = model.ActionUser; item.UpdatedDate = DateTime.Now; } } } } db.SaveChanges(); result.IsSuccess = true; return(result); } } } catch (Exception ex) { throw ex; } }
public ResponseBase InsertOrUpdate(ProductModel model, bool isOwner) { try { using (db = new IEDEntities()) { var result = new ResponseBase(); if (CheckExists(model.Name.Trim().ToUpper(), model.Id, model.CompanyId, true)) { result.IsSuccess = false; result.Errors.Add(new Error() { MemberName = "Insert Product Type", Message = "Tên mã hàng này đã tồn tại. Vui lòng chọn lại Tên khác !." }); return(result); } else { T_Product obj; if (model.ProductGroupId == 0) { model.ProductGroupId = null; } if (model.Id == 0) { obj = new T_Product(); Parse.CopyObject(model, ref obj); obj.CreatedDate = DateTime.Now; obj.CreatedUser = model.ActionUser; db.T_Product.Add(obj); db.SaveChanges(); result.IsSuccess = true; } else { obj = db.T_Product.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id); if (obj == null) { result.IsSuccess = false; result.Errors.Add(new Error() { MemberName = "Update Product Type", Message = "Loại mã hàng bạn đang thao tác đã bị xóa hoặc không tồn tại. Vui lòng kiểm tra lại !." }); return(result); } else { if (!checkPermis(obj, model.ActionUser, isOwner)) { result.IsSuccess = false; result.Errors.Add(new Error() { MemberName = "update", Message = "Bạn không phải là người tạo mã hàng này nên bạn không cập nhật được thông tin cho mã hàng này." }); } else { obj.CompanyId = model.CompanyId; obj.Name = model.Name; obj.Code = model.Code; obj.CustomerId = model.CustomerId; obj.ProductGroupId = model.ProductGroupId; obj.Description = model.Description; obj.UpdatedUser = model.ActionUser; obj.UpdatedDate = DateTime.Now; // cap nhat ben phan tich mat hang var commoAna = db.T_CommodityAnalysis.Where(x => !x.IsDeleted && x.ObjectId == obj.Id && x.ObjectType == (int)eObjectType.isCommodity); if (commoAna != null && commoAna.Count() > 0) { foreach (var item in commoAna) { item.Name = model.Name; item.UpdatedUser = model.ActionUser; item.UpdatedDate = DateTime.Now; } } db.SaveChanges(); result.IsSuccess = true; } } } if (!string.IsNullOrEmpty(model.Img)) { List <T_ProductFile> files = JsonConvert.DeserializeObject <List <T_ProductFile> >(model.Img); if (files != null && files.Count > 0) { foreach (var file in files) { file.ProductId = obj.Id; file.CreatedDate = DateTime.Now; file.CreatedUser = model.ActionUser; db.T_ProductFile.Add(file); } db.SaveChanges(); } } return(result); } } } catch (Exception ex) { throw ex; } }