/// <summary> /// 载入数据 /// </summary> /// <param name="info">BEProductDataInfo结构</param> private void LoadProductData(ProductData data) { this.m_id = data.id; this.HuoHao = data.huohao; this.DengJi_Id = data.dengji_id; this.MadePlace_Id = data.madeplace_id; this.PartName_Id = data.partname_id; this.SafeData_Id = data.safedata_id; this.StandardData_Id = data.standarddata_id; this.m_price = data.price; this.m_memo = data.memo; this.m_pwash = data.pwash == 1 ? true : false; this.m_tag_id = data.tag_id; this.m_wash_id = data.wash_id; this.m_lastamp = data.lastamp; this.m_pbad = data.pbad == 1 ? true : false; this.m_ptemplate = data.ptemplate == 1 ? true : false; this.m_wash_u = data.wash_u; this.m_template_data = data.template_data; this.Color_Id = (int)data.color_id; this.m_gyear = data.gyear; this.m_gmonth = data.gmonth; //加载EAN13信息 using (ProductContext ctx = new ProductContext()) { var ean13_data = from mater in ctx.BarcodeInfo where mater.product_id == this.m_id orderby mater.size_name select mater; foreach(var obj in ean13_data) { EAN13DataInfo info = new EAN13DataInfo(); info.Id = obj.id; info.SizeName = obj.size_name; info.BarcodeType = obj.barcode; info.Memo = obj.memo; this.m_ean13_data_list.Add(info); } } using (ProductContext ctx = new ProductContext()) { //洗唛宽度 this.m_wash_size = (from product in ctx.ProductData where product.id == this.m_id select product.WashPrintTemplate.daxiao).FirstOrDefault(); //处理成份信息 var materialData_entity = from mater in ctx.MaterialData where mater.product_id == this.m_id orderby mater.order_index select mater; foreach(var obj in materialData_entity) { MaterialDataInfo info = new MaterialDataInfo(); info.Id = obj.id; info.Type = obj.type; info.Sel = obj.sel; info.Memo = obj.memo; this.m_material_data_list.Add(info); } /*******************************************************/ //处理填充信息 var fill_entity = from fill in ctx.MaterialFill where fill.product_id == this.m_id orderby fill.size_name select fill; foreach(var obj in fill_entity) { UpdataMaterialFillList(obj.size_name, obj.fill); } this.MaterialFillInfo.material_type = (from fill in ctx.MaterialFill where fill.product_id == this.m_id select fill.type).FirstOrDefault(); //处理打印模板信息 } this.m_tagCODE93_filename = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["Template"], GetTagFileName()); //this.m_wash_filename = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["Template"], GetWashFileName()); this.m_wash_filename = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["Template"],GetWashFileNameById(this.Wash_Id)); this.m_tagEAN13_filename = string.Format("{0}\\13{1}", ConfigurationManager.AppSettings["Template"], GetTagFileName()); }
/// <summary> /// 保存记录 /// </summary> /// <returns></returns> public SaveResult Save() { SaveResult result = new SaveResult(); //save new if(this.m_id == 0) { if(this.m_huohao.Trim() == string.Empty) { result.Code = CodeType.Error; result.Message = "[产品货号]不能为空或输入的不合法,无法保存!"; return result; } if (CheckProductHuoHaoExist(this.m_huohao.Trim())) { result.Code = CodeType.Error; result.Message = "[产品货号]重复,无法保存!"; return result; } if(this.m_partname_id == 0) { result.Code = CodeType.Error; result.Message = "[产品种类]不能为空,无法保存!"; return result; } if(this.m_dengji_id == 0) { result.Code = CodeType.Error; result.Message = "[产品等级]不能为空,无法保存!"; return result; } if(this.m_madeplace_id == 0) { result.Code = CodeType.Error; result.Message = "[产品产地]不能为空,无法保存!"; return result; } if(this.m_price == 0) { result.Code = CodeType.Error; result.Message = "[产品价格]不能为空,无法保存!"; return result; } if(this.m_safedata_id == 0) { result.Code = CodeType.Error; result.Message = "[安全标准]不能为空,无法保存!"; return result; } if(this.m_standarddata_id == 0) { result.Code = CodeType.Error; result.Message = "[执行标准]不能为空,无法保存!"; return result; } if(this.m_material_data_list.Count == 0) { result.Code = CodeType.Error; result.Message = "[面料成份信息列表]不能为空,无法保存!"; return result; } //当填充材质不为空时处理填充数据 if(!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData data in this.MaterialFillInfo.m_material_fill_list) { if(data.Fill == "0") { result.Code = CodeType.Error; result.Message = "填充规则数据制定不完整,请重新制定!"; return result; } } } ProductData info = new ProductData(); info.huohao = this.m_huohao; info.partname_id = this.m_partname_id; info.dengji_id = this.m_dengji_id; info.madeplace_id = this.m_madeplace_id; info.price = this.m_price; info.safedata_id = this.m_safedata_id; info.standarddata_id = this.m_standarddata_id; info.pwash = this.m_pwash == true ? 1:0; info.pbad = this.m_pbad == true ? 1:0; info.tag_id = this.GetTagFileNameId(); info.memo = this.m_memo; info.wash_id = this.GetWashFileNameId(); info.color_id = this.m_color_id; info.gyear = this.m_gyear; info.gmonth = this.m_gmonth; info.lastamp = System.Guid.NewGuid(); if(this.m_ptemplate) { info.ptemplate = 1; info.template_data = this.m_template_data; } if(info.tag_id == 0) { result.Code = CodeType.Error; result.Message = "系统未能找到对应的吊牌模板文件,保存无法继续!"; return result; } if(info.wash_id == 0) { if (this.m_partname_id == 21) info.wash_id = 1; else { result.Code = CodeType.Error; result.Message = "系统未能找到对应的洗唛模板文件,保存无法继续!"; return result; } } using (ProductContext ctx = new ProductContext()) { ctx.ProductData.Add(info); if(ctx.SaveChanges() == 0) { result.Code = CodeType.Error; result.Message = "产品基本信息保存失败"; return result; } } using (ProductContext ctx = new ProductContext()) { this.m_id = (from product in ctx.ProductData where product.huohao == this.m_huohao select product.id).FirstOrDefault(); } int index = 1; foreach(MaterialDataInfo ob in this.m_material_data_list) { using (ProductContext ctx = new ProductContext()) { MaterialData entity = new MaterialData(); entity.product_id = this.m_id; entity.sel = ob.Sel; entity.type = ob.Type; entity.order_index = index++; entity.memo = ob.Memo; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialData.Add(entity); ctx.SaveChanges(); } } if(!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData fill in this.MaterialFillInfo.m_material_fill_list) { using (ProductContext ctx = new ProductContext()) { MaterialFill entity = new MaterialFill(); entity.product_id = this.m_id; entity.size_name = fill.SizeName; entity.type = this.MaterialFillInfo.material_type; entity.fill = fill.Fill; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialFill.Add(entity); ctx.SaveChanges(); } } } result.Code = CodeType.Ok; result.Message = "保存成功!"; return result; } //Edit Save if(this.m_id > 0) { if (this.m_huohao.Trim() == string.Empty) { result.Code = CodeType.Error; result.Message = "[产品货号]不能为空或输入的不合法,无法保存!"; return result; } using (ProductContext ctx = new ProductContext()) { int count = (from product in ctx.ProductData where product.id == this.m_id && product.huohao == this.m_huohao select product).Count(); if(count > 1) { result.Code = CodeType.Error; result.Message = "[产品货号]重复,无法保存!"; return result; } } if (this.m_price == 0) { result.Code = CodeType.Error; result.Message = "[产品价格]不能为空,无法保存!"; return result; } if (this.m_safedata_id == 0) { result.Code = CodeType.Error; result.Message = "[安全标准]不能为空,无法保存!"; return result; } if (this.m_standarddata_id == 0) { result.Code = CodeType.Error; result.Message = "[执行标准]不能为空,无法保存!"; return result; } if (this.m_material_data_list.Count == 0) { result.Code = CodeType.Error; result.Message = "[面料成份信息列表]不能为空,无法保存!"; return result; } //当填充材质不为空时处理填充数据 if (!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData data in this.MaterialFillInfo.m_material_fill_list) { if(data.Fill == "0") { result.Code = CodeType.Error; result.Message = "填充规则数据制定不完整,请重新制定!"; return result; } } } using (ProductContext ctx = new ProductContext()) { System.Guid entity_lastamp = (from product in ctx.ProductData where product.id == this.m_id select product.lastamp).FirstOrDefault(); if(entity_lastamp != this.m_lastamp) { result.Code = CodeType.Error; result.Message = "当前编辑的记录已经变更,无法保存!"; return result; } } using (ProductContext ctx = new ProductContext()) { ProductData info = (from entity in ctx.ProductData where entity.id == this.m_id select entity).FirstOrDefault(); info.huohao = this.m_huohao; info.partname_id = this.m_partname_id; info.dengji_id = this.m_dengji_id; info.madeplace_id = this.m_madeplace_id; info.price = this.m_price; info.safedata_id = this.m_safedata_id; info.standarddata_id = this.m_standarddata_id; info.pwash = this.m_pwash == true ? 1:0; info.pbad = this.m_pbad == true ?1:0; info.memo = this.m_memo; info.tag_id = this.GetTagFileNameId(); info.wash_id = this.GetWashFileNameId(); info.color_id = this.m_color_id; info.gyear = this.m_gyear; info.gmonth = this.m_gmonth; info.lastamp = System.Guid.NewGuid(); if (this.m_ptemplate) { info.ptemplate = 1; info.template_data = this.m_template_data; } if (info.tag_id == 0) { result.Code = CodeType.Error; result.Message = "系统未能找到对应的吊牌模板文件,保存无法继续!"; return result; } if (info.wash_id == 0 ) { if(this.m_partname_id == 21) { info.wash_id = 1; } else { result.Code = CodeType.Error; result.Message = "系统未能找到对应的洗唛模板文件,保存无法继续!"; return result; } } if (ctx.SaveChanges() == 0) { result.Code = CodeType.Error; result.Message = "产品基本信息保存失败"; return result; } } //保存成份信息 using (ProductContext ctx = new ProductContext()) { var mi = from entity in ctx.MaterialData where entity.product_id == this.m_id select entity; foreach(var obj in mi) { ctx.MaterialData.Remove(obj); } ctx.SaveChanges(); } int index = 1; foreach (MaterialDataInfo ob in this.m_material_data_list) { using (ProductContext ctx = new ProductContext()) { MaterialData entity = new MaterialData(); entity.product_id = this.m_id; entity.sel = ob.Sel; entity.type = ob.Type; entity.order_index = index++; entity.memo = ob.Memo; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialData.Add(entity); ctx.SaveChanges(); } } //////////////////////////////////////////////////////// using (ProductContext ctx = new ProductContext()) { var mi = from entity in ctx.MaterialFill where entity.product_id == this.m_id select entity; foreach (var obj in mi) { ctx.MaterialFill.Remove(obj); } ctx.SaveChanges(); } if (!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach (MaterialFillInfoObject.MaterialFillData fill in this.MaterialFillInfo.m_material_fill_list) { using (ProductContext ctx = new ProductContext()) { MaterialFill entity = new MaterialFill(); entity.product_id = this.m_id; entity.size_name = fill.SizeName; entity.type = this.MaterialFillInfo.material_type; entity.fill = fill.Fill; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialFill.Add(entity); ctx.SaveChanges(); } } } result.Code = CodeType.Ok; result.Message = "保存成功!"; return result; } return result; }