using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.FJC.Entity.Basic; using QMAPP.FJC.Entity.ProcessParameter; using QMAPP.FJC.DAL.Operation; using QMAPP.FJC.DAL.Basic; using QMAPP.FJC.Entity.Operation; using QMAPP.FJC.Entity; using QMFrameWork.Data; using QMAPP.FJC.DAL; using QMAPP.FJC.Entity.Injection; using QMAPP.FJC.DAL.Injection; namespace QMAPP.FJC.BLL.Process { /// /// 注塑加工处理类 /// 作者:闫永刚 /// 日期:2015-05-28 /// public class InjectionProcess { #region IProcess 成员 public void Process(MachineInfo machine, List parConfigList) { try { #region 获取注塑加工参数 InJectionParameter injectPara = new InJectionParameter(); Type t = typeof(InJectionParameter); foreach (ParameterConfig pc in parConfigList) { t.GetProperty(pc.COLUMNCODE).SetValue(injectPara, pc.PARAVALUE, null); } #endregion #region 是否是B9系统的条码信息 //产品条码中不包含B9 if (string.IsNullOrEmpty(injectPara.PRODUCTCODE) || injectPara.PRODUCTCODE.Contains("B9") == false) { if (string.IsNullOrEmpty(injectPara.PRODUCTCODE) == false) { //插入其他生产线的产品信息 } return; } #endregion #region 产品信息 Product product = new Product(); product.PID = Guid.NewGuid().ToString(); product.PRODUCTCODE = injectPara.PRODUCTCODE; //获取产品类别 product.PRODUCTTYPE = GetProductType(injectPara.PRODUCTCODE); product.MACHINENAME = machine.MACHINENAME; product.MACHINECODDE = machine.MACHINECODDE; //合格品 product.STATUS = EnumGeter.STATUS.QUALIFIED.GetHashCode().ToString(); //product.CURRENTPROCESS product.PRODUCELINE = "B9"; product.PRODUCESHIFTNAME = ""; product.PRODUCESHIFTTCODE = ""; //在库 product.OUTFLAG = EnumGeter.OUTFLAG.INWAREHOUSE.GetHashCode().ToString(); //未使用 product.USINGSTATE = EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString(); product.CAPACITY = 0; product.USINGCOUNT = 0; product.CREATEUSER = ""; product.CREATEDATE = System.DateTime.Now; product.UPDATEUSER = ""; product.UPDATEDATE = System.DateTime.Now; #endregion #region 加工工序信息 MainOperation operation = new MainOperation(); operation.PID = Guid.NewGuid().ToString(); operation.PDID = product.PID; operation.PRODUCTCODE = product.PRODUCTCODE; //搪塑 operation.PROCESSTYPE = GetProcessType(product.PRODUCTCODE); operation.PRODUCTTYPE = product.PRODUCTTYPE; operation.MACHINENAME = machine.MACHINENAME; operation.MACHINECODDE = machine.MACHINECODDE; operation.STATUS = EnumGeter.STATUS.QUALIFIED.GetHashCode().ToString(); operation.OPERATESTATE = EnumGeter.OPERATESTATE.COMPLETED.GetHashCode().ToString(); operation.OPERATEDDATE = System.DateTime.Now; operation.CURRENTPROCESS = EnumGeter.ProcessType.tangsu.GetHashCode().ToString(); operation.PRODUCESHIFTNAME = ""; operation.PRODUCESHIFTTCODE = ""; operation.PRODUCELINE = "B9"; operation.MODELSTATION = ""; operation.CREATEUSER = ""; operation.CREATEDATE = System.DateTime.Now; operation.UPDATEUSER = ""; operation.UPDATEDATE = System.DateTime.Now; #endregion #region 加工参数 injectPara.PID = Guid.NewGuid().ToString(); injectPara.PDID = product.PID; injectPara.MOID = operation.PID; injectPara.PRODUCTTYPE = product.PRODUCTTYPE; injectPara.CREATEDATE = System.DateTime.Now; #endregion #region 获取投料信息 //零件投料关联表 List addInjectItemList = new List(); InjectionRecorderDAL injectDal = new InjectionRecorderDAL(); List list = injectDal.GetLastRecorder(new InjectionRecorder() { MACHINECODDE = machine.MACHINECODDE, }); if (list.Count > 0) { InjectionRecorder inRecorder = list[0]; #region 零件投料关联记录 ProductInjection proInject = new ProductInjection(); proInject.PID = Guid.NewGuid().ToString(); proInject.IPID = inRecorder.PID; proInject.MPPID = product.PID; proInject.MATERIALNAME = inRecorder.MATERIALNAME; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.MATERIALTYPE = inRecorder.MATERIALTYPE; proInject.MATERIALBATCH = inRecorder.MATERIALBATCH; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.INJECTIONINDEX = inRecorder.INJECTIONINDEX; proInject.INJECTIONTERMINAL = inRecorder.INJECTIONTERMINAL; proInject.USEDWEIGHT = 0; proInject.CREATEDATE = System.DateTime.Now; proInject.CREATEUSER = inRecorder.CREATEUSER; proInject.UPDATEUSER = inRecorder.UPDATEUSER; addInjectItemList.Add(proInject); #endregion } #endregion #region 数据库操作 using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); ProductDAL productDal = new ProductDAL(); MainOperationDAL mainOpeDal = new MainOperationDAL(); //InjectionParameterDAL injectParaDal = new InjectionParameterDAL(); ProductInjectionDAL proInDal = new ProductInjectionDAL(); productDal.BaseSession = session; mainOpeDal.BaseSession = session; injectDal.BaseSession = session; //injectParaDal.BaseSession = session; proInDal.BaseSession = session; try { #region 插入产品信息 productDal.Insert(product); #endregion #region 插入操作记录 mainOpeDal.Insert(operation); #endregion #region 插入加工参数 ////injectParaDal.Insert(injectPara); #endregion #region 投料关联表 foreach (var proinject in addInjectItemList) { proInDal.Insert(proinject); } #endregion #region 风道注塑 //风道注塑时,一次生成两个风道产品 if (product.PRODUCTTYPE == EnumGeter.ProductType.fengdao.GetHashCode().ToString()) { #region 新增另一条风道记录 product.PID = Guid.NewGuid().ToString(); //最后五位流水号+1 product.PRODUCTCODE = product.PRODUCTCODE.Substring(0, 15) + (Convert.ToInt32(product.PRODUCTCODE.Substring(15, 5)) + 1).ToString().PadLeft(5, '0'); productDal.Insert(product); #endregion #region 新增另一条操作记录 operation.PID = Guid.NewGuid().ToString(); operation.PDID = product.PID; operation.PRODUCTCODE = product.PRODUCTCODE; #endregion #region 新增另一条加工参数 injectPara.PID = Guid.NewGuid().ToString(); injectPara.PDID = product.PID; injectPara.PRODUCTCODE = product.PRODUCTCODE; injectPara.MOID = operation.PID; injectPara.PRODUCTTYPE = product.PRODUCTTYPE; injectPara.CREATEDATE = System.DateTime.Now; #endregion #region 投料关联表 foreach (var proinject in addInjectItemList) { proinject.PID = Guid.NewGuid().ToString(); proinject.MPPID = product.PID; proInDal.Insert(proinject); } #endregion } #endregion session.CommitTs(); } catch (Exception ex) { session.RollbackTs(); throw; } } #region 打印风道的条码号 if (product.PRODUCTTYPE == EnumGeter.ProductType.fengdao.GetHashCode().ToString()) { string xmlPath = @"E:\富维江森\代码\B9\APPB9\QMAPP.WinForm\XMLResources\Biaopi.xml"; BarcodeLib.BarCodeGenerate generate = new BarcodeLib.BarCodeGenerate(xmlPath); generate.PrintBarCode(product.PRODUCTCODE); } #endregion #endregion } catch (Exception) { throw; } } public bool CheckParameter(string barCode,string dtime) { bool b = false; try { //b = new InjectionParameterDAL().CheckParameter(barCode, dtime); } catch (Exception e) { throw e; } return b; } public string GetMaxEDate(InJectionParameter param) { string b = ""; try { //b = new InjectionParameterDAL().GetMaxEDate(param); } catch (Exception e) { throw e; } return b; } public void ProcessAuto(MachineInfo machine, InJectionParameter injectPara) { try { #region 产品信息 List listUpdatePro = new List();//需要附加零件 Product product = new Product(); product.PID = Guid.NewGuid().ToString(); product.PRODUCTCODE = injectPara.PRODUCTCODE; //获取产品类别 product.PRODUCTTYPE = GetProductType(injectPara.PRODUCTCODE); #region 是否是B9系统的条码信息 //产品条码中不包含B9 if (string.IsNullOrEmpty(product.PRODUCTTYPE)) { return; } #endregion //判断当前零件类别是否包含其他零件 List proSets = new ProcessSetDAL().GetList(new ProcessSet { PRODUCTTYPE = product.PRODUCTTYPE, PROCESSTYPE = GetProcessType(product.PRODUCTCODE) } ); foreach (ProcessSet proSet in proSets) { List listRule = new ProcessRuleDAL().GetList(new ProcessRule { PSD = proSet.PID, RULETYPE = EnumGeter.RULETYPE.PARTS.GetHashCode().ToString() }); if (listRule.Count > 0)//是否需求零件 { //获取所有未完成的金属支架 List listPro = new ProductDAL().GetList(new Product { PRODUCTTYPE = listRule[0].PRODUCTTYPE, USINGSTATE = "3" }); if (listPro.Count > 0) { listPro.Sort((m, n) => m.CREATEDATE.CompareTo(n.CREATEDATE)); int needCount = listRule[0].RULEVALUE; foreach (Product item in listPro)//按顺序扣件数量 { if (item.CAPACITY - item.USINGCOUNT >= needCount) { item.USINGCOUNT = item.USINGCOUNT + needCount; item.USINGSTATE = EnumGeter.PRODUCTUSESTATE.USING.GetHashCode().ToString(); if (item.USINGCOUNT == item.CAPACITY) { item.USINGSTATE = EnumGeter.PRODUCTUSESTATE.USED.GetHashCode().ToString(); } item.useCount = needCount; needCount = 0; } else { item.useCount = item.CAPACITY - item.USINGCOUNT; needCount = needCount - item.CAPACITY + item.USINGCOUNT; item.USINGCOUNT = item.CAPACITY; item.USINGSTATE = EnumGeter.PRODUCTUSESTATE.USED.GetHashCode().ToString(); } listUpdatePro.Add(item); if (needCount == 0) { break; } } } else { //获取所有的金属支架 listPro = new ProductDAL().GetList(new Product { PRODUCTTYPE = listRule[0].PRODUCTTYPE }); if (listPro.Count > 0) { listPro.Sort((m, n) => n.CREATEDATE.CompareTo(m.CREATEDATE)); listUpdatePro.Add(listPro[0]); } } } } product.MACHINENAME = machine.MACHINENAME; product.MACHINECODDE = machine.MACHINECODDE; //获取添加物料号 product.MATERIAL_CODE = new MaterialCodeDAL().GetMaterialCode(new MaterialCode { PRODUCT_TYPES = product.PRODUCTTYPE }); if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.gujia.GetHashCode().ToString())) { //骨架当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.huoyanjiagong.GetHashCode().ToString(); } if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.biaopi.GetHashCode().ToString())) { //表皮当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.lengdaoruohua.GetHashCode().ToString(); } if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString())) { //气囊支架当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.hongwaihanjie.GetHashCode().ToString(); } if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.fengdao.GetHashCode().ToString())) { //风道当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.maojie.GetHashCode().ToString(); } if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.HUDfengdao.GetHashCode().ToString())) { //HUD风道当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.maojie.GetHashCode().ToString(); } if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.kaiguanzhijia.GetHashCode().ToString())) { //开关支架当前工序 product.CURRENTPROCESS = EnumGeter.ProcessType.chaoshengbohanjie.GetHashCode().ToString(); } product.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString(); //合格品 product.STATUS = EnumGeter.STATUS.QUALIFIED.GetHashCode().ToString(); //product.CURRENTPROCESS product.PRODUCELINE = "B9"; product.PRODUCESHIFTNAME = ""; product.PRODUCESHIFTTCODE = ""; //在库 product.OUTFLAG = EnumGeter.OUTFLAG.INWAREHOUSE.GetHashCode().ToString(); //未使用 product.USINGSTATE = EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString(); product.CAPACITY = 1; product.USINGCOUNT = 0; product.CREATEUSER = ""; product.CREATEDATE = System.DateTime.Now; product.UPDATEUSER = ""; product.UPDATEDATE = System.DateTime.Now; #endregion #region 加工工序信息 MainOperation operation = new MainOperation(); operation.PID = Guid.NewGuid().ToString(); operation.PDID = product.PID; operation.PRODUCTCODE = product.PRODUCTCODE; //搪塑 operation.PROCESSTYPE = GetProcessType(product.PRODUCTCODE); operation.PRODUCTTYPE = product.PRODUCTTYPE; operation.MACHINENAME = machine.MACHINENAME; operation.MACHINECODDE = machine.MACHINECODDE; operation.STATUS = EnumGeter.STATUS.QUALIFIED.GetHashCode().ToString(); operation.OPERATESTATE = EnumGeter.OPERATESTATE.COMPLETED.GetHashCode().ToString(); operation.OPERATEDDATE = injectPara.OPERATEDATE; operation.CURRENTPROCESS = EnumGeter.ProcessType.tangsu.GetHashCode().ToString(); operation.PRODUCESHIFTNAME = ""; operation.PRODUCESHIFTTCODE = ""; operation.PRODUCELINE = "B9"; operation.MODELSTATION = ""; operation.CREATEUSER = ""; operation.CREATEDATE = System.DateTime.Now; operation.UPDATEUSER = ""; operation.UPDATEDATE = System.DateTime.Now; #endregion #region 加工参数 injectPara.PID = Guid.NewGuid().ToString(); injectPara.PDID = product.PID; injectPara.MOID = operation.PID; injectPara.PRODUCTTYPE = product.PRODUCTTYPE; injectPara.CREATEDATE = System.DateTime.Now; #endregion #region 获取投料信息 //零件投料关联表 List addInjectItemList = new List(); InjectionRecorderDAL injectDal = new InjectionRecorderDAL(); List list = injectDal.GetLastRecorder(new InjectionRecorder() { MACHINECODDE = machine.MACHINECODDE, MATERIALTYPE = "0" });//0位原材料 if (list.Count > 0) { InjectionRecorder inRecorder = list[0]; #region 零件投料关联记录 ProductInjection proInject = new ProductInjection(); proInject.PID = Guid.NewGuid().ToString(); proInject.IPID = inRecorder.PID; proInject.MPPID = product.PID; proInject.MATERIALNAME = inRecorder.MATERIALNAME; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.MATERIALTYPE = inRecorder.MATERIALTYPE; proInject.MATERIALBATCH = inRecorder.MATERIALBATCH; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.INJECTIONINDEX = inRecorder.INJECTIONINDEX; proInject.INJECTIONTERMINAL = inRecorder.INJECTIONTERMINAL; proInject.USEDWEIGHT = 0; proInject.CREATEDATE = System.DateTime.Now; proInject.CREATEUSER = inRecorder.CREATEUSER; proInject.UPDATEUSER = inRecorder.UPDATEUSER; addInjectItemList.Add(proInject); #endregion } list = injectDal.GetLastRecorder(new InjectionRecorder() { MACHINECODDE = machine.MACHINECODDE, MATERIALTYPE = "1" });//1位织布 if (list.Count > 0) { InjectionRecorder inRecorder = list[0]; #region 零件投料关联记录 ProductInjection proInject = new ProductInjection(); proInject.PID = Guid.NewGuid().ToString(); proInject.IPID = inRecorder.PID; proInject.MPPID = product.PID; proInject.MATERIALNAME = inRecorder.MATERIALNAME; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.MATERIALTYPE = inRecorder.MATERIALTYPE; proInject.MATERIALBATCH = inRecorder.MATERIALBATCH; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.INJECTIONINDEX = inRecorder.INJECTIONINDEX; proInject.INJECTIONTERMINAL = inRecorder.INJECTIONTERMINAL; proInject.USEDWEIGHT = 0; proInject.CREATEDATE = System.DateTime.Now; proInject.CREATEUSER = inRecorder.CREATEUSER; proInject.UPDATEUSER = inRecorder.UPDATEUSER; addInjectItemList.Add(proInject); #endregion } List mainProducts = new List(); foreach (Product item in listUpdatePro) { MainProduct mainProduct = new MainProduct(); mainProduct.PID = Guid.NewGuid().ToString(); mainProduct.MID = product.PID; mainProduct.PDID = item.PID; mainProduct.COUNT = item.useCount; mainProduct.MOID = operation.PID;//加工记录pid mainProduct.CREATEUSER = ""; mainProduct.CREATEDATE = DateTime.Now; mainProduct.UPDATEUSER = ""; mainProduct.UPDATEDATE = mainProduct.CREATEDATE; mainProducts.Add(mainProduct); } list = injectDal.GetLastRecorder(new InjectionRecorder() { MACHINECODDE = machine.MACHINECODDE, MATERIALTYPE = "2" });//1金属支架 if (list.Count > 0) { InjectionRecorder inRecorder = list[0]; #region 零件投料关联记录 ProductInjection proInject = new ProductInjection(); proInject.PID = Guid.NewGuid().ToString(); proInject.IPID = inRecorder.PID; proInject.MPPID = product.PID; proInject.MATERIALNAME = inRecorder.MATERIALNAME; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.MATERIALTYPE = inRecorder.MATERIALTYPE; proInject.MATERIALBATCH = inRecorder.MATERIALBATCH; proInject.MATERIALCODE = inRecorder.MATERIALCODE; proInject.INJECTIONINDEX = inRecorder.INJECTIONINDEX; proInject.INJECTIONTERMINAL = inRecorder.INJECTIONTERMINAL; proInject.USEDWEIGHT = 0; proInject.CREATEDATE = System.DateTime.Now; proInject.CREATEUSER = inRecorder.CREATEUSER; proInject.UPDATEUSER = inRecorder.UPDATEUSER; addInjectItemList.Add(proInject); #endregion } #endregion #region 数据库操作 using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); ProductDAL productDal = new ProductDAL(); MainOperationDAL mainOpeDal = new MainOperationDAL(); //InjectionParameterDAL injectParaDal = new InjectionParameterDAL(); ProductInjectionDAL proInDal = new ProductInjectionDAL(); MainProductDAL mpDal = new MainProductDAL(); productDal.BaseSession = session; mainOpeDal.BaseSession = session; injectDal.BaseSession = session; //injectParaDal.BaseSession = session; proInDal.BaseSession = session; mpDal.BaseSession = session; try { #region 插入产品信息 productDal.Insert(product); #endregion #region 插入操作记录 mainOpeDal.Insert(operation); #endregion #region 插入加工参数 //injectParaDal.Insert(injectPara); #endregion #region 投料关联表 foreach (var proinject in addInjectItemList) { proInDal.Insert(proinject); } if (listUpdatePro.Count > 0) { productDal.Update(listUpdatePro); mpDal.Insert(mainProducts); } #endregion #region 风道注塑 //风道注塑时,一次生成两个风道产品 if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.fengdao.GetHashCode().ToString())) { #region 新增另一条风道记录 product.PID = Guid.NewGuid().ToString(); //最后五位流水号+1 //product.PRODUCTCODE = product.PRODUCTCODE.Substring(0, 15) // + (Convert.ToInt32(product.PRODUCTCODE.Substring(15, 5)) + 1).ToString().PadLeft(5, '0'); productDal.Insert(product); #endregion #region 新增另一条操作记录 operation.PID = Guid.NewGuid().ToString(); operation.PDID = product.PID; operation.PRODUCTCODE = product.PRODUCTCODE; #endregion #region 新增另一条加工参数 injectPara.PID = Guid.NewGuid().ToString(); injectPara.PDID = product.PID; injectPara.PRODUCTCODE = product.PRODUCTCODE; injectPara.MOID = operation.PID; injectPara.PRODUCTTYPE = product.PRODUCTTYPE; injectPara.CREATEDATE = System.DateTime.Now; #endregion #region 投料关联表 foreach (var proinject in addInjectItemList) { proinject.PID = Guid.NewGuid().ToString(); proinject.MPPID = product.PID; proInDal.Insert(proinject); } #endregion } #endregion session.CommitTs(); } catch (Exception ex) { session.RollbackTs(); throw ex; } } #region 打印风道的条码号 //if (product.PRODUCTTYPE == EnumGeter.ProductType.fengdao.GetHashCode().ToString()) //{ // string xmlPath = @"E:\富维江森\代码\B9\APPB9\QMAPP.WinForm\XMLResources\Biaopi.xml"; // BarcodeLib.BarCodeGenerate generate = new BarcodeLib.BarCodeGenerate(xmlPath); // generate.PrintBarCode(product.PRODUCTCODE); //} #endregion #endregion } catch (Exception e) { throw e; } } #region 获取产品类别 /// /// 通过产品条码判断产品类别 /// /// /// public string GetProductType(string productCode) { if (string.IsNullOrEmpty(productCode)) { return ""; } string sortMark = productCode.Substring(0, 3); string productType = ""; switch (sortMark) { case "B9A": productType = EnumGeter.ProductType.gujia.GetHashCode().ToString(); break; case "B9B": productType = EnumGeter.ProductType.fengdao.GetHashCode().ToString(); break; case "B9C": productType = EnumGeter.ProductType.HUDfengdao.GetHashCode().ToString(); break; //case "B9D": // productType = EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString(); // break; case "FJC": productType = EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString(); break; case "B90": productType = EnumGeter.ProductType.jinshuzhijia.GetHashCode().ToString(); break; case "Q5D": productType = EnumGeter.ProductType.Q5D.GetHashCode().ToString(); break; default: break; } return productType; } #endregion #region 获取加工工序 /// /// 通过产品判断加工工序类别 /// /// /// private string GetProcessType(string productCode) { if (string.IsNullOrEmpty(productCode)) { return ""; } string sortMark = productCode.Substring(0, 3); string prodcessType = ""; switch (sortMark) { case "B9A": prodcessType = EnumGeter.ProcessType.gujiazhusu.GetHashCode().ToString(); break; case "B9B": prodcessType = EnumGeter.ProcessType.fengdaozhusu.GetHashCode().ToString(); break; case "B9C": prodcessType = EnumGeter.ProcessType.HUDfengdaozhusu.GetHashCode().ToString(); break; case "FJC": prodcessType = EnumGeter.ProcessType.gujiazhusu.GetHashCode().ToString(); break; default: break; } return prodcessType; } #endregion #endregion } }