using System; using System.Collections.Generic; using System.Linq; using QMAPP.BLL; using QMAPP.Entity; using QMAPP.FJC.DAL.Basic; using QMAPP.FJC.DAL.FIS; using QMAPP.FJC.DAL.QdFis; using QMAPP.FJC.Entity; using QMAPP.FJC.Entity.Basic; using QMAPP.FJC.Entity.FileCopy.FIS; using QMAPP.FJC.Entity.QdFis; using QMAPP.MD.BLL; using QMAPP.MD.Entity; using QMFrameWork.Data; using QMFrameWork.Log; namespace QMAPP.FJC.BLL.QdFis { public class ybbM100BLL : BaseBLL { List materialList = null; /// /// 传入没有空格.-的Code返回正确格式的零件号 /// /// /// private string getMaterialCode(string materialCode) { //查询零件号和名称 if (materialList == null) { materialList = new MaterialBLL().GetAllList(new Material()); } foreach (var material in materialList) { var mCode = material.MATERIAL_CODE; mCode = mCode.Replace("-", ""); mCode = mCode.Replace(".", ""); mCode = mCode.Replace(" ", ""); if (mCode == materialCode) { return material.MATERIAL_CODE; } } return ""; } //查询零件号名称 private string getMaterialName(string materialCode) { //查询零件号和名称 //var materialList = new MaterialBLL().GetAllList(new Material //{ // MATERIAL_CODE = materialCode //}); //return materialList.Count <= 0 ? "" : materialList[0].MATERIAL_NAME; if (materialList == null) { materialList = new MaterialBLL().GetAllList(new Material()); } var mt = materialList.FirstOrDefault(p => p.MATERIAL_CODE == materialCode); return mt == null ? "" : mt.MATERIAL_NAME; } //查询工作中心 private string getWorkcenterCode(string materialCode) { var initList = new MaterialCodeInitDAL().GetList(new MaterialCodeInit { MATERIAL_CODE = materialCode }); return initList.Count <= 0 ? "" : initList[0].WORKCENTER_CODE; } //执行task程序 public void SelectQdFisYBBInsertPPtable() { var session70YBB = AppDataFactory.CreateSession("maindbYBB"); var session79YBB = AppDataFactory.CreateSession("maindbNCSYBB"); var ybbMD70Dal = new ybbM100DAL { BaseSession = session70YBB }; var ybbMD79Dal = new ybbM100DAL { BaseSession = session79YBB }; //获取70表数据 var ybbList70 = ybbMD70Dal.GetList100(); //获取79表数据 var ybbList79 = ybbMD79Dal.GetList110(); #region 10.111.144.70 //10.111.144.70获取NF数据和新NCS数据--T_PM_FISORDER if (ybbList70 != null && ybbList70.Count > 0) { foreach (var item in ybbList70) { using (IDataSession session = AppDataFactory.CreateMainSession()) { try { FISOrder fisOrder = new FISOrder { PID = Guid.NewGuid().ToString(), VWSEQ = item.SEQ, KIN = item.KIN, VIN = item.VIN, ORDER_NO = "IPFIS" + item.SYSDTM.ToString("yyyyMMddHHmmss") + item.SEQ.Substring(item.SEQ.Length - 4), //M100_ONLINEDATE = // DateTime.Parse(ds.Substring(0, 4) + "-" + ds.Substring(4, 2) + "-" + // ds.Substring(6, 2) + // " " + // ds.Substring(8, 2) + ":" + ds.Substring(10, 2) + ":00"), M100_ONLINEDATE = item.SYSDTM, M110_ONLINEDATE = item.SYSDTM, CP5A = item.CP5A, PRODNO = getMaterialCode(item.PRODNO), //LINENO = "BORAIPASSY", LINENO = item.LINENO, CREATETIME = DateTime.Now, SCANSTATE = "0", FLAGDEL = "0", }; fisOrder.CARSETDESC_CN = getMaterialName(fisOrder.PRODNO); //fisOrder.CP5A = fisOrder.M100_ONLINEDATE.ToString("yyyyMMddHHmm"); //查询是否存在数据 var fisOrderList = new FISOrderDAL().FISOrderIsNull(fisOrder); // 开始事务 session.OpenTs(); if (fisOrderList != null && fisOrderList.Count > 0) { fisOrderList[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE; fisOrderList[0].PRODNO = fisOrder.PRODNO; fisOrderList[0].ORDER_NO = fisOrder.ORDER_NO; fisOrderList[0].CARSETDESC_CN = getMaterialName(fisOrder.PRODNO); fisOrderList[0].CP5A = fisOrder.CP5A;//fisOrder.M100_ONLINEDATE.ToString("yyyyMMddHHmm"); session.Update(fisOrderList[0]); } else { session.Insert(fisOrder); } //插入FISOrederSendDetial --周晓东20180228 FISOrederSendDetial fisOrderSendDetial0 = new FISOrederSendDetial { PID = Guid.NewGuid().ToString(), FIS_PID = fisOrder.PID, STATE = "0", MATERIAL_CODE = fisOrder.PRODNO, MATERIAL_NAME = getMaterialName(fisOrder.PRODNO), //工作中心字段,原先是在T_BD_MATERIALCODEINIT表物料号对应相应工作中心, //但是以后会有东厂、西厂同时要同一产品的情况,所以要用vwseq字段写入工作中心。 //工作中心字段:IPFY+vwseq.sustring(0,2) //WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO) WORKCENTER_CODE = "IPFY" + fisOrder.VWSEQ.Substring(0, 2) }; session.Insert(fisOrderSendDetial0); //插入本地数据库T_PM_FISORDER_M02表(备份) session.Insert(item); // 事务提交 session.CommitTs(); //更新70数据库T_PM_FISORDER表--已读=1 ybbMD70Dal.Update100(item); } catch (Exception e) { session.RollbackTs(); throw e; } } } } #endregion #region 10.111.144.70 //10.111.144.70 [CdFisYbbDY].[dbo].[T_PM_FISORDER] if (ybbList79 != null && ybbList79.Count > 0) { foreach (var item in ybbList79) { using (IDataSession session = AppDataFactory.CreateMainSession()) { try { FISOrder fisOrder = new FISOrder { PID = Guid.NewGuid().ToString(), VWSEQ = item.SEQ, KIN = item.KIN, VIN = item.VIN, ORDER_NO = "IPFIS" + item.SYSDTM.ToString("yyyyMMddHHmmss") + item.SEQ.Substring(item.SEQ.Length - 4), //M100_ONLINEDATE = // DateTime.Parse(ds.Substring(0, 4) + "-" + ds.Substring(4, 2) + "-" + // ds.Substring(6, 2) + // " " + // ds.Substring(8, 2) + ":" + ds.Substring(10, 2) + ":00"), M100_ONLINEDATE = item.SYSDTM, M110_ONLINEDATE = item.SYSDTM, CP5A=item.CP5A, PRODNO = getMaterialCode(item.PRODNO), LINENO = item.LINENO, CREATETIME = DateTime.Now, SCANSTATE = "0", FLAGDEL = "0", }; fisOrder.CARSETDESC_CN = getMaterialName(fisOrder.PRODNO); //fisOrder.CP5A = fisOrder.M100_ONLINEDATE.ToString("yyyyMMddHHmm"); //查询是否存在数据 var fisOrderList = new FISOrderDAL().FISOrderIsNull(fisOrder); // 开始事务 session.OpenTs(); if (fisOrderList != null && fisOrderList.Count > 0) { fisOrderList[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE; fisOrderList[0].PRODNO = fisOrder.PRODNO; fisOrderList[0].ORDER_NO = fisOrder.ORDER_NO; fisOrderList[0].CARSETDESC_CN = getMaterialName(fisOrder.PRODNO); fisOrderList[0].CP5A = fisOrder.CP5A;// fisOrder.M100_ONLINEDATE.ToString("yyyyMMddHHmm"); session.Update(fisOrderList[0]); } else { session.Insert(fisOrder); } //插入FISOrederSendDetial --周晓东20180228 FISOrederSendDetial fisOrderSendDetial0 = new FISOrederSendDetial { PID = Guid.NewGuid().ToString(), FIS_PID = fisOrder.PID, STATE = "0", MATERIAL_CODE = fisOrder.PRODNO, MATERIAL_NAME = getMaterialName(fisOrder.PRODNO), //工作中心字段,原先是在T_BD_MATERIALCODEINIT表物料号对应相应工作中心, //但是以后会有东厂、西厂同时要同一产品的情况,所以要用vwseq字段写入工作中心。 //工作中心字段:IPFY+vwseq.sustring(0,2) //WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO) WORKCENTER_CODE = "IPFY"+fisOrder.VWSEQ.Substring(0,2) }; session.Insert(fisOrderSendDetial0); //插入本地数据库T_PM_FISORDER_M01表(备份) session.Insert(item); // 事务提交 session.CommitTs(); //更新79数据库T_PM_FISORDER表 ybbMD79Dal.Update110(item); } catch (Exception e) { session.RollbackTs(); throw e; } } } } #endregion } } }