using Core.Web.WebHelper; using CRM.Core.BLL.Base; using CRM.Core.BLL.FB; using CRM.Core.BLL.Util; using CRM.Core.Common; using CRM.Core.Common.WebHelper; using CRM.Core.DTO; using CRM.Core.Model; using CRM.Core.Model.Enum; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using WX.CRM.Common.Employee; namespace Core.Web.Controllers { public class ControlController : Controller { CACHE_BL _cache = new CACHE_BL(); private BAS_PARAMETER_BL paramter_bl = new BAS_PARAMETER_BL(); #region ToolBar(列表操作的顶端ToolBar控件) public ActionResult ToolBar(ToolBar tool) { //这里可以将Tool进行数据过滤 return View(tool); } #endregion #region public JsonResult GetDept(string companyCode) { ConStringHelper.CompanyCode code = (ConStringHelper.CompanyCode)Enum.Parse(typeof(ConStringHelper.CompanyCode), companyCode); var dept = new Bas_Org_BL(code).GetDept(); return Json(dept, JsonRequestBehavior.AllowGet); } public JsonResult GetGroup(string companyCode, int deptId) { ConStringHelper.CompanyCode code = (ConStringHelper.CompanyCode)Enum.Parse(typeof(ConStringHelper.CompanyCode), companyCode); var group = new Bas_Org_BL(code).GetGroup().Where(p => p.saledeptid == deptId); return Json(group, JsonRequestBehavior.AllowGet); } public JsonResult GetUser(string companyCode, int gId) { ConStringHelper.CompanyCode code = (ConStringHelper.CompanyCode)Enum.Parse(typeof(ConStringHelper.CompanyCode), companyCode); var user = new Bas_Org_BL(code).GetUser(gId); return Json(user, JsonRequestBehavior.AllowGet); } #endregion public JsonResult GetCompany() { var data = _cache.GetCompanyVirtual(); return Json(data, JsonRequestBehavior.AllowGet); } #region 导出 [HttpGet] public ActionResult ExcelExport() { string query = Server.UrlDecode(Request.QueryString["Query"]); int Index = query.IndexOf("?") + 1; string url = query.Substring(0, Index); string param = query.Substring(Index, query.Length - Index); foreach (string paramx in param.Split('&')) { if (!string.IsNullOrWhiteSpace(paramx)) { string[] paramaxs = paramx.Split('='); url += "&" + paramaxs[0] + "=" + Server.UrlEncode(paramaxs[1]); } } ViewBag.Query = url.Replace("?&", "?"); return View(); } [HttpGet] public ActionResult ExcelExport_cookie() { string query = Server.UrlDecode(Request.QueryString["Query"]); int Index = query.IndexOf("?") + 1; string url = query.Substring(0, Index); string param = query.Substring(Index, query.Length - Index); foreach (string paramx in param.Split('&')) { string[] paramaxs = paramx.Split('='); url += "&" + paramaxs[0] + "=" + Server.UrlEncode(paramaxs[1]); } ViewBag.Query = url.Replace("?&", "?"); return View(); } public JsonResult SetCookie(string checkedTitles, string checkedFilds) { int type = 1; string message = string.Empty; try { HttpCookie cokie = new HttpCookie("checkedTitles", checkedTitles); HttpCookie cokie2 = new HttpCookie("checkedFilds", checkedFilds); //cokie.Expires = DateTime.Now.AddMinutes(10); //cokie2.Expires = DateTime.Now.AddMinutes(10); Response.AddHeader("P3P", "CP=CAO PSA OUR"); Response.Cookies.Add(cokie); Response.Cookies.Add(cokie2); //Common.CacheHelper.Set("checkedTitles_", checkedTitles); //Common.CacheHelper.Set("checkedFilds_", checkedFilds); } catch (Exception ex) { LogHelper.Error(ex.ToString()); type = 0; message = "导出失败!"; } return Json(new { type = type, message = message }, JsonRequestBehavior.AllowGet); } #endregion public ActionResult SettingList(string module, decimal? eid) { ViewBag.Module = module; ViewBag.Eid = eid; return View(); } [HttpGet] public JsonResult GetSettingList(string module, decimal? eid) { var webapi = paramter_bl.GetValue_Parameter(Parameter.CrmWebApiUrl); var url = $"{webapi}Api/Field/UserSettingList"; //url = "https://localhost:5254/Api/Field/UserSettingList"; var para = $"module={module}&eid={eid}"; var data = Utility.GetData(url, para); var result = WX.CRM.Common.Utility.ToObject>>(data); if (result.code == 0) { return Json(new { result = true, message = "获取成功!", data = result.data }, JsonRequestBehavior.AllowGet); } return Json(new { result = false, message = "获取失败" }, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult ResetSettingList(string module, decimal? eid) { var webapi = paramter_bl.GetValue_Parameter(Parameter.CrmWebApiUrl); var url = $"{webapi}Api/Field/ResetSettingList"; //url = "https://localhost:5254/Api/Field/ResetSettingList"; var para = $"module={module}&eid={eid}"; var data = Utility.GetData(url, para); var result = WX.CRM.Common.Utility.ToObject(data); if (result.code == 0) { return Json(new { result = true, message = "重置成功!" }, JsonRequestBehavior.AllowGet); } return Json(new { result = false, message = "重置失败" }, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult GetTableFieldSettings(string module, decimal? eid) { var webapi = paramter_bl.GetValue_Parameter(Parameter.CrmWebApiUrl); var url = $"{webapi}Api/Field/UserSettings"; //url = "https://localhost:5254/Api/Field/UserSettings"; var para = $"module={module}&eid={eid}"; var data = Utility.GetData(url, para); var result = WX.CRM.Common.Utility.ToObject>>(data); if (result.code == 0) { return new JsonNetResult(new { result = true, message = "获取成功!", data = result.data }); } return Json(new { result = false, message = "获取失败" }, JsonRequestBehavior.AllowGet); } [HttpPost] public JsonResult SettingSave(List dto, int? eid, string module) { var webapi = paramter_bl.GetValue_Parameter(Parameter.CrmWebApiUrl); var url = $"{webapi}Api/Field/UserSetting"; //url = "https://localhost:5254/Api/Field/UserSetting"; var request = new { eid, module, data = dto, }; var data = WX.CRM.Common.Utility.PostAjaxData(url, JsonHelper.NewtonsoftToJson(request), "" , true); var result = WX.CRM.Common.Utility.ToObject(data); if (result.code != 0) { return Json(new { result = false, message = result.message }); } return Json(new { result = true, message = "更新成功!" }); } } public class UserTableFieldSettingDto { public int Id { get; set; } public bool Checkbox { get; set; } public string Field { get; set; } public string Title { get; set; } public string Fixed { get; set; } public int? Order { get; set; } } public class TableFieldSettingDto { [JsonProperty("checkbox", NullValueHandling = NullValueHandling.Ignore)] public bool? Checkbox { get; set; } [JsonProperty("field", NullValueHandling = NullValueHandling.Ignore)] public string Field { get; set; } [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] public string Type { get; set; } [JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)] public string Title { get; set; } [JsonProperty("width", NullValueHandling = NullValueHandling.Ignore)] public int? Width { get; set; } [JsonProperty("fixed", NullValueHandling = NullValueHandling.Ignore)] public string Fixed { get; set; } [JsonProperty("templet", NullValueHandling = NullValueHandling.Ignore)] public string Templet { get; set; } [JsonProperty("sort", NullValueHandling = NullValueHandling.Ignore)] public bool? Sort { get; set; } [JsonProperty("hide", NullValueHandling = NullValueHandling.Ignore)] public bool? Hide { get; set; } } public class JsonNetResult : JsonResult { public Encoding ContentEncoding { get; set; } public string ContentType { get; set; } public object Data { get; set; } public JsonSerializerSettings SerializerSettings { get; set; } public Formatting Formatting { get; set; } public JsonNetResult(object data, Formatting formatting) : this(data) { Formatting = formatting; } public JsonNetResult(object data) : this() { Data = data; } public JsonNetResult() { Formatting = Formatting.None; SerializerSettings = new JsonSerializerSettings(); } public override void ExecuteResult(ControllerContext context) { if (context == null) throw new ArgumentNullException("context"); var response = context.HttpContext.Response; response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json"; if (ContentEncoding != null) response.ContentEncoding = ContentEncoding; if (Data == null) return; var writer = new JsonTextWriter(response.Output) { Formatting = Formatting }; var serializer = JsonSerializer.Create(SerializerSettings); serializer.Serialize(writer, Data); writer.Flush(); } } }