CertisfierDistributeController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.ExamManage;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Common.Exceptions;
  10. using Bowin.Common.Utility;
  11. using Bowin.Common.Data;
  12. using Bowin.Web.Controls.Mvc;
  13. using EMIS.CommonLogic.CerificateManage;
  14. using System.Text;
  15. using EMIS.Utility;
  16. namespace EMIS.Web.Controllers.CerificateManage
  17. {
  18. [Authorization]
  19. public class CertisfierDistributeController : Controller
  20. {
  21. public IExamProjectControlServices IExamProjectControlService { get; set; }
  22. public ICertisfierDistributeServices ICertisfierDistributeService { get; set; }
  23. //
  24. // GET: /CertisfierDistribute/
  25. public ActionResult Index()
  26. {
  27. return View();
  28. }
  29. public ActionResult List()
  30. {
  31. return View();
  32. }
  33. public ActionResult StuList()
  34. {
  35. return View();
  36. }
  37. public ActionResult Confirm(string ViewID)
  38. {
  39. //try
  40. //{
  41. //List<Guid?> list = ViewID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  42. //ICertisfierDistributeService.CheckBeforeConfirm(list);
  43. return View();
  44. //}
  45. //catch (Exception ex)
  46. //{
  47. // return Json(new ReturnMessage()
  48. // {
  49. // IsSuccess = false,
  50. // Message = ex.Message
  51. // });
  52. //}
  53. }
  54. public ActionResult PrintDetail(Guid certisfierDistributeID)
  55. {
  56. var view = ICertisfierDistributeService.GetView(certisfierDistributeID);
  57. return View(view);
  58. }
  59. public ActionResult View(Guid ID)
  60. {
  61. var view = ICertisfierDistributeService.GetView(ID);
  62. return View(view);
  63. }
  64. public ActionResult StuEdit(Guid ID, int DistributeTypeID)
  65. {
  66. var view = ICertisfierDistributeService.GetView(ID);
  67. view.DistributeTypeID = DistributeTypeID;
  68. return View(view);
  69. }
  70. /// <summary>
  71. /// 收费项目编辑页提交
  72. /// </summary>
  73. /// <param name="campusView"></param>
  74. /// <returns></returns>
  75. [HttpPost]
  76. public ActionResult StuEdit(CerificateView view)
  77. {
  78. try
  79. {
  80. ICertisfierDistributeService.UpdateCertisfierDistributeType(view);
  81. return Json(new ReturnMessage()
  82. {
  83. IsSuccess = true,
  84. Message = "保存成功。"
  85. });
  86. }
  87. catch (Exception ex)
  88. {
  89. return Json(new ReturnMessage()
  90. {
  91. IsSuccess = false,
  92. Message = "保存失败,原因:" + ex.Message
  93. });
  94. }
  95. }
  96. /// <summary>
  97. /// Excel导入
  98. /// </summary>
  99. /// <param name="errorFile"></param>
  100. /// <param name="operationTips"></param>
  101. /// <returns></returns>
  102. [HttpGet]
  103. public ActionResult Import(string errorFile, string operationTips)
  104. {
  105. ViewBag.ErrorFile = errorFile;
  106. if (string.IsNullOrEmpty(operationTips))
  107. {
  108. operationTips = "点击查看失败原因...";
  109. }
  110. ViewBag.operationTips = operationTips;
  111. return View();
  112. }
  113. /// <summary>
  114. /// 项目列表查询
  115. /// </summary>
  116. /// <param name="pararms"></param>
  117. /// <returns></returns>
  118. [HttpPost]
  119. public ActionResult ProjectListViewGrid(QueryParamsModel pararms)
  120. {
  121. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  122. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  123. configuretViews.AddRange(pararms.getConditions());
  124. return base.Json(ICertisfierDistributeService.GetExamProjectListViewGrid((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
  125. }
  126. /// <summary>
  127. /// 列表查询
  128. /// </summary>
  129. /// <param name="pararms"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. public ActionResult List(QueryParamsModel pararms)
  133. {
  134. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  135. var schoolyearID = pararms.getExtraGuid("ddlSchoolyear");
  136. var examinationBatchID = pararms.getExtraGuid("cgExaminationBatch");
  137. var examinationTypeID = pararms.getExtraGuid("cgExaminationType");
  138. var examinationProjectID = pararms.getExtraGuid("cgExaminationProject");
  139. var collegeID = pararms.getExtraGuid("CollegeID");
  140. var schoolAreaID = pararms.getExtraInt("SchoolAreaID") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolAreaID");
  141. var year = pararms.getExtraInt("Years") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("Years");
  142. var classmajorID = pararms.getExtraGuid("ClassmajorID");
  143. var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
  144. var distributeTypeID = pararms.getExtraInt("DistributeTypeID") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DistributeTypeID");
  145. var recordStatus = pararms.getExtraInt("RecordStatus") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("RecordStatus");
  146. Guid? userID = null;//教师端
  147. //List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  148. //configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  149. //configuretViews.AddRange(pararms.getConditions());
  150. return base.Json(ICertisfierDistributeService.GetCertisfierListViewGrid(configuretView, schoolyearID,examinationProjectID,collegeID,schoolAreaID,year,classmajorID,standardID,distributeTypeID,recordStatus, userID, (int)pararms.page, (int)pararms.rows));
  151. }
  152. /// <summary>
  153. /// 学生端列表查询
  154. /// </summary>
  155. /// <param name="pararms"></param>
  156. /// <returns></returns>
  157. [HttpPost]
  158. public ActionResult StuList(QueryParamsModel pararms)
  159. {
  160. //List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  161. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  162. Guid? schoolyearID = null;
  163. Guid? collegeID = null;
  164. int? schoolAreaID = null;
  165. int? year = null;
  166. Guid? classmajorID = null;
  167. int? standardID = null;
  168. var userID = ((EMIS.Utility.FormValidate.CustomPrincipal)HttpContext.User).UserID;
  169. var examinationProjectID = pararms.getExtraGuid("ExaminationProjectID");
  170. var distributeTypeID = pararms.getExtraInt("DistributeTypeID") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DistributeTypeID");
  171. var recordStatus = pararms.getExtraInt("RecordStatus") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("RecordStatus");
  172. //configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  173. //configuretViews.AddRange(pararms.getConditions());
  174. //configuretViews.Add(new ConfiguretView()
  175. //{
  176. // Attribute = "UserID",
  177. // Condition = "=",
  178. // ConditionValue = ((EMIS.Utility.FormValidate.CustomPrincipal)HttpContext.User).UserID.ToString()
  179. //});
  180. return base.Json(ICertisfierDistributeService.GetCertisfierListViewGrid(configuretView, schoolyearID, examinationProjectID, collegeID, schoolAreaID, year, classmajorID, standardID, distributeTypeID, recordStatus, userID, (int)pararms.page, (int)pararms.rows));
  181. }
  182. /// <summary>
  183. /// 删除
  184. /// </summary>
  185. /// <param name="campusIDs"></param>
  186. /// <returns></returns>
  187. [HttpPost]
  188. public JsonResult Delete(string IDs)
  189. {
  190. try
  191. {
  192. List<Guid?> list = IDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  193. .Select(x => (Guid?)new Guid(x)).ToList();
  194. ICertisfierDistributeService.Delete(list);
  195. return base.Json("删除成功。");
  196. }
  197. catch (Exception ex)
  198. {
  199. string mge = ex.Message;
  200. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  201. if (num != null)
  202. {
  203. if (num.Number == 547)
  204. {
  205. mge = "请先删除与其有关联的数据";
  206. }
  207. }
  208. return base.Json("删除失败,原因:" + mge);
  209. }
  210. }
  211. /// <summary>
  212. /// 开放领取
  213. /// </summary>
  214. /// <param name="campusIDs"></param>
  215. /// <returns></returns>
  216. [HttpPost]
  217. public JsonResult OpenDistribute(string IDs)
  218. {
  219. try
  220. {
  221. List<Guid?> list = IDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  222. .Select(x => (Guid?)new Guid(x)).ToList();
  223. ICertisfierDistributeService.OpenDistribute(list);
  224. return base.Json("开放领取成功。");
  225. }
  226. catch (Exception ex)
  227. {
  228. return base.Json("开放领取失败,原因:" + ex.Message);
  229. }
  230. }
  231. /// <summary>
  232. /// 撤销开放
  233. /// </summary>
  234. /// <param name="campusIDs"></param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. public JsonResult CancelOpenDistribute(string IDs)
  238. {
  239. try
  240. {
  241. List<Guid?> list = IDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  242. .Select(x => (Guid?)new Guid(x)).ToList();
  243. ICertisfierDistributeService.CancelOpenDistribute(list);
  244. return base.Json(new ReturnMessage() { IsSuccess = true, Message = "撤销开放成功。" });
  245. }
  246. catch (Exception ex)
  247. {
  248. return base.Json(new ReturnMessage() { IsSuccess = false, Message = "撤销开放失败,原因:" + ex.Message });
  249. }
  250. }
  251. /// <summary>
  252. /// 撤销领取
  253. /// </summary>
  254. /// <param name="campusIDs"></param>
  255. /// <returns></returns>
  256. [HttpPost]
  257. public JsonResult CancelDistribute(string IDs)
  258. {
  259. try
  260. {
  261. List<Guid?> list = IDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  262. .Select(x => (Guid?)new Guid(x)).ToList();
  263. ICertisfierDistributeService.CancelDistribute(list);
  264. return base.Json("撤销领取成功。");
  265. }
  266. catch (Exception ex)
  267. {
  268. return base.Json("撤销领取失败,原因:" + ex.Message);
  269. }
  270. }
  271. /// <summary>
  272. /// 确认领取
  273. /// </summary>
  274. /// <param name="campusIDs"></param>
  275. /// <returns></returns>
  276. [HttpPost]
  277. public JsonResult ConfirmDistribute(string IDs, string Distributer)
  278. {
  279. try
  280. {
  281. List<Guid?> list = IDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  282. .Select(x => (Guid?)new Guid(x)).ToList();
  283. ICertisfierDistributeService.ConfirmDistribute(list, Distributer);
  284. return base.Json("确认领取成功。");
  285. }
  286. catch (Exception ex)
  287. {
  288. return base.Json("确认领取失败,原因:" + ex.Message);
  289. }
  290. }
  291. [HttpPost]
  292. public ActionResult Excel(string qpararms)
  293. {
  294. NpoiExcelHelper neh = new NpoiExcelHelper();
  295. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  296. var schoolyearID = Request.Form["ddlSchoolyear"].ParseStrTo<Guid>();
  297. var examinationBatchID = Request.Form["cgExaminationBatch"].ParseStrTo<Guid>();
  298. var examinationTypeID = Request.Form["cgExaminationType"].ParseStrTo<Guid>();
  299. var examinationProjectID = Request.Form["cgExaminationProject"].ParseStrTo<Guid>();
  300. var schoolAreaID = Request.Form["SchoolAreaID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolAreaID"].ParseStrTo<int>();
  301. var collegeID = Request.Form["CollegeID"].ParseStrTo<Guid>();
  302. var year = Request.Form["Years"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["Years"].ParseStrTo<int>();
  303. var classmajorID = Request.Form["ClassmajorID"].ParseStrTo<Guid>();
  304. var standardID = Request.Form["StandardID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["StandardID"].ParseStrTo<int>();
  305. var distributeTypeID = Request.Form["DistributeTypeID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DistributeTypeID"].ParseStrTo<int>();
  306. var recordStatus = Request.Form["RecordStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["RecordStatus"].ParseStrTo<int>();
  307. var certisfierDistributeIDs = Request.Form["SelectedID"];
  308. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  309. List<Guid?> selectIDlist = new List<Guid?>();
  310. if (certisfierDistributeIDs != "" && certisfierDistributeIDs != null)
  311. {
  312. selectIDlist = certisfierDistributeIDs.SplitIDString();
  313. }
  314. var dt = ICertisfierDistributeService.GetList(configuretView,schoolyearID,examinationProjectID,collegeID,schoolAreaID,year,classmajorID,standardID,distributeTypeID,recordStatus, selectIDlist).Select(q =>
  315. new
  316. {
  317. q.Schoolyear,
  318. q.ProjectName,
  319. q.SchoolAreaName,
  320. q.CollegeName,
  321. q.Years,
  322. q.StandardName,
  323. q.ClassmajorName,
  324. q.UserName,
  325. q.CertificatesTypeName,
  326. q.IDNumber,
  327. q.DistributeStateName,
  328. q.DistributeTypeName,
  329. q.ContactPerson,
  330. q.ContactNo,
  331. q.DeliveryNoteNo,
  332. q.Distributer,
  333. DistributeTime = q.DistributeTime.HasValue ? q.DistributeTime.Value.ToString("yyyy-MM-dd") : "",
  334. q.No,
  335. }).ToTable();
  336. string[] liststring = {
  337. "学年学期","考试项目", "校区", "院系所","年级","专业","班级","姓名","证件类型","证件号码",
  338. "领取状态","领取方式","联系人","联系电话","邮寄单号","领取人","领取时间","领取单号"};
  339. neh.Export(dt, liststring, "证书领取列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
  340. return RedirectToAction("MsgShow", "Common", new
  341. {
  342. msg = "导出成功!",
  343. url = Url.Content("~/ExaminationBatc/List").AddMenuParameter()
  344. });
  345. }
  346. [HttpPost]
  347. public ActionResult EmsExcel(string qpararms)
  348. {
  349. NpoiExcelHelper neh = new NpoiExcelHelper();
  350. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  351. var schoolyearID = Request.Form["ddlSchoolyear"].ParseStrTo<Guid>();
  352. var examinationBatchID = Request.Form["cgExaminationBatch"].ParseStrTo<Guid>();
  353. var examinationTypeID = Request.Form["cgExaminationType"].ParseStrTo<Guid>();
  354. var examinationProjectID = Request.Form["cgExaminationProject"].ParseStrTo<Guid>();
  355. var schoolAreaID = Request.Form["SchoolAreaID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolAreaID"].ParseStrTo<int>();
  356. var collegeID = Request.Form["CollegeID"].ParseStrTo<Guid>();
  357. var year = Request.Form["Years"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["Years"].ParseStrTo<int>();
  358. var classmajorID = Request.Form["ClassmajorID"].ParseStrTo<Guid>();
  359. var standardID = Request.Form["StandardID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["StandardID"].ParseStrTo<int>();
  360. var distributeTypeID = Request.Form["DistributeTypeID"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DistributeTypeID"].ParseStrTo<int>();
  361. var recordStatus = Request.Form["RecordStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["RecordStatus"].ParseStrTo<int>();
  362. var certisfierDistributeIDs = Request.Form["SelectedID"];
  363. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  364. List<Guid?> selectIDlist = new List<Guid?>();
  365. if (certisfierDistributeIDs != "" && certisfierDistributeIDs != null)
  366. {
  367. selectIDlist = certisfierDistributeIDs.SplitIDString();
  368. }
  369. var dt = ICertisfierDistributeService.GetList(configuretView, schoolyearID, examinationProjectID, collegeID, schoolAreaID, year, classmajorID, standardID, distributeTypeID, recordStatus, selectIDlist).Select(q =>
  370. new
  371. {
  372. q.Schoolyear,
  373. q.ProjectName,
  374. q.UserName,
  375. q.IDNumber,
  376. q.ContactPerson,
  377. q.ContactNo,
  378. q.Address,
  379. q.DeliveryNoteNo,
  380. }).ToTable();
  381. string[] liststring = {
  382. "学年学期","考试项目","姓名","证件号码","联系人","联系电话","地址","邮寄单号"};
  383. neh.Export(dt, liststring, "邮寄列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
  384. return RedirectToAction("MsgShow", "Common", new
  385. {
  386. msg = "导出成功!",
  387. url = Url.Content("~/ExaminationBatc/List").AddMenuParameter()
  388. });
  389. }
  390. /// <summary>
  391. /// Excel导入
  392. /// </summary>
  393. /// <param name="file"></param>
  394. /// <returns></returns>
  395. [HttpPost]
  396. public ActionResult Import(HttpPostedFileBase file)
  397. {
  398. try
  399. {
  400. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  401. {
  402. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  403. }
  404. Dictionary<string, string> cellheader = new Dictionary<string, string>
  405. {
  406. { "Schoolyear", "学年学期" },
  407. { "ProjectName", "考试项目" },
  408. { "UserName", "姓名" },
  409. { "IDNumber", "证件号码" },
  410. { "ContactPerson", "联系人" },
  411. { "ContactNo", "联系电话" },
  412. { "Address", "地址" },
  413. { "DeliveryNoteNo", "邮寄单号" },
  414. };
  415. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  416. string sourceWebPath = FileUploadHelper.UploadFile(file);
  417. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  418. List<CerificateView> errList = new List<CerificateView>();
  419. List<CerificateView> dataList = new List<CerificateView>();
  420. int? inCount = 0; //导入个数
  421. int? upCount = 0; //更新个数
  422. int? errCount = 0; //失败个数
  423. //导入
  424. ICertisfierDistributeService.Import(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  425. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  426. if (errList.Count() > 0)
  427. {
  428. //获取错误数据文件路径
  429. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "专业信息导入失败文件", sourcePhysicalPath));
  430. ViewBag.ErrorFile = errorWebPath;
  431. string Errinfo = string.Format("提示:{0}条导入成功,{1}条导入失败,点击查看。", upCount, errCount);
  432. ViewBag.operationTips = Errinfo;
  433. return RedirectToAction("MsgShow", "Common", new
  434. {
  435. WindowID = "none",
  436. msg = Errinfo,
  437. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  438. });
  439. }
  440. else
  441. {
  442. string successInfo = string.Format("提示:{0}条导入成功。", upCount);
  443. return RedirectToAction("MsgShow", "Common", new
  444. {
  445. WindowID = Request["WindowID"],
  446. msg = successInfo,
  447. url = Url.Action("List").AddMenuParameter()
  448. });
  449. }
  450. }
  451. catch (Exception ex)
  452. {
  453. return RedirectToAction("MsgShow", "Common", new
  454. {
  455. WindowID = "none",
  456. msg = "导入失败,原因:" + ex.Message,
  457. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  458. });
  459. }
  460. }
  461. [HttpGet]
  462. public ActionResult NumberImport(string errorFile, string operationTips)
  463. {
  464. ViewBag.ErrorFile = errorFile;
  465. if (string.IsNullOrEmpty(operationTips))
  466. {
  467. operationTips = "点击查看失败原因...";
  468. }
  469. ViewBag.operationTips = operationTips;
  470. return View();
  471. }
  472. /// <summary>
  473. /// 存放编号导入
  474. /// </summary>
  475. /// <param name="file"></param>
  476. /// <returns></returns>
  477. [HttpPost]
  478. public ActionResult NumberImport(HttpPostedFileBase file)
  479. {
  480. try
  481. {
  482. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  483. {
  484. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  485. }
  486. Dictionary<string, string> cellheader = new Dictionary<string, string>
  487. {
  488. { "Schoolyear", "学年学期" },
  489. { "ProjectName", "考试项目" },
  490. { "UserName", "姓名" },
  491. { "IDNumber", "证件号码" },
  492. { "SaveNo", "存放编号" }
  493. };
  494. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  495. string sourceWebPath = FileUploadHelper.UploadFile(file);
  496. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  497. List<CerificateView> errList = new List<CerificateView>();
  498. List<CerificateView> dataList = new List<CerificateView>();
  499. int? inCount = 0; //导入个数
  500. int? upCount = 0; //更新个数
  501. int? errCount = 0; //失败个数
  502. //导入
  503. ICertisfierDistributeService.NumberImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  504. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  505. if (errList.Count() > 0)
  506. {
  507. //获取错误数据文件路径
  508. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "专业信息导入失败文件", sourcePhysicalPath));
  509. ViewBag.ErrorFile = errorWebPath;
  510. string Errinfo = string.Format("提示:{0}条导入成功,{1}条导入失败,点击查看。", upCount, errCount);
  511. ViewBag.operationTips = Errinfo;
  512. return RedirectToAction("MsgShow", "Common", new
  513. {
  514. WindowID = "none",
  515. msg = Errinfo,
  516. url = Url.Action("NumberImport").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  517. });
  518. }
  519. else
  520. {
  521. string successInfo = string.Format("提示:{0}条导入成功。", upCount);
  522. return RedirectToAction("MsgShow", "Common", new
  523. {
  524. WindowID = Request["WindowID"],
  525. msg = successInfo,
  526. url = Url.Action("List").AddMenuParameter()
  527. });
  528. }
  529. }
  530. catch (Exception ex)
  531. {
  532. return RedirectToAction("MsgShow", "Common", new
  533. {
  534. WindowID = "none",
  535. msg = "导入失败,原因:" + ex.Message,
  536. url = Url.Action("NumberImport").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  537. });
  538. }
  539. }
  540. }
  541. }