/// <summary> /// 添加 /// </summary> protected void Add() { if (alarmSendDefine.Exist(ddlCoal.SelectedValue, hfDevName.Value, ddlAlarmType.SelectedValue)) { MessageBox.Show(this.Page, "该报警定义已经存在!"); ClearText(); } else { Model.TN_AlarmSendDefine define = new Model.TN_AlarmSendDefine(); #region commit by songhx at 2009-10-14 //define.AlarmGrade = lblAlarmGrade.Text; #endregion commit by songhx at 2009-10-14 #region at by songhx at 2009-10-14 for fix bug:系统不能选择由脚本改变的lblAlarmGrade的值 // define.AlarmGrade = hfAlarmGrade.Value; #endregion at by songhx at 2009-10-14 for fix bug:系统不能选择由脚本改变的lblAlarmGrade的值 define.AlarmGrade = ddlDevName.SelectedValue.ToString(); define.AlarmType = ddlAlarmType.SelectedValue; define.AutoUpdate = chkAutoUpdate.Checked; define.CoalCode = ddlCoal.SelectedValue; define.CoalName = ddlCoal.SelectedItem.Text; define.DevName = hfDevName.Value; define.FinishAlarmTime = string.IsNullOrEmpty(txtFinishAlarmTime.Text.Trim()) ? 0 : Convert.ToInt32(txtFinishAlarmTime.Text.Trim()); define.GUModel = txtGUModel.Text.ToString(); define.ReciverName = hfReciverName.Value; define.ReciverPhoneNo =string.Empty; define.SendFinishNote = chkSendFinishNote.Checked; //发送短信报警频率 if (String.IsNullOrEmpty(txtSendFrequency.Text.Trim()) || txtSendFrequency.Text == "0") { define.SendFrequency = 0; } else { define.SendFrequency = Convert.ToInt32(txtSendFrequency.Text); } define.ShiftRange = string.IsNullOrEmpty(txtShiftRange.Text.Trim()) ? 0 : Convert.ToDecimal(txtShiftRange.Text.Trim()); define.Valid = chkValid.Checked; if (alarmSendDefine.Add(define) == 1) { #region commit by songhx at zichang on 2009-10-13 //MessageBox.Show(this, "添加成功!"); #endregion commit by songhx at zichang on 2009-10-13 #region add by songhx at zichang on 2009-10-13 ClientScript.RegisterStartupScript(Page.GetType(), "", "alert('保存成功!');this.top.currForm.close();", true); #endregion add by songhx at zichang on 2009-10-13 } else { MessageBox.Show(this.Page, "添加失败!"); } } }
/// <summary> /// 获取报警定义 /// </summary> /// <param name="coalCode">煤矿编号</param> /// <param name="alarmType">报警类型</param> /// <param name="DevName">设备类型</param> /// <returns>报警定义实体</returns> public Model.TN_AlarmSendDefine GetModel(string coalCode, string alarmType, string DevName) { if (defineList.Count == 0 || stime.AddMinutes(timeSpan) < DateTime.Now) { DataSet ds = dal.GetAllValid(); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { Model.TN_AlarmSendDefine defineItem = new Model.TN_AlarmSendDefine { AlarmGrade = dr["AlarmGrade"].ToString(), AutoUpdate = Convert.ToBoolean(dr["AutoUpdate"]), Id = Convert.ToInt32(dr["Id"].ToString()), CoalCode = dr["CoalCode"].ToString(), CoalName = dr["CoalName"].ToString(), AlarmType = dr["AlarmType"].ToString(), DevName = dr["DevName"].ToString(), ShiftRange = Convert.ToDecimal(dr["ShiftRange"]), GUModel = dr["GUModel"].ToString(), ReciverName = dr["ReciverName"].ToString(), ReciverPhoneNo = dr["ReciverPhoneNo"].ToString(), FinishAlarmTime = Convert.ToInt32(dr["FinishAlarmTime"]), SendFinishNote = Convert.ToBoolean(dr["SendFinishNote"]), SendFrequency = Convert.ToInt32(dr["SendFrequency"]), Valid = Convert.ToBoolean(dr["Valid"]) }; //add the object to list defineList.Add(defineItem); } stime = DateTime.Now; } //移除列表中的老数据 int newItemCount = ds.Tables[0].Rows.Count; int currentItemCount = defineList.Count; if (currentItemCount > newItemCount) { defineList.RemoveRange(0, currentItemCount - newItemCount); } } Model.TN_AlarmSendDefine define = defineList.FindLast(d => d.CoalCode == coalCode && d.AlarmType == alarmType && d.DevName == DevName); return define; }
/// <summary> /// 获取报警定义 /// </summary> /// <param name="coalCode">煤矿编号</param> /// <param name="alarmType">报警类型</param> /// <param name="DevName">设备类型</param> /// <param name="AlarmGrade">报警级别</param> /// <returns>报警定义实体</returns> public Model.TN_AlarmSendDefine GetModel(string coalCode, string alarmType, string DevName, string alarmGrade) { Model.TN_AlarmSendDefine define = new Model.TN_AlarmSendDefine(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from TN_AlarmSendDefine where CoalCode='{0}'", coalCode); sb.AppendFormat(" and AlarmType='{0}'", alarmType); sb.AppendFormat(" and DevName='{0}'", DevName); sb.AppendFormat(" and AlarmGrade='{0}'",alarmGrade); sb.Append(" and Valid='True'"); DataTable dt = dal.GetDataTable(sb.ToString()); if (dt.Rows.Count != 0) { define.AlarmGrade = dt.Rows[0]["AlarmGrade"].ToString(); define.AlarmType = dt.Rows[0]["AlarmType"].ToString(); define.AutoUpdate = Convert.ToInt32(dt.Rows[0]["AutoUpdate"]) == 1 ? true : false; define.CoalCode = dt.Rows[0]["CoalCode"].ToString(); define.CoalName = dt.Rows[0]["CoalName"].ToString(); define.DevName = dt.Rows[0]["DevName"].ToString(); if (!string.IsNullOrEmpty(dt.Rows[0]["FinishAlarmTime"].ToString())) { define.FinishAlarmTime = Convert.ToInt32(dt.Rows[0]["FinishAlarmTime"]); } define.GUModel = dt.Rows[0]["GUModel"].ToString(); define.Id = Convert.ToInt32(dt.Rows[0]["Id"]); define.ReciverName = dt.Rows[0]["ReciverName"].ToString(); define.ReciverPhoneNo = dt.Rows[0]["ReciverPhoneNo"].ToString(); define.SendFinishNote = Convert.ToInt32(dt.Rows[0]["SendFinishNote"]) == 1 ? true : false; define.SendFrequency = Convert.ToInt32(dt.Rows[0]["SendFrequency"]); if (!string.IsNullOrEmpty(dt.Rows[0]["ShiftRange"].ToString())) { define.ShiftRange = Convert.ToDecimal(dt.Rows[0]["ShiftRange"]); } define.Valid = Convert.ToInt32(dt.Rows[0]["Valid"]) == 1 ? true : false; } return define; }