ClassmajorController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.ViewModel;
  7. using EMIS.Web.Controls;
  8. using EMIS.CommonLogic.Specialtyclass;
  9. using EMIS.ViewModel.Specialtyclass;
  10. using EMIS.Entities;
  11. using Bowin.Common.Utility;
  12. using Bowin.Common.Data;
  13. using Bowin.Web.Controls.Mvc;
  14. using EMIS.CommonLogic.CalendarManage;
  15. using Bowin.Common.Exceptions;
  16. using EMIS.Utility;
  17. using System.Text;
  18. using EMIS.CommonLogic.DataCenterSynch;
  19. namespace EMIS.Web.Controllers.Specialtyclass
  20. {
  21. [Authorization]
  22. public class ClassmajorController : Controller
  23. {
  24. public IClassmajorServices ClassmajorServices { get; set; }
  25. public IClassmajorSynchServices ClassmajorSynchServices { get; set; }
  26. /// <summary>
  27. /// 班级信息页面
  28. /// </summary>
  29. /// <returns></returns>
  30. public ActionResult List()
  31. {
  32. return View();
  33. }
  34. /// <summary>
  35. /// 班级信息页面列表查询
  36. /// </summary>
  37. /// <param name="pararms"></param>
  38. /// <returns></returns>
  39. [HttpPost]
  40. public ActionResult List(QueryParamsModel pararms)
  41. {
  42. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  43. var schoolAreaID = pararms.getExtraInt("ddlSchoolArea") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlSchoolArea");
  44. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  45. var schoolyearID = pararms.getExtraInt("DictionarySchoolyear") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolyear");
  46. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  47. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  48. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  49. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  50. //年级专业
  51. var grademajorID = pararms.getExtraGuid("GrademajorComboGrid");
  52. //在校状态
  53. var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus");
  54. return base.Json(ClassmajorServices.GetClassmajorViewGrid(configuretView, schoolAreaID, collegeID, schoolyearID,
  55. standardID, educationID, learningformID, learnSystem, grademajorID,
  56. inSchoolStatus, (int)pararms.page, (int)pararms.rows));
  57. }
  58. /// <summary>
  59. /// 班级信息页面列表查询
  60. /// </summary>
  61. /// <param name="pararms"></param>
  62. /// <returns></returns>
  63. [HttpPost]
  64. public ActionResult ListForInschool(QueryParamsModel pararms)
  65. {
  66. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  67. var schoolAreaID = pararms.getExtraInt("ddlSchoolArea") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlSchoolArea");
  68. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  69. var schoolyearID = pararms.getExtraInt("DictionarySchoolyear") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolyear");
  70. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  71. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  72. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  73. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  74. //年级专业
  75. var grademajorID = pararms.getExtraGuid("GrademajorComboGrid");
  76. return base.Json(ClassmajorServices.GetInschoolClassmajorViewGrid(configuretView, schoolAreaID, collegeID, schoolyearID,
  77. standardID, educationID, learningformID, learnSystem, grademajorID,(int)pararms.page, (int)pararms.rows));
  78. }
  79. /// <summary>
  80. /// 查询对应的班级信息View(带毕业学期)
  81. /// </summary>
  82. /// <param name="pararms"></param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. public ActionResult ListForGraduateReport(QueryParamsModel pararms)
  86. {
  87. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  88. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  89. var schoolyearID = pararms.getExtraInt("DictionarySchoolyear") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolyear");
  90. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  91. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  92. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  93. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  94. //毕业学期
  95. var graduatingSemesterID = pararms.getExtraGuid("GraduatingSemesterDropdown");
  96. return base.Json(ClassmajorServices.GetClassmajorViewGridForGraduateReport(configuretView, collegeID, standardID,
  97. schoolyearID, educationID, learningformID, learnSystem, graduatingSemesterID, (int)pararms.page, (int)pararms.rows));
  98. }
  99. /// <summary>
  100. /// 查询对应的班级信息(带数据范围)
  101. /// </summary>
  102. /// <param name="bindType"></param>
  103. /// <param name="campusID"></param>
  104. /// <param name="collegeID"></param>
  105. /// <param name="educationID"></param>
  106. /// <param name="schoolYearID"></param>
  107. /// <param name="standardID"></param>
  108. /// <param name="learningformID"></param>
  109. /// <returns></returns>
  110. [HttpPost]
  111. public ActionResult BindDropdownList(DropdownListBindType? bindType, int? schoolAreaID, Guid? collegeID, int? educationID,
  112. int? schoolYearID, int? standardID, int? learningformID)
  113. {
  114. List<DropdownListItem> list = this.ClassmajorServices.GetClassmajorViewList(new ConfiguretView(), schoolAreaID, collegeID,
  115. schoolYearID, standardID, educationID, learningformID, null, null, null)
  116. .Select(x => new DropdownListItem
  117. {
  118. Text = x.Name,
  119. Value = x.ClassmajorID
  120. }).ToList();
  121. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  122. DropdownList.FormatDropdownItemList(dbt, list);
  123. return base.Json(list);
  124. }
  125. /// <summary>
  126. /// 查询对应的班级信息(无数据范围)
  127. /// </summary>
  128. /// <param name="bindType"></param>
  129. /// <param name="grademajorID"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. public ActionResult BindDropdownListByGrademajorID(DropdownListBindType? bindType, Guid? grademajorID)
  133. {
  134. List<DropdownListItem> list = this.ClassmajorServices.GetClassmajorList(grademajorID)
  135. .Select(x => new DropdownListItem
  136. {
  137. Text = x.Name,
  138. Value = x.ClassmajorID
  139. }).ToList();
  140. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  141. DropdownList.FormatDropdownItemList(dbt, list);
  142. return base.Json(list);
  143. }
  144. /// <summary>
  145. /// 查询对应的班级信息List(带数据范围)
  146. /// </summary>
  147. /// <param name="bindType"></param>
  148. /// <param name="collegeID"></param>
  149. /// <param name="year"></param>
  150. /// <param name="standardID"></param>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public ActionResult BindDropdownListByYearOrStandard(DropdownListBindType? bindType, Guid? collegeID,
  154. int? year, int? standardID)
  155. {
  156. List<DropdownListItem> list = this.ClassmajorServices.GetClassmajorList(collegeID, year, standardID)
  157. .Select(x => new DropdownListItem
  158. {
  159. Text = x.Name,
  160. Value = x.ClassmajorID
  161. }).ToList();
  162. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  163. DropdownList.FormatDropdownItemList(dbt, list);
  164. return base.Json(list);
  165. }
  166. /// <summary>
  167. /// 查询对应的班级信息List(无数据范围)
  168. /// </summary>
  169. /// <param name="bindType"></param>
  170. /// <param name="collegeID"></param>
  171. /// <param name="year"></param>
  172. /// <param name="standardID"></param>
  173. /// <returns></returns>
  174. [HttpPost]
  175. public ActionResult BindDropdownListByYearOrStandardWithoutRange(DropdownListBindType? bindType, Guid? collegeID,
  176. int? year, int? standardID)
  177. {
  178. List<DropdownListItem> list = this.ClassmajorServices.GetClassmajorListWithoutRange(collegeID, year, standardID)
  179. .Select(x => new DropdownListItem
  180. {
  181. Text = x.Name,
  182. Value = x.ClassmajorID
  183. }).ToList();
  184. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  185. DropdownList.FormatDropdownItemList(dbt, list);
  186. return base.Json(list);
  187. }
  188. /// <summary>
  189. /// 复制新增
  190. /// </summary>
  191. /// <param name="classmajorID"></param>
  192. /// <returns></returns>
  193. public ActionResult CopyAdd(Guid classmajorID)
  194. {
  195. ClassmajorView classmajorView = new ClassmajorView();
  196. classmajorView = ClassmajorServices.GetClassmajorView(classmajorID);
  197. return View("Edit", classmajorView);
  198. }
  199. /// <summary>
  200. /// 复制新增
  201. /// </summary>
  202. /// <param name="classmajorView"></param>
  203. /// <returns></returns>
  204. [HttpPost]
  205. public ActionResult CopyAdd(ClassmajorView classmajorView)
  206. {
  207. classmajorView.ClassmajorID = Guid.Empty;
  208. return this.Edit(classmajorView);
  209. }
  210. /// <summary>
  211. /// 编辑(新增、修改,业务主键:班级编号或班级名称唯一)
  212. /// </summary>
  213. /// <param name="classmajorID"></param>
  214. /// <returns></returns>
  215. [HttpGet]
  216. public ActionResult Edit(Guid? classmajorID)
  217. {
  218. //临时性加参数控制、屏蔽列表进入无保存按钮权限
  219. ViewBag.Type = Request.Params["Type"];
  220. ClassmajorView classmajorView = new ClassmajorView();
  221. if (classmajorID.HasValue && classmajorID != Guid.Empty)
  222. {
  223. classmajorView = ClassmajorServices.GetClassmajorView(classmajorID);
  224. }
  225. else
  226. {
  227. //默认班级序号为1
  228. classmajorView.ClassNum = 1;
  229. }
  230. return View(classmajorView);
  231. }
  232. /// <summary>
  233. /// 编辑(新增、修改,业务主键:班级编号或班级名称唯一)
  234. /// </summary>
  235. /// <param name="classmajorView"></param>
  236. /// <returns></returns>
  237. [HttpPost]
  238. public ActionResult Edit(ClassmajorView classmajorView)
  239. {
  240. try
  241. {
  242. ClassmajorServices.ClassmajorEdit(classmajorView);
  243. return Json(new ReturnMessage()
  244. {
  245. IsSuccess = true,
  246. Message = "保存成功。"
  247. });
  248. }
  249. catch (Exception ex)
  250. {
  251. return Json(new ReturnMessage()
  252. {
  253. IsSuccess = false,
  254. Message = "保存失败,原因:" + ex.Message
  255. });
  256. }
  257. }
  258. /// <summary>
  259. /// 班级复制(批量添加)
  260. /// </summary>
  261. /// <returns></returns>
  262. public ActionResult BatchAdd()
  263. {
  264. return View();
  265. }
  266. /// <summary>
  267. /// 班级复制(批量添加)
  268. /// </summary>
  269. /// <param name="classmajorView"></param>
  270. /// <returns></returns>
  271. [HttpPost]
  272. public ActionResult BatchAdd(ClassmajorView classmajorView)
  273. {
  274. try
  275. {
  276. var addReturn = ClassmajorServices.ClassmajorBatchAdd(classmajorView);
  277. return Json(new ReturnMessage()
  278. {
  279. IsSuccess = true,
  280. Message = "添加成功:" + addReturn
  281. });
  282. }
  283. catch (Exception ex)
  284. {
  285. return Json(new ReturnMessage()
  286. {
  287. IsSuccess = false,
  288. Message = "添加失败,原因:" + ex.Message
  289. });
  290. }
  291. }
  292. /// <summary>
  293. /// 删除
  294. /// </summary>
  295. /// <param name="classmajorIDs"></param>
  296. /// <returns></returns>
  297. [HttpPost]
  298. public ActionResult Delete(string classmajorIDs)
  299. {
  300. try
  301. {
  302. List<Guid?> list = classmajorIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  303. .Select(x => (Guid?)new Guid(x)).ToList();
  304. ClassmajorServices.ClassmajorDelete(list);
  305. return base.Json("删除成功。");
  306. }
  307. catch (Exception ex)
  308. {
  309. string mge = ex.Message;
  310. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  311. if (num != null)
  312. {
  313. if (num.Number == 547)
  314. {
  315. mge = "请先删除所有关联的数据,如:新生名单、学生信息等";
  316. }
  317. }
  318. return base.Json("删除失败,原因:" + mge);
  319. }
  320. }
  321. /// <summary>
  322. /// 查询班级信息学生名单
  323. /// </summary>
  324. /// <returns></returns>
  325. public ActionResult ClassStudentListView()
  326. {
  327. return View();
  328. }
  329. /// <summary>
  330. /// 查询班级信息学生名单
  331. /// </summary>
  332. /// <param name="pararms"></param>
  333. /// <returns></returns>
  334. [HttpPost]
  335. public ActionResult ClassStudentListView(QueryParamsModel pararms)
  336. {
  337. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  338. var classmajorID = Request["classmajorID"].ParseStrTo<Guid>();
  339. int? inSchoolStatus = Request["DictionaryInschoolStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request["DictionaryInschoolStatus"].ParseStrTo<int>();
  340. return Json(ClassmajorServices.GetBaseStudentViewGrid(configuretView, classmajorID,
  341. inSchoolStatus, (int)pararms.page, (int)pararms.rows));
  342. }
  343. /// <summary>
  344. /// Excel导出
  345. /// </summary>
  346. /// <param name="pararms"></param>
  347. /// <returns></returns>
  348. [HttpPost]
  349. public ActionResult Excel()
  350. {
  351. NpoiExcelHelper neh = new NpoiExcelHelper();
  352. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  353. var schoolAreaID = Request.Form["ddlSchoolArea"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ddlSchoolArea"].ParseStrTo<int>();
  354. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  355. var schoolyearID = Request.Form["DictionarySchoolyear"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolyear"].ParseStrTo<int>();
  356. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  357. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  358. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  359. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  360. //年级专业
  361. var grademajorID = Request.Form["GrademajorComboGrid"].ParseStrTo<Guid>();
  362. //在校状态
  363. var inSchoolStatus = Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>();
  364. var dt = ClassmajorServices.GetClassmajorViewList(configuretView, schoolAreaID, collegeID, schoolyearID,
  365. standardID, educationID, learningformID, learnSystem, grademajorID, inSchoolStatus)
  366. .Select(x => new
  367. {
  368. x.No,
  369. x.Name,
  370. x.ClassNum,
  371. x.GrademajorName,
  372. x.SchoolyearID,
  373. x.StandardCode,
  374. x.StandardID,
  375. x.StandardName,
  376. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  377. x.EducationName,
  378. x.LearningformName,
  379. x.GraduatingSemesterCode,
  380. x.CollegeCode,
  381. x.CollegeName,
  382. x.UserName,
  383. x.AssistantUserName,
  384. x.StudentCount,
  385. x.Remark
  386. }).ToTable();
  387. string[] liststring = {
  388. "班级编号", "班级名称", "班序", "年级专业名称", "年级", "专业代码",
  389. "专业ID(Value)", "专业名称", "学制",RSL.Get("EducationID"),
  390. "学习形式", "毕业学期", RSL.Get("CollegeCode"),
  391. RSL.Get("College"), "班主任", "辅助员", "人数", "备注"
  392. };
  393. var title = "班级信息";
  394. if (inSchoolStatus == (int)CF_INOrOutSchoolStatus.No)
  395. {
  396. title = "班级信息(非在校)";
  397. }
  398. if (inSchoolStatus == (int)CF_INOrOutSchoolStatus.Yes)
  399. {
  400. title = "班级信息(在校)";
  401. }
  402. neh.Export(dt, liststring, title + DateTime.Now.ToString("yyyyMMdd"));
  403. return Json(new ReturnMessage()
  404. {
  405. IsSuccess = true,
  406. Message = "导出成功。"
  407. });
  408. }
  409. /// <summary>
  410. /// 班级学生明细Excel导出
  411. /// </summary>
  412. /// <param name="pararms"></param>
  413. /// <returns></returns>
  414. [HttpPost]
  415. public ActionResult Excel_ClassStudent()
  416. {
  417. NpoiExcelHelper neh = new NpoiExcelHelper();
  418. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  419. var classmajorID = Request["classmajorID"].ParseStrTo<Guid>();
  420. int? inSchoolStatus = Request["DictionaryInschoolStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request["DictionaryInschoolStatus"].ParseStrTo<int>();
  421. var dt = ClassmajorServices.GetBaseStudentViewList(configuretView, classmajorID, inSchoolStatus)
  422. .Select(x => new
  423. {
  424. x.LoginID,
  425. x.UserName,
  426. x.SexName,
  427. x.InSchoolStatusName,
  428. x.StudentStatusName,
  429. x.ClassmajorCode,
  430. x.ClassmajorName,
  431. x.SchoolyearID,
  432. x.GrademajorCode,
  433. x.GrademajorName,
  434. x.FacultymajorCode,
  435. x.FacultymajorName
  436. }).ToTable();
  437. string[] liststring = {
  438. "学号", "姓名", "性别", "在校状态", "学籍状态",
  439. "班级编号", "班级名称", "年级","年级专业编号", "年级专业名称",
  440. "院系专业编号", "院系专业名称"
  441. };
  442. var title = "班级学生信息";
  443. if (inSchoolStatus == (int)CF_INOrOutSchoolStatus.No)
  444. {
  445. title = "班级学生信息(非在校)";
  446. }
  447. if (inSchoolStatus == (int)CF_INOrOutSchoolStatus.Yes)
  448. {
  449. title = "班级学生信息(在校)";
  450. }
  451. neh.Export(dt, liststring, title + DateTime.Now.ToString("yyyyMMdd"));
  452. return Json(new ReturnMessage()
  453. {
  454. IsSuccess = true,
  455. Message = "导出成功。"
  456. });
  457. }
  458. /// <summary>
  459. /// Excel导入
  460. /// </summary>
  461. /// <param name="errorFile"></param>
  462. /// <param name="operationTips"></param>
  463. /// <returns></returns>
  464. [HttpGet]
  465. public ActionResult Import(string errorFile, string operationTips)
  466. {
  467. ViewBag.ErrorFile = errorFile;
  468. if (string.IsNullOrEmpty(operationTips))
  469. {
  470. operationTips = "点击查看失败原因...";
  471. }
  472. ViewBag.operationTips = operationTips;
  473. return View();
  474. }
  475. /// <summary>
  476. /// Excel导入
  477. /// </summary>
  478. /// <param name="file"></param>
  479. /// <returns></returns>
  480. [HttpPost]
  481. public ActionResult Import(HttpPostedFileBase file)
  482. {
  483. try
  484. {
  485. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  486. {
  487. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  488. }
  489. Dictionary<string, string> cellheader = new Dictionary<string, string>
  490. {
  491. { "No", "班级编号" },
  492. { "Name", "班级名称" },
  493. { "Abbreviation", "简称" },
  494. { "EnglishName", "英文名称" },
  495. { "GrademajorCode", "年级专业编号" },
  496. { "ClassNumStr", "班序" },
  497. { "UserName", "班主任" },
  498. { "AssistantUserName", "辅导员" },
  499. { "Fixedclassroom", "固定教室" },
  500. { "Remark", "备注" },
  501. { "ErrorMessage", "未导入原因" }
  502. };
  503. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  504. string sourceWebPath = FileUploadHelper.UploadFile(file);
  505. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  506. List<ClassmajorView> errList = new List<ClassmajorView>();
  507. List<ClassmajorView> dataList = new List<ClassmajorView>();
  508. int? inCount = 0; //导入个数
  509. int? upCount = 0; //更新个数
  510. int? errCount = 0; //失败个数
  511. //导入
  512. ClassmajorServices.ClassmajorImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  513. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  514. if (errList.Count() > 0)
  515. {
  516. //获取错误数据文件路径
  517. string errorWebPath = string.Format("{0}", NpoiExcelHelper
  518. .EntityListToExcel2003(cellheader, errList, "班级信息导入失败文件", sourcePhysicalPath));
  519. ViewBag.ErrorFile = errorWebPath;
  520. string Errinfo = string.Format("提示:{0}条班级信息导入成功,{1}条班级信息更新成功,{2}条班级信息导入失败,点击查看。",
  521. inCount, upCount, errCount);
  522. ViewBag.operationTips = Errinfo;
  523. return RedirectToAction("MsgShow", "Common", new
  524. {
  525. WindowID = "none",
  526. msg = Errinfo,
  527. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips="
  528. + Errinfo + "&WindowID=" + Request["WindowID"]
  529. });
  530. }
  531. else
  532. {
  533. string successInfo = string.Format("提示:{0}条班级信息导入成功,{1}条班级信息更新成功。", inCount, upCount);
  534. return RedirectToAction("MsgShow", "Common", new
  535. {
  536. WindowID = Request["WindowID"],
  537. msg = successInfo,
  538. url = Url.Action("List").AddMenuParameter()
  539. });
  540. }
  541. }
  542. catch (Exception ex)
  543. {
  544. return RedirectToAction("MsgShow", "Common", new
  545. {
  546. WindowID = "none",
  547. msg = "导入失败,原因:" + ex.Message,
  548. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  549. });
  550. }
  551. }
  552. [HttpPost]
  553. public ActionResult Synchr()
  554. {
  555. try
  556. {
  557. ClassmajorSynchServices.Synchr();
  558. return Json(new ReturnMessage { IsSuccess = true, Message = "同步成功。" });
  559. }
  560. catch (Exception ex)
  561. {
  562. return Json(new ReturnMessage { IsSuccess = false, Message = "同步失败:" + ex.Message });
  563. }
  564. }
  565. }
  566. }