From 7d577571a181319171586369b757208ffb62b2be Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 30 Mar 2017 15:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=AD=97=E5=85=B8=E8=A1=A8=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DictsController.cs | 4 +-- Bootstrap.DataAccess/DictHelper.cs | 35 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Bootstrap.Admin/Controllers/DictsController.cs b/Bootstrap.Admin/Controllers/DictsController.cs index 6aca510a..c9d20177 100644 --- a/Bootstrap.Admin/Controllers/DictsController.cs +++ b/Bootstrap.Admin/Controllers/DictsController.cs @@ -69,9 +69,9 @@ namespace Bootstrap.Admin.Controllers /// /// /// - /// + /// [HttpDelete] - public dynamic Delete([FromBody]string value) + public object Delete([FromBody]string value) { if (!LgbPrincipal.IsAdmin(User)) return new { result = false, msg = "当前用户权限不够" }; var result = DictHelper.DeleteDict(value); diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs index 0d3f4cb7..33b3ce27 100644 --- a/Bootstrap.DataAccess/DictHelper.cs +++ b/Bootstrap.DataAccess/DictHelper.cs @@ -13,18 +13,17 @@ namespace Bootstrap.DataAccess public static class DictHelper { internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts"; - internal const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; + private const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; /// /// 查询所有字典信息 /// - /// /// public static IEnumerable RetrieveDicts() { return CacheManager.GetOrAdd(RetrieveDictsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveDictsDataKey), key => { string sql = "select ID, Category, Name, Code, Define from Dicts"; - List Dicts = new List(); + List dicts = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); try { @@ -32,7 +31,7 @@ namespace Bootstrap.DataAccess { while (reader.Read()) { - Dicts.Add(new Dict() + dicts.Add(new Dict() { ID = (int)reader[0], Category = (string)reader[1], @@ -44,7 +43,7 @@ namespace Bootstrap.DataAccess } } catch (Exception ex) { ExceptionManager.Publish(ex); } - return Dicts; + return dicts; }, CacheSection.RetrieveDescByKey(RetrieveDictsDataKey)); } /// @@ -54,8 +53,8 @@ namespace Bootstrap.DataAccess /// public static bool DeleteDict(string ids) { + if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return false; var ret = false; - if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret; try { string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids); @@ -72,6 +71,7 @@ namespace Bootstrap.DataAccess } return ret; } + /// /// 保存新建/更新的字典信息 /// @@ -79,11 +79,10 @@ namespace Bootstrap.DataAccess /// public static bool SaveDict(Dict p) { - if (p == null) throw new ArgumentNullException("p"); bool ret = false; - if (p.Category.Length > 50) p.Category.Substring(0, 50); - if (p.Name.Length > 50) p.Name.Substring(0, 50); - if (p.Code.Length > 50) p.Code.Substring(0, 50); + if (p.Category.Length > 50) p.Category = p.Category.Substring(0, 50); + if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50); + if (p.Code.Length > 50) p.Code = p.Code.Substring(0, 50); 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"; @@ -91,11 +90,11 @@ namespace Bootstrap.DataAccess { using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.ID, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define, ParameterDirection.Input)); + 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; @@ -122,9 +121,9 @@ namespace Bootstrap.DataAccess { using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", name, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", code, ParameterDirection.Input)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category, ParameterDirection.Input)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", name)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", code)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } CacheManager.Clear(key => key.Contains(RetrieveDictsDataKey));