Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PermissionModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Permission(");
            strSql.Append("Id,MenuId,ButtonText,ButtonType)");
            strSql.Append(" values (");
            strSql.Append("@Id,@MenuId,@ButtonText,@ButtonType)");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@MenuId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@ButtonText", SqlDbType.VarChar,150),
                    new SqlParameter("@ButtonType", SqlDbType.Int,4)};
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = Guid.NewGuid();
            parameters[2].Value = model.ButtonText;
            parameters[3].Value = model.ButtonType;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PermissionModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Permission set ");
            strSql.Append("MenuId=@MenuId,");
            strSql.Append("ButtonText=@ButtonText,");
            strSql.Append("ButtonType=@ButtonType");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@MenuId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@ButtonText", SqlDbType.VarChar,150),
                    new SqlParameter("@ButtonType", SqlDbType.Int,4),
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = model.MenuId;
            parameters[1].Value = model.ButtonText;
            parameters[2].Value = model.ButtonType;
            parameters[3].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PermissionModel GetModel(Guid Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,MenuId,ButtonText,ButtonType from Permission ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = Id;

            PermissionModel model = new PermissionModel();
            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]["MenuId"] != null && ds.Tables[0].Rows[0]["MenuId"].ToString() != "")
                {
                    model.MenuId = new Guid(ds.Tables[0].Rows[0]["MenuId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ButtonText"] != null && ds.Tables[0].Rows[0]["ButtonText"].ToString() != "")
                {
                    model.ButtonText = ds.Tables[0].Rows[0]["ButtonText"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ButtonType"] != null && ds.Tables[0].Rows[0]["ButtonType"].ToString() != "")
                {
                    model.ButtonType = int.Parse(ds.Tables[0].Rows[0]["ButtonType"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }