Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Learning.Model.RoleModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update RoleModel set ");
            strSql.Append("RoleId=@RoleId,");
            strSql.Append("TreeNodeId=@TreeNodeId,");
            strSql.Append("ButtonId=@ButtonId");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleId",     SqlDbType.Int, 4),
                new SqlParameter("@TreeNodeId", SqlDbType.Int, 4),
                new SqlParameter("@ButtonId",   SqlDbType.Int, 4),
                new SqlParameter("@Id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleId;
            parameters[1].Value = model.TreeNodeId;
            parameters[2].Value = model.ButtonId;
            parameters[3].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Learning.Model.RoleModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into RoleModel(");
            strSql.Append("RoleId,TreeNodeId,ButtonId)");
            strSql.Append(" values (");
            strSql.Append("@RoleId,@TreeNodeId,@ButtonId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleId",     SqlDbType.Int, 4),
                new SqlParameter("@TreeNodeId", SqlDbType.Int, 4),
                new SqlParameter("@ButtonId",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleId;
            parameters[1].Value = model.TreeNodeId;
            parameters[2].Value = model.ButtonId;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Learning.Model.RoleModel DataRowToModel(DataRow row)
 {
     Learning.Model.RoleModel model = new Learning.Model.RoleModel();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["RoleId"] != null && row["RoleId"].ToString() != "")
         {
             model.RoleId = int.Parse(row["RoleId"].ToString());
         }
         if (row["TreeNodeId"] != null && row["TreeNodeId"].ToString() != "")
         {
             model.TreeNodeId = int.Parse(row["TreeNodeId"].ToString());
         }
         if (row["ButtonId"] != null && row["ButtonId"].ToString() != "")
         {
             model.ButtonId = int.Parse(row["ButtonId"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Learning.Model.RoleModel GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,RoleId,TreeNodeId,ButtonId from RoleModel ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }