123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.ViewModel;
- using EMIS.Web.Controls;
- using Bowin.Web.Controls.Mvc;
- using EMIS.ViewModel.SystemView;
- using EMIS.CommonLogic.TeachingMaterial;
- using EMIS.ViewModel.TeachingMaterial;
- using Bowin.Common.Utility;
- using Bowin.Common.Data;
- using Bowin.Common.Exceptions;
- using System.IO;
- using EMIS.Utility;
- using System.Text;
- namespace EMIS.Web.Controllers.TeachingMaterial
- {
- [Authorization]
- public class PublisherController : Controller
- {
- public IPublishServices PublishServices { get; set; }
- /// <summary>
- /// 出版单位页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult List()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- bool? isprivide = null;
- bool? ispublish = null;
- bool? isprint = null;
- if (pararms.getExtraInt("PrivideDropdown") != null && pararms.getExtraInt("PrivideDropdown") != DropdownList.SELECT_ALL)
- {
- isprivide = pararms.getExtraInt("PrivideDropdown") == 1 ? true : false; ;
- }
- if (pararms.getExtraInt("PublishDropdown") != null && pararms.getExtraInt("PublishDropdown") != DropdownList.SELECT_ALL)
- {
- ispublish = pararms.getExtraInt("PublishDropdown") == 1 ? true : false; ;
- }
- if (pararms.getExtraInt("PrintDropdown") != null && pararms.getExtraInt("PrintDropdown") != DropdownList.SELECT_ALL)
- {
- isprint = pararms.getExtraInt("PrintDropdown") == 1 ? true : false; ;
- }
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(PublishServices.GetPublishViewGrid(configuretView, isprivide, ispublish, isprint, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 查询是供应商的列表
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult SupplierList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- bool? isSupplier = true;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(PublishServices.GetPublishViewGrid(configuretView, isSupplier, null, null, (int)pararms.page, (int)pararms.rows));
- }
- [HttpPost]
- public ActionResult Excel(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- //避开全选值
- bool? isprivide = null;
- bool? ispublish = null;
- bool? isprint = null;
- if (Request.Form["PrivideDropdown"].ParseStrTo<int>() != null && Request.Form["PrivideDropdown"].ParseStrTo<int>() != DropdownList.SELECT_ALL)
- {
- isprivide = Request.Form["PrivideDropdown"].ParseStrTo<int>() == 1 ? true : false; ;
- }
- if (Request.Form["PublishDropdown"].ParseStrTo<int>() != null && Request.Form["PublishDropdown"].ParseStrTo<int>() != DropdownList.SELECT_ALL)
- {
- ispublish = Request.Form["PublishDropdown"].ParseStrTo<int>() == 1 ? true : false; ;
- }
- if (Request.Form["PrintDropdown"].ParseStrTo<int>() != null && Request.Form["PrintDropdown"].ParseStrTo<int>() != DropdownList.SELECT_ALL)
- {
- isprint = Request.Form["PrintDropdown"].ParseStrTo<int>() == 1 ? true : false; ;
- }
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- NpoiExcelHelper neh = new NpoiExcelHelper();
- var dt = PublishServices.GetPublishViewExcel(configuretView, isprivide, ispublish, isprint).Select(x => new
- {
- x.UnitCode,
- x.UnitName,
- x.ContectUser,
- x.Mobile,
- x.Phone,
- x.Address
- }).ToTable();
- string[] liststring = { "单位编码", "单位名称", "联系人", "移动电话", "固定电话", "单位地址" };
- neh.Export(dt, liststring, "出版单位信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/Publisher/List").AddMenuParameter()
- });
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? publishID)
- {
- PublisherView publishView;
- if (publishID != null && publishID != Guid.Empty)
- {
- publishView = PublishServices.GetSinglePublish(publishID.Value);
- }
- else
- {
- publishView = new PublisherView()
- {
- PublishID = Guid.Empty
- };
- }
- return View(publishView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(PublisherView publisherView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- PublishServices.EditPulish(publisherView, user.UserID);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string publishIDs)
- {
- try
- {
- var publishIDList = publishIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
- PublishServices.DeletePublish(publishIDList);
- return base.Json("删除成功");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
- if (num != null)
- {
- if (num.Number == 547)
- mge = "请先删除所有关联的数据,如:教材信息等";
- }
- return base.Json("删除失败,原因:" + mge + "!");
- }
- }
- #region 13.0 出版单位信息导入
- [HttpGet]
- public ActionResult Import(string errorFile, string operationTips)
- {
- ViewBag.ErrorFile = errorFile;
- if (string.IsNullOrEmpty(operationTips))
- {
- operationTips = "错误数据下载";
- }
- ViewBag.operationTips = operationTips;
- return View();
- }
- [HttpPost]
- public ActionResult Import(HttpPostedFileBase file)
- {
- try
- {
- //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
- //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
- var accept = new[] { ".xls", ".xlsx" };
- var p = Path.GetExtension(file.FileName);
- if (!accept.Contains(p))
- {
- throw new Exception("只允许上传xls格式的Excel文件!");
- }
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "UnitCode", "单位编号" },
- { "UnitName", "单位名称" },
- { "ContectUser", "联系人" },
- { "Mobile", "移动电话" },
- { "Phone", "固定电话" }, { "Fax", "传真" },
- { "Email", "邮箱" },
- { "BandName", "开户行名称" },{ "BandCard", "银行帐号" },
- { "Ein", "税号" },
- { "IsSupplierName", "是否供应商" }, { "IsPulishName", "是否出版单位" },
- { "IsPrintName", "是否印刷厂" }, { "Address", "单位地址" },{ "Desc", "备注" }, { "ErrorMessage", "错误信息" }
- };
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<PublisherView> errList = new List<PublisherView>();
- List<PublisherView> dataList = new List<PublisherView>();
- int errCount = 0;
- int OkCount = 0;
- PublishServices.PublishImport(cellheader, out errList, out errCount, out OkCount, sourcePhysicalPath);
- System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
- if (errList.Count() > 0)
- {
- //将异常文件路径显示
- string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "出版单位导入失败文件", sourcePhysicalPath));
- ViewBag.ErrorFile = errorWebPath;
- string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount);
- ViewBag.operationTips = Errinfo;
- // //return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo });
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = "none",
- msg = "导入失败!",
- url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
- });
- }
- else
- {
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = "导入成功!",
- url = Url.Action("List").AddMenuParameter()
- });
- }
- }
- catch (Exception ex)
- {
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = "导入失败,原因:" + ex.Message,
- url = Url.Action("List").AddMenuParameter()
- });
- }
- #endregion
- }
- }
- }
|