using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.FJC.Entity.ProcessParameter; using QMAPP.FJC.Entity.Operation; using System.Data; using QMFrameWork.Data; using QMFrameWork.Common.Util; namespace EQUIPINTERFACETEST.Deal { public class MillDeal { public void InsertParameter() { string sample = "select * from T_AW_MILINGPARAMETERSAMPLE "; List sampleList = new List(); string dateStr = @"select datestr from( select cast(m.OPERATEDDATE as date) as datestr,1 as piece from T_AW_MAINOPERATION m where processtype='12' and OPERATESTATE='2')t group by datestr having sum(1)>5"; List list = new List(); string moSql = "select * from T_AW_MAINOPERATION m where processtype='12' and OPERATESTATE='2'"; DataTable dt = new DataTable(); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(dateStr, new List().ToArray()); list = session.GetList(moSql, new List().ToArray()).ToList(); sampleList = session.GetList(sample, new List().ToArray()).ToList(); } List molist = new List(); for (int i = 0; i < dt.Rows.Count; i++) { string dayStr = dt.Rows[i][0].ToString(); DateTime dt1 = Convert.ToDateTime(dayStr); List list1 = list.Where(o => o.OPERATEDDATE > dt1 && o.OPERATEDDATE < dt1.AddDays(1)).ToList(); molist = molist.Concat(list1).ToList(); } List insertListParameter = new List(); foreach (var mo in molist) { mo.OPERATESTATE = "1"; mo.PRODUCTCODESTR += "."; MilingParameter bpindex = sampleList[0]; MilingParameter bp = new MilingParameter(); bp = BindHelper.CopyToModel(bpindex, false); bp.PID = Guid.NewGuid().ToString(); bp.PDID = mo.PDID; bp.MOID = mo.PID; bp.PRODUCTCODE = mo.PRODUCTCODE; bp.CREATEDATE = mo.OPERATEDDATE; insertListParameter.Add(bp); } using (IDataSession session = AppDataFactory.CreateMainSession()) { int j = 0; foreach (var mo in molist) { j++; session.Update(mo); Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString()); WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString()); } int i = 0; foreach (var bp in insertListParameter) { i++; session.Insert(bp); Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString()); WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString()); } } } public void InsertPressParameter() { string sample = "select * from T_AW_MILINGPARAMETERSAMPLE "; List sampleList = new List(); MainOperation moSample = new MainOperation(); moSample.PID = "36a10c8c-4aa6-4fd6-bd05-8f6e09264d8b"; string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS>'12' and m.CREATEDATE>'2016-05-1 00:24:32.427' and not exists(select 1 from T_AW_MAINOPERATION mo where mo.processtype='12' and mo.PDID=m.PID)"; List
mainList = new List
(); string sqlMao = @"select * from T_AW_MAINOPERATION mo where mo.PROCESSTYPE='13' and exists( select 1 from ( SELECT m.pid FROM T_aw_main m where m.CURRENTPROCESS>'12' and not exists(select 1 from T_AW_MAINOPERATION mo where mo.processtype='12' and mo.PDID=m.PID))f where f.PID=mo.PDID)"; List maoList = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { mainList = session.GetList
(mainSql, new List().ToArray()).ToList
(); sampleList = session.GetList(sample, new List().ToArray()).ToList(); moSample = session.Get(moSample); maoList = session.GetList(sqlMao, new List().ToArray()).ToList(); } List insertListParameter = new List(); List molist = new List(); foreach (Main m in mainList) { if(maoList.Count(o=>o.PRODUCTCODE==m.EPIDERMISCODE)==0) { continue; } MainOperation maoJie = maoList.First(o => o.PRODUCTCODE == m.EPIDERMISCODE); MilingParameter bpindex = new MilingParameter(); MainOperation mo = new MainOperation(); mo = BindHelper.CopyToModel(moSample, false); mo.PID = Guid.NewGuid().ToString(); mo.PDID = m.PID; mo.PRODUCTCODE = m.EPIDERMISCODE; mo.OPERATEDDATE = maoJie.OPERATEDDATE.AddSeconds(-20); mo.CREATEDATE = mo.OPERATEDDATE.AddSeconds(-55); mo.UPDATEDATE = mo.OPERATEDDATE; mo.PRODUCTCODESTR = "."; molist.Add(mo); bpindex = sampleList[0]; MilingParameter bp = new MilingParameter(); bp = BindHelper.CopyToModel(bpindex, false); bp.PID = Guid.NewGuid().ToString(); bp.PDID = mo.PDID; bp.MOID = mo.PID; bp.PRODUCTCODE = mo.PRODUCTCODE; bp.CREATEDATE = mo.OPERATEDDATE; insertListParameter.Add(bp); } using (IDataSession session = AppDataFactory.CreateMainSession()) { int j = 0; foreach (var mo in molist) { j++; session.Insert(mo); Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString()); WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString()); } int i = 0; foreach (var bp in insertListParameter) { i++; session.Insert(bp); Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString()); WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString()); } } } public void InsertMillParameter() { string sample = "select * from T_AW_MILINGPARAMETERSAMPLE "; List sampleList = new List(); MainOperation moSample = new MainOperation(); moSample.PID = "36a10c8c-4aa6-4fd6-bd05-8f6e09264d8b"; string mainSql = @"SELECT * FROM T_aw_main m where m.CURRENTPROCESS='12' and m.CREATEDATE>'2016-05-13 14:06:28' and m.CREATEDATE<'2017-01-1 00:00:00'"; List
mainList = new List
(); using (IDataSession session = AppDataFactory.CreateMainSession()) { mainList = session.GetList
(mainSql, new List().ToArray()).ToList
(); sampleList = session.GetList(sample, new List().ToArray()).ToList(); moSample = session.Get(moSample); } List insertListParameter = new List(); List molist = new List(); foreach (Main m in mainList) { m.UPDATEDATE = m.UPDATEDATE.AddSeconds(90); m.CURRENTPROCESS = "13"; MilingParameter bpindex = new MilingParameter(); MainOperation mo = new MainOperation(); mo = BindHelper.CopyToModel(moSample, false); mo.PID = Guid.NewGuid().ToString(); mo.PDID = m.PID; mo.PRODUCTCODE = m.EPIDERMISCODE; mo.OPERATEDDATE = m.UPDATEDATE; mo.CREATEDATE = mo.OPERATEDDATE.AddSeconds(-55); mo.UPDATEDATE = mo.OPERATEDDATE; mo.PRODUCTCODESTR = "."; molist.Add(mo); bpindex=sampleList[0]; MilingParameter bp = new MilingParameter(); bp = BindHelper.CopyToModel(bpindex, false); bp.PID = Guid.NewGuid().ToString(); bp.PDID = mo.PDID; bp.MOID = mo.PID; bp.PRODUCTCODE = mo.PRODUCTCODE; bp.CREATEDATE = mo.OPERATEDDATE; insertListParameter.Add(bp); } using (IDataSession session = AppDataFactory.CreateMainSession()) { int c = 0; foreach (var m in mainList) { c++; session.Update
(m); Console.WriteLine(m.EPIDERMISCODE + " - " + c.ToString()); WriteLog.Write(m.EPIDERMISCODE + " - " + c.ToString()); } int j = 0; foreach (var mo in molist) { j++; session.Insert(mo); Console.WriteLine(mo.PRODUCTCODE + " - " + j.ToString()); WriteLog.Write(mo.PRODUCTCODE + " - " + j.ToString()); } int i = 0; foreach (var bp in insertListParameter) { i++; session.Insert(bp); Console.WriteLine(bp.PRODUCTCODE + " - " + i.ToString()); WriteLog.Write(bp.PRODUCTCODE + " - " + i.ToString()); } } } } }