using System; using System.Collections.Generic; using System.Linq; using System.Web.Script.Serialization; using BLL; using Common; using Json; using Model; using wms; using System.Collections; using System.Data; using System.Web.Mvc; using Lib; namespace wms.Areas.SyetemSet.Controllers { public class DepartAjaxController : AjaxPage { // GET: DepartAjax public ActionResult GetDepartMentList() { var dd = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(dd); if (models != null) { PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize }; IDALDepartMent provider = new DALDepartMent(); 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", "响应成功"); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); return Content(this.ReturnJson.ToString()); } return Content(null); } public ActionResult AddDepartMent() { try { var list = Request["ajaxdata"]; var models = new JavaScriptSerializer().Deserialize(list); if (models != null) { DALDepartMent provider = new DALDepartMent(); ReturnJson.AddProperty("SubCode", 0); ReturnJson.AddProperty("SubMessage", ""); if (provider.IsExist(models)) { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "该部门已存在!"); return Content(this.ReturnJson.ToString()); } if (models.Operation == "Add") { models.CreatUser = this.LoginUserCode; if (provider.Add(models)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "添加部门成功!"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "添加部门失败!"); } } else if (models.Operation == "Edit") { models.UpdateUser = this.LoginUserCode; if (provider.Update(models)) { ReturnJson.AddProperty("Code", 1); ReturnJson.AddProperty("Message", "编辑部门成功!"); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "编辑部门失败!"); } } return Content(this.ReturnJson.ToString()); } return Content(null); } catch { return Content(null); } } public ActionResult DeleteDepart() { string dd = Request["list"]; ArrayList models = new JavaScriptSerializer().Deserialize(dd); string[] list = (string[])models.ToArray(typeof(string)); if (models != null) { DALDepartMent provider = new DALDepartMent(); string strAlert = provider.IsChecks(list); if (strAlert.Length <= 0) { bool value = provider.BatchDelete(list); 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", "删除失败。 "+strAlert); } return Content(this.ReturnJson.ToString()); } return Content(null); } public ActionResult ToExcel() { string dd = Request["list"]; if (dd != null) { ArrayList models = new JavaScriptSerializer().Deserialize(dd); string[] list = (string[])models.ToArray(typeof(string)); IDALDepartMent provider = new DALDepartMent(); DataTable dt = provider.GetDataTable(list); string filePath = Server.MapPath("~/UploadFiles/"); if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } string filename = string.Format("部门管理{0}.xls", DateTime.Now.ToString("YYYYMMddHHmmss")); NPOIExcel excel = new NPOIExcel("部门管理", "角色", System.IO.Path.Combine(filePath, filename)); excel.ToExcel(dt); ReturnJson.AddProperty("Code", 1000); ReturnJson.AddProperty("Message", Microsoft.JScript.GlobalObject.escape((object)("/UploadFiles/" + filename))); } else { ReturnJson.AddProperty("Code", -1); ReturnJson.AddProperty("Message", "没有选择要导出的数据!!"); } return Content(this.ReturnJson.ToString()); } } }