From ab6d78eb20d756a68fdc4caf333e34c704c4fbf3 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Fri, 2 Nov 2018 19:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9AMe?= =?UTF-8?q?nu=E7=A7=BB=E9=99=A4=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8BProc=5F?= =?UTF-8?q?DeleteMenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess.MySQL/Menu.cs | 32 --------------------------- Bootstrap.DataAccess.SQLite/Menu.cs | 34 +---------------------------- Bootstrap.DataAccess/Menu.cs | 22 ++++++++++++++++--- 3 files changed, 20 insertions(+), 68 deletions(-) diff --git a/Bootstrap.DataAccess.MySQL/Menu.cs b/Bootstrap.DataAccess.MySQL/Menu.cs index 5360cc30..1b3e3ac2 100644 --- a/Bootstrap.DataAccess.MySQL/Menu.cs +++ b/Bootstrap.DataAccess.MySQL/Menu.cs @@ -51,38 +51,6 @@ namespace Bootstrap.DataAccess.MySQL return menus; } - /// - /// 删除菜单信息 - /// - /// - public override bool DeleteMenu(IEnumerable value) - { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Navigations where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - } - return ret; - } - /// /// /// 通过角色ID保存当前授权菜单 diff --git a/Bootstrap.DataAccess.SQLite/Menu.cs b/Bootstrap.DataAccess.SQLite/Menu.cs index 8da7ba2d..abbf093b 100644 --- a/Bootstrap.DataAccess.SQLite/Menu.cs +++ b/Bootstrap.DataAccess.SQLite/Menu.cs @@ -12,38 +12,6 @@ namespace Bootstrap.DataAccess.SQLite /// public class Menu : DataAccess.Menu { - /// - /// 删除菜单信息 - /// - /// - public override bool DeleteMenu(IEnumerable value) - { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Navigations where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - } - return ret; - } - /// /// /// 通过角色ID保存当前授权菜单 @@ -66,7 +34,7 @@ namespace Bootstrap.DataAccess.SQLite //批插入菜单角色表 menuIds.ToList().ForEach(mId => { - cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})"; + cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ({mId}, {roleId})"; DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); }); transaction.CommitTransaction(); diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 785f3b2c..7bfd7452 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -23,10 +23,26 @@ namespace Bootstrap.DataAccess { bool ret = false; var ids = string.Join(",", value); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus")) + using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1; + using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})")) + { + try + { + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + cmd.CommandText = $"delete from Navigations where ID in ({ids})"; + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + transaction.CommitTransaction(); + ret = true; + } + catch (Exception ex) + { + transaction.RollbackTransaction(); + throw ex; + } + } } return ret; }