using BLL.DAL; using Common; using Json; using Lib; using Model; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using System.Web.Script.Serialization; namespace wms.Areas.BasicInfo.Controllers { public class DictionaryController : MasterPage { // GET: BasicInfo/Dictionary public ActionResult Index() { ViewBag.Title = "数据字典"; ViewBag.TopCode = LocalHelper.GetDictionarysHtml(); return View(); } public ActionResult AddEdit() { try { string Guid = Request.QueryString.Get("Guid"); DALDictionary dALDictionary = new DALDictionary(); if (Guid != null) { Dictionarys modelItems = new Dictionarys(); modelItems.Guid = Guid; PageInfo pageInfo = new PageInfo() { PageIndex = 1, PageSize = 1 }; List entity = dALDictionary.GetDictionaryItems(modelItems, ref pageInfo).ToList(); ViewBag.TypeName = entity[0].TypeName; ViewBag.TopCode = LocalHelper.GetDictionarysHtml(entity[0].TopCode); } else { ViewBag.TopCode = LocalHelper.GetDictionarysHtml(); } return View(); } catch (System.Exception) { return View(); } } } public class DictionaryAjaxController : AjaxPage { public ActionResult GetDictionaryItems() { try { var dd = Request["ajaxdata"]; var modelItems = new JavaScriptSerializer().Deserialize(dd); if (modelItems != null) { // 实例化分页信息 PageInfo pageInfo = new PageInfo() { PageIndex = modelItems.PageIndex, PageSize = modelItems.PageSize }; // 数据库交互,获取库区集合and分页信息。 DALDictionary provider = new DALDictionary(); List entity = provider.GetDictionaryItems(modelItems, ref pageInfo).ToList(); // Data =》json string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); // controller => view ReturnJson.AddProperty("Result", new JsonObject(json)); ReturnJson.AddProperty("PageInfo", new JsonObject(pjson)); ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "加载库区集合成功!"); return Content(this.ReturnJson.ToString()); } return Content(null); } catch (System.Exception) { return Content(null); } } public ActionResult SetDictionarys() { try { var dd = Request["ajaxdata"]; var depotsItems = new JavaScriptSerializer().Deserialize(dd); if (depotsItems != null) { // 数据库交互 DALDictionary provider = new DALDictionary(); if (provider.SetDictionarys(depotsItems, this.LoginUserCode)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "保存成功!"); } else { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "保存失败!"); } } return Content(this.ReturnJson.ToString()); } catch (System.Exception) { return Content(null); } } public ActionResult IsExist() { var dd = Request["ajaxdata"]; var model = new JavaScriptSerializer().Deserialize(dd); DALDictionary provider = new DALDictionary(); bool bl = provider.IsExist(model); ReturnJson.AddProperty("Result", bl.ToString()); return Content(this.ReturnJson.ToString()); } public ActionResult DelDictionarys() { try { string dd = Request["list"]; ArrayList models = new JavaScriptSerializer().Deserialize(dd); string[] list = (string[])models.ToArray(typeof(string)); if (models != null) { // 数据库交互 DALDictionary provider = new DALDictionary(); if (provider.DelDictionarys(list, this.LoginUserCode)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除成功!"); } else { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除失败!"); } } return Content(this.ReturnJson.ToString()); } catch (System.Exception) { return Content(null); } } } }