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 BrandController : MasterPage { // GET: BasicInfo/Brand [LoginFilter] public ActionResult Index() { ViewBag.Title = "品牌管理"; return View(); } [LoginFilter] public ActionResult AddEdit() { string ID = Request.QueryString.Get("ID"); if (ID.IsEmpty()) { ViewBag.Admin = new Brand(); } else { DALBrand provider = new DALBrand(); Brand entity = provider.GetModel(ID); entity = entity == null ? new Brand() : entity; ViewBag.Admin = entity; } return View(); } } public class BrandAjaxController : AjaxPage { public ActionResult GetBrandList() { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { DALBrand provider = new DALBrand(); PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; List entity = provider.GetList(models, ref pageInfo).ToList(); string json = JsonHelper.IListToJson(entity, "List"); string pjson = ConvertJson.Serializer(pageInfo); 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); } public ActionResult AddBrand() { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); string Operation = models.Operation; if (models != null) { DALBrand provider = new DALBrand(); if (Operation == "Add") { models.CreatUser = this.LoginUserCode; string sqlWhere = " (BrandCode = '"+ models.BrandCode + "' or BrandName = '" + models.BrandName+"') and isdel = '0' "; if (provider.IsExist(sqlWhere)) { bool value = provider.Add(models, this.LoginUserCode); if (value) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "添加品牌成功"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "添加品牌失败"); } } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "该品牌已存在!"); } } else if (Operation == "Edit") { if (provider.IsExist(models)) { if (provider.Update(models, this.LoginUserCode)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "编辑品牌信息成功"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "编辑品牌信息失败"); } } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "该品牌已存在!"); } } } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "品牌信息有误!!!"); } return Content(this.ReturnJson.ToString()); } public ActionResult DeleteBrand() { string dd = Request["list"]; ArrayList models = new JavaScriptSerializer().Deserialize(dd); string[] list = (string[])models.ToArray(typeof(string)); if (models != null) { DALBrand provider = new DALBrand(); bool value = provider.BatchDelete(list); if (value) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "删除品牌信息成功"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "删除品牌信息失败"); } return Content(this.ReturnJson.ToString()); } return Content(null); } } }