重构代码:更改DBAccessManager为DbAccessManager

This commit is contained in:
Argo-MacBookPro 2018-10-20 22:25:53 +08:00
parent 6f36170bd8
commit 4b9f44a1a3
24 changed files with 372 additions and 372 deletions

View File

@ -24,9 +24,9 @@ namespace Bootstrap.DataAccess.SQLServer
var ret = false;
var ids = string.Join(",", value);
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
CacheCleanUtility.ClearCache(dictIds: ids);
}
return ret;
@ -46,14 +46,14 @@ namespace Bootstrap.DataAccess.SQLServer
string sql = dict.Id == 0 ?
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
return ret;
@ -69,12 +69,12 @@ namespace Bootstrap.DataAccess.SQLServer
{
var ret = false;
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(dictIds: string.Empty);
return ret;
@ -89,8 +89,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
var ret = new List<string>();
string sql = "select distinct Category from Dicts";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -33,16 +33,16 @@ namespace Bootstrap.DataAccess.SQLServer
}
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
CacheManager.Clear(RetrieveExceptionsDataKey);
ClearExceptions();
}
@ -55,8 +55,8 @@ namespace Bootstrap.DataAccess.SQLServer
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Exceptions where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]}, GETDATE())";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
/// <summary>
@ -69,8 +69,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
List<Exceptions> exceptions = new List<Exceptions>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -26,8 +26,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select * from Groups";
List<Group> groups = new List<Group>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -51,10 +51,10 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(groupIds: value);
return ret;
@ -72,12 +72,12 @@ namespace Bootstrap.DataAccess.SQLServer
string sql = p.Id == 0 ?
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
return ret;
@ -94,9 +94,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
List<Group> groups = new List<Group>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -127,16 +127,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("GroupID", typeof(int));
//判断用户是否选定角色
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = "delete from UserGroup where UserID=@UserID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
@ -172,9 +172,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
List<Group> groups = new List<Group>();
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -203,16 +203,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("GroupID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除角色部门表该角色所有的部门
string sql = "delete from RoleGroup where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{

View File

@ -24,8 +24,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
List<Log> logs = new List<Log>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -55,8 +55,8 @@ namespace Bootstrap.DataAccess.SQLServer
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
/// <summary>
@ -69,14 +69,14 @@ namespace Bootstrap.DataAccess.SQLServer
if (p == null) throw new ArgumentNullException("p");
bool ret = false;
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheManager.Clear(RetrieveLogsDataKey);
DeleteLogAsync();

View File

@ -23,10 +23,10 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(menuIds: value);
return ret;
@ -46,19 +46,19 @@ namespace Bootstrap.DataAccess.SQLServer
string sql = p.Id == 0 ?
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
return ret;
@ -76,10 +76,10 @@ namespace Bootstrap.DataAccess.SQLServer
{
var menus = new List<BootstrapMenu>();
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -106,16 +106,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("NavigationID", typeof(int));
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = "delete from NavigationRole where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{

View File

@ -24,9 +24,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
List<Message> messages = new List<Message>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -25,8 +25,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select * from Roles";
var roles = new List<Role>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -56,16 +56,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = "delete from UserRole where UserID = @UserID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
if (dt.Rows.Count > 0)
{
// insert batch data into config table
@ -101,9 +101,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -127,10 +127,10 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(roleIds: value);
return ret;
@ -148,12 +148,12 @@ namespace Bootstrap.DataAccess.SQLServer
string sql = p.Id == 0 ?
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
return ret;
@ -170,9 +170,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
List<Role> roles = new List<Role>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -203,16 +203,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete role from config table
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
@ -248,9 +248,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -281,16 +281,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = "delete from RoleGroup where GroupID=@GroupID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))

View File

@ -18,8 +18,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc";
List<Task> tasks = new List<Task>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -28,9 +28,9 @@ namespace Bootstrap.DataAccess.SQLServer
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
{
List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -59,8 +59,8 @@ namespace Bootstrap.DataAccess.SQLServer
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -85,10 +85,10 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: value);
}
return ret;
@ -105,15 +105,15 @@ namespace Bootstrap.DataAccess.SQLServer
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@description", p.Description));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
}
return ret;
@ -131,13 +131,13 @@ namespace Bootstrap.DataAccess.SQLServer
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
}
return ret;
@ -152,11 +152,11 @@ namespace Bootstrap.DataAccess.SQLServer
{
var ret = false;
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
}
return ret;
@ -171,12 +171,12 @@ namespace Bootstrap.DataAccess.SQLServer
public override bool RejectUser(int id, string rejectBy)
{
var ret = false;
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
}
return ret;
@ -193,9 +193,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -224,16 +224,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("UserID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserRole where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
@ -267,9 +267,9 @@ namespace Bootstrap.DataAccess.SQLServer
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -298,16 +298,16 @@ namespace Bootstrap.DataAccess.SQLServer
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserGroup where GroupID = @GroupID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
@ -339,11 +339,11 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
string sql = "Update Users set Icon = @iconName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -358,11 +358,11 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -377,11 +377,11 @@ namespace Bootstrap.DataAccess.SQLServer
{
bool ret = false;
string sql = "Update Users set Css = @cssName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -398,7 +398,7 @@ namespace Bootstrap.DataAccess.SQLServer
{
BootstrapUser user = null;
var sql = "select UserName, DisplayName, case isnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end + Icon Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = N'头像地址' and Name = N'头像路径' where ApprovedTime is not null and UserName = @UserName";
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
using (DbDataReader reader = db.ExecuteReader(cmd))

View File

@ -24,9 +24,9 @@ namespace Bootstrap.DataAccess.SQLite
var ret = false;
var ids = string.Join(",", value);
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
CacheCleanUtility.ClearCache(dictIds: ids);
}
return ret;
@ -46,14 +46,14 @@ namespace Bootstrap.DataAccess.SQLite
string sql = dict.Id == 0 ?
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
return ret;
@ -69,12 +69,12 @@ namespace Bootstrap.DataAccess.SQLite
{
var ret = false;
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(dictIds: string.Empty);
return ret;
@ -89,8 +89,8 @@ namespace Bootstrap.DataAccess.SQLite
{
var ret = new List<string>();
string sql = "select distinct Category from Dicts";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -34,16 +34,16 @@ namespace Bootstrap.DataAccess.SQLite
}
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
var sql = "insert into Exceptions (ID, AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (NULL, @AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, datetime('now', 'localtime'))";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
CacheManager.Clear(RetrieveExceptionsDataKey);
ClearExceptions();
}
@ -56,8 +56,8 @@ namespace Bootstrap.DataAccess.SQLite
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Exceptions where LogTime < datetime('now', 'localtime', '-{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]} month')";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
/// <summary>
@ -70,8 +70,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc";
List<Exceptions> exceptions = new List<Exceptions>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -26,8 +26,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select * from Groups";
List<Group> groups = new List<Group>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -51,10 +51,10 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(groupIds: value);
return ret;
@ -72,12 +72,12 @@ namespace Bootstrap.DataAccess.SQLite
string sql = p.Id == 0 ?
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
return ret;
@ -94,9 +94,9 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
List<Group> groups = new List<Group>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -127,16 +127,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("GroupID", typeof(int));
//判断用户是否选定角色
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = "delete from UserGroup where UserID=@UserID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
@ -172,9 +172,9 @@ namespace Bootstrap.DataAccess.SQLite
{
List<Group> groups = new List<Group>();
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -203,16 +203,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("GroupID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除角色部门表该角色所有的部门
string sql = "delete from RoleGroup where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{

View File

@ -25,8 +25,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')";
List<Log> logs = new List<Log>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -56,8 +56,8 @@ namespace Bootstrap.DataAccess.SQLite
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Logs where LogTime < datetime('now', 'localtime', '-{ConfigurationManager.AppSettings["KeepLogsPeriod"]} month')";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
/// <summary>
@ -70,14 +70,14 @@ namespace Bootstrap.DataAccess.SQLite
if (p == null) throw new ArgumentNullException("p");
bool ret = false;
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, datetime('now', 'localtime'), @ClientIp, @ClientAgent, @RequestUrl)";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheManager.Clear(RetrieveLogsDataKey);
DeleteLogAsync();

View File

@ -24,10 +24,10 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(menuIds: value);
return ret;
@ -47,19 +47,19 @@ namespace Bootstrap.DataAccess.SQLite
string sql = p.Id == 0 ?
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
return ret;
@ -77,10 +77,10 @@ namespace Bootstrap.DataAccess.SQLite
{
var menus = new List<BootstrapMenu>();
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -107,16 +107,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("NavigationID", typeof(int));
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = "delete from NavigationRole where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{

View File

@ -24,9 +24,9 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
List<Message> messages = new List<Message>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -26,8 +26,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select * from Roles";
var roles = new List<Role>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -57,16 +57,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = "delete from UserRole where UserID = @UserID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
if (dt.Rows.Count > 0)
{
// insert batch data into config table
@ -102,9 +102,9 @@ namespace Bootstrap.DataAccess.SQLite
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -128,10 +128,10 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
}
CacheCleanUtility.ClearCache(roleIds: value);
return ret;
@ -149,12 +149,12 @@ namespace Bootstrap.DataAccess.SQLite
string sql = p.Id == 0 ?
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
return ret;
@ -171,9 +171,9 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
List<Role> roles = new List<Role>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -204,16 +204,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete role from config table
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
@ -249,9 +249,9 @@ namespace Bootstrap.DataAccess.SQLite
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -282,16 +282,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = "delete from RoleGroup where GroupID=@GroupID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))

View File

@ -19,8 +19,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
List<Task> tasks = new List<Task>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{

View File

@ -28,9 +28,9 @@ namespace Bootstrap.DataAccess.SQLite
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
{
List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -59,8 +59,8 @@ namespace Bootstrap.DataAccess.SQLite
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -85,10 +85,10 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: value);
}
return ret;
@ -105,15 +105,15 @@ namespace Bootstrap.DataAccess.SQLite
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@description", p.Description));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
}
return ret;
@ -131,13 +131,13 @@ namespace Bootstrap.DataAccess.SQLite
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
}
return ret;
@ -152,11 +152,11 @@ namespace Bootstrap.DataAccess.SQLite
{
var ret = false;
var sql = "update Users set ApprovedTime = datetime('now', 'localtime'), ApprovedBy = @approvedBy where ID = @id";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
}
return ret;
@ -171,12 +171,12 @@ namespace Bootstrap.DataAccess.SQLite
public override bool RejectUser(int id, string rejectBy)
{
var ret = false;
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
}
return ret;
@ -193,9 +193,9 @@ namespace Bootstrap.DataAccess.SQLite
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -224,16 +224,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("UserID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserRole where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
@ -267,9 +267,9 @@ namespace Bootstrap.DataAccess.SQLite
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
@ -298,16 +298,16 @@ namespace Bootstrap.DataAccess.SQLite
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserGroup where GroupID = @GroupID";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", id));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
@ -339,11 +339,11 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
string sql = "Update Users set Icon = @iconName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -358,11 +358,11 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -377,11 +377,11 @@ namespace Bootstrap.DataAccess.SQLite
{
bool ret = false;
string sql = "Update Users set Css = @cssName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
}
return ret;
@ -398,9 +398,9 @@ namespace Bootstrap.DataAccess.SQLite
{
BootstrapUser user = null;
var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
var cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
var cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
if (reader.Read())
{

View File

@ -6,7 +6,7 @@ namespace Bootstrap.DataAccess
/// <summary>
///
/// </summary>
public static class DBAccessManager
public static class DbAccessManager
{
private static readonly Lazy<IDbAccess> db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("ba"), true);
/// <summary>

View File

@ -89,7 +89,7 @@ namespace Bootstrap.DataAccess
{
string sql = "select ID, Category, Name, Code, Define from Dicts";
var Dicts = new List<BootstrapDict>();
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
using (var reader = db.ExecuteReader(cmd))
{

View File

@ -88,7 +88,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r =>
{
var entities = new List<string>();
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName"))
{
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));

View File

@ -113,7 +113,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(RetrieveMenusAll, k =>
{
var menus = new List<BootstrapMenu>();
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select n.ID, n.ParentId, n.Name, n.[Order], n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.[Application], d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID"))
{
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));

View File

@ -100,7 +100,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), r =>
{
var entities = new List<string>();
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @UserName union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join Groups g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@UserName"))
{
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
@ -127,7 +127,7 @@ namespace Bootstrap.DataAccess
{
string sql = "select distinct r.RoleName, r.[Description] from Roles r inner join NavigationRole nr on r.ID = nr.RoleID inner join Navigations n on nr.NavigationID = n.ID and n.[Application] = @AppId and n.Url like @Url";
var Roles = new List<string> { "Administrators" };
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(db.CreateParameter("@Url", string.Format("{0}%", url)));
cmd.Parameters.Add(db.CreateParameter("@AppId", LgbConvert.ReadValue(ConfigurationManager.AppSettings["AppId"], "0")));

View File

@ -73,7 +73,7 @@ namespace Bootstrap.DataAccess
string oldPassword = null;
string passwordSalt = null;
string sql = "select [Password], PassSalt from Users where ApprovedTime is not null and UserName = @UserName";
var db = DBAccessManager.DBAccess;
var db = DbAccessManager.DBAccess;
using (DbCommand cmd = db.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
@ -140,12 +140,12 @@ namespace Bootstrap.DataAccess
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
}
return ret;