using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.FJC.Entity.Operation; using QMFrameWork.Data; using QMAPP.FJC.Entity.ProcessParameter; namespace EQUIPINTERFACETEST { public class InsertCastingParameter { public void Insert() { string sql = @"select * from T_AW_MAINOPERATION t where t.PROCESSTYPE='9' and t.OPERATEDDATE>'2016-05-26 00:00:00' and t.OPERATESTATE='1' and not exists (select 1 from T_AW_CASTINGPARAMETER c where c.MOID=t.pid)"; string sql2 = @" select * from T_AW_CASTINGPARAMETER t where t.createdate>'2016-06-20 14:39:39.160' and t.createdate<'2016-06-20 16:39:39.160'"; List list2 = new List(); List molist = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { molist = session.GetList(sql, new List().ToArray()).ToList(); list2 = session.GetList(sql2, new List().ToArray()).ToList(); } int index = 0; List cplist = new List(); foreach (var mo in molist) { if (index == list2.Count - 1) index = 0; CastingParameter a = list2[index]; CastingParameter c = new CastingParameter(); c.PID = Guid.NewGuid().ToString(); c.PDID = mo.PDID; c.PRODUCTCODE = mo.PRODUCTCODE; c.MOID = mo.PID; c.PRODUCTTYPE = "8"; c.MACHINENAME = "AUDIB9浇注设备"; c.MACHINECODDE = "1A-FB0004"; c.CREATEDATE = mo.UPDATEDATE; if (mo.MOLDNUMBER.ToString() == "5") { c.MOULDNUMBER = 1; } else if (mo.MOLDNUMBER.ToString() == "1") { c.MOULDNUMBER = 2; } else { c.MOULDNUMBER = 4; } c.MAINCODE = "2"; //decimal flowValue = new Random().Next(3943, 3954); c.FLOW = a.FLOW; //decimal stressPercentValue = 6; c.STRESSPERCENT = a.STRESSPERCENT; //decimal mt1 = new Random().Next(271, 289); c.METARIALTEMPRATURE = a.METARIALTEMPRATURE; //decimal mt2 = new Random().Next(284, 293); c.METARIALTEMPRATURETWO = a.METARIALTEMPRATURETWO; using (IDataSession session = AppDataFactory.CreateMainSession()) { session.Insert(c); Console.WriteLine("Insert Complete"); } index++; } } } }