/// <summary> /// 获取新增预警信息 /// </summary> public void getdata() { short type = 0; long id = 0; Jc_BInfo jcb = null; Jc_BInfo obj = null; lock (StaticClass.bjobj) { try { #region 获取预警信息 foreach (long key in StaticClass.jcbdata.Keys) { jcb = StaticClass.jcbdata[key]; type = jcb.Type; if (type == StaticClass.itemStateToClient.EqpState7 || type == StaticClass.itemStateToClient.EqpState17) { id = long.Parse(jcb.ID); if (!jc_b.ContainsKey(id)) { #region 新增预警 obj = OprFuction.NewDTO(jcb); jc_b.Add(id, obj); addlist.Add(id); #endregion } else { #region 新增预警结束 if (!OprFuction.IsInitTime(jcb.Etime)) { if (OprFuction.IsInitTime(jc_b[id].Etime)) { obj = OprFuction.NewDTO(jcb); jc_b[id] = obj; updatelist.Add(id); } } #endregion } } } #region 判断是否预警还存在 foreach (long key in jc_b.Keys) { if (!StaticClass.jcbdata.ContainsKey(key)) { deletelist.Add(key); } } #endregion #endregion } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } }
/// <summary> /// 更新JC_B /// </summary> /// <param name="alarmInfo"></param> private static void UpdateJC_BInfo(Jc_BInfo alarmInfo) { Dictionary <string, object> updateItems = new Dictionary <string, object>(); //updateItems.Add("State", alarmInfo.State); updateItems.Add("Etime", alarmInfo.Etime); //updateItems.Add("Zdz", alarmInfo.Zdz); //updateItems.Add("Pjz", alarmInfo.Pjz); //updateItems.Add("Zdzs", alarmInfo.Zdzs); //updateItems.Add("Kzk", alarmInfo.Kzk); //updateItems.Add("Isalarm", alarmInfo.Isalarm); //更新到缓存 AlarmCacheUpdatePropertiesRequest alarmCacheUpdatePropertiesRequest = new AlarmCacheUpdatePropertiesRequest(); alarmCacheUpdatePropertiesRequest.AlarmKey = alarmInfo.ID; alarmCacheUpdatePropertiesRequest.UpdateItems = updateItems; alarmCacheService.UpdateAlarmInfoProperties(alarmCacheUpdatePropertiesRequest); //更新到数据库 System.Data.DataColumn[] cols = new System.Data.DataColumn[updateItems.Count]; for (int i = 0; i < updateItems.Count; i++) { cols[i] = new System.Data.DataColumn(updateItems.Keys.ToList()[i]); } Jc_BModel alarmModel = ObjectConverter.Copy <Jc_BInfo, Jc_BModel>(alarmInfo); List <Jc_BModel> alarmModels = new List <Jc_BModel>(); alarmModels.Add(alarmModel); alarmRecordRepository.BulkUpdate("KJ_DataAlarm" + alarmInfo.Stime.ToString("yyyyMM"), alarmModels, cols, "ID"); }
/// <summary> /// 生成报警记录 /// </summary> /// <param name="defInfo"></param> /// <param name="sTime"></param> /// <param name="dataState"></param> /// <param name="state"></param> public static void CreateJC_BInfo(Jc_DefInfo defInfo, DateTime sTime, DeviceDataState dataState, DeviceRunState state) { Jc_BInfo alarmInfo = new Jc_BInfo(); string controlport = string.Empty; alarmInfo.Cs = ""; alarmInfo.PointID = defInfo.PointID; alarmInfo.ID = IdHelper.CreateLongId().ToString(); alarmInfo.Devid = defInfo.Devid; alarmInfo.Fzh = defInfo.Fzh; alarmInfo.Kh = defInfo.Kh; alarmInfo.Dzh = defInfo.Dzh; alarmInfo.Kzk = controlport; alarmInfo.Point = defInfo.Point; alarmInfo.Ssz = EnumHelper.GetEnumDescription(state); alarmInfo.Isalarm = (short)defInfo.Alarm; alarmInfo.Stime = sTime; alarmInfo.Etime = new DateTime(1900, 1, 1, 0, 0, 0); alarmInfo.Type = (short)dataState; alarmInfo.State = GetState((DeviceRunState)state, defInfo.Bz4); alarmInfo.Upflag = "0"; alarmInfo.Wzid = defInfo.Wzid; InsertJC_BInfo(alarmInfo); }
/// <summary> /// 插入新记录 /// </summary> /// <param name="alarmInfo"></param> private static void InsertJC_BInfo(Jc_BInfo alarmInfo) { //添加记录入缓存 alarmInfo.Zdzs = new DateTime(1900, 1, 1, 0, 0, 0); AlarmCacheAddRequest addRequest = new AlarmCacheAddRequest(); addRequest.AlarmInfo = alarmInfo; alarmCacheService.AddAlarmCache(addRequest); //添加报警信息至数据库 DataToDbAddRequest <Jc_BInfo> dataToDbAddRequest = new DataToDbAddRequest <Jc_BInfo>(); dataToDbAddRequest.Item = alarmInfo; alarmTodbService.AddItem(dataToDbAddRequest); }
/// <summary> /// 结束设备报警 /// </summary> /// <returns></returns> private bool EndDeviceAlarm() { AlarmRecordGetDateIdRequest alarmgetByIdrequest = new AlarmRecordGetDateIdRequest { Id = _alarmId, AlarmDate = _stime }; var response = alarmRecordService.GetDateAlarmRecordById(alarmgetByIdrequest); if (response != null && response.IsSuccess && response.Data != null) { Jc_BInfo alarmInfo = response.Data; ClientItem _ClientItem = Basic.Framework.Data.PlatRuntime.Items[KeyConst.ClientItemKey] as ClientItem; if (_ClientItem != null) { alarmInfo.Bz1 = _ClientItem.UserName; } //alarmInfo.Etime = DateTime.Now; alarmInfo.Bz2 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); alarmInfo.Remark = reasonEdit.Text; alarmInfo.Cs = measureEdit.Text; Dictionary <string, object> updateItems = new Dictionary <string, object>(); updateItems.Add("Bz1", alarmInfo.Bz1); updateItems.Add("Bz2", alarmInfo.Bz2); updateItems.Add("Remark", alarmInfo.Remark); updateItems.Add("Cs", alarmInfo.Cs); AlarmRecordUpdateProperitesRequest updateRequest = new AlarmRecordUpdateProperitesRequest() { AlarmInfo = alarmInfo, UpdateItems = updateItems }; var updateResponse = alarmRecordService.UpdateAlarmInfoProperties(updateRequest); if (updateResponse != null && updateResponse.IsSuccess) { return(updateResponse.Data); } } return(false); }
/// <summary> /// 刷新预警数据 /// </summary> public void refresh(DateTime nowtime) { string point = "", ssz1, ssz2; double ssz, zdz, zxz, pjz, allvlaue, count; DataRow[] row; DataRow r; TimeSpan span; int countn = 0; long id = 0; Jc_BInfo obj = null; int tbcount = 0; long key = 0; List <long> listkey; #region 除已结束的记录 try { if (deletelist.Count > 0) { #region 除显示 countn = showdt.Rows.Count; lock (objShowDt) { for (int i = 0; i < countn; i++) { try { if (deletelist.Contains(long.Parse(showdt.Rows[i]["id"].ToString()))) { showdt.Rows.Remove(showdt.Rows[i]); i--; countn--; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } #endregion #region 除内存 for (int kj = 0; kj < deletelist.Count; kj++) { key = deletelist[kj]; if (jc_b.ContainsKey(key)) { jc_b.Remove(key); } } deletelist.Clear(); #endregion } } catch (Exception ex) { OprFuction.SaveErrorLogs("删除预警记录", ex); } #endregion #region 刷新实时值、最大值、最小值、平均值 持续时间 结束时间 try { lock (objShowDt)//防止删除的时候,遍历datatable修改对象找不到对象 { for (int i = 0; i < showdt.Rows.Count; i++) { if (showdt.Rows[i].IsNull("endtime") || showdt.Rows[i]["endtime"].ToString() == "") { id = long.Parse(showdt.Rows[i]["id"].ToString()); if (updatelist.Contains(id)) { #region 刷新 最大值、平均值 结束时间 obj = jc_b[id]; //showdt.Rows[i]["zdz"] = obj .Zdz; showdt.Rows[i]["pjz"] = obj.Pjz; showdt.Rows[i]["endtime"] = OprFuction.TimeToString(obj.Etime); #endregion #region 刷新持续时间 span = obj.Etime - Convert.ToDateTime(showdt.Rows[i]["stime"]); showdt.Rows[i]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); #endregion } else { #region 刷新持续时间 span = nowtime - Convert.ToDateTime(showdt.Rows[i]["stime"]); showdt.Rows[i]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); #endregion #region 刷新实时值、最大值、最小值、平均值 point = showdt.Rows[i]["point"].ToString(); ssz2 = showdt.Rows[i]["ssz"].ToString(); lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { ssz1 = row[0]["ssz"].ToString(); if (ssz1 != ssz2) { if (double.TryParse(ssz1, out ssz)) { zdz = Convert.ToDouble(showdt.Rows[i]["zdz"]); zxz = Convert.ToDouble(showdt.Rows[i]["zxz"]); pjz = Convert.ToDouble(showdt.Rows[i]["pjz"]); count = Convert.ToDouble(showdt.Rows[i]["count"]); allvlaue = Convert.ToDouble(showdt.Rows[i]["allvalue"]); if (ssz > zdz) { zdz = ssz; } else if (ssz < zxz) { zxz = ssz; } count += 1; allvlaue += ssz; pjz = Math.Round(allvlaue / count, 2); showdt.Rows[i]["zdz"] = zdz; showdt.Rows[i]["zxz"] = zxz; showdt.Rows[i]["pjz"] = pjz; showdt.Rows[i]["ssz"] = ssz; showdt.Rows[i]["count"] = count; if (showdt.Rows[i].Table.Columns.Contains("allvlaue")) { showdt.Rows[i]["allvlaue"] = allvlaue; } } } } } #endregion } } } } updatelist.Clear(); } catch (Exception ex) { OprFuction.SaveErrorLogs("刷新实时值、最大值、最小值、平均值", ex); } #endregion #region 添加记录 if (addlist.Count > 0) { lock (objShowDt) { for (int kj = 0; kj < addlist.Count; kj++) { key = addlist[kj]; if (jc_b.ContainsKey(key)) { obj = jc_b[key]; r = showdt.NewRow(); r["point"] = obj.Point; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + obj.Point + "'"); if (row.Length > 0) { r["wz"] = row[0]["wz"]; if (obj.Type == StaticClass.itemStateToClient.EqpState7) { r["yjz"] = row[0]["sxyj"]; } else { r["yjz"] = row[0]["xxyj"]; } } } //TODO:和其它业务模块相关联 //r["fzh"] = obj.Fzh + "/" + obj.Kh + "/" + obj.Dzh; //r["ssz"] = obj.Ssz; //r["state"] = OprFuction.StateChange(obj.Type.ToString()); //r["sbstate"] = OprFuction.StateChange(obj.State.ToString()); //r["stime"] = OprFuction.TimeToString(obj.Stime); //if (!OprFuction.IsInitTime(obj.Etime)) //{ // r["endtime"] = OprFuction.TimeToString(obj.Etime); //} //span = nowtime - obj.Stime; //r["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); //r["zdz"] = obj.Ssz; //r["zxz"] = obj.Ssz; //r["pjz"] = obj.Ssz; //r["count"] = 1; //r["allvalue"] = obj.Ssz; r["id"] = key; showdt.Rows.InsertAt(r, 0);//添加新记录 } } } addlist.Clear(); //mainGridView.FocusedRowHandle = 0; } #endregion #region 当前报警条数 tbcount = showdt.Rows.Count; StaticClass.yccount[0] = tbcount; #endregion }
/// <summary> /// 获取新增报警断电信息 /// </summary> public void getdata() { short type = 0; Jc_BInfo jcb = null; Jc_BInfo obj = null; DateTime maxtime = timenow; long key = 0; List <long> listkey; lock (StaticClass.bjobj) { #region 获取控制数据 try { listkey = StaticClass.jcbdata.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; jcb = StaticClass.jcbdata[key]; type = jcb.Type; if (!string.IsNullOrEmpty(jcb.Kzk)) { if (OprFuction.IsInitTime(jcb.Etime)) { if (!jc_b.ContainsKey(long.Parse(jcb.ID))) { #region 新增主控点引发控制 obj = OprFuction.NewDTO(jcb); jc_b.Add(long.Parse(jcb.ID), obj); addlist.Add(long.Parse(jcb.ID)); #endregion } else { if (jc_b[long.Parse(jcb.ID)].Kzk != jcb.Kzk) { obj = OprFuction.NewDTO(jcb); jc_b[long.Parse(jcb.ID)] = obj; addlist.Add(long.Parse(jcb.ID)); } } } else//只要列表中未结束的记录都更新,此处不需要每次加到uplist中 20170715 { //if (jc_b.ContainsKey(long.Parse(jcb.ID)))//&& !OprFuction.IsInitTime(jc_b[long.Parse(jcb.ID)].Etime) 20170706 //{ // #region 新增主控点引发控制 // obj = OprFuction.NewDTO(jcb); // jc_b[long.Parse(jcb.ID)] = obj; // uplist.Add(long.Parse(jcb.ID)); // #endregion //} } } else { //解决控制口取消绑定后,无法删除实时控制记录问题 2017.7.11 by if (jc_b.ContainsKey(long.Parse(jcb.ID))) { deletelist.Add(long.Parse(jcb.ID)); } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } #region 判断记录是否可以删除 DateTime now = Model.RealInterfaceFuction.GetServerNowTime(); listkey = jc_b.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; if (!StaticClass.jcbdata.ContainsKey(key)) { deletelist.Add(key); } } #endregion #endregion } }
/// <summary> /// 刷新报警数据 /// </summary> public void refresh(DateTime nowtime, List <Jc_DefInfo> pointDefineControlList) { string point = ""; DataRow[] row, row1; DataRow r; int countn = 0; string[] kzk = null; Jc_BInfo obj = null; Jc_DefInfo tempdef = null; int state1 = 0, state2 = 0; int tbcount = 0; Dictionary <string, string> kzkd = new Dictionary <string, string>(); string kdk = ""; object wz = "", dw = "", bjz = "", ddz = "", fzh = "", sszn = "", bjtime = "", ddtime = "", cs = "", idn = "", qy = "", sbstate = ""; long key = 0; List <long> listkey; #region 除已结束的记录 try { if (deletelist.Count > 0) { #region 除显示 countn = showdt.Rows.Count; lock (objShowDt) { for (int i = 0; i < countn; i++) { try { if (deletelist.Contains(long.Parse(showdt.Rows[i]["id"].ToString()))) { showdt.Rows.Remove(showdt.Rows[i]); i--; countn--; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } #endregion #region 除内存 for (int kj = 0; kj < deletelist.Count; kj++) { key = deletelist[kj]; if (jc_b.ContainsKey(key)) { jc_b.Remove(key); } } deletelist.Clear(); #endregion } } catch (Exception ex) { OprFuction.SaveErrorLogs("删除控制记录", ex); } #endregion #region 添加记录 if (addlist.Count > 0) { //tbcount = showdt.Rows.Count; try { #region 添加记录 for (int kj = 0; kj < addlist.Count; kj++) { key = addlist[kj]; kzkd.Clear(); if (jc_b.ContainsKey(key)) { obj = jc_b[key]; point = obj.Point; sbstate = OprFuction.StateChange(obj.State.ToString()); if (obj.State == (short)StaticClass.itemStateToClient.EqpState32) { continue;//类型有误不做处理 } lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { sszn = obj.Ssz + "/" + OprFuction.TimeToString(obj.Stime); if (obj.Type == StaticClass.itemStateToClient.EqpState9) { ddz = row[0]["sxbj"] + "|" + row[0]["sxyj"]; } else if (obj.Type == StaticClass.itemStateToClient.EqpState11) { ddz = row[0]["sxdd"] + "|" + row[0]["sxfd"]; } else if (obj.Type == StaticClass.itemStateToClient.EqpState19) { ddz = row[0]["xxbj"] + "|" + row[0]["xxyj"]; } else if (obj.Type == StaticClass.itemStateToClient.EqpState21) { ddz = row[0]["xxdd"] + "|" + row[0]["xxfd"]; } else { bjz = obj.Ssz; ddz = obj.Ssz; } } } bjtime = OprFuction.TimeToString(obj.Stime); idn = key; #region 控制口 if (!string.IsNullOrEmpty(obj.Kzk)) { kzk = obj.Kzk.Split('|'); if (kzk.Length > 0) { for (int i = 0; i < kzk.Length; i++) { #region 添加记录 //tempdef = Model.RealInterfaceFuction.Getpoint(kzk[i]); tempdef = pointDefineControlList.Find(a => a.Point == kzk[i]); if (tempdef != null) { lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["ddz"] = ddz; r["ssz"] = sszn; r["sbstate"] = sbstate; r["qy"] = tempdef.Wz; r["kzk"] = kzk[i]; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + kzk[i] + "'"); if (row.Length > 0) { kdk = OprFuction.StateChange(row[0]["zt"].ToString()); if (kdk == "0态") { r["kzzt"] = row[0]["0t"].ToString(); } else if (kdk == "1态") { r["kzzt"] = row[0]["1t"].ToString(); } else { r["kzzt"] = kdk; } } } if (tempdef.K2 != 0) { lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("fzh='" + tempdef.Fzh + "' and tdh='" + tempdef.K2 + "' and lx='开关量'"); if (row.Length > 0) { r["kdk"] = row[0]["point"].ToString(); kdk = OprFuction.StateChange(row[0]["zt"].ToString()); if (kdk == "0态") { r["kdkzt"] = row[0]["0t"].ToString(); } else if (kdk == "1态") { r["kdkzt"] = row[0]["1t"].ToString(); } else if (kdk == "2态") { r["kdkzt"] = row[0]["2t"].ToString(); } else { r["kdkzt"] = kdk; } } } r["kdzt"] = "检测中"; } else { r["kdk"] = "无"; r["kdkzt"] = "无"; r["kdzt"] = "无"; } r["stime"] = bjtime; r["id"] = key; r["endtime"] = ""; r["alarmstate"] = "进行中"; row = showdt.Select("id='" + key + "' and kzk='" + kzk[i] + "'"); if (row.Length < 1) { showdt.Rows.InsertAt(r, 0);//添加新记录 } } } #endregion } } } #endregion } } #endregion } catch (Exception ex) { OprFuction.SaveErrorLogs("添加控制记录", ex); } //tbcount = showdt.Rows.Count - tbcount; //StaticClass.yccount[4] += tbcount; addlist.Clear(); //mainGridView.FocusedRowHandle = 0; } #endregion #region 刷新记录,控制状态、馈电开关状态、馈电状态 try { if (showdt.Rows.Count > 0) { lock (objShowDt) { for (int i = 0; i < showdt.Rows.Count; i++) { r = showdt.Rows[i]; if (r["endtime"].ToString() == "")//只要在列表中,并且未结束,就实时更新控制口状态 20170712 { if (!r.IsNull("kzk")) { #region 控制口状态 lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + r["kzk"].ToString() + "'"); // 20170326 if (row.Length > 0) { if (row[0].Table.Columns.Contains("zt")) { if (!row[0].IsNull("zt")) { kdk = OprFuction.StateChange(row[0]["zt"].ToString()); if (kdk == "0态") { r["kzzt"] = row[0]["0t"].ToString(); } else if (kdk == "1态") { r["kzzt"] = row[0]["1t"].ToString(); } else { r["kzzt"] = kdk; } state1 = int.Parse(row[0]["zt"].ToString()); } } } } #endregion #region 馈电及状态 if (!r.IsNull("kdk") && r["kdk"].ToString() != "无") { lock (StaticClass.allPointDtLockObj) { row1 = StaticClass.AllPointDt.Select("point='" + r["kdk"].ToString() + "'"); // 20170326 if (row1.Length > 0) { if (row1[0].Table.Columns.Contains("zt")) { if (!row1[0].IsNull("zt")) { kdk = OprFuction.StateChange(row1[0]["zt"].ToString()); if (kdk == "0态") { r["kdkzt"] = row1[0]["0t"].ToString(); } else if (kdk == "1态") { r["kdkzt"] = row1[0]["1t"].ToString(); } else if (kdk == "2态") { r["kdkzt"] = row1[0]["2t"].ToString(); } else { r["kdkzt"] = kdk; } state2 = int.Parse(row1[0]["zt"].ToString()); //if (((nowtime -DateTime .Parse (row [0]["stime"].ToString ())).TotalSeconds>20)) //{ #region 馈电判断 //if (state1 == StaticClass.itemStateToClient.EqpState44)//控制口断开 //{ // if (state2 == StaticClass.itemStateToClient.EqpState26)//馈电开关量为2态 // { // r["kdzt"] = "断电失败"; // } // else if (state2 == StaticClass.itemStateToClient.EqpState25)//馈电开关量为1态 // { // r["kdzt"] = "断电成功"; // } // else//馈电开关量为0态 // { // r["kdzt"] = "断电成功";//0态默认是断电成功 20170622 // } //} //else//控制口接通 //{ // r["kdzt"] = "断电失败"; //} //不自己判断,取内存中的控制量对应的馈电状态 if (row[0]["NCtrlSate"].ToString() == "0") //复电成功 { r["kdzt"] = "复电成功"; } else if (row[0]["NCtrlSate"].ToString() == "2") //断电成功 { r["kdzt"] = "断电成功"; } else if (row[0]["NCtrlSate"].ToString() == "30") //复电失败 { r["kdzt"] = "复电失败"; } else if (row[0]["NCtrlSate"].ToString() == "32") //断电失败 { r["kdzt"] = "断电失败"; } else if (row[0]["NCtrlSate"].ToString() == "46") //未知 { r["kdzt"] = "未知"; } #endregion //} //else //{ // if (state1 == StaticClass.itemStateToClient.EqpState44) // { // if (state2 == StaticClass.itemStateToClient.EqpState25) // { // r["kdzt"] = "断电成功"; // } // } //} } } } } } #endregion #region 结束时间 //if (uplist.Contains(long.Parse(r["id"].ToString()))) //{ // r["endtime"] = "jieshu"; //} lock (StaticClass.bjobj) { if (!OprFuction.IsInitTime(StaticClass.jcbdata[long.Parse(r["id"].ToString())].Etime)) { r["endtime"] = StaticClass.jcbdata[long.Parse(r["id"].ToString())].Etime.ToString("yyyy-MM-dd HH:mm:ss"); r["alarmstate"] = "已结束"; } } #endregion } } } } //uplist.Clear(); } } catch (Exception ex) { OprFuction.SaveErrorLogs("刷新控制记录", ex); } #endregion #region 当前报警条数 tbcount = showdt.Select("endtime=''").Length; StaticClass.yccount[4] = tbcount; #endregion }
private void getdt(DateTime nowtime) { DataRow[] rows = null; DataRow row = null, r = null; TimeSpan span; string point = "", ssz1, ssz2; double ssz, zdz, zxz, pjz, allvlaue; int zt = -1; DataTable dt = showdt.Clone(); List <int> fzh; int x = -1, y = -1, count = 0, toprowindex = 0; long temp = 0; string[] kdid1; Jc_BInfo tempobj = null; bool updateflag = true; List <Jc_BInfo> endkdlist = new List <Jc_BInfo>(); Jc_BInfo lb = new Jc_BInfo(); string nt = string.Empty; try { #region 模拟量信息 lock (StaticClass.allPointDtLockObj) { rows = StaticClass.AllPointDt.Select("lx='开关量' ", "fzh,tdh,dzh"); //modified by 20170315 //在调试代码时,发现此select返回的行,第一行有时有为null的情况(估计是datatable读写并发引起返回为空行记录,临时通过特殊处理空行记录), if (rows != null && rows.Length > 0) { List <DataRow> list = new List <DataRow>(); foreach (DataRow dr in rows) { if (dr != null) //移除空行 { list.Add(dr); } } rows = list.ToArray(); } if (rows.Length > 0) { DataTable dt1 = rows.CopyToDataTable(); #region 除已结束的报警 lock (objShowDt) { for (int i = 0; i < showdt.Rows.Count; i++) { rows = dt1.Select("point='" + showdt.Rows[i]["point"].ToString() + "'"); if (rows.Length > 0) { #region 刷新实时值、最大值、最小值、平均值 point = showdt.Rows[i]["point"].ToString(); ssz2 = showdt.Rows[i]["ssz"].ToString(); ssz1 = rows[0]["ssz"].ToString(); if (ssz1 != ssz2) { showdt.Rows[i]["ssz"] = ssz1; showdt.Rows[i]["state"] = OprFuction.StateChange(rows[0]["zt"].ToString()); showdt.Rows[i]["sbstate"] = OprFuction.StateChange(rows[0]["sbzt"].ToString()); showdt.Rows[i]["stime"] = OprFuction.TimeToString(DateTime.Parse(rows[0]["time"].ToString())); showdt.Rows[i]["time"] = OprFuction.TimeToString(DateTime.Parse(rows[0]["time"].ToString())); } #endregion lock (StaticClass.bjobj) { var bjobj = StaticClass.jcbdata.Values.Where(pp => pp.Point == showdt.Rows[i]["point"].ToString() && ( (OprFuction.KGLisAlarm(pp) || !string.IsNullOrEmpty(pp.Kzk))) && (OprFuction.IsInitTime(pp.Etime))).OrderByDescending(pp => pp.Stime).FirstOrDefault(); if (bjobj != null && !string.IsNullOrEmpty(bjobj.Point)) { if (OprFuction.KGLisAlarm(bjobj)) { if (showdt.Rows[i]["bjtime"] != null && showdt.Rows[i]["bjtime"].ToString() != "报警/" + OprFuction.TimeToString(bjobj.Etime)) { showdt.Rows[i]["bjtime"] = "报警/" + OprFuction.TimeToString(bjobj.Stime); } } else { if (showdt.Rows[i]["bjtime"] != null && showdt.Rows[i]["bjtime"].ToString() != "断电/" + OprFuction.TimeToString(bjobj.Stime)) { showdt.Rows[i]["bjtime"] = "断电/" + OprFuction.TimeToString(bjobj.Stime); } } if (!string.IsNullOrEmpty(bjobj.Kzk)) { string[] kzk = bjobj.Kzk.Split('|'); string kzqy = ""; if (kzk.Length > 0) { for (int k = 0; k < kzk.Length; k++) { lock (StaticClass.allPointDtLockObj) { DataRow[] row1 = StaticClass.AllPointDt.Select("point='" + kzk[i] + "'"); if (row1.Length > 0) { kzqy = kzqy + kzk[i] + "(" + row1[0]["wz"] + ")|"; } } } } if (kzqy.Length > 1) { kzqy = kzqy.Substring(0, kzqy.Length - 1); } showdt.Rows[i]["ddqy"] = kzqy; } else { showdt.Rows[i]["ddqy"] = ""; } if (showdt.Rows[i]["cstime"] != null && showdt.Rows[i]["cstime"].ToString() != bjobj.Cs + "/" + bjobj.Bz2) { showdt.Rows[i]["cstime"] = bjobj.Cs + "/" + bjobj.Bz2; } if (!string.IsNullOrEmpty(bjobj.Kdid)) { if (null != showdt.Rows[i]["kdid"]) { if (showdt.Rows[i]["kdid"].ToString() != bjobj.Kdid) { #region 修改馈电 kdid1 = bjobj.Kdid.Split(','); lock (StaticClass.bjobj) { try { for (int z = 0; z < kdid1.Length; z++) { if (!string.IsNullOrEmpty(kdid1[z])) { temp = long.Parse(kdid1[z]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; showdt.Rows[i]["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } showdt.Rows[i]["kdid"] = bjobj.Kdid; #endregion } else { updateflag = true; kdid1 = bjobj.Kdid.Split(','); for (int z = 0; z < kdid1.Length; z++) { if (!string.IsNullOrEmpty(kdid1[z])) { temp = long.Parse(kdid1[z]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; endkdlist.Add(tempobj); if (OprFuction.IsInitTime(tempobj.Etime)) { updateflag = false; } } } } if (updateflag) { lb = endkdlist.OrderByDescending(pp => pp.Etime).First(); if (lb.Type == (short)DeviceDataState.DataPowerOffFail) { nt = ((short)DeviceDataState.DataPowerOffSuc).ToString(); } else if (lb.Type == (short)DeviceDataState.DataPowerOnFail) { nt = ((short)DeviceDataState.DataPowerOnSuc).ToString(); } showdt.Rows[i]["kdtime"] = OprFuction.StateChange(nt) + "/" + lb.Etime; } } } } } else { showdt.Rows[i]["bjtime"] = ""; showdt.Rows[i]["ddqy"] = ""; showdt.Rows[i]["kdtime"] = ""; showdt.Rows[i]["cstime"] = ""; } } } else { showdt.Rows.RemoveAt(i); i--; } } } #endregion #region 添加新的报警 lock (objShowDt) { for (int kj = 0; kj < dt1.Rows.Count; kj++) { r = dt1.Rows[kj]; rows = showdt.Select("point='" + r["point"].ToString() + "'"); { if (rows.Length > 0) { continue; } } row = showdt.NewRow(); row["point"] = r["point"]; row["wz"] = r["wz"]; if (r["zt"].ToString() == StaticClass.itemStateToClient.EqpState7.ToString()) { row["yjz"] = r["sxyj"]; } else { row["yjz"] = r["xxyj"]; } row["fzh"] = r["fzh"] + "/" + r["tdh"] + "/" + r["dzh"]; row["ssz"] = r["ssz"]; row["state"] = OprFuction.StateChange(r["zt"].ToString()); row["sbstate"] = OprFuction.StateChange(r["sbzt"].ToString()); row["stime"] = OprFuction.TimeToString(DateTime.Parse(r["time"].ToString())); row["time"] = OprFuction.TimeToString(DateTime.Parse(r["time"].ToString())); span = nowtime - DateTime.Parse(r["time"].ToString()); row["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); row["zdz"] = r["ssz"]; row["zxz"] = r["ssz"]; row["pjz"] = r["ssz"]; row["count"] = 1; row["allvalue"] = r["ssz"]; row["id"] = 0; row["devname"] = r["lb"]; row["dw"] = r["dw"]; showdt.Rows.InsertAt(row, 0);//添加新记录 } } #endregion } else { lock (objShowDt) { showdt.Rows.Clear(); } } } #endregion } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } }
/// <summary> /// 获取新增报警断电信息 /// </summary> public void getdata() { long id = 0; Jc_BInfo jcb = null; Jc_BInfo obj = null; long key = 0; List <long> listkey; lock (StaticClass.bjobj) { try { #region 获取馈电异常信息 listkey = StaticClass.jcbdata.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; jcb = StaticClass.jcbdata[key]; if (!string.IsNullOrEmpty(jcb.Kdid)) { id = long.Parse(jcb.ID); if (!jc_b.ContainsKey(id)) { #region 新增报警断电馈电 obj = OprFuction.NewDTO(jcb); jc_b.Add(id, obj); addlist.Add(id); #endregion } else { #region update 报警 断电 if (jc_b[id].Kdid != jcb.Kdid) { obj = OprFuction.NewDTO(jcb); jc_b[id] = obj; updatelist.Add(id); } else if (jc_b[id].Cs != jcb.Cs)//措施改变进行页面更新 20180206 { obj = OprFuction.NewDTO(jcb); jc_b[id] = obj; updatelist.Add(id); } #endregion } } } #region 判断报警断电是否还存在 listkey = jc_b.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; if (!StaticClass.jcbdata.ContainsKey(key)) { deletelist.Add(key); } } #endregion #endregion } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } }
/// <summary> /// 刷新报警数据 /// </summary> public void refresh(DateTime nowtime) { string point = ""; DataRow[] row; DataRow r; int countn = 0; string[] kzk = null, kdid = null; long temp = 0; Jc_BInfo obj = null, tempobj = null; int tbcount = 0; Dictionary <string, string> kzkd = new Dictionary <string, string>(); object wz = "", dw = "", bjz = "", ddz = "", fzh = "", sszn = "", bjtime = "", ddtime = "", cs = "", idn = "", qy = "", sbstate = ""; long key = 0; #region 除已结束的记录 try { if (deletelist.Count > 0) { #region 除显示 countn = showdt.Rows.Count; lock (objShowDt) { for (int i = 0; i < countn; i++) { try { if (deletelist.Contains(long.Parse(showdt.Rows[i]["id"].ToString()))) { if (jc_kd.ContainsKey(long.Parse(showdt.Rows[i]["kdid"].ToString()))) { jc_kd.Remove(long.Parse(showdt.Rows[i]["kdid"].ToString())); } showdt.Rows.Remove(showdt.Rows[i]); i--; countn--; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } #endregion #region 除内存 for (int kj = 0; kj < deletelist.Count; kj++) { key = deletelist[kj]; if (jc_b.ContainsKey(key)) { jc_b.Remove(key); } } deletelist.Clear(); #endregion } } catch (Exception ex) { OprFuction.SaveErrorLogs("删除馈电记录", ex); } #endregion #region 修改及刷新记录 if (updatelist.Count > 0) { try { #region 添加记录 for (int kj = 0; kj < updatelist.Count; kj++) { key = updatelist[kj]; kzkd.Clear(); if (jc_b.ContainsKey(key)) { obj = jc_b[key]; point = obj.Point; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { wz = row[0]["wz"]; sbstate = OprFuction.StateChange(obj.State.ToString()); sszn = obj.Ssz + "/" + OprFuction.TimeToString(obj.Stime); if (int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState9 || int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState11) { bjz = row[0]["sxbj"] + "/" + row[0]["sxyj"]; ddz = row[0]["sxdd"] + "/" + row[0]["sxfd"]; dw = row[0]["dw"]; } else if (int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState19 || int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState21) { bjz = row[0]["xxbj"] + "/" + row[0]["xxyj"]; ddz = row[0]["xxdd"] + "/" + row[0]["xxfd"]; dw = row[0]["dw"]; } else { bjz = obj.Ssz; ddz = obj.Ssz; } } } fzh = obj.Fzh + "/" + obj.Kh + "/" + obj.Dzh; bjtime = ddtime = OprFuction.TimeToString(obj.Stime); cs = obj.Cs; idn = key; #region 控制口 //if (!string.IsNullOrEmpty(obj.Kdid)) //{ // kdid = obj.Kdid.Split('|'); // if (kdid.Length > 0) // { // if (!string.IsNullOrEmpty(kdid[0])) // { // kdid1 = kdid[0].Split(','); // #region 断电失败 // lock (StaticClass.bjobj) // { // for (int i = 0; i < kdid1.Length; i++) // { // temp = long.Parse(kdid1[i]); // if (StaticClass.jcbdata.ContainsKey(temp)) // { // tempobj = StaticClass.jcbdata[temp]; // if (!jc_kd.ContainsKey(temp)) // { // jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); // #region 添加记录 // row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); // if (row.Length > 0) // { // qy = row[0]["wz"]; // } // r = showdt.NewRow(); // r["point"] = point; // r["wz"] = wz; // r["bjz"] = bjz; // r["ddz"] = ddz; // r["dw"] = dw; // //r["fzh"] = fzh; // r["ssz"] = sszn; // r["bjtime"] = bjtime; // r["ddtime"] = ddtime; // r["kdid"] = temp; // r["id"] = key; // r["qy"] = qy; // r["kzk"] = tempobj.Point; // r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; // showdt.Rows.InsertAt(r, 0);//添加新记录 // #endregion // } // } // } // } // #endregion // } // if (kdid.Length > 1) // { // #region 复电失败 // if (!string.IsNullOrEmpty(kdid[1])) // { // kdid1 = kdid[1].Split(','); // lock (StaticClass.bjobj) // { // for (int i = 0; i < kdid1.Length; i++) // { // temp = long.Parse(kdid1[i]); // if (StaticClass.jcbdata.ContainsKey(temp)) // { // tempobj = StaticClass.jcbdata[temp]; // if (!jc_kd.ContainsKey(temp)) // { // jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); // #region 添加记录 // row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); // if (row.Length > 0) // { // qy = row[0]["wz"]; // } // r = showdt.NewRow(); // r["point"] = point; // r["wz"] = wz; // r["bjz"] = bjz; // r["ddz"] = ddz; // r["dw"] = dw; // //r["fzh"] = fzh; // r["ssz"] = sszn; // r["bjtime"] = bjtime; // r["ddtime"] = ddtime; // r["kdid"] = temp; // r["id"] = key; // r["qy"] = qy; // r["kzk"] = tempobj.Point; // r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; // showdt.Rows.InsertAt(r, 0);//添加新记录 // #endregion // } // } // } // } // } // #endregion // } // } //} #endregion #region 控制口 if (!string.IsNullOrEmpty(obj.Kdid)) { kdid = obj.Kdid.Split(','); if (kdid.Length > 0) { #region 馈电异常 lock (StaticClass.bjobj) { try { for (int i = 0; i < kdid.Length; i++) { if (!string.IsNullOrEmpty(kdid[i])) { temp = long.Parse(kdid[i]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; if (!jc_kd.ContainsKey(temp))// { jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); #region 添加记录 lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); if (row.Length > 0) { qy = row[0]["wz"]; } } lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["sbstate"] = sbstate; r["wz"] = wz; r["bjz"] = bjz; r["ddz"] = ddz; r["dw"] = dw; //r["fzh"] = fzh; r["ssz"] = sszn; r["bjtime"] = bjtime; r["ddtime"] = ddtime; r["kdid"] = temp; r["id"] = key; r["qy"] = qy; r["kzk"] = tempobj.Point; r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; r["cs"] = cs; showdt.Rows.InsertAt(r, 0);//添加新记录 } #endregion } else {//措施改变之后,对对应的记录更新 20180206 for (int k = 0; k < showdt.Rows.Count; k++) { if (showdt.Rows[k]["id"].ToString() == key.ToString()) { showdt.Rows[k]["cs"] = cs; } } } } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } #endregion } } #endregion } } #endregion } catch (Exception ex) { OprFuction.SaveErrorLogs("添加馈电记录1", ex); } updatelist.Clear(); } #endregion #region 添加记录 if (addlist.Count > 0) { //tbcount = showdt.Rows.Count; try { #region 添加记录 for (int kj = 0; kj < addlist.Count; kj++) { key = addlist[kj]; kzkd.Clear(); if (jc_b.ContainsKey(key)) { obj = jc_b[key]; point = obj.Point; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { wz = row[0]["wz"]; sbstate = OprFuction.StateChange(obj.State.ToString()); sszn = obj.Ssz + "/" + OprFuction.TimeToString(obj.Stime); if (int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState9 || int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState11) { bjz = row[0]["sxbj"] + "/" + row[0]["sxyj"]; ddz = row[0]["sxdd"] + "/" + row[0]["sxfd"]; dw = row[0]["dw"]; } else if (int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState19 || int.Parse(obj.Type.ToString()) == StaticClass.itemStateToClient.EqpState21) { bjz = row[0]["xxbj"] + "/" + row[0]["xxyj"]; dw = row[0]["dw"]; ddz = row[0]["xxdd"] + "/" + row[0]["xxfd"]; } else { bjz = obj.Ssz; ddz = obj.Ssz; } } } fzh = obj.Fzh + "/" + obj.Kh + "/" + obj.Dzh; bjtime = ddtime = OprFuction.TimeToString(obj.Stime); cs = obj.Cs; idn = key; #region 控制口 //if (!string.IsNullOrEmpty(obj.Kdid)) //{ // kdid = obj.Kdid.Split('|'); // if (kdid.Length > 0) // { // if (!string.IsNullOrEmpty(kdid[0])) // { // kdid1 = kdid[0].Split(','); // #region 断电失败 // lock (StaticClass.bjobj) // { // for (int i = 0; i < kdid1.Length; i++) // { // temp = long.Parse(kdid1[i]); // if (StaticClass.jcbdata.ContainsKey(temp)) // { // tempobj = StaticClass.jcbdata[temp]; // if (!jc_kd.ContainsKey(temp)) // { // jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); // } // #region 添加记录 // row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); // if (row.Length > 0) // { // qy = row[0]["wz"]; // } // r = showdt.NewRow(); // r["point"] = point; // r["wz"] = wz; // r["bjz"] = bjz; // r["ddz"] = ddz; // r["dw"] = dw; // //r["fzh"] = fzh; // r["ssz"] = sszn; // r["bjtime"] = bjtime; // r["ddtime"] = ddtime; // r["kdid"] = temp; // r["id"] = key; // r["qy"] = qy; // r["kzk"] = tempobj.Point; // r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; // showdt.Rows.InsertAt(r, 0);//添加新记录 // #endregion // } // } // } // #endregion // } // if (kdid.Length>1) // { // #region 复电失败 // if (!string.IsNullOrEmpty(kdid[1])) // { // kdid1 = kdid[1].Split(','); // lock (StaticClass.bjobj) // { // for (int i = 0; i < kdid1.Length; i++) // { // temp = long.Parse(kdid1[i]); // if (StaticClass.jcbdata.ContainsKey(temp)) // { // tempobj = StaticClass.jcbdata[temp]; // if (!jc_kd.ContainsKey(temp)) // { // jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); // } // #region 添加记录 // row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); // if (row.Length > 0) // { // qy = row[0]["wz"]; // } // r = showdt.NewRow(); // r["point"] = point; // r["wz"] = wz; // r["bjz"] = bjz; // r["ddz"] = ddz; // r["dw"] = dw; // //r["fzh"] = fzh; // r["ssz"] = sszn; // r["bjtime"] = bjtime; // r["ddtime"] = ddtime; // r["kdid"] = temp; // r["id"] = key; // r["qy"] = qy; // r["kzk"] = tempobj.Point; // r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; // showdt.Rows.InsertAt(r, 0);//添加新记录 // } // } // } // #endregion // } // #endregion // } // } //} #endregion #region 控制口 if (!string.IsNullOrEmpty(obj.Kdid)) { kdid = obj.Kdid.Split(','); if (kdid.Length > 0) { #region 馈电异常 lock (StaticClass.bjobj) { try { for (int i = 0; i < kdid.Length; i++) { if (!string.IsNullOrEmpty(kdid[i])) { temp = long.Parse(kdid[i]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; if (!jc_kd.ContainsKey(temp)) { jc_kd.Add(temp, OprFuction.NewDTO(tempobj)); } #region 添加记录 lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + tempobj.Point + "'"); if (row.Length > 0) { qy = row[0]["wz"]; } } lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["wz"] = wz; r["sbstate"] = sbstate; r["bjz"] = bjz; r["ddz"] = ddz; r["dw"] = dw; //r["fzh"] = fzh; r["ssz"] = sszn; r["bjtime"] = bjtime; r["ddtime"] = ddtime; r["kdid"] = temp; r["id"] = key; r["qy"] = qy; r["kzk"] = tempobj.Point; r["kdtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; r["cs"] = cs; showdt.Rows.InsertAt(r, 0);//添加新记录 } #endregion } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } #endregion } } #endregion } } #endregion } catch (Exception ex) { OprFuction.SaveErrorLogs("添加馈电记录", ex); } //tbcount = showdt.Rows.Count - tbcount; //StaticClass.yccount[3] += tbcount; addlist.Clear(); //mainGridView.FocusedRowHandle = 0; } #endregion #region 当前报警条数 tbcount = showdt.Rows.Count; StaticClass.yccount[3] = tbcount; #endregion }
/// <summary> /// 获取新增报警断电信息 /// </summary> public void getdata() { short type = 0; int count = 0; long id = 0; List <long> keylist; Jc_BInfo jcb = null; Jc_BInfo obj = null; lock (StaticClass.bjobj) { try { #region 获取报警信息 keylist = new List <long>(StaticClass.jcbdata.Keys); for (int i = 0; i < keylist.Count; i++) { if (StaticClass.jcbdata.ContainsKey(keylist[i])) { jcb = StaticClass.jcbdata[keylist[i]]; type = jcb.Type; if (type == 27) { } if (type == StaticClass.itemStateToClient.EqpState24 || type == StaticClass.itemStateToClient.EqpState25 || type == StaticClass.itemStateToClient.EqpState26) { id = long.Parse(jcb.ID); if (!jc_b.ContainsKey(id) && (OprFuction.KGLisAlarm(jcb) || !string.IsNullOrEmpty(jcb.Kzk)))//增加如果未选择报警,勾选了控制的也进行显示 20170726 { #region 新增报警断电 obj = OprFuction.NewDTO(jcb); jc_b.Add(id, obj); addlist.Add(id); #endregion } else { #region update 报警 断电 if (jc_b.ContainsKey(id)) { #region 控制口改变 if (jc_b[id].Kzk != jcb.Kzk)//报警断电结束 { obj = OprFuction.NewDTO(jcb); jc_b[id] = obj; addlist.Add(id); } #endregion if (OprFuction.IsInitTime(jc_b[id].Etime) && !OprFuction.IsInitTime(jcb.Etime) || jc_b[id].Kdid != jcb.Kdid)//报警断电结束 { obj = OprFuction.NewDTO(jcb); if (jc_b[id].Kdid != jcb.Kdid)//馈电改变 { kdlist.Add(id); } jc_b[id] = obj; updatelist.Add(id); } else if (jc_b[id].Cs != jcb.Cs)//措施改变//&& !OprFuction.GetClientType() 注释 20170817 { obj = OprFuction.NewDTO(jcb); jc_b[id] = obj; updatelist.Add(id); } //else if (jc_b[id].Isalarm != jcb.Isalarm) //{ // //2017.7.14 by // obj = OprFuction.NewDTO(jcb); // jc_b[id] = obj; // updatelist.Add(id); //} else//无变化,直接更新结束时间 20170627 { updatelist.Add(id); } } #endregion } } } } #region 判断报警断电是否还存在 foreach (long key in jc_b.Keys) { if (!StaticClass.jcbdata.ContainsKey(key) || (StaticClass.jcbdata[key].Isalarm == 0 && string.IsNullOrEmpty(StaticClass.jcbdata[key].Kzk)))//如果用户取消报警(只有报警,没有控制时,可取消),此时数据处理会将标记置成正常,客户端显示的时候也取消报警 20170627 { deletelist.Add(key); } } #endregion #endregion } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } }
/// <summary> /// 刷新报警数据 /// </summary> public void refresh(DateTime nowtime) { string point = ""; DataRow[] row, row1; DataRow r; TimeSpan span; int countn = 0; long id = 0; string[] kzk = null, kdid = null, kdid1 = null; long temp = 0; Jc_BInfo obj = null, tempobj = null; int tbcount = 0; long key = 0; List <long> listkey; Dictionary <string, string> kzkd = new Dictionary <string, string>(); object wz = "", devname = "", bjddzt = "", bjz = "", ddz = "", fzh = "", sszn = "", state = "", stime = "", etime = "", cxtime = "", ddtime = "", cs = "", cut = "", allvalue = "", idn = "", qy = "", sbstate = ""; #region 除已结束的记录 try { if (deletelist.Count > 0) { #region 除显示 countn = showdt.Rows.Count; lock (objShowDt) { for (int i = 0; i < countn; i++) { try { if (deletelist.Contains(long.Parse(showdt.Rows[i]["id"].ToString()))) { showdt.Rows.Remove(showdt.Rows[i]); i--; countn--; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } #endregion #region 除内存 for (int kj = 0; kj < deletelist.Count; kj++) { key = deletelist[kj]; if (jc_b.ContainsKey(key)) { jc_b.Remove(key); } if (CSlist.ContainsKey(key)) { CSlist.Remove(key); } } deletelist.Clear(); #endregion } } catch (Exception ex) { OprFuction.SaveErrorLogs("删除开关量报警断电记录", ex); } #endregion #region 修改及刷新记录 //foreach (long key in jc_b.Keys) //{ //try //{ // listkey = jc_b.Keys.ToList(); // for (int kj = 0; kj < listkey.Count; kj++) // { // key = listkey[kj]; // if (updatelist.Contains(key)) // { // row = showdt.Select("id='" + key + "'"); // if (row.Length > 0) // { // #region 刷新 结束时间 持续时间 // if (row[0]["endtime"].ToString() == "")//结束时间更新 // { // for (int i = 0; i < row.Length; i++) // { // #region 刷新 结束时间 持续时间 // obj = jc_b[key]; // if (!OprFuction.IsInitTime(obj.Etime)) // { // row[i]["endtime"] = OprFuction.TimeToString(obj.Etime); // span = obj.Etime - Convert.ToDateTime(row[i]["stime"]); // row[i]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); // } // else // { // span = nowtime - Convert.ToDateTime(row[i]["stime"]); // row[i]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); // } // #endregion // } // } // #endregion // #region 刷新cs // if (row[0]["cs"].ToString() != jc_b[key].Cs && !OprFuction.GetClientType()) // { // for (int i = 0; i < row.Length; i++) // { // #region 刷新 cs // row[i]["cs"] = jc_b[key]; // #endregion // } // } // #endregion // } // #region 修改馈电 // if (kdlist.Contains(key)) // { // obj = jc_b[key]; // kdid = obj.Kdid.Split('|'); // if (kdid.Length > 0) // { // if (!string.IsNullOrEmpty(kdid[0])) // { // kdid1 = kdid[0].Split(','); // lock (StaticClass.bjobj) // { // try // { // for (int i = 0; i < kdid1.Length; i++) // { // if (!string.IsNullOrEmpty(kdid1[i])) // { // temp = long.Parse(kdid1[i]); // if (StaticClass.jcbdata.ContainsKey(temp)) // { // tempobj = StaticClass.jcbdata[temp]; // row = showdt.Select("id ='" + obj.ID + "' and point='" + obj.Point + "' and kzk='" + tempobj.Point + "'"); // if (row.Length > 0) // { // row[0]["ddtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; // } // } // } // } // } // catch (Exception ex) // { // Basic.Framework.Logging.LogHelper.Error(ex); // } // } // } // } // } // #endregion // } // else // { // row = showdt.Select("id='" + key + "'"); // if (row.Length > 0) // { // if (row[0]["endtime"].ToString() == "") // { // #region //刷新持续时间 // span = nowtime - Convert.ToDateTime(row[0]["stime"]); // cxtime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); // for (int j = 0; j < row.Length; j++) // { // row[j]["cxtime"] = cxtime; // } // #endregion // } // } // } // } //} //catch (Exception ex) //{ // OprFuction.SaveErrorLogs("修改开关量报警记录", ex); //} #region//重写刷新方法,每次刷新会导致客户端卡死 20170719 try { listkey = jc_b.Keys.ToList(); for (int kj = 0; kj < showdt.Rows.Count; kj++) { key = long.Parse(showdt.Rows[kj]["id"].ToString()); if (updatelist.Contains(key)) { #region 刷新 结束时间 持续时间 if (showdt.Rows[kj]["endtime"].ToString() == "")//结束时间更新 { #region 刷新 结束时间 持续时间 obj = jc_b[key]; if (!OprFuction.IsInitTime(obj.Etime)) { showdt.Rows[kj]["endtime"] = OprFuction.TimeToString(obj.Etime); span = obj.Etime - Convert.ToDateTime(showdt.Rows[kj]["stime"]); showdt.Rows[kj]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); } else { span = nowtime - Convert.ToDateTime(showdt.Rows[kj]["stime"]); showdt.Rows[kj]["cxtime"] = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); } #endregion } #endregion #region 刷新cs if (!string.IsNullOrEmpty(jc_b[key].Cs)) { if (showdt.Rows[kj]["cs"].ToString() != (jc_b[key].Cs + "/" + jc_b[key].Bz2))//&& !OprFuction.GetClientType() 注释 20170817 { #region 刷新 cs showdt.Rows[kj]["cs"] = (jc_b[key].Cs + "/" + jc_b[key].Bz2); #endregion } } else { showdt.Rows[kj]["cs"] = ""; } #endregion #region 修改馈电 if (kdlist.Contains(key)) { obj = jc_b[key]; kdid = obj.Kdid.Split('|'); if (kdid.Length > 0) { if (!string.IsNullOrEmpty(kdid[0])) { kdid1 = kdid[0].Split(','); lock (StaticClass.bjobj) { try { for (int i = 0; i < kdid1.Length; i++) { if (!string.IsNullOrEmpty(kdid1[i])) { temp = long.Parse(kdid1[i]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; row = showdt.Select("id ='" + obj.ID + "' and point='" + obj.Point + "' and kzk='" + tempobj.Point + "'"); if (row.Length > 0) { showdt.Rows[kj]["ddtime"] = OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime; } } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } } } #endregion } else { if (showdt.Rows[kj]["endtime"].ToString() == "") { #region //刷新持续时间 span = nowtime - Convert.ToDateTime(showdt.Rows[kj]["stime"]); cxtime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); showdt.Rows[kj]["cxtime"] = cxtime; #endregion } } } } catch (Exception ex) { OprFuction.SaveErrorLogs("修改开关量报警记录", ex); } #endregion //} updatelist.Clear(); kdlist.Clear(); #endregion #region 添加记录 if (addlist.Count > 0) { //tbcount = showdt.Rows.Count; try { #region 添加记录 for (int kj = 0; kj < addlist.Count; kj++) { key = addlist[kj]; kzkd.Clear(); if (jc_b.ContainsKey(key)) { obj = jc_b[key]; point = obj.Point; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { wz = row[0]["wz"]; devname = row[0]["devname"]; } } fzh = obj.Fzh + "/" + obj.Kh + "/" + obj.Dzh; sszn = obj.Ssz; bjz = sszn; ddz = sszn; state = OprFuction.StateChange(obj.Type.ToString()); sbstate = OprFuction.StateChange(obj.State.ToString()); stime = OprFuction.TimeToString(obj.Stime); span = nowtime - obj.Stime; cxtime = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", span.Days, span.Hours, span.Minutes, span.Seconds); etime = ""; //by if (!OprFuction.IsInitTime(obj.Etime)) { etime = OprFuction.TimeToString(obj.Etime); } ddtime = OprFuction.TimeToString(obj.Stime); if (obj.Isalarm > 0 && string.IsNullOrEmpty(obj.Kzk)) { bjddzt = "报警"; } else if (!string.IsNullOrEmpty(obj.Kzk)) { bjddzt = "断电"; } cs = obj.Cs; cut = 1; allvalue = obj.Ssz; id = key; if (!string.IsNullOrEmpty(obj.Kzk)) { #region 控制口 kzk = obj.Kzk.Split('|'); if (!string.IsNullOrEmpty(obj.Kdid)) { kdid = obj.Kdid.Split('|'); if (kdid.Length > 0) { if (!string.IsNullOrEmpty(kdid[0])) { kdid1 = kdid[0].Split(','); lock (StaticClass.bjobj) { try { for (int i = 0; i < kdid1.Length; i++) { if (!string.IsNullOrEmpty(kdid1[i])) { temp = long.Parse(kdid1[i]); if (StaticClass.jcbdata.ContainsKey(temp)) { tempobj = StaticClass.jcbdata[temp]; kzkd.Add(tempobj.Point, OprFuction.StateChange(tempobj.Type.ToString()) + "/" + tempobj.Stime); } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } } } if (kzk.Length > 0) { for (int i = 0; i < kzk.Length; i++) { #region 添加记录 lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + kzk[i] + "'"); if (row.Length > 0) { qy = row[0]["wz"]; } } lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["wz"] = wz; r["devname"] = devname; r["bjddzt"] = bjddzt; r["bjz"] = bjz; r["ddz"] = ddz; //r["fzh"] = fzh; r["ssz"] = sszn; r["sbstate"] = sbstate; //r["state"] = state; r["stime"] = stime; r["cxtime"] = cxtime; r["endtime"] = etime; r["ddtime"] = ddtime; if (!string.IsNullOrEmpty(cs.ToString())) { r["cs"] = cs + "/" + obj.Bz2; } else { r["cs"] = ""; } //r["count"] = 1; r["id"] = key; r["qy"] = qy; r["kzk"] = kzk[i]; if (kzkd.ContainsKey(kzk[i])) { r["ddtime"] = kzkd[kzk[i]]; } row1 = showdt.Select("id='" + key + "' and kzk='" + kzk[i] + "'"); if (row1.Length < 1) { showdt.Rows.InsertAt(r, 0);//添加新记录 } } //showdt.Rows.InsertAt(r, 0);//添加新记录 #endregion } } #endregion } else { #region 无控制口 lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["wz"] = wz; r["devname"] = devname; r["bjddzt"] = bjddzt; r["bjz"] = bjz; //r["fzh"] = fzh; r["ssz"] = sszn; r["sbstate"] = sbstate; //r["state"] = state; r["stime"] = stime; r["cxtime"] = cxtime; r["endtime"] = etime; if (!string.IsNullOrEmpty(cs.ToString())) { r["cs"] = cs + "/" + obj.Bz2; } else { r["cs"] = ""; } //r["count"] = 1; //r["allvalue"] = obj.Ssz; r["id"] = key; row1 = showdt.Select("id='" + key + "'"); if (row1.Length < 1) { showdt.Rows.InsertAt(r, 0);//添加新记录 } } #endregion } } } #endregion } catch (Exception ex) { OprFuction.SaveErrorLogs("添加开关量报警记录", ex); } //tbcount = showdt.Rows.Count - tbcount; //StaticClass.yccount[2] += tbcount; addlist.Clear(); //mainGridView.FocusedRowHandle = 0; } #endregion #region 当前报警条数 tbcount = showdt.Select("endtime='' or endtime='1900-01-01 00:00:00'", "").Length; StaticClass.yccount[2] = tbcount; #endregion }
/// <summary> /// 定时,处理馈电记录,每2秒处理一次 /// </summary> private void CheckAlarmFeeding() { //控制口不为空,并且upflag=0 为主控,控制量取断电失败和复电失败 Jc_KdInfo kdInfo; DataTable dtpointcur = new DataTable(); DataTable dtcontrolcur = new DataTable(); DateTime etime = Convert.ToDateTime(DateTime.Now.ToShortDateString()); DateTime stime = Convert.ToDateTime(DateTime.Now.AddDays(-1.0f).ToShortDateString()); DateTime dtimecur = new DateTime(); string kzklst = ""; string oldkdid = "", tempkdid = "", Curkdid = "";; int feedingtime = 60;//关于复电失败的只计算60秒以内的。 byte upflag = 0; for (; stime <= etime; stime = stime.AddDays(1.0f)) { dtpointcur = _Repository.GetAlarmFeedingList("KJ_DataAlarm" + stime.ToString("yyyyMM"), stime.ToString(), stime.AddDays(1.0f).ToShortDateString()); if (dtpointcur != null)//找到当天控制口未空,并且upflag=0的记录 { for (int i = 0; i < dtpointcur.Rows.Count; i++) { dtimecur = DateTime.Parse(dtpointcur.Rows[i]["etime"].ToString()); kzklst = dtpointcur.Rows[i]["kzk"].ToString().Replace("|", "','"); oldkdid = dtpointcur.Rows[i]["kdid"].ToString(); upflag = 0; if (dtimecur.Year == 1900) { dtcontrolcur = _Repository.GetAlarmFeedingControlList("KJ_DataAlarm" + stime.ToString("yyyyMM"), dtpointcur.Rows[i]["stime"].ToString(), "", kzklst, false); } else { dtcontrolcur = _Repository.GetAlarmFeedingControlList("KJ_DataAlarm" + stime.ToString("yyyyMM"), dtpointcur.Rows[i]["stime"].ToString(), dtpointcur.Rows[i]["etime"].ToString(), kzklst); if ((DateTime.Now - dtimecur).TotalSeconds >= feedingtime) { upflag = 1; } } Curkdid = oldkdid; for (int j = 0; j < dtcontrolcur.Rows.Count; j++) { tempkdid = dtcontrolcur.Rows[j]["id"].ToString(); if (!Curkdid.Contains(tempkdid)) { if (Curkdid == "") { Curkdid = tempkdid; } else { Curkdid += "," + tempkdid; } ///更新馈电信息表 kdInfo = GetNewJCKDInfo(dtpointcur.Rows[i]["id"].ToString(), tempkdid, DateTime.Now); addJCKDRecordToDB(kdInfo); } } //以主控的ID,更新kdid和upflag if (Curkdid != oldkdid || upflag == 1) { Jc_BInfo alarmInfo = new Jc_BInfo(); alarmInfo.Upflag = upflag.ToString(); alarmInfo.Kdid = Curkdid; alarmInfo.ID = dtpointcur.Rows[i]["id"].ToString(); alarmInfo.Stime = (DateTime)(dtpointcur.Rows[i]["stime"]); Dictionary <string, object> updateItems = new Dictionary <string, object>(); updateItems.Add("Upflag", alarmInfo.Upflag); updateItems.Add("Kdid", alarmInfo.Kdid); AlarmRecordUpdateProperitesRequest updateRequest = new AlarmRecordUpdateProperitesRequest() { AlarmInfo = alarmInfo, UpdateItems = updateItems }; UpdateAlarm(updateRequest); } } } } }
/// <summary> /// 获取新增报警断电信息 /// </summary> public void getdata() { short type = 0; long id = 0; Jc_BInfo jcb = null; Jc_BInfo obj = null; DateTime maxtime = timenow; long key = 0; List <long> listkey; lock (StaticClass.bjobj) { #region 获取开关量状态变动数据 try { listkey = StaticClass.jcbdata.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; jcb = StaticClass.jcbdata[key]; type = jcb.Type; if (jcb.Stime >= timenow) { if (OprFuction.IsKGL(jcb) && !jc_b.ContainsKey(long.Parse(jcb.ID))) { if (jcb.Stime > maxtime) { maxtime = jcb.Stime; id = long.Parse(jcb.ID); } #region 新增开关量状态 obj = OprFuction.NewDTO(jcb); jc_b.Add(long.Parse(obj.ID), obj); addlist.Add(long.Parse(obj.ID)); #endregion } } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } if (id > dqid) { dqid = id; } if (maxtime > timenow) { timenow = maxtime; } #region 判断开关量状态记录是否可以删除 DateTime now = Model.RealInterfaceFuction.GetServerNowTime(); listkey = jc_b.Keys.ToList(); for (int kj = 0; kj < listkey.Count; kj++) { key = listkey[kj]; if ((now - jc_b[key].Stime).TotalMinutes > 1) { deletelist.Add(key); } } #endregion #endregion } }
/// <summary> /// 刷新报警数据 /// </summary> public void refresh(DateTime nowtime) { string point = ""; DataRow[] row; DataRow r; int countn = 0; long id = 0; Jc_BInfo obj = null; int tbcount = 0; object wz = "", fzh = "", sszn = "", state = "", stime = "", sbstate = ""; long key = 0; #region 除已结束的记录 try { if (deletelist.Count > 0) { #region 除显示 countn = showdt.Rows.Count; lock (objShowDt) { for (int i = 0; i < countn; i++) { try { if (deletelist.Contains(long.Parse(showdt.Rows[i]["id"].ToString()))) { showdt.Rows.Remove(showdt.Rows[i]); i--; countn--; } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } #endregion #region 除内存 for (int kj = 0; kj < deletelist.Count; kj++) { key = deletelist[kj]; if (jc_b.ContainsKey(key)) { jc_b.Remove(key); } } deletelist.Clear(); #endregion } } catch (Exception ex) { OprFuction.SaveErrorLogs("删除开关量记录", ex); } #endregion #region 添加记录 if (addlist.Count > 0) { //tbcount = showdt.Rows.Count; try { #region 添加记录 for (int kj = 0; kj < addlist.Count; kj++) { key = addlist[kj]; if (jc_b.ContainsKey(key)) { obj = jc_b[key]; point = obj.Point; lock (StaticClass.allPointDtLockObj) { row = StaticClass.AllPointDt.Select("point='" + point + "'"); if (row.Length > 0) { wz = row[0]["wz"]; } } fzh = obj.Fzh + "/" + obj.Kh + "/" + obj.Dzh; sszn = obj.Ssz; state = OprFuction.StateChange(obj.Type.ToString()); sbstate = OprFuction.StateChange(obj.State.ToString()); stime = OprFuction.TimeToString(obj.Stime); id = key; lock (objShowDt) { r = showdt.NewRow(); r["point"] = point; r["wz"] = wz; //r["fzh"] = fzh; //r["ssz"] = sszn; if (state.ToString() == "0态") { r["state"] = row[0]["0t"].ToString(); } else if (state.ToString() == "1态") { r["state"] = row[0]["1t"].ToString(); } else { r["state"] = row[0]["2t"].ToString(); } r["sbstate"] = sbstate; r["time"] = stime; r["id"] = key; showdt.Rows.InsertAt(r, 0);//添加新记录 } } } #endregion } catch (Exception ex) { OprFuction.SaveErrorLogs("添加开关量报警记录", ex); } //tbcount = showdt.Rows.Count - tbcount; //StaticClass.yccount[5] += tbcount; addlist.Clear(); //mainGridView.FocusedRowHandle = 0; } #endregion #region 当前报警条数 tbcount = showdt.Rows.Count; StaticClass.yccount[5] = tbcount; #endregion }