/// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">相应的数据实体</param>
 /// <returns>真表示有记录被更新,否表示没有记录被更新</returns>
 public bool Update(RelayTest.Model.ModelDEV_POWER_SWITCH model)
 {
     try
     {
         Log.Info("BllDEV_POWER_SWITCH->Update---START");
         ConnectionOpen();
         dal.SetDBAccess(GetDBAccess());
         return(dal.Update(model));
     }
     catch (Exception ex)
     {
         Log.Error("BllDEV_POWER_SWITCH->Update---FAILED", ex);
         throw ex;
     }
     finally
     {
         ConnectionClose();
         Log.Info("BllDEV_POWER_SWITCH->Update---finally");
     }
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(RelayTest.Model.ModelDEV_POWER_SWITCH model)
 {
     try
     {
         Log.Info("BllDEV_POWER_SWITCH->Add---START");
         ConnectionOpen();
         dal.SetDBAccess(GetDBAccess());
         dal.Add(model);
     }
     catch (Exception ex)
     {
         Log.Error("BllDEV_POWER_SWITCH->Add---FAILED", ex);
         throw ex;
     }
     finally
     {
         ConnectionClose();
         Log.Info("BllDEV_POWER_SWITCH->Add---finally");
     }
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RelayTest.Model.ModelDEV_POWER_SWITCH GetModel(string F_POWER_ID, string F_POWER_SWITCH_ID)
        {
            try
            {
                Log.Info("DalDEV_POWER_SWITCH->GetModel---START");
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select ");
                //供电柜编号
                strSql.Append("F_POWER_ID,  ");
                //开关报警阈值(按时长)
                strSql.Append("F_ALARM_LIFEDURANCE,  ");
                //开关报警阈值(按使用次数)
                strSql.Append("F_ALARM_TIMEDURANCE,  ");
                //开关动作次数
                strSql.Append("F_SWITCH_TIMES,  ");
                //创建时间
                strSql.Append("F_CREATE_TIME,  ");
                //操作员
                strSql.Append("F_OPERATOR_ID,  ");
                //操作时间
                strSql.Append("F_OPERATIONTIME,  ");
                //是否删除
                strSql.Append("F_DEL,  ");
                //开关序号
                strSql.Append("F_POWER_SWITCH_ID,  ");
                //供电柜开关地址
                strSql.Append("F_POWER_SWITCH_ADDRESS,  ");
                //通道号
                strSql.Append("F_COM_ADDRESS,  ");
                //F_HOLDREG
                strSql.Append("F_HOLDREG,  ");
                //校准编号
                strSql.Append("F_POWER_SWITCH_CALIBRATION,  ");
                //输入输出类型
                strSql.Append("F_POWER_SWITCH_TYPE,  ");
                //供电柜开关状态
                strSql.Append("F_POWER_SWITCH_STATUS,  ");
                //负荷容量
                strSql.Append("F_LOAD_CAPACITY  ");
                strSql.Append("  from T_DEV_POWER_SWITCH ");
                strSql.Append(" where 1=1 AND  F_POWER_ID=:F_POWER_ID and F_POWER_SWITCH_ID=:F_POWER_SWITCH_ID ");
                OracleParameter[] parameters =
                {
                    new OracleParameter(":F_POWER_ID",        OracleType.VarChar, 20),
                    new OracleParameter(":F_POWER_SWITCH_ID", OracleType.VarChar, 20)
                };
                parameters[0].Value = F_POWER_ID;
                parameters[1].Value = F_POWER_SWITCH_ID;


                RelayTest.Model.ModelDEV_POWER_SWITCH model = new RelayTest.Model.ModelDEV_POWER_SWITCH();
                DataSet ds = Query(strSql.ToString(), parameters);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    model.F_POWER_ID = ds.Tables[0].Rows[0]["F_POWER_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["F_ALARM_LIFEDURANCE"].ToString() != "")
                    {
                        model.F_ALARM_LIFEDURANCE = decimal.Parse(ds.Tables[0].Rows[0]["F_ALARM_LIFEDURANCE"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_ALARM_TIMEDURANCE"].ToString() != "")
                    {
                        model.F_ALARM_TIMEDURANCE = decimal.Parse(ds.Tables[0].Rows[0]["F_ALARM_TIMEDURANCE"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_SWITCH_TIMES"].ToString() != "")
                    {
                        model.F_SWITCH_TIMES = decimal.Parse(ds.Tables[0].Rows[0]["F_SWITCH_TIMES"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_CREATE_TIME"].ToString() != "")
                    {
                        model.F_CREATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_CREATE_TIME"].ToString());
                    }
                    model.F_OPERATOR_ID = ds.Tables[0].Rows[0]["F_OPERATOR_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["F_OPERATIONTIME"].ToString() != "")
                    {
                        model.F_OPERATIONTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_OPERATIONTIME"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_DEL"].ToString() != "")
                    {
                        model.F_DEL = decimal.Parse(ds.Tables[0].Rows[0]["F_DEL"].ToString());
                    }
                    model.F_POWER_SWITCH_ID = ds.Tables[0].Rows[0]["F_POWER_SWITCH_ID"].ToString();
                    if (ds.Tables[0].Rows[0]["F_POWER_SWITCH_ADDRESS"].ToString() != "")
                    {
                        model.F_POWER_SWITCH_ADDRESS = decimal.Parse(ds.Tables[0].Rows[0]["F_POWER_SWITCH_ADDRESS"].ToString());
                    }
                    model.F_COM_ADDRESS = ds.Tables[0].Rows[0]["F_COM_ADDRESS"].ToString();
                    if (ds.Tables[0].Rows[0]["F_HOLDREG"].ToString() != "")
                    {
                        model.F_HOLDREG = decimal.Parse(ds.Tables[0].Rows[0]["F_HOLDREG"].ToString());
                    }
                    model.F_POWER_SWITCH_CALIBRATION = ds.Tables[0].Rows[0]["F_POWER_SWITCH_CALIBRATION"].ToString();
                    if (ds.Tables[0].Rows[0]["F_POWER_SWITCH_TYPE"].ToString() != "")
                    {
                        model.F_POWER_SWITCH_TYPE = decimal.Parse(ds.Tables[0].Rows[0]["F_POWER_SWITCH_TYPE"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_POWER_SWITCH_STATUS"].ToString() != "")
                    {
                        model.F_POWER_SWITCH_STATUS = decimal.Parse(ds.Tables[0].Rows[0]["F_POWER_SWITCH_STATUS"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["F_LOAD_CAPACITY"].ToString() != "")
                    {
                        model.F_LOAD_CAPACITY = decimal.Parse(ds.Tables[0].Rows[0]["F_LOAD_CAPACITY"].ToString());
                    }

                    return(model);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Log.Error("DalDEV_POWER_SWITCH->GetModel---FAILED", ex);
                throw ex;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <RelayTest.Model.ModelDEV_POWER_SWITCH> DataTableToList(DataTable dt)
        {
            try
            {
                Log.Info("BllDEV_POWER_SWITCH->DataTableToList---START");
                ConnectionOpen();
                dal.SetDBAccess(GetDBAccess());
                List <RelayTest.Model.ModelDEV_POWER_SWITCH> modelList = new List <RelayTest.Model.ModelDEV_POWER_SWITCH>();
                int rowsCount = dt.Rows.Count;
                if (rowsCount > 0)
                {
                    RelayTest.Model.ModelDEV_POWER_SWITCH model;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        model = new RelayTest.Model.ModelDEV_POWER_SWITCH();

                        //供电柜编号
                        model.F_POWER_ID = dt.Rows[n]["F_POWER_ID"].ToString();

                        //开关报警阈值(按时长)
                        if (dt.Rows[n]["F_ALARM_LIFEDURANCE"].ToString() != "")
                        {
                            model.F_ALARM_LIFEDURANCE = decimal.Parse(dt.Rows[n]["F_ALARM_LIFEDURANCE"].ToString());
                        }

                        //开关报警阈值(按使用次数)
                        if (dt.Rows[n]["F_ALARM_TIMEDURANCE"].ToString() != "")
                        {
                            model.F_ALARM_TIMEDURANCE = decimal.Parse(dt.Rows[n]["F_ALARM_TIMEDURANCE"].ToString());
                        }

                        //开关动作次数
                        if (dt.Rows[n]["F_SWITCH_TIMES"].ToString() != "")
                        {
                            model.F_SWITCH_TIMES = decimal.Parse(dt.Rows[n]["F_SWITCH_TIMES"].ToString());
                        }

                        //创建时间
                        if (dt.Rows[n]["F_CREATE_TIME"].ToString() != "")
                        {
                            model.F_CREATE_TIME = DateTime.Parse(dt.Rows[n]["F_CREATE_TIME"].ToString());
                        }

                        //操作员
                        model.F_OPERATOR_ID = dt.Rows[n]["F_OPERATOR_ID"].ToString();

                        //操作时间
                        if (dt.Rows[n]["F_OPERATIONTIME"].ToString() != "")
                        {
                            model.F_OPERATIONTIME = DateTime.Parse(dt.Rows[n]["F_OPERATIONTIME"].ToString());
                        }

                        //是否删除
                        if (dt.Rows[n]["F_DEL"].ToString() != "")
                        {
                            model.F_DEL = decimal.Parse(dt.Rows[n]["F_DEL"].ToString());
                        }

                        //开关序号
                        model.F_POWER_SWITCH_ID = dt.Rows[n]["F_POWER_SWITCH_ID"].ToString();

                        //供电柜开关地址
                        if (dt.Rows[n]["F_POWER_SWITCH_ADDRESS"].ToString() != "")
                        {
                            model.F_POWER_SWITCH_ADDRESS = decimal.Parse(dt.Rows[n]["F_POWER_SWITCH_ADDRESS"].ToString());
                        }

                        //通道号
                        model.F_COM_ADDRESS = dt.Rows[n]["F_COM_ADDRESS"].ToString();

                        //F_HOLDREG
                        if (dt.Rows[n]["F_HOLDREG"].ToString() != "")
                        {
                            model.F_HOLDREG = decimal.Parse(dt.Rows[n]["F_HOLDREG"].ToString());
                        }

                        //校准编号
                        model.F_POWER_SWITCH_CALIBRATION = dt.Rows[n]["F_POWER_SWITCH_CALIBRATION"].ToString();

                        //输入输出类型
                        if (dt.Rows[n]["F_POWER_SWITCH_TYPE"].ToString() != "")
                        {
                            model.F_POWER_SWITCH_TYPE = decimal.Parse(dt.Rows[n]["F_POWER_SWITCH_TYPE"].ToString());
                        }

                        //供电柜开关状态
                        if (dt.Rows[n]["F_POWER_SWITCH_STATUS"].ToString() != "")
                        {
                            model.F_POWER_SWITCH_STATUS = decimal.Parse(dt.Rows[n]["F_POWER_SWITCH_STATUS"].ToString());
                        }

                        //负荷容量
                        if (dt.Rows[n]["F_LOAD_CAPACITY"].ToString() != "")
                        {
                            model.F_LOAD_CAPACITY = decimal.Parse(dt.Rows[n]["F_LOAD_CAPACITY"].ToString());
                        }


                        modelList.Add(model);
                    }
                }
                return(modelList);
            }
            catch (Exception ex)
            {
                Log.Error("BllDEV_POWER_SWITCH->DataTableToList---FAILED", ex);
                throw ex;
            }
            finally
            {
                ConnectionClose();
                Log.Info("BllDEV_POWER_SWITCH->DataTableToList---finally");
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(RelayTest.Model.ModelDEV_POWER_SWITCH model)
        {
            try
            {
                Log.Info("DalDEV_POWER_SWITCH->Add---START");
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into T_DEV_POWER_SWITCH(");

                //供电柜编号
                strSql.Append("  F_POWER_ID,");
                //开关报警阈值(按时长)
                strSql.Append("  F_ALARM_LIFEDURANCE,");
                //开关报警阈值(按使用次数)
                strSql.Append("  F_ALARM_TIMEDURANCE,");
                //开关动作次数
                strSql.Append("  F_SWITCH_TIMES,");
                //创建时间
                strSql.Append("  F_CREATE_TIME,");
                //操作员
                strSql.Append("  F_OPERATOR_ID,");
                //操作时间
                strSql.Append("  F_OPERATIONTIME,");
                //是否删除
                strSql.Append("  F_DEL,");
                //开关序号
                strSql.Append("  F_POWER_SWITCH_ID,");
                //供电柜开关地址
                strSql.Append("  F_POWER_SWITCH_ADDRESS,");
                //通道号
                strSql.Append("  F_COM_ADDRESS,");
                //F_HOLDREG
                strSql.Append("  F_HOLDREG,");
                //校准编号
                strSql.Append("  F_POWER_SWITCH_CALIBRATION,");
                //输入输出类型
                strSql.Append("  F_POWER_SWITCH_TYPE,");
                //供电柜开关状态
                strSql.Append("  F_POWER_SWITCH_STATUS,");
                //负荷容量
                strSql.Append("  F_LOAD_CAPACITY");
                strSql.Append(") values (");
                strSql.Append(" :F_POWER_ID,");
                strSql.Append(" :F_ALARM_LIFEDURANCE,");
                strSql.Append(" :F_ALARM_TIMEDURANCE,");
                strSql.Append(" :F_SWITCH_TIMES,");
                strSql.Append(" :F_CREATE_TIME,");
                strSql.Append(" :F_OPERATOR_ID,");
                strSql.Append(" :F_OPERATIONTIME,");
                strSql.Append(" :F_DEL,");
                strSql.Append(" :F_POWER_SWITCH_ID,");
                strSql.Append(" :F_POWER_SWITCH_ADDRESS,");
                strSql.Append(" :F_COM_ADDRESS,");
                strSql.Append(" :F_HOLDREG,");
                strSql.Append(" :F_POWER_SWITCH_CALIBRATION,");
                strSql.Append(" :F_POWER_SWITCH_TYPE,");
                strSql.Append(" :F_POWER_SWITCH_STATUS,");
                strSql.Append(" :F_LOAD_CAPACITY");
                strSql.Append(") ");

                OracleParameter[] parameters =
                {
                    new OracleParameter(":F_POWER_ID",                 OracleType.VarChar,    20),
                    new OracleParameter(":F_ALARM_LIFEDURANCE",        OracleType.Number,     18),
                    new OracleParameter(":F_ALARM_TIMEDURANCE",        OracleType.Number,     18),
                    new OracleParameter(":F_SWITCH_TIMES",             OracleType.Number,     18),
                    new OracleParameter(":F_CREATE_TIME",              OracleType.DateTime),
                    new OracleParameter(":F_OPERATOR_ID",              OracleType.VarChar,    10),
                    new OracleParameter(":F_OPERATIONTIME",            OracleType.DateTime),
                    new OracleParameter(":F_DEL",                      OracleType.Number,      4),
                    new OracleParameter(":F_POWER_SWITCH_ID",          OracleType.VarChar,    20),
                    new OracleParameter(":F_POWER_SWITCH_ADDRESS",     OracleType.Number,      4),
                    new OracleParameter(":F_COM_ADDRESS",              OracleType.VarChar,    20),
                    new OracleParameter(":F_HOLDREG",                  OracleType.Number,      4),
                    new OracleParameter(":F_POWER_SWITCH_CALIBRATION", OracleType.VarChar,   100),
                    new OracleParameter(":F_POWER_SWITCH_TYPE",        OracleType.Number,      4),
                    new OracleParameter(":F_POWER_SWITCH_STATUS",      OracleType.Number,      4),
                    new OracleParameter(":F_LOAD_CAPACITY",            OracleType.Number, 18)
                };

                //供电柜编号
                if (model.F_POWER_ID == null)
                {
                    parameters[0].Value = DBNull.Value;
                }
                else
                {
                    parameters[0].Value = model.F_POWER_ID;
                }

                //开关报警阈值(按时长)
                if (model.F_ALARM_LIFEDURANCE == null)
                {
                    parameters[1].Value = DBNull.Value;
                }
                else
                {
                    parameters[1].Value = model.F_ALARM_LIFEDURANCE;
                }

                //开关报警阈值(按使用次数)
                if (model.F_ALARM_TIMEDURANCE == null)
                {
                    parameters[2].Value = DBNull.Value;
                }
                else
                {
                    parameters[2].Value = model.F_ALARM_TIMEDURANCE;
                }

                //开关动作次数
                if (model.F_SWITCH_TIMES == null)
                {
                    parameters[3].Value = DBNull.Value;
                }
                else
                {
                    parameters[3].Value = model.F_SWITCH_TIMES;
                }

                //创建时间
                if (model.F_CREATE_TIME == null)
                {
                    parameters[4].Value = DBNull.Value;
                }
                else
                {
                    parameters[4].Value = model.F_CREATE_TIME;
                }

                //操作员
                if (model.F_OPERATOR_ID == null)
                {
                    parameters[5].Value = DBNull.Value;
                }
                else
                {
                    parameters[5].Value = model.F_OPERATOR_ID;
                }

                //操作时间
                if (model.F_OPERATIONTIME == null)
                {
                    parameters[6].Value = DBNull.Value;
                }
                else
                {
                    parameters[6].Value = model.F_OPERATIONTIME;
                }

                //是否删除
                if (model.F_DEL == null)
                {
                    parameters[7].Value = DBNull.Value;
                }
                else
                {
                    parameters[7].Value = model.F_DEL;
                }

                //开关序号
                if (model.F_POWER_SWITCH_ID == null)
                {
                    parameters[8].Value = DBNull.Value;
                }
                else
                {
                    parameters[8].Value = model.F_POWER_SWITCH_ID;
                }

                //供电柜开关地址
                if (model.F_POWER_SWITCH_ADDRESS == null)
                {
                    parameters[9].Value = DBNull.Value;
                }
                else
                {
                    parameters[9].Value = model.F_POWER_SWITCH_ADDRESS;
                }

                //通道号
                if (model.F_COM_ADDRESS == null)
                {
                    parameters[10].Value = DBNull.Value;
                }
                else
                {
                    parameters[10].Value = model.F_COM_ADDRESS;
                }

                //F_HOLDREG
                if (model.F_HOLDREG == null)
                {
                    parameters[11].Value = DBNull.Value;
                }
                else
                {
                    parameters[11].Value = model.F_HOLDREG;
                }

                //校准编号
                if (model.F_POWER_SWITCH_CALIBRATION == null)
                {
                    parameters[12].Value = DBNull.Value;
                }
                else
                {
                    parameters[12].Value = model.F_POWER_SWITCH_CALIBRATION;
                }

                //输入输出类型
                if (model.F_POWER_SWITCH_TYPE == null)
                {
                    parameters[13].Value = DBNull.Value;
                }
                else
                {
                    parameters[13].Value = model.F_POWER_SWITCH_TYPE;
                }

                //供电柜开关状态
                if (model.F_POWER_SWITCH_STATUS == null)
                {
                    parameters[14].Value = DBNull.Value;
                }
                else
                {
                    parameters[14].Value = model.F_POWER_SWITCH_STATUS;
                }

                //负荷容量
                if (model.F_LOAD_CAPACITY == null)
                {
                    parameters[15].Value = DBNull.Value;
                }
                else
                {
                    parameters[15].Value = model.F_LOAD_CAPACITY;
                }

                ExecuteSql(strSql.ToString(), parameters);
            }
            catch (Exception ex)
            {
                Log.Error("DalDEV_POWER_SWITCH->Add---FAILED", ex);
                throw ex;
            }
        }