/// <summary>
 /// 得到一个对象实体
 /// </summary>
 public HTNResp.Model.Permission DataRowToModel(DataRow row)
 {
     HTNResp.Model.Permission model = new HTNResp.Model.Permission();
     if (row != null)
     {
         if (row["TableName"] != null)
         {
             model.TableName = row["TableName"].ToString();
         }
         if (row["PermissionLevel"] != null && row["PermissionLevel"].ToString() != "")
         {
             model.PermissionLevel = int.Parse(row["PermissionLevel"].ToString());
         }
         if (row["TableRoute"] != null)
         {
             model.TableRoute = row["TableRoute"].ToString();
         }
     }
     return(model);
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HTNResp.Model.Permission GetModel(string TableName)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" TableName,PermissionLevel,TableRoute ");
            strSql.Append(" from Permission ");
            strSql.Append(" where TableName='" + TableName + "' ");
            HTNResp.Model.Permission model = new HTNResp.Model.Permission();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(HTNResp.Model.Permission model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.TableName != null)
            {
                strSql1.Append("TableName,");
                strSql2.Append("'" + model.TableName + "',");
            }
            if (model.PermissionLevel != null)
            {
                strSql1.Append("PermissionLevel,");
                strSql2.Append("" + model.PermissionLevel + ",");
            }
            if (model.TableRoute != null)
            {
                strSql1.Append("TableRoute,");
                strSql2.Append("'" + model.TableRoute + "',");
            }
            strSql.Append("insert into Permission(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HTNResp.Model.Permission model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Permission set ");
            if (model.PermissionLevel != null)
            {
                strSql.Append("PermissionLevel=" + model.PermissionLevel + ",");
            }
            else
            {
                strSql.Append("PermissionLevel= null ,");
            }
            if (model.TableRoute != null)
            {
                strSql.Append("TableRoute='" + model.TableRoute + "',");
            }
            else
            {
                strSql.Append("TableRoute= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where TableName='" + model.TableName + "' ");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }