/// <summary>
		/// 默认构造函数
		/// </summary>
		public SystemPrivilegeBase()
		{
			_privilege_id = 0; 
			_operation_id =  null; 
			_resources_id =  null; 
			_privilegecnname = String.Empty; 
			_privilegeenname = String.Empty; 
			_defaultvalue = String.Empty; 
			_description = String.Empty; 
			_privilegeorder = 0; 
		}
Пример #2
0
        public async Task <QueryResult <SystemOperation> > QueryByPage(string name, int page, int pageSize)
        {
            QueryResult <SystemOperation> result = new QueryResult <SystemOperation>();

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForWhitelistPolicy(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"set @currentpage=@page
		                           select @count= count(*) from SystemOperation where [name] like @name
		                           if @pagesize*@page>=@count
			                          begin
				                           set @currentpage= @count/@pagesize
				                           if @count%@pagesize<>0
					                           begin
						                            set @currentpage=@currentpage+1
					                           end
				                           if @currentpage=0
					                           set @currentpage=1
			                          end
		                            else if @page<1 
			                           begin 
				                           set @currentpage=1
			                           end
	
                                    select {0} from SystemOperation
                                    where [name] like @name
                                    order by sequence
		                            offset (@pagesize * (@currentpage - 1)) rows 
		                            fetch next @pagesize rows only;"        , StoreHelper.GetSystemOperationSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@page", SqlDbType.Int)
                    {
                        Value = page
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                    {
                        Value = pageSize
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@name", SqlDbType.NVarChar, 100)
                    {
                        Value = $"{name.ToSqlLike()}%"
                    };
                    commond.Parameters.Add(parameter);


                    parameter = new SqlParameter("@count", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@currentpage", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    commond.Parameters.Add(parameter);

                    commond.Prepare();

                    SqlDataReader reader = null;

                    using (reader = await commond.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var systemOperation = new SystemOperation();
                            StoreHelper.SetSystemOperationSelectFields(systemOperation, reader, string.Empty);

                            result.Results.Add(systemOperation);
                        }



                        reader.Close();

                        result.TotalCount  = (int)commond.Parameters["@count"].Value;
                        result.CurrentPage = (int)commond.Parameters["@currentpage"].Value;
                    }
                }
            });

            return(result);
        }
Пример #3
0
        public async Task Add(SystemOperation operation)
        {
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _dbConnectionFactory.CreateAllForWhitelistPolicy(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran
                })
                {
                    SqlParameter parameter;
                    if (operation.ID == Guid.Empty)
                    {
                        commond.CommandText = @"insert into systemoperation
                                                ([id],[name],[createtime],[modifytime],[status])
                                            values
                                                (default,@name,getutcdate(),getutcdate(),@status);
                                            select @newid =[id] from systemoperation where [sequence] = SCOPE_IDENTITY()";
                        parameter           = new SqlParameter("@newid", SqlDbType.UniqueIdentifier)
                        {
                            Direction = ParameterDirection.Output
                        };
                        commond.Parameters.Add(parameter);
                    }
                    else
                    {
                        commond.CommandText = @"insert into systemoperation
                                                ([id],[name],[createtime],[modifytime],[status])
                                            values
                                                (@id,@name,getutcdate(),getutcdate(),@status);";
                        parameter           = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                        {
                            Value = operation.ID
                        };
                        commond.Parameters.Add(parameter);
                    }

                    parameter = new SqlParameter("@name", SqlDbType.NVarChar, 500)
                    {
                        Value = operation.Name
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@status", SqlDbType.Int)
                    {
                        Value = operation.Status
                    };
                    commond.Parameters.Add(parameter);

                    commond.Prepare();


                    try
                    {
                        await commond.ExecuteNonQueryAsync();
                    }
                    catch (SqlException ex)
                    {
                        if (ex == null)
                        {
                            throw;
                        }
                        if (ex.Number == 2601)
                        {
                            var fragment = new TextFragment()
                            {
                                Code = TextCodes.ExistSystemOperationByName,
                                DefaultFormatting = "系统操作中存在相同的名称\"{0}\"数据",
                                ReplaceParameters = new List <object>()
                                {
                                    operation.Name
                                }
                            };

                            throw new UtilityException((int)Errors.ExistSystemOperationByName, fragment);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    //如果用户未赋值ID则创建成功后返回ID
                    if (operation.ID == Guid.Empty)
                    {
                        operation.ID = (Guid)commond.Parameters["@newid"].Value;
                    }
                    ;
                }
            });
        }
Пример #4
0
        public async Task <QueryResult <SystemOperation> > QueryByPage(int page, int pageSize)
        {
            QueryResult <SystemOperation> result = new QueryResult <SystemOperation>();

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForWhitelistPolicy(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SET @currentpage = @page;
                                                SELECT @count = COUNT(*)
                                                FROM SystemOperation;
                                                IF @pagesize * @page >= @count
                                                BEGIN
                                                    SET @currentpage = @count / @pagesize;
                                                    IF @count % @pagesize <> 0
                                                    BEGIN
                                                        SET @currentpage = @currentpage + 1;
                                                    END;
                                                    IF @currentpage = 0
                                                        SET @currentpage = 1;
                                                END;
                                                ELSE IF @page < 1
                                                BEGIN
                                                    SET @currentpage = 1;
                                                END;

                                                SELECT {0}
                                                FROM SystemOperation
                                                ORDER BY sequence OFFSET (@pagesize * (@currentpage - 1)) ROWS FETCH NEXT @pagesize ROWS ONLY;",
                                                StoreHelper.GetSystemOperationSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@page", SqlDbType.Int)
                    {
                        Value = page
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                    {
                        Value = pageSize
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@count", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@currentpage", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    commond.Parameters.Add(parameter);

                    commond.Prepare();

                    SqlDataReader reader = null;

                    using (reader = await commond.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var systemOperation = new SystemOperation();
                            StoreHelper.SetSystemOperationSelectFields(systemOperation, reader, string.Empty);

                            result.Results.Add(systemOperation);
                        }



                        reader.Close();

                        result.TotalCount  = (int)commond.Parameters["@count"].Value;
                        result.CurrentPage = (int)commond.Parameters["@currentpage"].Value;
                    }
                }
            });

            return(result);
        }
Пример #5
0
 public SystemOperationCheckAttribute(SystemOperation op)
 {
     this.op = op;
 }