/// <summary>
        /// 根据父权限ID和排序获得权限实例
        /// </summary>
        /// <param name="AuthorityHandlerPage">处理权限的页面</param>
        /// <returns>如果存在,则返回权限实例,否则返回NULL</returns>
        public OnLineTest.Model.Authority GetModel(int AuthorityParentId, int?AuthorityOrderNum)
        {
            StringBuilder strSql = new StringBuilder();

            //strSql.Append("select  top 1 AuthorityId,AuthorityName,AuthorityDeep,AuthorityParentId,AuthorityScore,AuthorityHandlerPage,AuthorityClickNum,AuthoriryRemark from Authority ");
            strSql.Append("select  top 1 * from Authority ");
            strSql.Append(" where AuthorityParentId=@AuthorityParentId and AuthorityOrderNum=@AuthorityOrderNum");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AuthorityParentId", SqlDbType.Int, 4),
                new SqlParameter("@AuthorityOrderNum", SqlDbType.Int, 4)
            };
            parameters[0].Value = AuthorityParentId;
            parameters[1].Value = AuthorityOrderNum;

            OnLineTest.Model.Authority model = new OnLineTest.Model.Authority();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 利用存储过程来处理Authority的增、删、改操作
        /// model:add,delete,update
        /// </summary>

        public int OperateAuthoritybyTran(OnLineTest.Model.Authority authority, string model, out int affectrows)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@model",                SqlDbType.NVarChar, 20),
                new SqlParameter("@AuthorityId",          SqlDbType.Int,       4),
                new SqlParameter("@AuthorityName",        SqlDbType.NVarChar, 20),
                new SqlParameter("@AuthorityDeep",        SqlDbType.Int,       4),
                new SqlParameter("@AuthorityParentId",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityScore",       SqlDbType.Int,       4),
                new SqlParameter("@AuthorityHandlerPage", SqlDbType.VarChar,  50),
                new SqlParameter("@AuthorityOrderNum",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityRemark",      SqlDbType.Text)
            };
            parameters[0].Value = model;
            parameters[1].Value = authority.AuthorityId;
            parameters[2].Value = authority.AuthorityName;
            parameters[3].Value = authority.AuthorityDeep;
            parameters[4].Value = authority.AuthorityParentId;
            parameters[5].Value = authority.AuthorityScore;
            parameters[6].Value = authority.AuthorityHandlerPage;
            parameters[7].Value = authority.AuthorityOrderNum;
            parameters[8].Value = authority.AuthorityRemark;
            //result行号,affectrows受影响的行数
            int result = DbHelperSQL.RunProcedure("OperateAuthoritybyTran", parameters, out affectrows);

            if (affectrows == 0)
            {
                return(0);
            }
            else
            {
                return(result);
            }
        }
示例#3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OnLineTest.Model.Authority model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Authority set ");
            strSql.Append("AuthorityName=@AuthorityName,");
            strSql.Append("AuthorityDeep=@AuthorityDeep,");
            strSql.Append("AuthorityParentId=@AuthorityParentId,");
            strSql.Append("AuthorityScore=@AuthorityScore,");
            strSql.Append("AuthorityOrderNum=@AuthorityOrderNum,");
            strSql.Append("AuthorityRemark=@AuthorityRemark");
            strSql.Append(" where AuthorityId=@AuthorityId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AuthorityName",        SqlDbType.NVarChar, 20),
                new SqlParameter("@AuthorityDeep",        SqlDbType.Int,       4),
                new SqlParameter("@AuthorityParentId",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityScore",       SqlDbType.Int,       4),
                new SqlParameter("@AuthorityOrderNum",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityRemark",      SqlDbType.Text),
                new SqlParameter("@AuthorityId",          SqlDbType.Int,       4),
                new SqlParameter("@AuthorityHandlerPage", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.AuthorityName;
            parameters[1].Value = model.AuthorityDeep;
            parameters[2].Value = model.AuthorityParentId;
            parameters[3].Value = model.AuthorityScore;
            parameters[4].Value = model.AuthorityOrderNum;
            parameters[5].Value = model.AuthorityRemark;
            parameters[6].Value = model.AuthorityId;
            parameters[7].Value = model.AuthorityHandlerPage;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OnLineTest.Model.Authority DataRowToModel(DataRow row)
 {
     OnLineTest.Model.Authority model = new OnLineTest.Model.Authority();
     if (row != null)
     {
         if (row["AuthorityId"] != null && row["AuthorityId"].ToString() != "")
         {
             model.AuthorityId = int.Parse(row["AuthorityId"].ToString());
         }
         if (row["AuthorityName"] != null)
         {
             model.AuthorityName = row["AuthorityName"].ToString();
         }
         if (row["AuthorityDeep"] != null && row["AuthorityDeep"].ToString() != "")
         {
             model.AuthorityDeep = int.Parse(row["AuthorityDeep"].ToString());
         }
         if (row["AuthorityParentId"] != null && row["AuthorityParentId"].ToString() != "")
         {
             model.AuthorityParentId = int.Parse(row["AuthorityParentId"].ToString());
         }
         if (row["AuthorityScore"] != null && row["AuthorityScore"].ToString() != "")
         {
             model.AuthorityScore = int.Parse(row["AuthorityScore"].ToString());
         }
         if (row["AuthorityHandlerPage"] != null)
         {
             model.AuthorityHandlerPage = row["AuthorityHandlerPage"].ToString();
         }
         if (row["AuthorityOrderNum"] != null && row["AuthorityOrderNum"].ToString() != "")
         {
             model.AuthorityOrderNum = int.Parse(row["AuthorityOrderNum"].ToString());
         }
         if (row["AuthorityRemark"] != null)
         {
             model.AuthorityRemark = row["AuthorityRemark"].ToString();
         }
     }
     return(model);
 }
示例#5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OnLineTest.Model.Authority model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Authority(");
            strSql.Append("AuthorityName,AuthorityDeep,AuthorityParentId,AuthorityScore,AuthorityHandlerPage,AuthorityOrderNum,AuthorityRemark)");
            strSql.Append(" values (");
            strSql.Append("@AuthorityName,@AuthorityDeep,@AuthorityParentId,@AuthorityScore,@AuthorityHandlerPage,@AuthorityOrderNum,@AuthorityRemark)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AuthorityName",        SqlDbType.NVarChar, 20),
                new SqlParameter("@AuthorityDeep",        SqlDbType.Int,       4),
                new SqlParameter("@AuthorityParentId",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityScore",       SqlDbType.Int,       4),
                new SqlParameter("@AuthorityHandlerPage", SqlDbType.VarChar,  50),
                new SqlParameter("@AuthorityOrderNum",    SqlDbType.Int,       4),
                new SqlParameter("@AuthorityRemark",      SqlDbType.Text)
            };
            parameters[0].Value = model.AuthorityName;
            parameters[1].Value = model.AuthorityDeep;
            parameters[2].Value = model.AuthorityParentId;
            parameters[3].Value = model.AuthorityScore;
            parameters[4].Value = model.AuthorityHandlerPage;
            parameters[5].Value = model.AuthorityOrderNum;
            parameters[6].Value = model.AuthorityRemark;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }