Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(RoleModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into RoleInfo(");
            strSql.Append("Id,RoleName,ParentId,RoleDes)");
            strSql.Append(" values (");
            strSql.Append("@Id,@RoleName,@ParentId,@RoleDes)");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@RoleName", SqlDbType.VarChar,150),
                    new SqlParameter("@ParentId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@RoleDes", SqlDbType.VarChar)};
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = model.RoleName;
            parameters[2].Value = Guid.NewGuid();
            parameters[3].Value = model.RoleDes;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(RoleModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update RoleInfo set ");
            strSql.Append("RoleName=@RoleName,");
            strSql.Append("ParentId=@ParentId,");
            strSql.Append("RoleDes=@RoleDes");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@RoleName", SqlDbType.VarChar,150),
                    new SqlParameter("@ParentId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@RoleDes", SqlDbType.VarChar),
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.ParentId;
            parameters[2].Value = model.RoleDes;
            parameters[3].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RoleModel GetModel(Guid Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,RoleName,ParentId,RoleDes from RoleInfo ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = Id;

            RoleModel model = new RoleModel();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = new Guid(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RoleName"] != null && ds.Tables[0].Rows[0]["RoleName"].ToString() != "")
                {
                    model.RoleName = ds.Tables[0].Rows[0]["RoleName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ParentId"] != null && ds.Tables[0].Rows[0]["ParentId"].ToString() != "")
                {
                    model.ParentId = new Guid(ds.Tables[0].Rows[0]["ParentId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RoleDes"] != null && ds.Tables[0].Rows[0]["RoleDes"].ToString() != "")
                {
                    model.RoleDes = ds.Tables[0].Rows[0]["RoleDes"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }