using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using QMFrameWork.WebUI.Attribute; using QMAPP.Web.Models.Sys; using QMAPP.Common.Web.Controllers; using QMFrameWork.Data; using QMAPP.Entity.Sys; using QMFrameWork.WebUI.DataSource; using QMFrameWork.Common.Serialization; using System.Collections; using QMAPP.ServicesAgent; using System.Data; using System.Configuration; namespace QMAPP.Web.Controllers { /// /// 问题管理控制器 /// 创建人:wangyf /// 创建时间:2015.03.30 /// public class SupportInteractionController : QController { #region 字符串常量 private const string NOTCLOSED = "未关闭"; private const string CLOSED = "已关闭"; private const string SHOW = "查看"; private const string uploadFolder = "\\SupportInteraction\\"; #endregion #region 编辑 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult SupportInteractionEdit() { SupportInteractionModel model = new SupportInteractionModel(); string ID = Request.Params["PID"]; SupportInteraction entity = new SupportInteraction(); try { if (string.IsNullOrEmpty(ID) == false) { //修改获取原数据 entity.PID = ID; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); entity = agent.InvokeServiceFunction("SupportInteractionBLL_GetInfo", entity); model = CopyToModel(entity); } return View(model); } catch (Exception ex) { throw ex; } } #endregion #region 编辑载入 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult SupportInteractionDeal(SupportInteractionModel model) { string ID = Request.Params["PID"]; SupportInteraction entity = new SupportInteraction(); try { if (string.IsNullOrEmpty(ID) == false) { //修改获取原数据 entity.PID = ID; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); entity = agent.InvokeServiceFunction("SupportInteractionBLL_GetInfo", entity); model = CopyToModel(entity); } return View(model); } catch (Exception ex) { throw ex; } } #endregion #region 保存 /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] public ActionResult SupportInteractionSave(HttpPostedFileBase attfile, SupportInteractionModel saveModel) { SupportInteraction info = null; //原附件名 string oldFileName = saveModel.AttachFile; //上传的附件名 string fileName = null; if (attfile != null) { fileName = attfile.FileName; //判断文件大小是否符合要求 if (!CheckFileSize(attfile)) { SetMessage("上传附件不能大于5M"); return View("SupportInteractionEdit", saveModel); } } try { info = CopyToModel(saveModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); if (string.IsNullOrEmpty(info.PID)) { //新建的文件名 info.PID = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(fileName)) { //应用程序物理路径 string PhysicsRootPath = Server.MapPath(HttpRuntime.AppDomainAppVirtualPath); //附件名 info.AttachFileName = fileName; //附件GUID名 info.AttachFile = info.PID + fileName.Substring(fileName.LastIndexOf(".")); //创建附件上传文件夹 SaveAttachFile(attfile, PhysicsRootPath, uploadFolder, info.AttachFile); } //新增 agent.InvokeServiceFunction("SupportInteractionBLL_Insert", info); } return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SubmitSuccess)); } catch (Exception ex) { throw ex; } } #endregion #region 判断附件大小 /// /// 判断附件大小 /// /// /// 附件路径,结果 [HttpPost] [HandleException] public Boolean CheckFileSize(HttpPostedFileBase file) { SupportInteractionModel model = new SupportInteractionModel(); try { //计算文件大小 int fileLength = file.ContentLength / 1024; //判断如果文件大小超过5M,不允许上传 if (fileLength > 5120) { return false; } return true; } catch (Exception ex) { throw ex; } } #endregion #region 保存附件 /// /// 保存附件 /// /// /// /// [HandleException] private void SaveAttachFile(HttpPostedFileBase file,string PhysicsRootPath, string uploadFolder, string guidFileName) { if (file != null) { //判断路径是否在,不存在则创建 CheckUploadPath(PhysicsRootPath, uploadFolder); //保存文件 file.SaveAs(PhysicsRootPath + uploadFolder + guidFileName); } } #endregion #region 删除原有附件 /// /// 删除原有附件 /// /// /// [HandleException] private void DeleteAttachFile(string PhysicsRootPath, string uploadFolder, string oldFileName) { string oldFilePath = PhysicsRootPath + uploadFolder + oldFileName; //如果文件存在则删除 if (System.IO.File.Exists(oldFilePath)) { System.IO.File.Delete(oldFilePath); } } #endregion #region 创建附件上传文件夹 /// /// 创建附件上传文件夹 /// /// 物理路径 /// 附件存放路径 [HandleException] private void CheckUploadPath(string PhysicsRootPath, string uploadFolder) { //获取配置文件上传附件文件夹名称 string siUploadFile = ConfigurationManager.AppSettings.Get("UploadFileRoot"); //附件目录 string UploadFile = PhysicsRootPath + siUploadFile + uploadFolder; //如果文件夹不存在则创建文件夹 if (System.IO.Directory.Exists(UploadFile) == false) { System.IO.Directory.CreateDirectory(UploadFile); } //附件文件路径 string siPath = PhysicsRootPath + uploadFolder; //如果文件夹不存在则创建文件夹 if (System.IO.Directory.Exists(siPath) == false) { System.IO.Directory.CreateDirectory(siPath); } } #endregion #region 下载附件 /// /// 下载文件名 /// /// [HttpPost] [HandleException] public FilePathResult DownAttach(string fileName, string oldFileName) { try { //应用程序物理路径 string PhysicsRootPath = Server.MapPath(HttpRuntime.AppDomainAppVirtualPath); string contentType = GetContenType(fileName.Substring(fileName.LastIndexOf("."))); return File(PhysicsRootPath + uploadFolder + fileName, contentType, Url.Encode(oldFileName)); } catch (Exception ex) { throw ex; } } #endregion #region 根据后缀获取返回CONTENTTYPE /// /// 根据后缀获取返回CONTENTTYPE /// /// 后缀 /// CONTENTTYPE [HandleException] private string GetContenType(string suffix) { string resultType = ""; if (".txt".Equals(suffix.ToLower())) { resultType = ""; } switch (suffix.ToLower()) { case ".txt": resultType = "text/plain"; break; case ".xls": resultType = "application/vnd.ms-excel"; break; case ".xlsx": resultType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case ".doc": resultType = "application/msword"; break; case ".docx": resultType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template"; break; case ".ppt": resultType = "application/vnd.ms-powerpoint"; break; case ".pptx": resultType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; case ".bmp": resultType = "application/x-MS-bmp"; break; case ".jpg": resultType = "aimage/jpeg"; break; case ".jpeg": resultType = "image/jpeg"; break; case ".gif": resultType = "image/gif"; break; case ".png": resultType = "image/png"; break; case ".rar": resultType = "application/x-rar-compressed"; break; case ".zip": resultType = "application/zip"; break; } return resultType; } #endregion #region 获取列表 /// /// 加载列表 /// /// 结果 [HandleException] public ActionResult SupportInteractionList(bool? callBack) { SupportInteractionModel seachModel = new SupportInteractionModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); else seachModel.PStatus = "0"; seachModel.rownumbers = false; seachModel.url = "/SupportInteraction/GetProblemList"; return View("SupportInteractionList", seachModel); } /// /// 获取问题列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetProblemList(bool? callBack) { SupportInteractionModel seachModel = null; DataPage page = null; SupportInteraction condition = null; try { //获取查询对象 seachModel = GetModel(); #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页设置信息 page = this.GetDataPage(seachModel); seachModel.Ecind = seachModel.PStatus; condition = CopyToModel(seachModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("SupportInteractionBLL_GetProblemList", condition, page); List list = (List)JsonConvertHelper.GetDeserialize>(page.Result.ToString()); List modelList = new List(); //设置问题状态 foreach (SupportInteraction si in list) { SupportInteractionModel tmp = CopyToModel(si); if (si.Ecind == "1") { tmp.PStatus = CLOSED; } else { tmp.PStatus = NOTCLOSED; } tmp.DealList = "查看"; modelList.Add(tmp); } DataGridResult result = new DataGridResult(); result.Total = page.RecordCount; result.Rows = modelList; return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 获取部门下的人员 /// /// 取得当前部门下的人员 /// /// 结果 [HandleException] public ActionResult GetUserList() { string organId = Request["orgaID"].ToString(); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); List userlist = agent.InvokeServiceFunction>("UserManageBLL_GetOrgaUserList", organId); return Content(QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(userlist)); } #endregion #region 搜索问题解决方案 /// /// 搜索问题解决方案 /// /// /// [HandleException] public ActionResult SearchProlemSolution(bool? callBack) { SearchSIModel seachModel = new SearchSIModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); seachModel.rownumbers = false; seachModel.url = "/SupportInteraction/GetList"; seachModel.checkbox = false; string mode = Request.QueryString["mode"]; if(string.IsNullOrEmpty(mode)==true) return View("SearchProlemSolution", seachModel); else return View("SelectProlemSolution", seachModel); } /// /// 获取问题处理方法列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { SearchSIModel seachModel = null; DataPage page = null; SupportInteraction condition = null; try { //获取查询对象 seachModel = GetModel(); #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("SupportInteractionBLL_GetList", condition, page); List siList = new List(); List resultList = JsonConvertHelper.GetDeserialize>(page.Result.ToString()); foreach (SupportInteraction si in resultList) { SearchSIModel tempModel = CopyToModel(si); tempModel.CDate = Convert.ToDateTime(tempModel.CDate) == new DateTime() ? "" : Convert.ToDateTime(tempModel.CDate).ToString("yyyy-MM-dd hh:mm:ss"); siList.Add(tempModel); } DataGridResult result = new DataGridResult(); result.Total = siList.Count; result.Rows = siList; return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 选择问题参照解决方案 /// /// 选择问题参照解决方案 /// /// /// [HandleException] public ActionResult SelectProlemSolution(bool? callBack) { SearchSIModel seachModel = new SearchSIModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); seachModel.rownumbers = false; seachModel.url = "/SupportInteraction/GetSloveList"; string mode = Request.QueryString["mode"]; if (string.IsNullOrEmpty(mode) == true) return View("SelectProlemSolution", seachModel); else return View("SelectProlemSolution", seachModel); } /// /// 选择问题参照解决方案列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetSloveList(bool? callBack) { SearchSIModel seachModel = null; DataPage page = null; SupportInteraction condition = null; try { //获取查询对象 seachModel = GetModel(); #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("SupportInteractionBLL_GetList", condition, page); List siList = new List(); List resultList = JsonConvertHelper.GetDeserialize>(page.Result.ToString()); foreach (SupportInteraction si in resultList) { SearchSloveModel tempModel = CopyToModel(si); tempModel.VCDate = tempModel.CDate == new DateTime() ? "" : tempModel.CDate.ToString("yyyy-MM-dd hh:mm:ss"); siList.Add(tempModel); } DataGridResult result = new DataGridResult(); result.Total = siList.Count; result.Rows = siList; return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 获取问题状态列表 /// /// 获取问题状态列表 /// /// 数据源 [HandleException] public ActionResult GetPStatusList() { try { ComboboxResult model = new ComboboxResult(); model.Add(new ComboboxItem { ID = "", Text = new DictController().EmptyItemTitle, Selected = "Selected" }); model.Add(new ComboboxItem { ID = "0", Text = NOTCLOSED }); model.Add(new ComboboxItem { ID = "1", Text = CLOSED }); return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 选择支持用户 /// /// 选择支持用户 /// /// [HandleException] public ActionResult SelectSupportUser(SupportInteractionModel model) { return View("SelectSupportUser", model); } #endregion #region 提交 /// /// 提交 /// /// [HandleException] public ActionResult SaveSupportInteraction(SupportInteractionModel seachModel) { ServiceAgent wcfAgent = this.GetServiceAgent(); Boolean retBool = false; try { SupportInteraction seachEntity = new SupportInteraction(); seachEntity = CopyToModel(seachModel); retBool = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_UpdateSupportInteraction", seachEntity); return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SubmitSuccess)); } catch (Exception ex) { throw ex; } } #endregion #region 解决问题 /// /// 解决问题 /// /// [HandleException] public ActionResult SloveSupportInteraction(SupportInteractionModel seachModel) { ServiceAgent wcfAgent = this.GetServiceAgent(); Boolean retBool = false; try { SupportInteraction seachEntity = new SupportInteraction(); seachEntity = CopyToModel(seachModel); retBool = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_SloveSupportInteraction", seachEntity); return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SloveSuccess)); } catch (Exception ex) { throw ex; } } #endregion #region 获取处理用户的机构列表 /// /// 获取处理用户的机构列表 /// /// 结果 [HttpPost] [HandleException] public ActionResult GetCurrentHandleOrga() { ServiceAgent wcfAgent = this.GetServiceAgent(); try { ZPFlow entity = new ZPFlow(); List resultList = wcfAgent.InvokeServiceFunction>("SupportInteractionBLL_GetCurrentHandleOrga", entity); ComboboxResult model = new ComboboxResult(); //添加第一行空行 if (resultList != null && resultList.Count > 0) { model.Add(new ComboboxItem { ID = "", Text = new DictController().EmptyItemTitle }); } foreach (ZPFlow o in resultList) { model.Add(new ComboboxItem { ID = o.SDept, Text = o.SOrgaDesc }); } return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 处理记录列表 /// /// 跳转到行为记录页面 /// /// [HandleException] public ActionResult SIDealInfoList() { SIDealInfoModel seachModel = new SIDealInfoModel(); //提交的ID string ZPDDBPID = Request["ZPDDBPID"].ToString(); seachModel.rownumbers = false; seachModel.url = "/SupportInteraction/GetSIDealList?ZPDDBPID=" + ZPDDBPID; seachModel.checkbox = false; return View("SIDealInfoList", seachModel); } /// /// 获取处理记录列表 /// /// [HandleException] public ActionResult GetSIDealList() { SIDealInfoModel seachModel = new SIDealInfoModel(); ZPDealInfo condition = null; DataPage page = null; try { //提交的ID string ZPDDBPID = Request["ZPDDBPID"].ToString(); seachModel.ZPDDBPID = ZPDDBPID; //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("SupportInteractionBLL_GetSIDealList", condition, page); DataGridResult result = new DataGridResult(); result.Total = page.RecordCount; result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString()); return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 获取问题列表 /// /// 获取问题状态列表 /// /// 数据源 [HandleException] public ActionResult GetTypeList() { try { QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); List typeList = agent.InvokeServiceFunction>("SupportInteractionBLL_GetTypeList"); ComboboxResult model = new ComboboxResult(); model.Add(new ComboboxItem { ID = "" , Text = new DictController().EmptyItemTitle }); if(typeList != null && typeList.Count > 0) { foreach(SupportInteraction si in typeList){ model.Add(new ComboboxItem { ID = si.PID, Text = si.PTypeName }); } } return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 导出问题处理方法excel /// /// 导出问题处理方法excel /// /// 结果 [HttpPost] [HandleException] public ActionResult ExportExcel() { SearchSIModel seachModel = null; SupportInteraction seachEntity = null; ServiceAgent wcfAgent = this.GetServiceAgent(); DataTable exportDt = null; try { //获取查询条件 TryGetSelectBuffer(out seachModel); seachEntity = CopyToModel(seachModel); //获取数据 exportDt = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_GetExportData", seachEntity); //转换日期格式 foreach (DataRow dr in exportDt.Rows) { string cd = dr["CDate"].ToString(); if (!string.IsNullOrEmpty(cd)) { dr["CDate"] = Convert.ToDateTime(cd).ToString("yyyy-MM-dd hh:mm:ss"); } } //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("ProblemSulotion", "问题处理方法.xls", exportDt); } catch (Exception ex) { throw ex; } } #endregion #region 导出问题管理excel /// /// 导出问题管理excel /// /// 结果 [HttpPost] [HandleException] public ActionResult ProblemManageExportExcel() { SupportInteractionModel seachModel = null; SupportInteraction seachEntity = null; ServiceAgent wcfAgent = this.GetServiceAgent(); DataTable exportDt = null; string selectKey = Request.Form["selectKey"]; try { //获取查询条件 TryGetSelectBuffer(out seachModel); seachEntity = CopyToModel(seachModel); //获取数据 exportDt = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_GetProblemManageExportData", seachEntity); //导出 if (selectKey != "") { DataView dv = new DataView(exportDt); string strWhere = ""; string[] list = selectKey.Split(":".ToCharArray()); foreach (string pid in list) { strWhere += " PID='" + pid + "' or"; } if (strWhere != "") { strWhere = strWhere.Remove((strWhere.Length - 2), 2); } dv.RowFilter = strWhere; exportDt = dv.ToTable(); } //添加列 //处理记录 exportDt.Columns.Add("DEALLIST"); //处理状态 exportDt.Columns.Add("PSTATUS"); //处理状态 exportDt.Columns.Add("CD"); //设置问题状态 foreach (DataRow dr in exportDt.Rows) { dr["DEALLIST"] = SHOW; if (dr["ECIND"].ToString() == "1") { dr["PSTATUS"] = CLOSED; } else { dr["PSTATUS"] = NOTCLOSED; } string cd = dr["CreateDate"].ToString(); if (!string.IsNullOrEmpty(cd)) { dr["CD"] = Convert.ToDateTime(cd).ToString("yyyy-MM-dd hh:mm:ss"); } } //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("ProblemManage", "问题管理.xls", exportDt); } catch (Exception ex) { throw ex; } } #endregion #region 判断选中的问题是否已经关闭 /// /// 判断选中的问题是否已经关闭 /// /// 结果 [HttpPost] [HandleException] public ActionResult CheckProblemClosed() { ServiceAgent wcfAgent = this.GetServiceAgent(); string PID = Request.Form["PID"]; Boolean retBool = false; try { SupportInteraction seachEntity = new SupportInteraction(); seachEntity.PID = PID; retBool = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_CheckProblemClosed", seachEntity); return Json(retBool); } catch (Exception ex) { throw ex; } } #endregion #region 校验选中问题的处理部门是否为当前用户部门 /// /// 校验选中问题的处理部门是否为当前用户部门 /// /// 结果 [HttpPost] [HandleException] public ActionResult CheckProblemDept() { ServiceAgent wcfAgent = this.GetServiceAgent(); string PID = Request.Form["PID"]; Boolean retBool = false; try { SupportInteraction seachEntity = new SupportInteraction(); seachEntity.PID = PID; retBool = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_CheckProblemDept", seachEntity); return Json(retBool); } catch (Exception ex) { throw ex; } } #endregion #region 校验选中问题的处理人是否为当前用户 /// /// 校验选中问题的处理人是否为当前用户 /// /// 结果 [HttpPost] [HandleException] public ActionResult CheckProblemUser() { ServiceAgent wcfAgent = this.GetServiceAgent(); string PID = Request.Form["PID"]; Boolean retBool = false; try { SupportInteraction seachEntity = new SupportInteraction(); seachEntity.PID = PID; retBool = wcfAgent.InvokeServiceFunction("SupportInteractionBLL_CheckProblemUser", seachEntity); return Json(retBool); } catch (Exception ex) { throw ex; } } #endregion } }