级联删除(使用存储过程)功能完成
This commit is contained in:
parent
61c49e4609
commit
3135ff24f0
|
@ -59,17 +59,13 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
public static bool DeleteGroup(string ids)
|
public static bool DeleteGroup(string ids)
|
||||||
{
|
{
|
||||||
var ret = false;
|
bool ret = false;
|
||||||
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||||
sql += string.Format("delete from RoleGroup where GroupID in ({0});", ids);
|
|
||||||
sql += string.Format("delete from UserGroup where GroupID in ({0});", ids);
|
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: ids);
|
CacheCleanUtility.ClearCache(groupIds: ids);
|
||||||
|
@ -78,11 +74,9 @@ namespace Bootstrap.DataAccess
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ExceptionManager.Publish(ex);
|
ExceptionManager.Publish(ex);
|
||||||
transaction.RollbackTransaction();
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存新建/更新的群组信息
|
/// 保存新建/更新的群组信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -130,14 +130,11 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids);
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||||
sql += string.Format("delete from NavigationRole where NavigationID in ({0});", ids);
|
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||||
|
@ -146,8 +143,6 @@ namespace Bootstrap.DataAccess
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ExceptionManager.Publish(ex);
|
ExceptionManager.Publish(ex);
|
||||||
transaction.RollbackTransaction();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,30 +141,23 @@ namespace Bootstrap.DataAccess
|
||||||
/// 删除角色表
|
/// 删除角色表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="IDs"></param>
|
/// <param name="IDs"></param>
|
||||||
public static bool DeleteRole(string IDs)
|
public static bool DeleteRole(string ids)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (string.IsNullOrEmpty(IDs) || IDs.Contains("'")) return ret;
|
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Roles where ID in ({0});", IDs);
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||||
sql += string.Format("delete from UserRole where RoleID in ({0});", IDs);
|
|
||||||
sql += string.Format("delete from RoleGroup where RoleID in ({0});", IDs);
|
|
||||||
sql += string.Format("delete from NavigationRole where RoleID in ({0});", IDs);
|
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(roleIds: IDs);
|
CacheCleanUtility.ClearCache(roleIds: ids);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ExceptionManager.Publish(ex);
|
ExceptionManager.Publish(ex);
|
||||||
transaction.RollbackTransaction();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,3 +27,82 @@ BEGIN
|
||||||
exec(@sql)
|
exec(@sql)
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
Drop PROCEDURE Proc_DeleteRoles
|
||||||
|
GO
|
||||||
|
-- =============================================
|
||||||
|
-- Author: LiuChun
|
||||||
|
-- Create date: 2016-11-07
|
||||||
|
-- Description:
|
||||||
|
-- =============================================
|
||||||
|
Create PROCEDURE Proc_DeleteRoles
|
||||||
|
-- Add the parameters for the stored procedure here
|
||||||
|
@ids varchar(max)
|
||||||
|
WITH ENCRYPTION
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
-- SET NOCOUNT ON added to prevent extra result sets from
|
||||||
|
-- interfering with SELECT statements.
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET XACT_ABORT ON;
|
||||||
|
-- Insert statements for procedure here
|
||||||
|
declare @sql varchar(max)
|
||||||
|
set @sql = 'delete from UserRole where RoleID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from RoleGroup where RoleID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from NavigationRole where RoleID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from Roles where ID in (' + @ids + ');'
|
||||||
|
exec(@sql)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
|
||||||
|
Drop PROCEDURE Proc_DeleteGroups
|
||||||
|
GO
|
||||||
|
-- =============================================
|
||||||
|
-- Author: LiuChun
|
||||||
|
-- Create date: 2016-11-07
|
||||||
|
-- Description:
|
||||||
|
-- =============================================
|
||||||
|
Create PROCEDURE Proc_DeleteGroups
|
||||||
|
-- Add the parameters for the stored procedure here
|
||||||
|
@ids varchar(max)
|
||||||
|
WITH ENCRYPTION
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
-- SET NOCOUNT ON added to prevent extra result sets from
|
||||||
|
-- interfering with SELECT statements.
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET XACT_ABORT ON;
|
||||||
|
-- Insert statements for procedure here
|
||||||
|
declare @sql varchar(max)
|
||||||
|
set @sql = 'delete from UserGroup where GroupID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from RoleGroup where GroupID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from Groups where ID in (' + @ids + ');'
|
||||||
|
exec(@sql)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
Drop PROCEDURE Proc_DeleteMenus
|
||||||
|
GO
|
||||||
|
-- =============================================
|
||||||
|
-- Author: LiuChun
|
||||||
|
-- Create date: 2016-11-07
|
||||||
|
-- Description:
|
||||||
|
-- =============================================
|
||||||
|
Create PROCEDURE Proc_DeleteMenus
|
||||||
|
-- Add the parameters for the stored procedure here
|
||||||
|
@ids varchar(max)
|
||||||
|
WITH ENCRYPTION
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
-- SET NOCOUNT ON added to prevent extra result sets from
|
||||||
|
-- interfering with SELECT statements.
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
SET XACT_ABORT ON;
|
||||||
|
-- Insert statements for procedure here
|
||||||
|
declare @sql varchar(max)
|
||||||
|
set @sql = 'delete from NavigationRole where NavigationID in (' + @ids + ');'
|
||||||
|
set @sql += 'delete from Navigations where ID in (' + @ids + ');'
|
||||||
|
exec(@sql)
|
||||||
|
END
|
||||||
|
GO
|
Loading…
Reference in New Issue