private void lbSave2_Click(object sender, EventArgs e) { int tCount = this.dataGridView2.Rows.Count - 1; for (int i = 0; i < tCount; i++) { string GNFunction = this.dataGridView2.Rows[i].Cells[0].Value.ToString(); string AlarmH = this.dataGridView2.Rows[i].Cells[1].Value.ToString(); string AlarmL = this.dataGridView2.Rows[i].Cells[2].Value.ToString(); string AlarmData = this.dataGridView2.Rows[i].Cells[3].Value.ToString(); string AlarmAbs = this.dataGridView2.Rows[i].Cells[4].Value.ToString(); // string AlarmTimeAbs = this.dataGridView2.Rows[i].Cells[5].Value.ToString(); YBAlarmSet ybs = new YBAlarmSet(); ybs.AlarmTimeAbs = AlarmAbs; ybs.AlarmDataAbs = AlarmData; ybs.AlarmH = AlarmH; ybs.AlarmL = AlarmL; ybs.GNFcontion = GNFunction; //ybs.AlarmAbsTime = AlarmTimeAbs; ProDefine.g_YBAlarm.Add(ybs); } m_Pro.SaveAlarm(); }
public void GetAlarm() { try { ProDefine.g_YBSetSignle.Clear(); string SQL = "select * from " + YBSetOutSignle + " where GUIDSTR='" + ProDefine.g_SMExpermentParam.GUID.ToString() + "'"; DataTable dt = AccessHelper.GetDataTableFromDB(SQL); if (dt != null) { if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { string GN = dt.Rows[i][1].ToString(); string AlarmH = dt.Rows[i][2].ToString(); string AlarmL = dt.Rows[i][3].ToString(); string AlarmData = dt.Rows[i][4].ToString(); string AlarmAbs = dt.Rows[i][5].ToString(); string YBList = dt.Rows[i][6].ToString(); YBAlarmSet ybs = new YBAlarmSet(); ybs.GNFcontion = GN; ybs.AlarmTimeAbs = AlarmAbs; ybs.AlarmDataAbs = AlarmData; ybs.AlarmH = AlarmH; ybs.AlarmL = AlarmL; ybs.m_YBList = new List <string>(); ybs.m_YBList.AddRange(YBList.Split(',')); ProDefine.g_YBAlarm.Add(ybs); } } } } catch (System.Exception ex) { } }
private int JudageAlarmData(int EclipsTime, int YBNumber, string GNFucntion, double flVolt) { try { //获取当前时间段对应的数据,如果数据在范围内,为正常数据,范围外,判断是否在上下限值如果超出判定为报警值,如果报警时间,在报警时间误差范围内,不做报警 YBAlarmSet ybAlarm = ProDefine.g_YBAlarm.Where(m => m.GNFcontion == GNFucntion).SingleOrDefault(); YBSingleSetInput YBs = ProDefine.g_YBSetSignle.Where(m => m.GNFunction == GNFucntion).SingleOrDefault(); if ((YBs != null) && (ybAlarm != null)) { double lowValue = 0; double HightValue = 0; //if (YBs.SetType == 0) { lowValue = HightValue = YBs.m_ValueList[0]; if (flVolt > (Convert.ToDouble(ybAlarm.AlarmH) + Convert.ToDouble(ybAlarm.AlarmDataAbs))) { return(1);//超高报警 } else if (flVolt < (Convert.ToDouble(ybAlarm.AlarmL) - Convert.ToDouble(ybAlarm.AlarmDataAbs))) { return(2);//超低报警 } else { return(0); } } } //if (ybAlarm == null) { if (YBs.SetType == 0)//恒定信号 { if (flVolt != YBs.m_ValueList[0]) { return(4); } else { return(0); } } else if ((YBs.SetType == 1) || (YBs.SetType == 2))//循环信号 变化信号 { int SumTimeValue = 0; /*取得对应时间对应的值范围*/ for (int i = 0; i < YBs.m_TimeList.Count; i++) { if (YBs.m_TimeList[i] == -1) { break; } SumTimeValue = YBs.m_TimeList[i]; } int Posi = EclipsTime % SumTimeValue; SumTimeValue = 0; int Kindex = 0; for (Kindex = 0; Kindex < YBs.m_TimeList.Count; Kindex++) { SumTimeValue = YBs.m_TimeList[Kindex]; if (Posi <= SumTimeValue) { break; } } double dValue1 = YBs.m_ValueList[Kindex - 1]; double dValue2 = YBs.m_ValueList[Kindex]; if ((flVolt >= Math.Min(dValue1, dValue2)) && (flVolt <= Math.Max(dValue1, dValue2))) { return(0); } else { return(4); } } } return(0); } catch (System.Exception ex) { return(-1); } }