/// <summary> /// 修改原材料信息 /// </summary> /// <param name="request">请求</param> /// <returns></returns> public ResultJson EditMaterialInfo(EditMaterialRequest request) { ResultJson result = new ResultJson(); #region 判断销售信息是否完整 List <SalesInfo> SalesList = new List <SalesInfo>(); foreach (var item in request.SalesList) { if (item.ShopQuantity != "" && item.ChinaPrice != "" && item.ChinaDiscountRate != "" && item.DollarPrice != "" && item.DollarDiscountRate != "") { SalesList.Add(item); } } request.SalesList = SalesList; if (request.SalesList.Count == 0) { result.HttpCode = 300; result.Message = "请至少输入一条完整销售信息"; return(result); } #endregion #region 判断印刷信息是否完整 List <PrintDetailInfo> PrintList = new List <PrintDetailInfo>(); foreach (var item in request.PrintList) { if (item.MaximumArea != "" && item.PositionDescription != "" && item.PrintableColor != "" && item.PrintFunc != "" && item.PrintingPosition != "" && item.PrintingProcess != "" && item.PrintingProcess != "-1") { PrintList.Add(item); } } request.PrintList = PrintList; //if (request.PrintList.Count == 0) //{ // result.HttpCode = 300; // result.Message = "至少有一条完整印刷信息"; // return result; //} #endregion #region 产品 var producerCount = request.producer.Select(p => p.ProdecerCode).Distinct().ToList().Count; if (producerCount != request.producer.Count) { result.HttpCode = 300; result.Message = "颜色请不要重复"; return(result); } #endregion #region 颜色图片 var ColorCount = request.ColorList.Select(p => p.ColorID).Distinct().ToList().Count; if (ColorCount != request.ColorList.Count) { result.HttpCode = 300; result.Message = "颜色请不要重复"; return(result); } foreach (var item in request.ColorList) { item.SKUImage = item.SKUImage.Replace(AdminUrl, ""); if (item.SKUImage != null && item.SKUImage.Contains("temp")) { if (item.SKUImage.Contains("temp")) { FileHelper.Instance.Move(FileUrl + item.SKUImage, FileUrl + $"/current/images/Material/" + item.SKUImage.Split('/').Last(), FileUrl + $"/current/images/Material/"); item.SKUImage = $"/current/images/Material/{item.SKUImage.Split('/').Last()}"; } } item.PrintInfo = ""; foreach (var PrintItem in item.Print) { PrintItem.ColorInfo_Diagram = PrintItem.ColorInfo_Diagram.Replace(AdminUrl, ""); if (PrintItem.ColorInfo_Diagram != null && PrintItem.ColorInfo_Diagram.Contains("temp")) { if (PrintItem.ColorInfo_Diagram.Contains("temp")) { FileHelper.Instance.Move(FileUrl + PrintItem.ColorInfo_Diagram, FileUrl + $"/current/images/Material/" + PrintItem.ColorInfo_Diagram.Split('/').Last(), FileUrl + $"/current/images/Material/"); PrintItem.ColorInfo_Diagram = $"/current/images/Material/{PrintItem.ColorInfo_Diagram.Split('/').Last()}"; } } item.PrintInfo = $"{item.PrintInfo}{PrintItem.Print},{PrintItem.PositionDescrip},{PrintItem.ColorInfo_Diagram}|"; } } #endregion if (Raw_MaterialsFunc.Instance.UpdateMateroalsInfo(request)) { ColorinfoFunc.Instance.ReSetList(); CommodityFunc.Instance.ReGetAllCommList(); result.HttpCode = 200; result.Message = "更新成功!"; return(result); } else { result.HttpCode = 300; result.Message = "程序出现个小问题,请重新操作!"; return(result); } }
/// <summary> /// 更新原材料信息 /// </summary> /// <param name="request"></param> /// <returns></returns> public bool UpdateMateroalsInfo(EditMaterialRequest request) { var MysqlHelper = SqlHelper.GetMySqlHelper("transaction"); var connection = MysqlHelper.CreatConn(); var transaction = MysqlHelper.GetTransaction(); try { #region 更新原材料信息 var SalesInfoList = ""; var Key = request.MaterialId; foreach (var item in request.SalesList) { SalesInfoList = SalesInfoList + "|" + item.ShopQuantity + "|" + item.ChinaPrice + "|" + item.ChinaDiscountRate + "|" + item.DollarPrice + "|" + item.DollarDiscountRate + ";"; } var PrintInfoList = ""; for (int i = 1; i <= 3; i++) { var printdetailList = request.PrintList.Where(p => p.PrintFunc.ToLower() == $"printfunc{i}").ToList(); PrintInfoList = $"{PrintInfoList}PrintFunc{i}("; foreach (var item in printdetailList) { PrintInfoList = $"{PrintInfoList}{item.PrintingProcess},{item.PrintingPosition},{item.PositionDescription},{item.MaximumArea},{item.PrintableColor}|"; } PrintInfoList = $"{PrintInfoList})"; } Raw_Materials materials = new Raw_Materials { Attributes = request.Attributes, ChinaProductName = request.ChinaProductName, ChinaUnit = request.ChinaUnit, Description = request.ChinaDescibe, ProductDesibe = request.ProductDesibe, DevePerson = request.DevePerson, DeveTime = request.DeveTime, EnglishProductName = request.EnglishProductName, EnglishUnit = request.EnglishUnit, Genera = request.Genera, HSCODE = request.HSCODE, Id = request.MaterialId, MatAndPro = request.MatAndPro, NetWeight = request.NetWeight, NumMiddleBoxes = request.NumMiddleBoxes, NumOuterBoxes = request.NumOuterBoxes, OuterBoxesHeight = request.OuterBoxesHeight, OuterBoxesLength = request.OuterBoxesLength, OuterBoxesVolume = request.OuterBoxesVolume, OuterBoxesWidth = request.OuterBoxesWidth, ProductNo = request.ProductNo, Specification = request.Specification, TaxRate = request.TaxRate, Weight = request.Weight, Subclass = request.Subclass, SalesInfoList = SalesInfoList, SyloonPatent = request.SyloonPatent, EngDescription = request.EngDescibe, TypeInfo = request.Attributes1 + "|" + request.Attributes2 + "|" + request.Attributes3 + "|" + request.Attributes4, PrintFuncInfo = "PrintFunc1:" + request.PrintFunc1 + "|" + "PrintFunc2:" + request.PrintFunc2 + "|" + "PrintFunc3:" + request.PrintFunc3 + "|", Printingdetail = PrintInfoList, PercentageInfo = "PrintFunc1:" + request.Percentage1 + "|" + "PrintFunc2:" + request.Percentage2 + "|" + "PrintFunc3:" + request.Percentage3 + "|", TipPercentInfo = "PrintFunc1:" + request.TipPercent1 + "|" + "PrintFunc2:" + request.TipPercent2 + "|" + "PrintFunc3:" + request.TipPercent3 + "|" }; #region 根据Id判断是插入还是新建 if (request.MaterialId == 0) { Key = Raw_MaterialsOper.Instance.InsertReturnKey(materials, connection, transaction); if (Key <= 0) { transaction.Rollback(); connection.Close(); return(false); } } else { if (!Raw_MaterialsOper.Instance.Update(materials, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } } #endregion #endregion #region 更新采购信息 #region 除原有信息 Materials_ProducerOper.Instance.DeleteModel(new Materials_Producer { MaterialsId = Key }, connection, transaction); #endregion #region 遍历插入 foreach (var item in request.producer) { Materials_Producer producer = new Materials_Producer { MaterialsId = Key, MinQuantity = item.MinQuantity, ProCycle = item.ProCycle, FactoryNumber = item.FactoryNumber, PurchasePrice = item.PurchasePrice, QuotationDate = item.QuotationDate, ProducerId = item.ProdecerCode, PriceTag = item.PriceTag }; if (!Materials_ProducerOper.Instance.Insert(producer, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } } #endregion #endregion #region 更新颜色信息 #region 除原有信息 Materials_ColorinfoOper.Instance.DeleteModel(new Materials_Colorinfo { MaterialsId = Key }, connection, transaction); #endregion #region 遍历插入 foreach (var item in request.ColorList) { var returnkey = 0; if (item.ColorID == -1) { returnkey = ColorinfoFunc.Instance.InsertReturnKey(new Colorinfo { StandardColor = item.PantongColor, ChinaDescribe = item.ColorDesc, EngDescibe = item.EngColorDesc, HtmlCode = item.HtmlCode, ParentId = item.ColorSystem.ParseInt(), IsDelete = false }); } Materials_Colorinfo colorinfo = new Materials_Colorinfo { ColorId = item.ColorID == -1 ? returnkey : item.ColorID, MaterialsId = Key, MinStockNum = item.MinStock, SKU = item.SKU, SKUImage = item.SKUImage, PositionInfo = item.PrintInfo }; if (!Materials_ColorinfoOper.Instance.Insert(colorinfo, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } } #endregion #endregion #region 找到对应商品 var commdityList = CommodityOper.Instance.SelectAll(new Commodity { MaterialId = Key }, null, connection, transaction); foreach (var commdity in commdityList) { Commodity comm = new Commodity(); comm.Id = commdity.Id; #region 价格列表 var commodityzero = Commodity_Stage_PriceOper.Instance.SelectAll(new Commodity_Stage_Price { StageAmount = 0, CommodityId = commdity.Id }, null, connection, transaction).FirstOrDefault(); Commodity_Stage_PriceOper.Instance.DeleteModel(new Commodity_Stage_Price { CommodityId = commdity.Id }, connection, transaction); foreach (var item in request.SalesList) { if (!Commodity_Stage_PriceOper.Instance.Insert(new Commodity_Stage_Price { StageAmount = item.ShopQuantity.ParseInt(), DiscountRate = item.ChinaDiscountRate.ParseDouble(), StagePrice = item.ChinaPrice.ParseDecimal(), CommodityId = commdity.Id }, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } } if (!Commodity_Stage_PriceOper.Instance.Insert(new Commodity_Stage_Price { StageAmount = 0, DiscountRate = 0, StagePrice = commodityzero != null ? commodityzero.StagePrice : (decimal)2.0, CommodityId = commdity.Id }, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } #endregion #region 设置颜色图片 var MaterialColorList = ""; var MaterialColorInfo = ""; var colorInfoList = ColorinfoFunc.Instance.GetColorListBase(); var Material_ColorList = Materials_ColorinfoOper.Instance.SelectAll(new Materials_Colorinfo { MaterialsId = Key }, null, connection, transaction); foreach (var item in Material_ColorList) { var thisColorInfo = colorInfoList.Where(p => p.Id == item.ColorId).FirstOrDefault(); if (thisColorInfo != null) { MaterialColorInfo = $"{MaterialColorInfo}{item.ColorId};{item.SKUImage}|"; MaterialColorList = $"{MaterialColorList}{thisColorInfo.Id},"; } } comm.Color = MaterialColorList; var ImageList = commdity.ImageList.Split('|').Where(p => !string.IsNullOrEmpty(p)).Where(p => !p.Contains(';')).ToList(); comm.ImageList = $"{ImageList.ConvertToStr("|")}{MaterialColorInfo}"; #endregion #region 设置位置 var Position = ""; foreach (var item in Material_ColorList) { Position = $"{Position}{item.ColorId}({item.PositionInfo})"; } #endregion comm.GradeId = request.Genera.ParseInt().Value; if (!CommodityOper.Instance.Update(comm, connection, transaction)) { transaction.Rollback(); connection.Close(); return(false); } } #endregion transaction.Commit(); connection.Close(); return(true); } catch (System.Exception ex) { transaction.Rollback(); connection.Close(); throw ex; } }