123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Mvc;
- using Bowin.Common.Data;
- using Bowin.Common.Exceptions;
- using Bowin.Common.Utility;
- using Bowin.Web.Controls.Mvc;
- using EMIS.CommonLogic.AdministrativeOrgan;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.CommonLogic.TeacherManagement;
- using EMIS.Utility;
- using EMIS.ViewModel;
- using EMIS.ViewModel.TeacherManagement;
- using EMIS.Web.Controls;
- using System.Web;
- using System.IO;
- using System.Text;
- using Bowin.Common.DataTime;
- namespace EMIS.Web.Controllers.UserManagement
- {
- [Authorization]
- public class StaffController : Controller
- {
- public Lazy<IStaffServices> staffServices { get; set; }
- public Lazy<IUserServices> userServices { get; set; }
- public Lazy<ICampusServices> campusServices { get; set; }
- public Lazy<ICollegeServices> collegeServices { get; set; }
- public Lazy<IDepartmentServices> departmentServices { get; set; }
-
- /// <summary>
- /// 教师信息页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var userID = pararms.getExtraGuid("SaffDropdown");
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var departmentID = pararms.getExtraGuid("DepartmentDropdown");
- var isphotoUrl = pararms.getExtraInt("PhotoUrltmentDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("PhotoUrltmentDropdown");
- return base.Json(staffServices.Value.GetStaffViewGrid(configuretView, campusID, collegeID, departmentID, isphotoUrl, userID, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ListWithNoDataRange(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var userID = pararms.getExtraGuid("SaffDropdown");
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var departmentID = pararms.getExtraGuid("DepartmentDropdown");
- var isphotoUrl = pararms.getExtraInt("PhotoUrltmentDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("PhotoUrltmentDropdown");
- return base.Json(staffServices.Value.GetStaffViewGridWithNoDataRange(configuretView, campusID, collegeID, departmentID, isphotoUrl, userID, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ListForTeacherEdit(QueryParamsModel pararms)
- {
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var loginID = pararms.getExtraString("LoginID");
- var name = pararms.getExtraString("Name");
- return base.Json(staffServices.Value.GetStaffViewGrid(campusID, collegeID, loginID, name, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? userID)
- {
- ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
- StaffView staffView = new StaffView();
- if (userID.HasValue)
- staffView = staffServices.Value.GetStaffView(userID.Value);
- return View(staffView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="facultymajorView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(StaffView staffView)
- {
- try
- {
- var accepts = new List<string> { ".jpg" };
- var postedFile = Request.Files["PhotoUrl"];
- if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
- {
- throw new Exception("只允许上传.jpg格式的文件。");
- }
- string photoUrl = FileUploadHelper.UploadFile(postedFile);
- staffServices.Value.StaffAdd(staffView, photoUrl);
- 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()
- });
- }
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edits(Guid? userID)
- {
- ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
- StaffView staffView = new StaffView();
- if (userID.HasValue)
- staffView = staffServices.Value.GetStaffView(userID.Value);
- return View(staffView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="facultymajorView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edits(StaffView staffView)
- {
- try
- {
- var accepts = new List<string> { ".jpg" };
- var postedFile = Request.Files["PhotoUrl"];
- if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
- {
- throw new Exception("只允许上传.jpg格式的文件。");
- }
- string photoUrl = FileUploadHelper.UploadFile(postedFile);
- staffServices.Value.StaffAdd(staffView, photoUrl);
- 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()
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="facultymajorView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string userIDs)
- {
- try
- {
- List<Guid> list = new List<Guid>();
- for (int i = 0; i < userIDs.Split(',').Length; i++)
- {
- string id = userIDs.Split(',')[i];
- if (!string.IsNullOrEmpty(id))
- {
- Guid userID = new Guid(id);
- list.Add(userID);
- }
- }
- staffServices.Value.StaffDelete(list);
- 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 + "。");
- }
- }
-
- /// <summary>
- /// 添加更新前验证
- /// </summary>
- /// <param name="universityID"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Verification(Guid? userID, string Code, Guid? CollegeID, Guid? DepartmentID)
- {
- return Json(staffServices.Value.GetVerification(userID, Code, CollegeID, DepartmentID));
- }
- [HttpPost]
- public ActionResult DeletePhoto(Guid userID)
- {
- try
- {
- this.staffServices.Value.DeletePhoto(userID);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "删除成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "删除失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 获取教师信息
- /// </summary>
- [HttpPost]
- public ActionResult GetStaffDataBind(DropdownListBindType? bindType, Guid? userID)
- {
- List<DropdownListItem> list = null;
- if (userID == null)
- list = new List<DropdownListItem>();
- else
- list = staffServices.Value.GetListStaffView(userID).Select(x => new DropdownListItem { Text = x.Name, Value = x.UserID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 获取教师信息
- /// </summary>
- [HttpPost]
- public ActionResult GetAllStaffDataBind(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- return base.Json(staffServices.Value.GetAllStaffView(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 获取教师信息
- /// </summary>
- [HttpPost]
- public ActionResult GetDepartmentStaffDataBind(DropdownListBindType? bindType, Guid? departmentID)
- {
- List<DropdownListItem> list = null;
- if (departmentID == null)
- list = new List<DropdownListItem>();
- else
- list = staffServices.Value.GetStaffViewList(new ConfiguretView(), null, null, departmentID, null)
- .Select(x => new DropdownListItem { Text = x.Name, Value = x.UserID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 教师信息Excel导入
- /// </summary>
- /// <param name="errorFile"></param>
- /// <param name="operationTips"></param>
- /// <returns></returns>
- [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
- if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
- {
- throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
- }
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<StaffView> errList = new List<StaffView>();
- int errCount = 0;//失败条数
- int OkCount = 0;//成功条数
- string errorWebPath = "";
- string Errinfo = "";
- staffServices.Value.StaffImport(out errCount, out errList, out OkCount, sourcePhysicalPath,sourceWebPath,out errorWebPath,out Errinfo);
- System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
- if (errCount > 0)
- {
- ViewBag.ErrorFile = errorWebPath;
- ViewBag.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()
- });
- }
- }
- /// <summary>
- /// Excel导出
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
- var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
- var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
- var isphotoUrl = Request.Form["ChekBoxPhotoUrl"].ParseStrTo<int>();
- var dt = staffServices.Value.GetStaffViewList(configuretView, campusID, collegeID, departmentID, isphotoUrl).Select(x => new
- {
- x.StaffCode,
- x.Name,
- x.CampusCode,
- x.CampusName,
- x.CollegeNo,
- x.CollegeName,
- x.DepartmentCode,
- x.DepartmentName,
- BirthDate = x.BirthDate.HasValue == true ? x.BirthDate.Value.ToString("yyyy-MM-dd") : "",
- x.SexName,
- x.UsedName,
- x.NationName,
- x.Place,
- x.EducationCodeName,
- x.Telephone,
- x.OfficeTelephone,
- x.Mobile,
- x.Email,
- x.QQ,
- x.Nationality,
- x.HealthStateName,
- x.HousePhone,
- x.Address,
- x.Postcode,
- x.HomeAddress,
- x.NowAddress,
- x.Residence,
- x.Speciality,
- x.WeChatNum,
- x.ReligionName,
- x.TeacherTypeName,
- x.IncumbencyStateName,
- x.CertificatesTypeName,
- x.CertificatesNum,
- x.SituationName,
- x.LiteracyLevelsName,
- x.DegreeStateName,
- x.LearnPositionName,
- x.TitleName,
- x.PaymentLevelName,
- x.IsDualTeacherName,
- WorkDate = x.WorkDate.HasValue == true ? x.WorkDate.Value.ToString("yyyy-MM") : "",
- ComeSchoolDate = x.ComeSchoolDate.HasValue == true ? x.ComeSchoolDate.Value.ToString("yyyy-MM") : "",
- TeachingDate = x.TeachingDate.HasValue == true ? x.TeachingDate.Value.ToString("yyyy-MM") : "",
- x.Profile,
- x.Remarks
- }).ToTable();
- string[] liststring = { "教职工号", "姓名", RSL.Get("CampusCode"), RSL.Get("CampusName"), RSL.Get("CollegeCode"),
- RSL.Get("College"), "所在教研室代码", "所在教研室", "出生日期", "性别",
- "曾用名", "民族", "籍贯", "学历", "家庭电话", "办公室电话", "移动电话", "电子邮箱", "QQ",
- "国籍","健康状况", "住宅电话", "通信地址", "邮政编码", "家庭住址", "现住地址", "户口所在地",
- "特长", "微信号", "宗教信仰","教师类别", "在职状态", "证件类型", "证件号码", "任课状况",
- "文化程度", "学位状况", "授予学位", "职称", "课酬级别", "是否双师型教师", "参加工作年月",
- "来校日期", "从教年月", "简介", "备注" };
- neh.Export(dt, liststring, "教职工信息" + DateTime.Now.ToString("yyyyMMdd"));
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "导出成功。"
- });
- }
- }
- }
|