重构代码:移除Try/Catch模块,数据库操作使用影响行数判断是否成功
This commit is contained in:
parent
e556556e7c
commit
52427c77b2
|
@ -1,6 +1,5 @@
|
|||
using Bootstrap.Security;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -35,20 +34,12 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteDict(IEnumerable<int> value)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -67,24 +58,16 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.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";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
ret = true;
|
||||
CacheCleanUtility.ClearCache(dictIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(dictIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -98,22 +81,14 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var ret = false;
|
||||
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", dict.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", dict.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", dict.Category));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", dict.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", dict.Code));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", dict.Category));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -127,17 +102,13 @@ namespace Bootstrap.DataAccess
|
|||
var ret = new List<BootstrapDict>();
|
||||
string sql = "select distinct Category from Dicts";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
|
||||
}
|
||||
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -31,22 +30,18 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select * from Groups";
|
||||
List<Group> groups = new List<Group>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
groups.Add(new Group()
|
||||
{
|
||||
groups.Add(new Group()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
});
|
||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||
|
@ -58,21 +53,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteGroup(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: ids);
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -88,22 +75,14 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -120,23 +99,19 @@ namespace Bootstrap.DataAccess
|
|||
List<Group> groups = new List<Group>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
groups.Add(new Group()
|
||||
{
|
||||
groups.Add(new Group()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
}, RetrieveGroupsByUserIdDataKey);
|
||||
return ret;
|
||||
|
@ -182,8 +157,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -202,23 +177,19 @@ namespace Bootstrap.DataAccess
|
|||
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.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
groups.Add(new Group()
|
||||
{
|
||||
groups.Add(new Group()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
GroupName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return groups;
|
||||
}, RetrieveGroupsByRoleIdDataKey);
|
||||
}
|
||||
|
@ -261,8 +232,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -24,26 +23,22 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select top 1000 * from Logs";
|
||||
List<Log> logs = new List<Log>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
logs.Add(new Log()
|
||||
{
|
||||
logs.Add(new Log()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
CRUD = (string)reader[1],
|
||||
UserName = (string)reader[2],
|
||||
LogTime = (DateTime)reader[3],
|
||||
ClientIp = (string)reader[4],
|
||||
ClientAgent = (string)reader[5],
|
||||
RequestUrl = (string)reader[6]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
CRUD = (string)reader[1],
|
||||
UserName = (string)reader[2],
|
||||
LogTime = (DateTime)reader[3],
|
||||
ClientIp = (string)reader[4],
|
||||
ClientAgent = (string)reader[5],
|
||||
RequestUrl = (string)reader[6]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return logs;
|
||||
});
|
||||
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
|
||||
|
@ -56,20 +51,12 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteLog(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Logs where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Logs where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
CacheCleanUtility.ClearCache(logIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
CacheCleanUtility.ClearCache(logIds: ids);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -83,24 +70,16 @@ namespace Bootstrap.DataAccess
|
|||
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)";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(logIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(logIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -27,21 +26,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteMenu(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -59,29 +50,21 @@ namespace Bootstrap.DataAccess
|
|||
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";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", DBAccessFactory.ToDBValue(p.Icon)));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", DBAccessFactory.ToDBValue(p.Url)));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", DBAccessFactory.ToDBValue(p.Icon)));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", DBAccessFactory.ToDBValue(p.Url)));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -96,25 +79,21 @@ namespace Bootstrap.DataAccess
|
|||
return CacheManager.GetOrAdd(key, k =>
|
||||
{
|
||||
var menus = new List<BootstrapMenu>();
|
||||
try
|
||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
menus.Add(new BootstrapMenu()
|
||||
{
|
||||
menus.Add(new BootstrapMenu()
|
||||
{
|
||||
Id = (int)reader[0]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return menus;
|
||||
}, RetrieveMenusByRoleIdDataKey);
|
||||
}
|
||||
|
@ -156,8 +135,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -27,33 +26,29 @@ namespace Bootstrap.DataAccess
|
|||
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.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
messages.Add(new Message()
|
||||
{
|
||||
messages.Add(new Message()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
Title = (string)reader[1],
|
||||
Content = (string)reader[2],
|
||||
From = (string)reader[3],
|
||||
To = (string)reader[4],
|
||||
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
|
||||
Status = (string)reader[6],
|
||||
Mark = (int)reader[7],
|
||||
IsDelete = (int)reader[8],
|
||||
Label = (string)reader[9],
|
||||
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
|
||||
FromIcon = (string)reader[11],
|
||||
FromDisplayName = (string)reader[12]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
Title = (string)reader[1],
|
||||
Content = (string)reader[2],
|
||||
From = (string)reader[3],
|
||||
To = (string)reader[4],
|
||||
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
|
||||
Status = (string)reader[6],
|
||||
Mark = (int)reader[7],
|
||||
IsDelete = (int)reader[8],
|
||||
Label = (string)reader[9],
|
||||
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
|
||||
FromIcon = (string)reader[11],
|
||||
FromDisplayName = (string)reader[12]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return messages;
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -31,22 +30,18 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select * from Roles";
|
||||
List<Role> roles = new List<Role>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
roles.Add(new Role()
|
||||
{
|
||||
roles.Add(new Role()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
});
|
||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||
|
@ -93,8 +88,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -110,25 +105,21 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
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";
|
||||
try
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
roles.Add(new Role()
|
||||
{
|
||||
roles.Add(new Role()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByUserIdDataKey);
|
||||
}
|
||||
|
@ -139,21 +130,13 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteRole(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: ids);
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -169,22 +152,14 @@ namespace Bootstrap.DataAccess
|
|||
string sql = p.Id == 0 ?
|
||||
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
||||
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
||||
try
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -201,23 +176,19 @@ namespace Bootstrap.DataAccess
|
|||
List<Role> roles = new List<Role>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId));
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
roles.Add(new Role()
|
||||
{
|
||||
roles.Add(new Role()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByMenuIdDataKey);
|
||||
return ret;
|
||||
|
@ -257,8 +228,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -276,24 +247,20 @@ namespace Bootstrap.DataAccess
|
|||
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.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
roles.Add(new Role()
|
||||
{
|
||||
roles.Add(new Role()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
RoleName = (string)reader[1],
|
||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||
Checked = (string)reader[3]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return roles;
|
||||
}, RetrieveRolesByGroupIdDataKey);
|
||||
}
|
||||
|
@ -339,8 +306,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Longbow.Cache;
|
||||
using Longbow.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -21,27 +20,23 @@ namespace Bootstrap.DataAccess
|
|||
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.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
tasks.Add(new Task()
|
||||
{
|
||||
tasks.Add(new Task()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
TaskName = (string)reader[1],
|
||||
AssignName = (string)reader[2],
|
||||
UserName = (string)reader[3],
|
||||
TaskTime = (int)reader[4],
|
||||
TaskProgress = (double)reader[5],
|
||||
AssignTime = (DateTime)reader[6],
|
||||
AssignDisplayName = (string)reader[7]
|
||||
});
|
||||
}
|
||||
Id = (int)reader[0],
|
||||
TaskName = (string)reader[1],
|
||||
AssignName = (string)reader[2],
|
||||
UserName = (string)reader[3],
|
||||
TaskTime = (int)reader[4],
|
||||
TaskProgress = (double)reader[5],
|
||||
AssignTime = (DateTime)reader[6],
|
||||
AssignDisplayName = (string)reader[7]
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return tasks;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue