/// <summary> /// 保存问题 /// </summary> /// <param name="list_ad"></param> /// <returns></returns> public bool SaveAlarm(alarmdetail ad) { using (sartas3 db = new sartas3()) { try { alarmdetail old = db.alarmdetail.FirstOrDefault(n => n.AlarmDetail_ID == ad.AlarmDetail_ID); if (old != null) { old.HandleResult = ad.HandleResult; old.OpUser = ad.OpUser; } else { ad.AlarmDetail_ID = Guid.NewGuid().ToString(); ad.AlarmLevel = 1; ad.AlgResult = 0; db.alarmdetail.Add(ad); } db.SaveChanges(); return(true); } catch (Exception e) { throw e; } } }
public void Set_SysCode(sys_code c) { using (sartas3 db = new sartas3()) { //sys_code tmp = db.sys_code.SingleOrDefault(n => n.Code_ID == c.Code_ID); db.sys_code.Attach(c); db.Entry(c).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
/// <summary> /// 只更新备注字段 /// </summary> /// <param name="c"></param> public void Set_SysCodeRemark(sys_code c) { using (sartas3 db = new sartas3()) { sys_code tmp = db.sys_code.SingleOrDefault(n => n.Code_ID == c.Code_ID); if (tmp != null) { tmp.Remark = c.Remark; db.SaveChanges(); } } }
public static void Error(string ApplicationName, string FunctionName, string Detail) { using (sartas3 db = new sartas3()) { sys_log l = new sys_log(); l.LogID = Guid.NewGuid().ToString(); l.ApplicationName = ApplicationName; l.FunctionName = FunctionName; l.Detail = Detail; l.OpTime = DateTime.Now; l.State = "异常"; db.sys_log.Add(l); db.SaveChanges(); } }
/// <summary> /// 更新车厢报警等级 /// </summary> /// <param name="TrainDetailID"></param> public void Update_CarAlarmLevel(string TrainDetailID) { try { using (sartas3 db = new sartas3()) { var q = db.alarmdetail.Where(n => n.TrainDetail_ID == TrainDetailID && n.AlarmLevel != 0 && n.AlarmLevel != null).Min(n => n.AlarmLevel); Guid g = new Guid(TrainDetailID); traindetail oldtd = db.traindetail.Where(n => n.TrainDetail_ID == g).FirstOrDefault(); if (oldtd != null) { oldtd.AlarmLevel = q.ToString(); } db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新列车报警等级 /// </summary> /// <param name="TrainID"></param> public void Update_TrainAlarmLevel(string TrainID) { try { using (sartas3 db = new sartas3()) { Guid tmp = new Guid(TrainID); var q = db.traindetail.Where(n => n.Train_ID == tmp && n.AlarmLevel != "0" && n.AlarmLevel != "" && n.AlarmLevel != null).Min(n => n.AlarmLevel); train oldt = db.train.Where(n => n.Train_ID == tmp).FirstOrDefault(); if (oldt != null) { oldt.AlarmLevel = q; } db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 保存问题(修改和新增) /// 【WebService 使用】【不根据id进行判别】 /// </summary> /// <returns></returns> public bool SaveAlarms(List <alarmdetail> list_ad, int LineID, DateTime TrainComeDate, string TelexCode, int TrainDetailOrderNum) { try { //由于入库导致的 Thread.Sleep(new TimeSpan(0, Config.DelayTime4Save, 0)); if (list_ad != null && list_ad.Count > 0) { using (sartas3 db = new sartas3()) { train t = db.train.SingleOrDefault(n => n.Train_ComeDate == TrainComeDate && n.Line_ID == LineID && n.TelexCode == TelexCode); if (t != null) { //首先根据时间找到指定的分表 string TableName = "traindetail"; if (TrainComeDate.Month < DateTime.Now.Month) { for (DateTime i = TrainComeDate; i.Month < DateTime.Now.Month; i = i.AddMonths(1)) { TableName = "traindetail_" + i.ToString("MM"); string SQL_BeSureTableExist = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='" + Config.DB_SCHEMA + "' AND TABLE_NAME = 'traindetail_" + i.ToString("yyyyMM") + "'"; string resName = db.Database.SqlQuery <string>(SQL_BeSureTableExist).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(resName)) { break; } else { TableName = "traindetail"; } } } //根据分表名称进行查询 string SQL_Query = @"SELECT * FROM " + Config.DB_SCHEMA + "." + TableName + @" td WHERE td.Train_ID = '" + t.Train_ID + "' AND td.TrainDetail_OrderNo='" + TrainDetailOrderNum + "' ORDER BY td.TrainDetail_OrderNo"; traindetail td = db.Database.SqlQuery <traindetail>(SQL_Query).SingleOrDefault(); if (td != null) { foreach (alarmdetail ad in list_ad) { if (!string.IsNullOrWhiteSpace(ad.AlarmDetail_ID)) { alarmdetail oldone = db.alarmdetail.SingleOrDefault(n => n.AlarmDetail_ID == ad.AlarmDetail_ID); if (oldone != null) { //修改 oldone.HandleResult = ad.HandleResult; oldone.OpTime = DateTime.Now; } else { //新增 ad.Train_ID = t.Train_ID.ToString(); ad.TrainDetail_ID = td.TrainDetail_ID.ToString(); ad.HandleResult = "0";//新增 ad.AlarmLevel = 1; db.alarmdetail.Add(ad); } db.SaveChanges(); } else { throw new Exception("AlarmDetailID为Null"); } } //更新车厢报警等级 new BLL_Car().Update_CarAlarmLevel(td.TrainDetail_ID.ToString()); } else { throw new Exception("未找到该车车厢"); } //更新列车报警等级 new BLL_Train().Update_TrainAlarmLevel(t.Train_ID.ToString()); } else { throw new Exception("未找到该列车"); } } return(true); } else { throw new Exception("AlarmDetail为空"); } } catch (Exception ex) { throw ex; } }