public void RecToDB() { //true为启动,false为退出 act.启动 = active ? (byte)1 : (byte)0; act.退出 = active ? (byte)0 : (byte)1; act.时间 = time; act.IP地址 = GetLocalIP(); try { using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return; } db.Activate.InsertOnSubmit(act); db.CommandTimeout = 30; db.SubmitChanges(); } } catch (Exception ex) { errStr = ex.ToString(); return; } }
public PingInfoHelper(DbAppDataContext db, PgInfo pInfo, bool beginRec) { this.db = db; if (!db.DatabaseExists()) { return; } this.pInfo = pInfo; AssignmentInsertInfo(beginRec); }
public void RecToPlanDB() { using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return; } DeleteFromDbPlan(editPlan); AddToDbPlan(editPlan); db.SubmitChanges(); } }
/// <summary> /// 从DB中按条件查询联锁信息 /// </summary> /// <param name="start">查询起始时间</param> /// <param name="end">查询终止时间</param> /// <param name="room">按炉号查询时,room>0</param> /// <returns></returns> public DataTable QueryRec(DateTime start, DateTime end, byte room) { //记录查询: //0日期,1计划炉号,2实际炉号,3联锁,***T-L-X车号,4推物理地址,5拦物理地址,6熄物理地址,7煤物理地址,8实际推,9预定推,10实际装,11实际结焦,12Max推焦电流,13Avg推焦电流,14Avg平煤电流,15时段,16班组 DataTable table = new DataTable("Rec"); SetCloumnsName(table); using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } // 判断是否为按炉号查询 :(room > 0 ? (pInfo.计划炉号 == room || rec.实际炉号 == room) : 1 == 1) 条件表达式返回值为一条语句 var recs = from rec in db.PushInfo where rec.预定出焦时间 >= start && rec.预定出焦时间 < end && (room > 0 ? (rec.实际炉号 == room || rec.计划炉号 == room) : 1 == 1) select rec; if (recs == null || recs.Count() <= 0) { return(null); } foreach (var p in recs) { DataRow r = table.NewRow(); int index = 0; r[index++] = p.预定出焦时间.Value.Date.ToString("d"); //0日期 r[index++] = p.计划炉号.Value.ToString("000"); //1计划炉号 r[index++] = p.T炉号 != null?p.T炉号.Value.ToString("000") : "0"; r[index++] = p.L炉号 != null?p.L炉号.Value.ToString("000") : "0"; r[index++] = p.X炉号 != null?p.X炉号.Value.ToString("000") : "0"; r[index++] = ByteToLockStatus(p.联锁.Value);//3联锁 r[index++] = p.Push工作车序列 != null?p.Push工作车序列.Value.ToString("0-0-0") : "0-0-0"; r[index++] = p.Max推焦电流 != null?p.Max推焦电流.Value.ToString("000") : "0"; //Max推焦电流 r[index++] = p.实际推焦时间 != null?p.实际推焦时间.Value.ToString("G") : " "; //8实际推焦时间 r[index++] = p.预定出焦时间 != null?p.预定出焦时间.Value.ToString("g") : " "; //9预定出焦时间 r[index++] = p.实际推焦时间 != null?IntToTimeFormat(((int)(p.实际推焦时间.Value - p.次装煤时间.Value).TotalMinutes)) : "19:00"; //实际结焦时间 r[index++] = p.PlanIndex != null ? p.PlanIndex.Value : -1; r[index++] = p.PlanCount != null ? p.PlanCount.Value : 0; table.Rows.Add(r); } } return(table); }
/// <summary> /// 计算得到K系数 /// </summary> /// <param name="start"> 起始时间</param> /// <param name="period"> 时段</param> /// <param name="_12H">决定24H分为白中夜三班,还是白夜两班 </param> /// <returns></returns> public List <SumHelper> QuerySumInfo(DateTime start, int period, bool _12H) { using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } DateTime[] time = PeriodToTime(start, period, _12H); var recs = from rec in db.PushInfo from rec1 in db.PingInfo where rec.预定出焦时间 >= time[0] && rec.预定出焦时间 < time[1] && rec1.预定出焦时间 >= time[0] && rec1.预定出焦时间 < time[1] && (rec.预定出焦时间 == rec1.预定出焦时间) select new { rec.计划炉号, rec.预定出焦时间, rec.计划结焦时间, rec.规定结焦时间, rec.实际结焦时间, rec.实际推焦时间, rec1.Begin平煤时间, //装煤时间 rec.Max推焦电流, }; if (recs == null || recs.Count() <= 0) { return(null); } List <SumHelper> sum = new List <SumHelper>(); int index = 1; foreach (var r in recs) { SumHelper s = new SumHelper(); s.Num = index++;//炉数 s.RoomNum = r.计划炉号 != null ? (int)r.计划炉号 : 0; s.PushTime = r.预定出焦时间 != null ? (DateTime)r.预定出焦时间 : DateTime.Now; s.ActualPushTime = r.实际推焦时间 != null ? (DateTime)r.实际推焦时间 : DateTime.Now; s.ActualStokingTime = r.Begin平煤时间 != null ? (DateTime)r.Begin平煤时间 : DateTime.Now; s.StandardBurnTime = r.规定结焦时间 != null ? (int)r.规定结焦时间 : 0; s.BurnTime = r.计划结焦时间 != null ? (int)r.计划结焦时间 : 0; s.ActualBurnTime = r.实际结焦时间 != null ? (int)r.实际结焦时间 : 0; s.PushCur = r.Max推焦电流 != null ? (int)r.Max推焦电流 : 0; sum.Add(s); } return(sum); } }
public void RecToDB() { try { using (db) { if (!db.DatabaseExists()) { return; } db.SubmitChanges(); } } catch (Exception err) { Log.LogErr.Info("类:PingInfoHelper.cs,方法:RECToDB();" + err.ToString()); } }
public DataTable QueryPlanDB(DateTime start, DateTime end) { //计划查询: //1炉号,2预定出焦时间,3实际推焦时间(删除0829),4上次装煤时间,5实际结焦时间(删除0829),6计划结焦时间,7规定结焦时间,8实际结焦时间 //起始时间:Start,结束时间End DataTable table = new DataTable("Plan"); string[] columnsName = { "日期", "炉号", "预定出焦时间", "上次装煤时间", "规定结焦时间", "计划结焦时间" }; Type[] types = { typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }; for (int i = 0; i < columnsName.Length; i++) { table.Columns.Add(columnsName[i], types[i]); } using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } var plans = from p in db.PushPlan where p.预定出焦时间 >= start && p.预定出焦时间 < end select p; if (plans.Count() <= 0) { return(null); } List <PushPlan> lstPlan = plans.ToList(); plans = plans.OrderBy(p => p.预定出焦时间);//按预定出焦时间排序 foreach (var p in plans) { DataRow r = table.NewRow(); r[0] = p.预定出焦时间.Value.ToShortDateString(); //日期 r[1] = p.炉号.Value.ToString("000"); //炉号 r[2] = p.预定出焦时间.Value.ToString("g"); //预定出焦时间 r[3] = p.次装煤时间.Value.ToString("g"); //装煤时间 r[4] = ToTimeFormat(p.规定结焦时间.Value); //规定结焦时间 r[5] = ToTimeFormat(p.计划结焦时间.Value); //计划结焦时间 table.Rows.Add(r); } return(table); } }
public DataTable QueryLogIn() { DataTable table = new DataTable(); string[] columnsName = { "日期", "记录", "时间", "IP地址" }; for (int i = 0; i < columnsName.Length; i++) { table.Columns.Add(columnsName[i], typeof(string)); } using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } var logs = from p in db.Activate where p.时间 >= start && p.时间 < end select p; if (logs.Count() <= 0) { return(null); } List <Activate> lstLog = logs.ToList(); logs = logs.OrderBy(p => p.时间);//按预定出焦时间排序 foreach (var p in logs) { DataRow r = table.NewRow(); r[0] = p.时间.Value.ToShortDateString(); //日期 r[1] = p.启动.Value == 1 ? "登陆" : "退出"; //登陆or退出 r[2] = p.时间.Value.ToString("G"); //实际发生时间 r[3] = p.IP地址.ToString(); table.Rows.Add(r); } return(table); } }
public List <CurHelper> QueryCurInfo(DateTime start, DateTime end, byte room) { using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } var recs = from rec in db.PushInfo where rec.预定出焦时间 >= start && rec.预定出焦时间 < end && (room > 0 ? (rec.计划炉号 == room) : 1 == 1) select new { //<!--6联锁信息:日期,炉号,预定出焦时间,Max推焦电流,Avg平煤电流,时段,班组, rec.计划炉号, rec.预定出焦时间, rec.Max推焦电流, rec.Avg推焦电流, rec.时段, rec.班组, rec.推焦杆长, rec.推焦电流, }; var recs1 = from rec1 in db.PingInfo where rec1.预定出焦时间 >= start && rec1.预定出焦时间 < end && (room > 0 ? (rec1.预定装煤炉号 == room) : 1 == 1) select new { rec1.预定出焦时间, rec1.Avg平煤电流, rec1.Pole平煤杆长, rec1.Cur平煤电流 }; if (recs == null || recs.Count() == 0) { return(null); } List <CurHelper> cur = new List <CurHelper>(); foreach (var r in recs) { CurHelper c = new CurHelper(); c.Date = r.预定出焦时间 != null?r.预定出焦时间.Value.ToString("d") : "0000"; c.Room = r.计划炉号 != null?r.计划炉号.Value.ToString("000") : "000"; c.PushTime = r.预定出焦时间 != null?r.预定出焦时间.Value.ToString("g") : "000"; c.MaxCur = r.Max推焦电流 != null?r.Max推焦电流.Value.ToString("000") : "000"; c.AvgPushCur = r.Avg推焦电流 != null?r.Avg推焦电流.Value.ToString("000") : "000"; c.PushPole = r.推焦杆长; c.PushCur = r.推焦电流; cur.Add(c); } if (recs1.Count() > 0) { foreach (var r in recs1) { int index = cur.FindIndex(x => x.PushTime == ((DateTime)r.预定出焦时间).ToString("g")); if (index >= 0) { cur[index].AvgPingCur = r.Avg平煤电流 != null?r.Avg平煤电流.Value.ToString("000") : "000"; cur[index].PingPole = r.Pole平煤杆长; cur[index].PingCur = r.Cur平煤电流; } } } return(cur); } }
/// <summary> /// 20170910把返回值Datatable改为List<LockInfoHelper> .别删除注释的代码 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="room"></param> /// <returns></returns> public List <LockInfoHelper> QueryLockInfo(DateTime start, DateTime end, byte room) { //DataTable dt = new DataTable(); //SetCloumnsName(dt, false); using (db = new DbAppDataContext(Setting.ConnectionStr)) { if (!db.DatabaseExists()) { return(null); } var recs = from rec in db.PushInfo where rec.预定出焦时间 >= start && rec.预定出焦时间 < end && (room > 0 ? (rec.计划炉号 == room) : 1 == 1) select new { //<!--6联锁信息:日期,炉号,预定出焦时间,实际推焦时间,计划装煤时间,实际装煤时间,Max推焦电流,Avg平煤电流,时段,班组, //T炉号Push,L炉号Push,X炉号Push,Push联锁数据,M炉号,Ping联锁数据,T物理地址,L物理地址,X物理地址--> rec.计划炉号, rec.预定出焦时间, rec.实际推焦时间, rec.Max推焦电流, rec.时段, rec.班组, rec.T炉号, rec.L炉号, rec.X炉号, rec.TAddr, rec.LAddr, rec.XAddr, rec.Push对中序列, rec.Push联锁信息, rec.Push工作车序列, rec.联锁 }; if (recs == null || recs.Count() <= 0) { return(null); } List <LockInfoHelper> locks = new List <LockInfoHelper>(); foreach (var r in recs) { //<!--6联锁信息:1日期,2炉号,3预定出焦时间,4实际推焦时间,5计划装煤时间,6实际装煤时间,7Max推焦电流,8Avg平煤电流,9时段,10班组, //11T炉号Push,12L炉号Push,13X炉号Push,14对中信号,15Push联锁数据,16M炉号,17Ping联锁数据--> //DataRow row = dt.NewRow(); LockInfoHelper helper = new LockInfoHelper(); DateTime invalidTime = Convert.ToDateTime("2012-04-03 13:14"); helper.Date = r.预定出焦时间.Value.ToString("d"); //1日期 helper.Room = r.计划炉号 != null?r.计划炉号.Value.ToString("000") : "000"; //2炉号 helper.PushTime = r.预定出焦时间 != null ? r.预定出焦时间.Value : invalidTime; //3预定出焦时间 helper.ActualPushTime = r.实际推焦时间 != null ? r.实际推焦时间.Value : invalidTime; //4实际推焦时间 helper.MaxCur = r.Max推焦电流 != null?r.Max推焦电流.Value.ToString("000") : "0"; //7Max推焦电流 helper.Period = r.时段 != null?ByteToPeriod(r.时段.Value) : null; //9时段 helper.Group = r.班组 != null?ByteToGroup(r.班组.Value) : null; //10班组 helper.TRoom = r.T炉号 != null?r.T炉号.Value.ToString("000") : "0"; //11T炉号Push helper.LRoom = r.L炉号 != null?r.L炉号.Value.ToString("000") : "0"; //12L炉号Push helper.XRoom = r.X炉号 != null?r.X炉号.Value.ToString("000") : "0"; //13X炉号Push14 helper.TAddr = r.TAddr != null?r.TAddr.Value.ToString() : "0"; helper.LAddr = r.LAddr != null?r.LAddr.Value.ToString() : "0"; helper.XAddr = r.XAddr != null?r.XAddr.Value.ToString() : "0"; helper.Ready = r.Push对中序列 != null ? r.Push对中序列.Value : 0; //14对中信号 helper.PushInfo = r.Push联锁信息 != null ? r.Push联锁信息.Value : 0; //15Push联锁数据 helper.PushTogether = r.联锁 != null ? (r.联锁.Value == 1 ? true : false) : false; helper.CarsNum = r.Push工作车序列 != null ? r.Push工作车序列.Value : (short)0; helper.GetAllCarArrows(); helper.GetUIRoom(); helper.GetTogetherInfo(); locks.Add(helper); } return(locks); } }