From 3135ff24f02995208348f602d5cfc089f657ca1c Mon Sep 17 00:00:00 2001 From: "liuchun_0206@163.com" Date: Mon, 7 Nov 2016 15:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A7=E8=81=94=E5=88=A0=E9=99=A4=EF=BC=88?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=EF=BC=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess/GroupHelper.cs | 30 +++++------ Bootstrap.DataAccess/MenuHelper.cs | 25 ++++----- Bootstrap.DataAccess/RoleHelper.cs | 31 +++++------ DatabaseScripts/Procedures.sql | 79 +++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 52 deletions(-) diff --git a/Bootstrap.DataAccess/GroupHelper.cs b/Bootstrap.DataAccess/GroupHelper.cs index dee1b0c8..d3c0ed63 100644 --- a/Bootstrap.DataAccess/GroupHelper.cs +++ b/Bootstrap.DataAccess/GroupHelper.cs @@ -59,29 +59,23 @@ namespace Bootstrap.DataAccess /// public static bool DeleteGroup(string ids) { - var ret = false; + bool ret = false; if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret; - using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) + try { - try + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups")) { - string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids); - 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)) - { - DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - } - CacheCleanUtility.ClearCache(groupIds: ids); - ret = true; + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input)); + DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } - catch (Exception ex) - { - ExceptionManager.Publish(ex); - transaction.RollbackTransaction(); - } - return ret; + CacheCleanUtility.ClearCache(groupIds: ids); + ret = true; } + catch (Exception ex) + { + ExceptionManager.Publish(ex); + } + return ret; } /// /// 保存新建/更新的群组信息 diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index 3b441533..53082ed7 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -130,24 +130,19 @@ namespace Bootstrap.DataAccess { bool ret = false; if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret; - using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) + try { - try + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus")) { - string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids); - sql += string.Format("delete from NavigationRole where NavigationID in ({0});", ids); - using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) - { - DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - } - CacheCleanUtility.ClearCache(menuIds: ids); - ret = true; - } - catch (Exception ex) - { - ExceptionManager.Publish(ex); - transaction.RollbackTransaction(); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input)); + DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } + CacheCleanUtility.ClearCache(menuIds: ids); + ret = true; + } + catch (Exception ex) + { + ExceptionManager.Publish(ex); } return ret; } diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs index 4ea35963..290ecebb 100644 --- a/Bootstrap.DataAccess/RoleHelper.cs +++ b/Bootstrap.DataAccess/RoleHelper.cs @@ -141,30 +141,23 @@ namespace Bootstrap.DataAccess /// 删除角色表 /// /// - public static bool DeleteRole(string IDs) + public static bool DeleteRole(string ids) { bool ret = false; - if (string.IsNullOrEmpty(IDs) || IDs.Contains("'")) return ret; - using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) + if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret; + try { - try + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles")) { - string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Roles where ID in ({0});", IDs); - 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)) - { - DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - } - CacheCleanUtility.ClearCache(roleIds: IDs); - ret = true; - } - catch (Exception ex) - { - ExceptionManager.Publish(ex); - transaction.RollbackTransaction(); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids, ParameterDirection.Input)); + DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } + CacheCleanUtility.ClearCache(roleIds: ids); + ret = true; + } + catch (Exception ex) + { + ExceptionManager.Publish(ex); } return ret; } diff --git a/DatabaseScripts/Procedures.sql b/DatabaseScripts/Procedures.sql index 130a8e14..37a29d3b 100644 --- a/DatabaseScripts/Procedures.sql +++ b/DatabaseScripts/Procedures.sql @@ -27,3 +27,82 @@ BEGIN exec(@sql) END 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 \ No newline at end of file