using System; using System.Data; using System.ServiceProcess; using System.Threading; using System.Windows.Forms; using QMAPP.FJC.BLL.FIS; using QMAPP.FJC.BLL.MesB9; using QMAPP.FJC.Entity.FileCopy.FIS; using QMAPP.FJC.Entity.FIS; namespace DbService { partial class AutoDbCopyService : ServiceBase { private int timerIntno = 60000; public AutoDbCopyService() { InitializeComponent(); timer.Interval = timerIntno; timer.Enabled = true; } protected override void OnStart(string[] args) { // TODO: 在此处添加代码以启动服务。 } protected override void OnStop() { // TODO: 在此处添加代码以执行停止服务所需的关闭操作。 QMFrameWork.Log.LogManager.LogHelper.Info( new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "DbService服务停止" }); } private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { lock (this) { // TODO: 在此处添加代码以启动服务。 timer.Enabled = false; //获取Mes_B9表数据 MesB9BLL mesB9Bll = new MesB9BLL(); var MesB9BLLList = mesB9Bll.GetAllList(); if (MesB9BLLList != null) foreach (var item in MesB9BLLList) { FISOrderBLL fisOrderBll = new FISOrderBLL(); FISOrder fisOrder = new FISOrder(); fisOrder.PID = Guid.NewGuid().ToString(); fisOrder.VWSEQ = item.seq; fisOrder.KIN = item.kin; fisOrder.VIN = item.vin; fisOrder.ORDER_NO = item.m100dtm; var ds = item.m100dtm + "00"; fisOrder.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"); fisOrder.PRODNO = item.ProdNo; fisOrder.LINENO = item.assemblyline; fisOrder.CREATETIME=DateTime.Now; fisOrder.SCANSTATE = "0"; //插入T_PP_FISORDER表 fisOrderBll.Insert(fisOrder); OrderPlanBLL orderPlanBll = new OrderPlanBLL(); OrderPlan orderPlan = new OrderPlan(); orderPlan.PID = Guid.NewGuid().ToString(); orderPlan.PLAN_NO = fisOrder.ORDER_NO; orderPlan.PLAN_SEQ = fisOrder.VWSEQ; orderPlan.PLAN_STATE = "0"; orderPlan.MATERIAL_CODE = fisOrder.PRODNO; orderPlan.QTY = 1; orderPlan.COMPLETE_QTY = 0; orderPlan.PLAN_DATE=DateTime.Now; orderPlan.PLANSOURCE = "0"; orderPlan.PRODUCEREQUIRE = "1"; //插入T_PP_ORDERPLAN表,T_PP_WORKORDER表. orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan,null); //跟新Mes_B9表 item.ReadFlag = 1; mesB9Bll.Update(item); } timer.Enabled = true; } } catch (Exception ex) { timer.Enabled = true; QMFrameWork.Log.LogManager.LogHelper.Error( new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "DbService服务失败:", ErrorInfo = ex }); throw; } } } }