/// <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> /// 获取新增报警断电信息 /// </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 refresh(DateTime nowtime) { string point = "", ssz1, ssz2; double ssz, sszcopy, 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) && double.TryParse(ssz2, out sszcopy) && ssz == sszcopy) { } else { showdt.Rows[i]["state"] = OprFuction.StateChange(row[0]["zt"].ToString()); showdt.Rows[i]["sbstate"] = OprFuction.StateChange(row[0]["sbzt"].ToString()); showdt.Rows[i]["stime"] = OprFuction.TimeToString(DateTime.Parse(row[0]["time"].ToString())); if (double.TryParse(ssz1, out ssz)) { //zdz = Convert.ToDouble(showdt.Rows[i]["zdz"].ToString()); double.TryParse(showdt.Rows[i]["zdz"].ToString(), out zdz); //zxz = Convert.ToDouble(showdt.Rows[i]["zxz"].ToString()); double.TryParse(showdt.Rows[i]["zxz"].ToString(), out zxz); //pjz = Convert.ToDouble(showdt.Rows[i]["pjz"].ToString()); double.TryParse(showdt.Rows[i]["pjz"].ToString(), out pjz); //count = Convert.ToDouble(showdt.Rows[i]["count"].ToString()); double.TryParse(showdt.Rows[i]["count"].ToString(), out count); //allvlaue = Convert.ToDouble(showdt.Rows[i]["allvalue"].ToString()); double.TryParse(showdt.Rows[i]["allvalue"].ToString(), out allvlaue); 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; } lock (StaticClass.bjobj) { try { var bjobj = StaticClass.jcbdata.Values.Where(pp => pp.Point == showdt.Rows[i]["point"].ToString() && ( pp.Type == StaticClass.itemStateToClient.EqpState9 || pp.Type == StaticClass.itemStateToClient.EqpState19 || pp.Type == StaticClass.itemStateToClient.EqpState16 || pp.Type == StaticClass.itemStateToClient.EqpState15)).OrderByDescending(pp => pp.Stime).FirstOrDefault(); if (bjobj != null && !string.IsNullOrEmpty(bjobj.Point)) { if (OprFuction.IsInitTime(bjobj.Etime)) { showdt.Rows[i]["lastbjtime"] = OprFuction.TimeToString(bjobj.Stime); } else { showdt.Rows[i]["lastbjtime"] = OprFuction.TimeToString(bjobj.Etime); } } bjobj = StaticClass.jcbdata.Values.Where(pp => pp.Point == showdt.Rows[i]["point"].ToString() && ( pp.Type == StaticClass.itemStateToClient.EqpState11 || pp.Type == StaticClass.itemStateToClient.EqpState21)).OrderByDescending(pp => pp.Stime).FirstOrDefault(); if (bjobj != null && !string.IsNullOrEmpty(bjobj.Point)) { if (OprFuction.IsInitTime(bjobj.Etime)) { showdt.Rows[i]["lastddtime"] = OprFuction.TimeToString(bjobj.Stime); } else { showdt.Rows[i]["lastddtime"] = OprFuction.TimeToString(bjobj.Etime); } } } catch (Exception ex) { Basic.Framework.Logging.LogHelper.Error(ex); } } } } } } } #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.Select("endtime='' or endtime='1900-01-01 00:00:00'", "").Length; StaticClass.yccount[0] = 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 }