private void simpleButton8_Click(object sender, EventArgs e) { try { if (comboBoxEdit_SensorName.Text.Trim() == string.Empty) { XtraMessageBox.Show("请选择设备名称"); return; } if (comboBoxEdit_GasName.Text.Trim() == string.Empty) { XtraMessageBox.Show("请选择气体名称"); return; } TimeSpan ts = dateEdit_end.DateTime - dateEdit_Start.DateTime; TimeSpan ts1 = new TimeSpan(0, 0, 0, 1); if (ts < ts1) { XtraMessageBox.Show("截止时间必须大于起始时间"); return; } Equipment eq = mainList.Find(c => c.Name == comboBoxEdit_SensorName.Text.Trim() && c.GasName == comboBoxEdit_GasName.Text.Trim() && c.Address == Convert.ToByte(comboBoxEdit_Address.Text.Trim())); List <Alert> data = AlertDal.GetListByTime(eq.ID, dateEdit_Start.DateTime, dateEdit_end.DateTime); if (data == null || data.Count < 1) { gridControl3.DataSource = null; LogLib.Log.GetLogger(this).Warn("数据库中没有记录"); return; } selectEq = eq; gridControl3.DataSource = data; gridView3.BestFitColumns(); } catch (Exception ex) { LogLib.Log.GetLogger(this).Warn(ex); } }
private void btn_searchAlert_Click(object sender, EventArgs e) { TimeSpan ts = dateEdit_EndAlert.DateTime - dateEdit_StartAlert.DateTime; TimeSpan ts1 = new TimeSpan(0, 0, 0, 1); if (ts < ts1) { XtraMessageBox.Show("截止时间必须大于起始时间"); return; } //Equipment eq = mainList.Find(c => c.Name == comboBoxEdit_SensorName.Text.Trim() && c.GasName == comboBoxEdit_GasName.Text.Trim()); List <Alert> data = AlertDal.GetListByTime(dateEdit_StartAlert.DateTime, dateEdit_EndAlert.DateTime); if (data == null || data.Count < 1) { gridControl_Alert.DataSource = null; LogLib.Log.GetLogger(this).Warn("数据库中没有记录"); return; } gridControl_Alert.DataSource = data; gridView_Alert.BestFitColumns(); }
/// <summary> /// 删除查询到的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void simpleButton1_Click(object sender, EventArgs e) { try { if (selectEq == null) { return; } //if (Gloabl.Userinfo.Level != EM_UserType.Admin) //{ // XtraMessageBox.Show("只有管理员才能删除数据"); // return; //} TimeSpan ts = dateEdit_end.DateTime - dateEdit_Start.DateTime; TimeSpan ts1 = new TimeSpan(0, 0, 0, 1); if (ts < ts1) { XtraMessageBox.Show("截止时间必须大于起始时间"); return; } if (XtraMessageBox.Show("数据将要被删除,是否继续", "注意", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } int count = AlertDal.DeleteByTime(selectEq.ID, dateEdit_Start.DateTime, dateEdit_end.DateTime); gridControl3.DataSource = null; selectEq = null; XtraMessageBox.Show(string.Format("本次删除{0}条数据", count)); } catch (Exception ex) { LogLib.Log.GetLogger(this).Warn(ex); } }
// 读取主表类容 private void readMain(Equipment eq) { Command cd = new Command(eq.Address, 0x00, 0x00, 3); if (Gloabl.IsAdmin) { this.Invoke(new Action <string>(addText), "W: " + Parse.byteToHexStr(cd.SendByte)); } if (!CommandResult.GetResult(cd)) { if (eq.lostNum >= 10) { eq.IsConnect = false; } else { eq.lostNum++; } return; } else { eq.IsConnect = true; eq.lostNum = 0; } if (Gloabl.IsAdmin) { this.Invoke(new Action <string>(addText), "R: " + Parse.byteToHexStr(cd.ResultByte)); } EquipmentData data = Parse.GetRealData(cd.ResultByte, eq); data.EquipmentID = eq.ID; // 添加数据库 EquipmentDataDal.AddOne(data); eq.Chroma = data.Chroma; // 绘制曲线 if (eq.ID == Convert.ToInt32(seriesOne.Tag)) { this.Invoke(new Action <EquipmentData>(c => addPoint(c)), data); } if (eq.AlertType == 0) { eq.ChromaAlertStr = Gloabl.NormalStr; } else { // 报警记录 if (eq.ChromaAlertStr != data.ChromaAlertStr) { if (eq.ChromaAlertStr.Equals(Gloabl.NormalStr, StringComparison.OrdinalIgnoreCase)) { Alert art = new Alert(); art.AlertName = data.ChromaAlertStr; art.EquipmentID = eq.ID; eq.AlertObject = AlertDal.AddOneR(art); } else { eq.AlertObject.EndTime = DateTime.Now; AlertDal.UpdateOne(eq.AlertObject); if (!eq.ChromaAlertStr.Equals(data.ChromaAlertStr, StringComparison.OrdinalIgnoreCase)) { Alert art = new Alert(); art.AlertName = data.ChromaAlertStr; art.EquipmentID = eq.ID; eq.AlertObject = AlertDal.AddOneR(art); } } eq.ChromaAlertStr = data.ChromaAlertStr; } else { if (!eq.ChromaAlertStr.Equals(Gloabl.NormalStr, StringComparison.OrdinalIgnoreCase)) { eq.AlertObject.EndTime = DateTime.Now; if (!AlertDal.UpdateOne(eq.AlertObject)) { Alert art = new Alert(); art.AlertName = data.ChromaAlertStr; art.EquipmentID = eq.ID; eq.AlertObject = AlertDal.AddOneR(art); } } } } }
public static void AddAlert(Equipment newData, Equipment originalData) { if (newData.Chroma >= originalData.A2) { newData.ChromaAlertStr = "高报警"; } else if (newData.Chroma >= originalData.A1 && newData.Chroma < originalData.A2) { newData.ChromaAlertStr = "低报警"; } else { newData.ChromaAlertStr = "无报警"; } if (originalData.ChromaAlertStr != newData.ChromaAlertStr) { if (originalData.ChromaAlertStr == "无报警" || string.IsNullOrWhiteSpace(originalData.ChromaAlertStr)) { Alert art = new Alert(); art.AlertName = newData.ChromaAlertStr; art.EquipmentID = originalData.ID; originalData.AlertObject = AlertDal.AddOneR(art); } else { originalData.AlertObject.EndTime = DateTime.Now; AlertDal.UpdateOne(originalData.AlertObject); if (!string.IsNullOrWhiteSpace(newData.ChromaAlertStr)) { Alert art = new Alert(); art.AlertName = newData.ChromaAlertStr; art.EquipmentID = originalData.ID; originalData.AlertObject = AlertDal.AddOneR(art); } } originalData.ChromaAlertStr = newData.ChromaAlertStr; } else { if (!string.IsNullOrWhiteSpace(originalData.ChromaAlertStr)) { originalData.AlertObject.EndTime = DateTime.Now; if (!AlertDal.UpdateOne(originalData.AlertObject)) { Alert art = new Alert(); art.AlertName = newData.ChromaAlertStr; art.EquipmentID = originalData.ID; originalData.AlertObject = AlertDal.AddOneR(art); } } //Trace.WriteLine(string.Format("[{1}] {0}:相同报警", eq.SensorType, DateTime.Now.ToLongTimeString())); } //if (eq.THAlertStr != data.THAlertStr) //{ // if (!string.IsNullOrWhiteSpace(eq.THAlertStr)) // { // eq.THAlertObject.EndTime = DateTime.Now; // AlertDal.UpdateOne(eq.THAlertObject); // if (!string.IsNullOrWhiteSpace(data.THAlertStr)) // { // Alert art = new Alert(); // art.AlertName = data.THAlertStr; // art.EquipmentID = eq.ID; // eq.THAlertObject = AlertDal.AddOneR(art); // } // } // else // { // Alert art = new Alert(); // art.AlertName = data.THAlertStr; // art.EquipmentID = eq.ID; // eq.THAlertObject = AlertDal.AddOneR(art); // } // eq.THAlertStr = data.THAlertStr; //} //else //{ // if (!string.IsNullOrWhiteSpace(eq.THAlertStr)) // { // eq.THAlertObject.EndTime = DateTime.Now; // AlertDal.UpdateOne(eq.THAlertObject); // } //} }