public AllAlarms GetAllAlarmsByPerson(AlarmSearchArgAll args) { AllAlarms alarms = new AllAlarms(); try { string sqlwhere1 = ""; string sqlwhere2 = ""; string personnels = ""; if (args != null) { if (args.personnels != null) { foreach (int person in args.personnels) { personnels += person.ToString() + ","; } personnels = personnels.Substring(0, personnels.Length - 1); sqlwhere1 += " and PersonnelId in (" + personnels + ")"; } if (args.startTime != null && args.endTime != null) { sqlwhere1 += string.Format(@" and AlarmTimeStamp>{0} and AlarmTimeStamp<{1}", args.startTime.ToStamp(), args.endTime.ToStamp()); sqlwhere2 += string.Format(@" and AlarmTimeStamp>{0} and AlarmTimeStamp<{1}", args.startTime.ToStamp(), args.endTime.ToStamp()); } } string sql1 = string.Format(@"select id,AlarmId,AlarmType,AlarmLevel,LocationCardId,PersonnelId,CardRoleId,AreaId,AuzId,AllAuzId,Content,AlarmTime,AlarmTimeStamp,HandleTime,HandleTimeStamp,`Handler`,HandleType from location.locationalarms where 1=1 " + sqlwhere1); string sql2 = string.Format(@"select id,AlarmId,AlarmType,AlarmLevel,LocationCardId,PersonnelId,CardRoleId,areadid,AuzId,AllAuzId,Content,AlarmTime,AlarmTimeStamp,HandleTime,HandleTimeStamp,`Handler`,HandleType, HistoryTime, HistoryTimeStamp from locationhistory.locationalarmhistories where 1=1 " + sqlwhere1); string sql3 = string.Format(@"select id,Abutment_Id,Title,Msg,`LEVEL`,`Code`,Src,DevInfoId,Device_desc,AlarmTime,AlarmTimeStamp from location.devalarms where 1=1 " + sqlwhere2); string sql4 = string.Format(@"select id,Abutment_Id,Title,Msg,`LEVEL`,`Code`,Src,DevInfoId,Device_desc,AlarmTime,AlarmTimeStamp,historyTime,historyTimeStamp from locationhistory.devalarmhistories where 1=1 " + sqlwhere2); List <DbModel.Location.Alarm.LocationAlarm> list1 = db.LocationAlarms.GetListBySql <DbModel.Location.Alarm.LocationAlarm>(sql1); List <LocationAlarmHistory> list2 = db.LocationAlarmHistorys.GetListBySql <LocationAlarmHistory>(sql2); List <DbModel.Location.Alarm.LocationAlarm> listalarm = new List <DbModel.Location.Alarm.LocationAlarm>(); listalarm.AddRange(list1); foreach (LocationAlarmHistory alarmHis in list2) { DbModel.Location.Alarm.LocationAlarm alarm = alarmHis.ConvertToAlarm(); listalarm.Add(alarm); } List <DevAlarm> list3 = db.DevAlarms.GetListBySql <DevAlarm>(sql3); List <DevAlarmHistory> devalarmHiss = db.DevAlarmHistorys.GetListBySql <DevAlarmHistory>(sql4); List <DevAlarm> devalarms = new List <DevAlarm>(); devalarms.AddRange(list3); foreach (DevAlarmHistory devalarmhis in devalarmHiss) { DevAlarm devalarm = devalarmhis.ConvertToDevAlarm(); devalarms.Add(devalarm); } alarms.alarmList = listalarm.ToTModel(); alarms.devAlarmList = devalarms.ToTModel(); } catch (Exception ex) { alarms.alarmList = new List <T_LocationAlarm>(); alarms.devAlarmList = new List <DeviceAlarm>(); Log.Error("AlarmService.GetAllAlarmsByPerson:" + ex.ToString()); } return(alarms); }
public void TryAddNewAlarmCode(int alarmCodeID, string alarmText, EnumAlarmLevel level, string description) { Alarm newAlarm = new Alarm(); newAlarm.Id = alarmCodeID; newAlarm.AlarmText = alarmText; newAlarm.Level = level; newAlarm.Description = description; if (!AllAlarms.ContainsKey(newAlarm.Id)) { AllAlarms.Add(newAlarm.Id, newAlarm); } }
public void SetAlarm(int alarmCodeID) { try { DateTime timeStamp = DateTime.Now; Alarm alarm = AllAlarms.ContainsKey(alarmCodeID) ? AllAlarms[alarmCodeID] : new Alarm { Id = alarmCodeID }; alarm.SetTime = timeStamp; lock (lockObject) { if (dicHappeningAlarms.ContainsKey(alarmCodeID)) { ; } else { dicHappeningAlarms.Add(alarmCodeID, alarm); SetAlarmHistroyLogByAlarm(alarm); switch (alarm.Level) { case EnumAlarmLevel.Alarm: HasAlarm = true; break; case EnumAlarmLevel.Warn: default: HasWarn = true; break; } } } } catch (Exception ex) { WriteLog(5, "", "Exception : ", ex.ToString()); WriteLog(5, "", "Exception : ", ex.StackTrace); } }
private void LoadAlarmFile() { try { string alarmFullPath = Path.Combine(LocalData.Instance.MapConfig.FileDirectory, alarmFileName); if (!File.Exists(alarmFullPath)) { WriteLog(3, "", String.Concat("找不到AlarmCode.csv, path : ", alarmFullPath)); return; } Dictionary <string, int> dicAlarmIndexes = new Dictionary <string, int>(); AllAlarms.Clear(); string[] allRows = File.ReadAllLines(alarmFullPath, Encoding.UTF8); if (allRows == null || allRows.Length < 2) { WriteLog(3, "", "There are no alarms in file"); return; } string[] titleRow = allRows[0].Split(','); allRows = allRows.Skip(1).ToArray(); int nRows = allRows.Length; int nColumns = titleRow.Length; //Id, AlarmText, PlcAddress, PlcBitNumber, Level, Description for (int i = 0; i < nColumns; i++) { var keyword = titleRow[i].Trim(); if (!string.IsNullOrWhiteSpace(keyword)) { dicAlarmIndexes.Add(keyword, i); } } for (int i = 0; i < nRows; i++) { string[] getThisRow = LoadAlarmFile_SplitCsvLine(allRows[i]); Alarm oneRow = new Alarm(); oneRow.Id = int.Parse(getThisRow[dicAlarmIndexes["Id"]]); oneRow.AlarmText = getThisRow[dicAlarmIndexes["AlarmText"]]; oneRow.Level = EnumAlarmLevelParse(getThisRow[dicAlarmIndexes["Level"]]); oneRow.Description = getThisRow[dicAlarmIndexes["Description"]]; if (AllAlarms.ContainsKey(oneRow.Id)) { WriteLog(3, "", String.Concat("Alarm code : ", oneRow.Id.ToString(), "repeat")); } else { AllAlarms.Add(oneRow.Id, oneRow); } } } catch (Exception ex) { WriteLog(3, "", String.Concat("Exception : ", ex.ToString())); WriteLog(3, "", String.Concat("Exception : ", ex.StackTrace)); } }