/// <summary> /// 新编辑如库 /// </summary> /// <param name="oBunch"></param> /// <returns></returns> public static Msg NEditInBunch(List <Tbl_ProductBatch> list) { Msg msg = null; //构造调码对象 List <Tbl_BarCodeBatch> lBarcode = new List <Tbl_BarCodeBatch>(); // List<Tbl_BarCodeInfo> lBarCodeInfo = new List<Tbl_BarCodeInfo>(); try { using (var en = new LingYunEntities()) { List <string> BarCodes = new List <string>(); foreach (Tbl_ProductBatch oPro in list) { en.Tbl_ProductBatch.AddObject(oPro); en.SaveChanges(); Tbl_ProductBatch oProduct = en.Tbl_ProductBatch.Where(a => a.MateriesID == oPro.MateriesID).ToList().LastOrDefault(); //批次 List <string> lCodes = BarCode.BuildBarCode(oProduct.WorkMapID, (int)BarCodeType.批次); BarCodes.Add(lCodes[0]); Tbl_BarCodeBatch oBunchBarCode = new Tbl_BarCodeBatch(); oBunchBarCode.BarCodeBatchID = oProduct.BuildBatchID; oBunchBarCode.BarCodeType = (int)BarCodeType.批次; oBunchBarCode.BarCodeNo = lCodes[0]; oBunchBarCode.CreateTime = DateTime.Now; oBunchBarCode.BuildBatchID = oProduct.BuildBatchID; Tbl_BarCodeInfo oBarCodeInfo = new Tbl_BarCodeInfo(); oBarCodeInfo.BarCodeInfoID = oProduct.BuildBatchID; oBarCodeInfo.BuildName = oPro.BuildName; oBarCodeInfo.CreateTime = DateTime.Now; oBarCodeInfo.MateriesType = oPro.MateriesType; oBarCodeInfo.WorkMapID = oPro.WorkMapID; oBarCodeInfo.ProjectName = oPro.ProjectName; oBarCodeInfo.BarCodeBatchID = oProduct.BuildBatchID; en.Tbl_BarCodeBatch.AddObject(oBunchBarCode); en.Tbl_BarCodeInfo.AddObject(oBarCodeInfo); // List <string> lSigleCodes = BarCode.BuildBarCode(oProduct.WorkMapID, (int)BarCodeType.单件, oPro.Count); for (int i = 0; i < lSigleCodes.Count; i++) { Tbl_BarCodeBatch oSigleBunch = new Tbl_BarCodeBatch(); oSigleBunch.BarCodeBatchID = oProduct.BuildBatchID; oSigleBunch.BarCodeType = (int)BarCodeType.单件; oSigleBunch.BarCodeNo = lSigleCodes[i]; oSigleBunch.CreateTime = DateTime.Now; Tbl_BarCodeInfo oSigleInfo = new Tbl_BarCodeInfo(); oSigleInfo.BarCodeBatchID = oProduct.BuildBatchID; oSigleInfo.BarCodeInfoID = oProduct.BuildBatchID; oSigleInfo.BuildName = oPro.BuildName; oSigleInfo.CreateTime = DateTime.Now; oSigleInfo.MateriesType = oPro.MateriesType; oSigleInfo.WorkMapID = oPro.WorkMapID; oSigleInfo.ProjectName = oPro.ProjectName; en.Tbl_BarCodeBatch.AddObject(oSigleBunch); en.Tbl_BarCodeInfo.AddObject(oSigleInfo); } } en.SaveChanges(); msg = new Msg(true) { UserData = BarCodes }; } } catch (Exception ex) { msg = new Msg() { Status = false, Message = ex.Message }; } return(msg); }
public static Msg EditInBunch(Tbl_ProductBatch oBunch) { //构造调码对象 List <Tbl_BarCodeBatch> lBarcode = new List <Tbl_BarCodeBatch>(); // List<Tbl_BarCodeInfo> lBarCodeInfo = new List<Tbl_BarCodeInfo>(); Msg msg = null; if (oBunch != null) { try { using (var en = new LingYunEntities()) { Tbl_ProductBatch obj = en.Tbl_ProductBatch.Where(a => a.PlanID == oBunch.PlanID && oBunch.MateriesID == a.MateriesID).FirstOrDefault(); //if (obj == null) { en.Tbl_ProductBatch.AddObject(oBunch); en.SaveChanges(); Tbl_ProductBatch oProduct = en.Tbl_ProductBatch.Where(a => a.PlanID == oBunch.PlanID).ToList().LastOrDefault(); //批次 List <string> lCodes = BarCode.BuildBarCode(oProduct.WorkMapID, (int)BarCodeType.批次); Tbl_BarCodeBatch oBunchBarCode = new Tbl_BarCodeBatch(); oBunchBarCode.BarCodeBatchID = oProduct.BuildBatchID; oBunchBarCode.BarCodeType = (int)BarCodeType.批次; oBunchBarCode.BarCodeNo = lCodes[0]; oBunchBarCode.CreateTime = DateTime.Now; oBunchBarCode.BuildBatchID = oProduct.BuildBatchID; Tbl_BarCodeInfo oBarCodeInfo = new Tbl_BarCodeInfo(); oBarCodeInfo.BarCodeInfoID = oProduct.BuildBatchID; oBarCodeInfo.BuildName = oBunch.BuildName; oBarCodeInfo.CreateTime = DateTime.Now; oBarCodeInfo.MateriesType = oBunch.MateriesType; oBarCodeInfo.WorkMapID = oBunch.WorkMapID; oBarCodeInfo.ProjectName = oBunch.ProjectName; oBarCodeInfo.BarCodeBatchID = oProduct.BuildBatchID; en.Tbl_BarCodeBatch.AddObject(oBunchBarCode); en.Tbl_BarCodeInfo.AddObject(oBarCodeInfo); // List <string> lSigleCodes = BarCode.BuildBarCode(oProduct.WorkMapID, (int)BarCodeType.单件, oBunch.Count); for (int i = 0; i < lSigleCodes.Count; i++) { Tbl_BarCodeBatch oSigleBunch = new Tbl_BarCodeBatch(); oSigleBunch.BarCodeBatchID = oProduct.BuildBatchID; oSigleBunch.BarCodeType = (int)BarCodeType.单件; oSigleBunch.BarCodeNo = lSigleCodes[i]; oSigleBunch.CreateTime = DateTime.Now; Tbl_BarCodeInfo oSigleInfo = new Tbl_BarCodeInfo(); oSigleInfo.BarCodeBatchID = oProduct.BuildBatchID; oSigleInfo.BarCodeInfoID = oProduct.BuildBatchID; oSigleInfo.BuildName = oBunch.BuildName; oSigleInfo.CreateTime = DateTime.Now; oSigleInfo.MateriesType = oBunch.MateriesType; oSigleInfo.WorkMapID = oBunch.WorkMapID; oSigleInfo.ProjectName = oBunch.ProjectName; en.Tbl_BarCodeBatch.AddObject(oSigleBunch); en.Tbl_BarCodeInfo.AddObject(oSigleInfo); } en.SaveChanges(); msg = new Msg(true) { UserData = lCodes }; } //else //{ // obj.Count = oBunch.Count; // List<Tbl_BarCodeBatch> lDelBunch = en.Tbl_BarCodeBatch.Where(a => a.BuildBatchID == obj.BuildBatchID).ToList(); // List<Tbl_BarCodeInfo> lDelInfo = en.Tbl_BarCodeInfo.Where(a => a.BarCodeBatchID == obj.BuildBatchID).ToList(); // for(int j=0;j<lDelBunch.Count;j++) // { // en.Tbl_BarCodeBatch.DeleteObject(lDelBunch[j]); // en.Tbl_BarCodeInfo.DeleteObject(lDelInfo[j]); // }en.SaveChanges(); // string conStr = ConfigurationManager.AppSettings["ConStr"]; // SqlConnection con = new SqlConnection(conStr); // con.Open(); // //插入单件 // // SqlTransaction tran = con.BeginTransaction();//开始事务 // List<string> lSigleCodes = BarCode.BuildBarCode(int.Parse(obj.BuildBatchID.ToString()), (int)BarCodeType.单件, oBunch.Count); // for (int i = 0; i < lSigleCodes.Count; i++) // { // Tbl_BarCodeBatch oSigleBunch = new Tbl_BarCodeBatch(); // oSigleBunch.BuildBatchID = obj.BuildBatchID; // oSigleBunch.BarCodeType = (int)BarCodeType.单件; // oSigleBunch.BarCodeNo = lSigleCodes[i]; // oSigleBunch.CreateTime = DateTime.Now; // Tbl_BarCodeInfo oSigleInfo = new Tbl_BarCodeInfo(); // oSigleInfo.BarCodeBatchID = obj.BuildBatchID; // oSigleInfo.BuildName = oBunch.BuildName; // oSigleInfo.CreateTime = DateTime.Now; // oSigleInfo.MateriesType = oBunch.MateriesType; // oSigleInfo.WorkMapID = oBunch.WorkMapID; // oSigleInfo.ProjectName = oBunch.ProjectName; // //en.Tbl_BarCodeBatch.AddObject(oSigleBunch); // //en.Tbl_BarCodeInfo.AddObject(oSigleInfo); // SqlCommand com1 = new SqlCommand("insert into Tbl_BarCodeBatch(BuildBatchID,BarCodeNo,CreateTime,BarCodeType) values(" + oSigleBunch.BuildBatchID + ",'" + oSigleBunch.BarCodeNo + "','" + oSigleBunch.CreateTime + "'," + oSigleBunch.BarCodeType + ")", con); // SqlCommand com2 = new SqlCommand("insert into Tbl_BarCodeInfo(BarCodeBatchID,CreateTime,ProjectName,BuildName,MateriesType,WorkMapID) values(" + oSigleInfo.BarCodeBatchID + ",'" + oSigleInfo.CreateTime + "','" + oSigleInfo.ProjectName + "','" + oSigleInfo.BuildName + "','" + oSigleInfo.MateriesType + "','" + oSigleInfo.WorkMapID + "')", con); // com1.ExecuteScalar(); // com2.ExecuteScalar(); // } // //批次 // List<string> lCodes = BarCode.BuildBarCode(int.Parse(obj.BuildBatchID.ToString()), (int)BarCodeType.批次); // Tbl_BarCodeBatch oBunchBarCode = new Tbl_BarCodeBatch(); // oBunchBarCode.BuildBatchID = obj.BuildBatchID; // oBunchBarCode.BarCodeType = (int)BarCodeType.批次; // oBunchBarCode.BarCodeNo = lCodes[0]; // oBunchBarCode.CreateTime = DateTime.Now; // Tbl_BarCodeInfo oBarCodeInfo = new Tbl_BarCodeInfo(); // oBarCodeInfo.BarCodeBatchID = obj.BuildBatchID; // oBarCodeInfo.BuildName = oBunch.BuildName; // oBarCodeInfo.CreateTime = DateTime.Now; // oBarCodeInfo.MateriesType = oBunch.MateriesType; // oBarCodeInfo.WorkMapID = oBunch.WorkMapID; // oBarCodeInfo.ProjectName = oBunch.ProjectName; // SqlCommand com3 = new SqlCommand("insert into Tbl_BarCodeBatch(BuildBatchID,BarCodeNo,CreateTime,BarCodeType) values(" + oBunchBarCode.BuildBatchID + ",'" + oBunchBarCode.BarCodeNo + "','" + oBunchBarCode.CreateTime + "'," + oBunchBarCode.BarCodeType + ")", con); // SqlCommand com4 = new SqlCommand("insert into Tbl_BarCodeInfo(BarCodeBatchID,CreateTime,ProjectName,BuildName,MateriesType,WorkMapID) values(" + oBarCodeInfo.BarCodeBatchID + ",'" + oBarCodeInfo.CreateTime + "','" + oBarCodeInfo.ProjectName + "','" + oBarCodeInfo.BuildName + "','" + oBarCodeInfo.MateriesType + "','" + oBarCodeInfo.WorkMapID + "')", con); // com3.ExecuteScalar(); // com4.ExecuteScalar(); // // tran.Commit(); // con.Close(); // msg = new Msg(true) { UserData = lCodes }; } } catch (Exception ex) { msg = new Msg() { Status = false, Message = ex.Message }; } } return(msg); }