private bool CheckAlarmLoc(AlarmItem alarmItem, AlarmLoc alarmLoc, string currLocNo, int alarmIndex) { if (string.IsNullOrEmpty(alarmItem.AlarmLocNo)) { return(false); } if (alarmItem.AlarmLocNo == currLocNo) { return(false); } var oldAlarmLoc = locList.FirstOrDefault(p => p.LocArea.ToString() + p.LocCode.ToString() == alarmItem.AlarmLocNo); if (oldAlarmLoc == null) { return(false); } ShowFormData.Instance.ShowFormInfo(new ShowInfoData(oldAlarmLoc.LocPlcNo, InfoType.locStatus)); if (oldAlarmLoc.alarmInfo[alarmIndex].Objid <= 0) { return(false); } var errMsg = string.Empty; //更新报警已处理信息 if (DbAction.Instance.UpdateAlarmData(oldAlarmLoc, alarmIndex, ref errMsg)) { oldAlarmLoc.alarmInfo[alarmIndex].Objid = 0; ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"[报警]下位机[{oldAlarmLoc.LocPlcNo}]变更[{alarmLoc?.LocPlcNo}]报警[{alarmLoc.alarmInfo[alarmIndex].AlarmDesc}]复位")); } else { ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"[报警]下位机[{oldAlarmLoc.LocPlcNo}]变更[{alarmLoc?.LocPlcNo}]报警[{alarmLoc.alarmInfo[alarmIndex].AlarmDesc}]复位失败:{errMsg}")); return(false); } return(true); }
/// <summary> /// 初始化项信息 /// </summary> public bool InitItems() { try { var dtGroup = DbAction.Instance.GetAlarmGroup(); if (dtGroup == null || dtGroup.Rows.Count == 0) { ShowFormData.Instance.ShowFormInfo(new ShowInfoData("未获取到配置OPC组信息")); return(false); } foreach (DataRow row in dtGroup.Rows) { var groupName = row["group_name"].ToString(); var dtLoc = DbAction.Instance.GetOpcLocItems(groupName); if (dtLoc == null || dtLoc.Rows.Count == 0) { ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"组{groupName}未获取到OPC分区、编号、类型配置项信息")); continue; } //获取OPC分区、编号、类型长名 var alarmAreaKey = string.Empty; var alarmCodeKey = string.Empty; var alarmTypeKey = string.Empty; foreach (DataRow locRow in dtLoc.Rows) { switch (locRow["tagname"].ToString()) { case "Alarm_Area": alarmAreaKey = locRow["tagLongName"].ToString(); break; case "Alarm_Code": alarmCodeKey = locRow["tagLongName"].ToString(); break; case "Alarm_Type": alarmTypeKey = locRow["tagLongName"].ToString(); break; } } //获取OPC项 var dtItems = DbAction.Instance.GetOpcAlarmItems(groupName); if (dtItems == null || dtItems.Rows.Count == 0) { ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"组{groupName}未获取到OPC配置项信息")); continue; } foreach (DataRow itemRow in dtItems.Rows) { var alarmItem = new AlarmItem(); alarmItem.AlarmAreaKey = alarmAreaKey; alarmItem.AlarmCodeKey = alarmCodeKey; alarmItem.AlarmTypeKey = alarmTypeKey; alarmItem.Kind = Convert.ToInt32(itemRow["kind"]); alarmItem.AlarmIndex = Convert.ToInt32(itemRow["tagindex"]); alarmItem.TagLongName = itemRow["tagLongName"].ToString(); alarmItems.Add(alarmItem.TagLongName, alarmItem); } } ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"初始化OPC配置项成功")); return(true); } catch (Exception ex) { ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"[异常]初始化OPC配置项,[原因]{ex.Message}")); return(false); } }