/// <summary>
        /// 插入t_AlarmPolicyManagement
        /// </summary>
        public virtual bool Insert(AlarmPolicyManagementOR objPolicy)
        {
            string sql = string.Format("insert into t_AlarmPolicyManagement (StationID,DeviceTypeID,DeviceID,DeviceChannelID,ValueType,MaxValue,MinValue,SwitchValue,MaxTiggerType,MinTiggerType,AlarmTimes , AlarmfilterTimes,EventID,IsEnable,AlarmAudioFile,DisAlarmAudioFile,SmsMsg,LightID,ReleaseLightID)"
               + "values ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},'{12}',{13},'{14}','{15}','{16}',{17},{18})", objPolicy.Stationid, objPolicy.Devicetypeid, objPolicy.Deviceid, objPolicy.Devicechannelid, objPolicy.Valuetype,
               objPolicy.Maxvalue, objPolicy.Minvalue, objPolicy.Switchvalue,
               objPolicy.Mintiggertype, objPolicy.Mintiggertype,
               objPolicy.Alarmtimes, objPolicy.Alarmfiltertimes, objPolicy.Eventid, objPolicy.Isenable, objPolicy.Alarmaudiofile, objPolicy.Disalarmaudiofile,
               objPolicy.Smsmsg, objPolicy.Lightid, objPolicy.Releaselightid);

            return db.ExecuteNoQuery(sql) > 0;

            //string sql = "insert into t_AlarmPolicyManagement (StationID, DeviceTypeID, DeviceID, DeviceChannelID, ValueType, MaxTiggerType, MaxValue, MinTiggerType, MinValue, SwitchValue, AlarmLevel, AlarmTarget, AlarmWay, IsEnableFrequency, AlarmAudioFile, DisAlarmAudioFile, AlarmTimes, AlarmfilterTimes, SmsMsg, AlarmVerify, IsEnable, EventID, LightID, ReleaseLightID) values ( @StationID, @DeviceTypeID, @DeviceID, @DeviceChannelID, @ValueType, @MaxTiggerType, @MaxValue, @MinTiggerType, @MinValue, @SwitchValue, @AlarmLevel, @AlarmTarget, @AlarmWay, @IsEnableFrequency, @AlarmAudioFile, @DisAlarmAudioFile, @AlarmTimes, @AlarmfilterTimes, @SmsMsg, @AlarmVerify, @IsEnable, @EventID, @LightID, @ReleaseLightID)";
            //SqlParameter[] parameters = new SqlParameter[]
            //{
            //    new SqlParameter("@StationID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "StationID", DataRowVersion.Default, alarmPolicyManagement.Stationid),
            //    new SqlParameter("@DeviceTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceTypeID", DataRowVersion.Default, alarmPolicyManagement.Devicetypeid),
            //    new SqlParameter("@DeviceID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceID", DataRowVersion.Default, alarmPolicyManagement.Deviceid),
            //    new SqlParameter("@DeviceChannelID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceChannelID", DataRowVersion.Default, alarmPolicyManagement.Devicechannelid),
            //    new SqlParameter("@ValueType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "ValueType", DataRowVersion.Default, alarmPolicyManagement.Valuetype),
            //    new SqlParameter("@MaxTiggerType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "MaxTiggerType", DataRowVersion.Default, alarmPolicyManagement.Maxtiggertype),
            //    new SqlParameter("@MaxValue", SqlDbType.Float, 8, ParameterDirection.Input, false, 0, 0, "MaxValue", DataRowVersion.Default, alarmPolicyManagement.Maxvalue),
            //    new SqlParameter("@MinTiggerType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "MinTiggerType", DataRowVersion.Default, alarmPolicyManagement.Mintiggertype),
            //    new SqlParameter("@MinValue", SqlDbType.Float, 8, ParameterDirection.Input, false, 0, 0, "MinValue", DataRowVersion.Default, alarmPolicyManagement.Minvalue),
            //    new SqlParameter("@SwitchValue", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "SwitchValue", DataRowVersion.Default, alarmPolicyManagement.Switchvalue),
            //    new SqlParameter("@AlarmLevel", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmLevel", DataRowVersion.Default, alarmPolicyManagement.Alarmlevel),
            //    new SqlParameter("@AlarmTarget", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "AlarmTarget", DataRowVersion.Default, alarmPolicyManagement.Alarmtarget),
            //    new SqlParameter("@AlarmWay", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "AlarmWay", DataRowVersion.Default, alarmPolicyManagement.Alarmway),
            //    new SqlParameter("@IsEnableFrequency", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "IsEnableFrequency", DataRowVersion.Default, alarmPolicyManagement.Isenablefrequency),
            //    new SqlParameter("@AlarmAudioFile", SqlDbType.VarChar, 500, ParameterDirection.Input, false, 0, 0, "AlarmAudioFile", DataRowVersion.Default, alarmPolicyManagement.Alarmaudiofile),
            //    new SqlParameter("@DisAlarmAudioFile", SqlDbType.VarChar, 500, ParameterDirection.Input, false, 0, 0, "DisAlarmAudioFile", DataRowVersion.Default, alarmPolicyManagement.Disalarmaudiofile),
            //    new SqlParameter("@AlarmTimes", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmTimes", DataRowVersion.Default, alarmPolicyManagement.Alarmtimes),
            //    new SqlParameter("@AlarmfilterTimes", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmfilterTimes", DataRowVersion.Default, alarmPolicyManagement.Alarmfiltertimes),
            //    new SqlParameter("@SmsMsg", SqlDbType.VarChar, 200, ParameterDirection.Input, false, 0, 0, "SmsMsg", DataRowVersion.Default, alarmPolicyManagement.Smsmsg),
            //    new SqlParameter("@AlarmVerify", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmVerify", DataRowVersion.Default, alarmPolicyManagement.Alarmverify),
            //    new SqlParameter("@IsEnable", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "IsEnable", DataRowVersion.Default, alarmPolicyManagement.Isenable),
            //    new SqlParameter("@EventID", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "EventID", DataRowVersion.Default, alarmPolicyManagement.Eventid),
            //    new SqlParameter("@LightID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "LightID", DataRowVersion.Default, alarmPolicyManagement.Lightid),
            //    new SqlParameter("@ReleaseLightID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "ReleaseLightID", DataRowVersion.Default, alarmPolicyManagement.Releaselightid)
            //};
            //return db.ExecuteNoQuery(sql, parameters) > -1;
        }
 public AlarmPolicyManagementOR selectARowDate(string strAlarmPolicyManagementID)
 {
     string sql = string.Format(@"select * from t_AlarmPolicyManagement where
     AlarmPolicyManagementID={0}", strAlarmPolicyManagementID);
     DataTable dt = null;
     try
     {
         dt = db.ExecuteQueryDataSet(sql).Tables[0];
     }
     catch (Exception ex)
     {
         throw ex;
     }
     if (dt == null)
         return null;
     if (dt.Rows.Count == 0)
         return null;
     DataRow dr = dt.Rows[0];
     AlarmPolicyManagementOR m_Alar = new AlarmPolicyManagementOR(dr);
     return m_Alar;
 }
 /// <summary>
 /// 更新t_AlarmPolicyManagement
 /// </summary>
 public virtual bool Update(AlarmPolicyManagementOR objPolicy)
 {
     string sql = string.Format("update dbo.t_AlarmPolicyManagement set ValueType={0},MaxValue={1},MinValue={2},SwitchValue={3},MaxTiggerType={4},MinTiggerType={5},  "
        + " AlarmTimes={6} , AlarmfilterTimes={7},EventID='{8}',IsEnable={9},AlarmAudioFile='{10}',DisAlarmAudioFile='{11}',SmsMsg='{12}',LightID={13},ReleaseLightID={14} where   StationID ={15} and DeviceTypeID = {16} and DeviceID ={17} and DeviceChannelID = {18}",
        objPolicy.Valuetype, objPolicy.Maxvalue, objPolicy.Minvalue, objPolicy.Switchvalue, objPolicy.Maxtiggertype, objPolicy.Mintiggertype, objPolicy.Alarmtimes, objPolicy.Alarmfiltertimes, objPolicy.Eventid, objPolicy.Isenable,
        objPolicy.Alarmaudiofile, objPolicy.Disalarmaudiofile, objPolicy.Smsmsg, objPolicy.Lightid, objPolicy.Releaselightid, objPolicy.Stationid, objPolicy.Devicetypeid, objPolicy.Deviceid, objPolicy.Devicechannelid);
     return db.ExecuteNoQuery(sql) > 0;
     //            string sql = @"update t_AlarmPolicyManagement set  ValueType = @ValueType,  MaxTiggerType = @MaxTiggerType,  MaxValue = @MaxValue,  MinTiggerType = @MinTiggerType,
     //MinValue = @MinValue,  SwitchValue = @SwitchValue,  AlarmLevel = @AlarmLevel,  AlarmTarget = @AlarmTarget,  AlarmWay = @AlarmWay,
     //IsEnableFrequency = @IsEnableFrequency,  AlarmAudioFile = @AlarmAudioFile,  DisAlarmAudioFile = @DisAlarmAudioFile,  AlarmTimes = @AlarmTimes,
     //AlarmfilterTimes = @AlarmfilterTimes,  SmsMsg = @SmsMsg,  AlarmVerify = @AlarmVerify,  IsEnable = @IsEnable,  EventID = @EventID,  LightID = @LightID,
     //ReleaseLightID = @ReleaseLightID where  StationID = @StationID and DeviceTypeID = @DeviceTypeID and DeviceID = @DeviceID and
     //DeviceChannelID = @DeviceChannelID";
     //            SqlParameter[] parameters = new SqlParameter[]
     //            {
     //                new SqlParameter("@AlarmPolicyManagementID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmPolicyManagementID", DataRowVersion.Default, alarmPolicyManagement.Alarmpolicymanagementid),
     //                new SqlParameter("@StationID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "StationID", DataRowVersion.Default, alarmPolicyManagement.Stationid),
     //                new SqlParameter("@DeviceTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceTypeID", DataRowVersion.Default, alarmPolicyManagement.Devicetypeid),
     //                new SqlParameter("@DeviceID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceID", DataRowVersion.Default, alarmPolicyManagement.Deviceid),
     //                new SqlParameter("@DeviceChannelID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "DeviceChannelID", DataRowVersion.Default, alarmPolicyManagement.Devicechannelid),
     //                new SqlParameter("@ValueType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "ValueType", DataRowVersion.Default, alarmPolicyManagement.Valuetype),
     //                new SqlParameter("@MaxTiggerType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "MaxTiggerType", DataRowVersion.Default, alarmPolicyManagement.Maxtiggertype),
     //                new SqlParameter("@MaxValue", SqlDbType.Float, 8, ParameterDirection.Input, false, 0, 0, "MaxValue", DataRowVersion.Default, alarmPolicyManagement.Maxvalue),
     //                new SqlParameter("@MinTiggerType", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "MinTiggerType", DataRowVersion.Default, alarmPolicyManagement.Mintiggertype),
     //                new SqlParameter("@MinValue", SqlDbType.Float, 8, ParameterDirection.Input, false, 0, 0, "MinValue", DataRowVersion.Default, alarmPolicyManagement.Minvalue),
     //                new SqlParameter("@SwitchValue", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "SwitchValue", DataRowVersion.Default, alarmPolicyManagement.Switchvalue),
     //                new SqlParameter("@AlarmLevel", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmLevel", DataRowVersion.Default, alarmPolicyManagement.Alarmlevel),
     //                new SqlParameter("@AlarmTarget", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "AlarmTarget", DataRowVersion.Default, alarmPolicyManagement.Alarmtarget),
     //                new SqlParameter("@AlarmWay", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "AlarmWay", DataRowVersion.Default, alarmPolicyManagement.Alarmway),
     //                new SqlParameter("@IsEnableFrequency", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "IsEnableFrequency", DataRowVersion.Default, alarmPolicyManagement.Isenablefrequency),
     //                new SqlParameter("@AlarmAudioFile", SqlDbType.VarChar, 500, ParameterDirection.Input, false, 0, 0, "AlarmAudioFile", DataRowVersion.Default, alarmPolicyManagement.Alarmaudiofile),
     //                new SqlParameter("@DisAlarmAudioFile", SqlDbType.VarChar, 500, ParameterDirection.Input, false, 0, 0, "DisAlarmAudioFile", DataRowVersion.Default, alarmPolicyManagement.Disalarmaudiofile),
     //                new SqlParameter("@AlarmTimes", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmTimes", DataRowVersion.Default, alarmPolicyManagement.Alarmtimes),
     //                new SqlParameter("@AlarmfilterTimes", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmfilterTimes", DataRowVersion.Default, alarmPolicyManagement.Alarmfiltertimes),
     //                new SqlParameter("@SmsMsg", SqlDbType.VarChar, 200, ParameterDirection.Input, false, 0, 0, "SmsMsg", DataRowVersion.Default, alarmPolicyManagement.Smsmsg),
     //                new SqlParameter("@AlarmVerify", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "AlarmVerify", DataRowVersion.Default, alarmPolicyManagement.Alarmverify),
     //                new SqlParameter("@IsEnable", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "IsEnable", DataRowVersion.Default, alarmPolicyManagement.Isenable),
     //                new SqlParameter("@EventID", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "EventID", DataRowVersion.Default, alarmPolicyManagement.Eventid),
     //                new SqlParameter("@LightID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "LightID", DataRowVersion.Default, alarmPolicyManagement.Lightid),
     //                new SqlParameter("@ReleaseLightID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "ReleaseLightID", DataRowVersion.Default, alarmPolicyManagement.Releaselightid)
     //            };
     //return db.ExecuteNoQuery(sql, parameters) > -1;
 }
 public AlarmPolicyManagementOR selectARowDate(string StationID, string DeviceTypeID,
     string DeviceID, string DeviceChannelID)
 {
     string sql = string.Format(@"select * from t_AlarmPolicyManagement where
     StationID={0} and DeviceTypeID={1} and DeviceID={2} and DeviceChannelID={3}",
     StationID, DeviceTypeID, DeviceID, DeviceChannelID);
     DataTable dt = null;
     try
     {
         dt = db.ExecuteQueryDataSet(sql).Tables[0];
     }
     catch (Exception ex)
     {
         throw ex;
     }
     if (dt == null)
         return null;
     if (dt.Rows.Count == 0)
         return null;
     DataRow dr = dt.Rows[0];
     AlarmPolicyManagementOR m_Alar = new AlarmPolicyManagementOR(dr);
     return m_Alar;
 }
        public void showAlarmPolicyInfo(AlarmPolicyManagementOR m_Alar)
        {
            string EventID = m_Alar.Eventid;
            string[] evds = EventID.Split('-');
            if (evds.Length > 1)
            {
                string hi = "-1";
                string lo = "-1";
                if (evds[0] != "")
                {
                    hi = evds[0];
                    this.cmbEventHi.SelectedValue = hi;
                }

                if (evds[1] != "")
                {
                    lo = evds[1];
                    this.cmbEventLo.SelectedValue = lo;
                }
            }
            else if (evds.Length == 1)
            {
                if (evds[0] != "")
                {
                    this.cmbEvent.SelectedValue = evds[0];
                }
            }

            txt_MaxValue.Text = m_Alar.Maxvalue.ToString();
            txt_MinValue.Text = m_Alar.Minvalue.ToString();
            string s = m_Alar.Switchvalue.ToString();
            if (s.Trim() != "" && s.Trim() != null && s.Trim() != "NULL" && s.Trim() != "null")
            {
                //string s = dt.Rows[0]["SwitchValue"].ToString();
                int ValueType = int.Parse(s);
                if (ValueType == 1)
                {
                    cmb_AlarmValue.Text = "高电平";
                }
                else
                    cmb_AlarmValue.Text = "低电平";
            }
            else
                cmb_AlarmValue.Text = "未配置";

            if (m_Alar.Maxtiggertype == 0)
                check_EqualMax.Checked = false;
            else
                check_EqualMax.Checked = true;

            if (m_Alar.Mintiggertype == 0)
                check_EqualMinValue.Checked = false;
            else
                check_EqualMinValue.Checked = true;

            txtAlarmtimes.Text = m_Alar.Alarmtimes.ToString();//AlarmTimes  AlarmfilterTimes
            txtAlarmfiltertimes.Text = m_Alar.Alarmfiltertimes.ToString();

            //2011-10-26  增加语音文件
            txtAlarmaudiofile.Text = m_Alar.Alarmaudiofile;
            txtDisalarmaudiofile.Text = m_Alar.Disalarmaudiofile;

            cbIsenable.Checked = (m_Alar.Isenable == 1);

            txtSmsmsg.Text = m_Alar.Smsmsg;

            this.LightID.SelectedValue = m_Alar.Lightid.ToString();

            this.ReleaseLightID.SelectedValue = m_Alar.Releaselightid.ToString();
        }
        private AlarmPolicyManagementOR SetValue()
        {
            AlarmPolicyManagementOR m_Alar = new AlarmPolicyManagementOR();

            m_Alar.Stationid = int.Parse(Request.QueryString["StationID"]);//机房名称
            m_Alar.Devicetypeid = int.Parse(Request.QueryString["DeviceTypeID"]);//设备类型
            m_Alar.Deviceid = int.Parse(Request.QueryString["DeviceID"]);//设备名称
            m_Alar.Devicechannelid = int.Parse(Request.QueryString["ChanncelID"]);//通道

            m_Alar.Isenable = cbIsenable.Checked ? 1 : 0;

            string EvHi, EvLo, EvSg;
            string EventID = "";
            int ValueType = m_devi.GetChannelValueType(Request.QueryString["DeviceID"],
                Request.QueryString["ChanncelID"]);
            m_Alar.Valuetype = ValueType;
            if (ValueType == 0)
            {
                if (this.cmbEventHi.SelectedValue != null)
                    EvHi = this.cmbEventHi.SelectedValue.ToString();
                else
                    EvHi = "";

                if (this.cmbEventLo.SelectedValue != null)
                    EvLo = this.cmbEventLo.SelectedValue.ToString();
                else
                    EvLo = "";

                EventID = EvHi + "-" + EvLo;

                if (txt_MaxValue.Text != string.Empty && txt_MaxValue.Text != "")
                    m_Alar.Maxvalue =txt_MaxValue.Text.Trim();
                if (txt_MinValue.Text != string.Empty && txt_MinValue.Text != "")
                    m_Alar.Minvalue =txt_MinValue.Text.Trim();
            }
            else
            {
                if (this.cmbEvent.SelectedValue != null)
                    EvSg = this.cmbEvent.SelectedValue.ToString();
                else
                    EvSg = "";

                EventID = EvSg;

                m_Alar.Maxvalue = "NULL";
                m_Alar.Minvalue = "NULL";
                //if (cmb_AlarmValue.Text.Trim() == "")
                //    objPolicyModel.SwitchValue;
                if (cmb_AlarmValue.Text.Trim() == "高电平")
                    m_Alar.Switchvalue = 1;

                else if (cmb_AlarmValue.Text.Trim() == "低电平")
                    m_Alar.Switchvalue = 0;
            }

            if (check_EqualMax.Checked)
                m_Alar.Maxtiggertype = 1;//高于高限触发
            else
                m_Alar.Maxtiggertype = 0;//等于或高于高限触发
            if (check_EqualMinValue.Checked)
                m_Alar.Mintiggertype = 1;
            else
                m_Alar.Mintiggertype = 0;

            if (txtAlarmtimes.Text.Trim() != string.Empty)
                m_Alar.Alarmtimes = int.Parse(txtAlarmtimes.Text);
            if (txtAlarmfiltertimes.Text.Trim() != string.Empty)
                m_Alar.Alarmfiltertimes = int.Parse(txtAlarmfiltertimes.Text);

            //报警语音文件以及解除报警语音文件名
            if (txtAlarmaudiofile.Text.Trim() != string.Empty)
            {
                m_Alar.Alarmaudiofile = txtAlarmaudiofile.Text.Trim();
            }
            else
            {
                m_Alar.Alarmaudiofile = null;
            }
            if (txtDisalarmaudiofile.Text.Trim() != string.Empty)
            {
                m_Alar.Disalarmaudiofile = txtDisalarmaudiofile.Text.Trim();
            }
            else
            {
                m_Alar.Disalarmaudiofile = null;
            }

            //短信、Email、语音报警内容格式
            if (txtSmsmsg.Text.Trim() != string.Empty && cbDefultAlert.Checked == false)
            {
                m_Alar.Smsmsg = txtSmsmsg.Text.Trim();
            }
            //保存默认的报警内容
            else if (this.txt_defaultSmsMsg.Text != string.Empty && this.txt_defaultSmsMsg.Enabled == true && cbDefultAlert.Checked)
                m_Alar.Smsmsg = txt_defaultSmsMsg.Text.Trim();

            m_Alar.Lightid = int.Parse(LightID.SelectedItem.Value);
            m_Alar.Releaselightid = int.Parse(ReleaseLightID.SelectedItem.Value);
            m_Alar.Eventid = EventID;
            return m_Alar;
        }