/// <summary>
 /// 读取DataRow数据到Model中
 /// </summary>
 private void DataRowToModel(Plan_Beginwork_Rule model, DataRow dr)
 {
     model.strWorkShopGUID  = ObjectConvertClass.static_ext_string(dr["strWorkShopGUID"]);
     model.strWorkShopName  = ObjectConvertClass.static_ext_string(dr["strWorkShopName"]);
     model.strKeyStepName   = ObjectConvertClass.static_ext_string(dr["strKeyStepName"]);
     model.nExecByStepIndex = ObjectConvertClass.static_ext_int(dr["nExecByStepIndex"]);
     model.nID = ObjectConvertClass.static_ext_int(dr["nID"]);
 }
        /// <summary>
        /// 检查数据是否存在
        /// </summary>
        public bool Exists(Plan_Beginwork_Rule _Plan_Beginwork_Rule)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select count(*) from TAB_Plan_Beginwork_Rule where nID=@nID");
            SqlParameter[] parameters =
            {
                new SqlParameter("nID", _Plan_Beginwork_Rule.nID)
            };

            return(Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters)) > 0);
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        public int Add(Plan_Beginwork_Rule model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TAB_Plan_Beginwork_Rule");
            strSql.Append("(strWorkShopGUID,strWorkShopName,strKeyStepName,nExecByStepIndex)");
            strSql.Append("values(@strWorkShopGUID,@strWorkShopName,@strKeyStepName,@nExecByStepIndex)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@strWorkShopGUID",  model.strWorkShopGUID),
                new SqlParameter("@strWorkShopName",  model.strWorkShopName),
                new SqlParameter("@strKeyStepName",   model.strKeyStepName),
                new SqlParameter("@nExecByStepIndex", model.nExecByStepIndex),
            };
            return(Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters)));
        }
        /// <summary>
        /// 获得数据List
        /// </summary>
        public Plan_Beginwork_RuleList GetExecByStepList(string strWorkShopGUID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * ");
            strSql.Append(" FROM TAB_Plan_Beginwork_Rule where 1=1 and strWorkShopGUID='" + strWorkShopGUID + "' and len(nExecByStepIndex)>0 ");
            DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql.ToString()).Tables[0];
            Plan_Beginwork_RuleList list = new Plan_Beginwork_RuleList();

            foreach (DataRow dr in dt.Rows)
            {
                Plan_Beginwork_Rule _Plan_Beginwork_Rule = new Plan_Beginwork_Rule();
                DataRowToModel(_Plan_Beginwork_Rule, dr);
                list.Add(_Plan_Beginwork_Rule);
            }
            return(list);
        }
        /// <summary>
        /// 获得一个实体对象
        /// </summary>
        public Plan_Beginwork_Rule GetModel(Plan_Beginwork_RuleQueryCondition QueryCondition)
        {
            SqlParameter[] sqlParams;
            StringBuilder  strSqlOption = new StringBuilder();

            QueryCondition.OutPut(out strSqlOption, out sqlParams);
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 * ");
            strSql.Append(" FROM TAB_Plan_Beginwork_Rule where 1=1 " + strSqlOption.ToString());
            DataTable           dt = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), sqlParams).Tables[0];
            Plan_Beginwork_Rule _Plan_Beginwork_Rule = null;

            if (dt.Rows.Count > 0)
            {
                _Plan_Beginwork_Rule = new Plan_Beginwork_Rule();
                DataRowToModel(_Plan_Beginwork_Rule, dt.Rows[0]);
            }
            return(_Plan_Beginwork_Rule);
        }