using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using Bowin.Common.Data; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.Utility; using EMIS.Web.Controls; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.TeacherManage; using EMIS.CommonLogic.UniversityManage.TeacherManage; namespace EMIS.Web.Controllers.UniversityManage.TeacherManage { [Authorization] public class StaffController : Controller { public Lazy staffServices { get; set; } /// /// 教师信息页面 /// /// public ActionResult List() { return View(); } /// /// 教师信息页面列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); var collegeID = pararms.getExtraGuid("CollegeDropdown"); var departmentID = pararms.getExtraGuid("DepartmentDropdown"); var isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown"); var teacherTypeID = pararms.getExtraInt("DictionaryTeacherType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeacherType"); var incumbencyState = pararms.getExtraInt("DictionaryIncumbencyState") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIncumbencyState"); var titleID = pararms.getExtraInt("DictionaryTitle") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTitle"); var isDualTeacher = pararms.getExtraInt("IsDualTeacherDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDualTeacherDropdown"); return base.Json(staffServices.Value.GetStaffViewGrid(configuretView, campusID, collegeID, departmentID, isPhotoUrl, teacherTypeID, incumbencyState, titleID, isDualTeacher, (int)pararms.page, (int)pararms.rows)); } /// /// 教师信息页面列表查询(无数据范围) /// /// /// [HttpPost] public ActionResult ListWithNoDataRange(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); var collegeID = pararms.getExtraGuid("CollegeDropdown"); var departmentID = pararms.getExtraGuid("DepartmentDropdown"); var isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown"); var teacherTypeID = pararms.getExtraInt("DictionaryTeacherType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeacherType"); var incumbencyState = pararms.getExtraInt("DictionaryIncumbencyState") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIncumbencyState"); var titleID = pararms.getExtraInt("DictionaryTitle") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTitle"); var isDualTeacher = pararms.getExtraInt("IsDualTeacherDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDualTeacherDropdown"); return base.Json(staffServices.Value.GetStaffViewGridWithNoDataRange(configuretView, campusID, collegeID, departmentID, isPhotoUrl, teacherTypeID, incumbencyState, titleID, isDualTeacher, (int)pararms.page, (int)pararms.rows)); } /// /// 教师信息列表 /// /// /// [HttpPost] public ActionResult ListForTeacherEdit(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(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(configuretView, campusID, collegeID, loginID, name, (int)pararms.page, (int)pararms.rows)); } /// /// 教师信息查询 /// /// /// /// [HttpPost] public ActionResult GetStaffDataBind(DropdownListBindType? bindType, Guid? userID) { List list = new List(); 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); } /// /// 教师信息查询 /// /// /// [HttpPost] public ActionResult GetAllStaffDataBind(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); return base.Json(staffServices.Value.GetAllStaffView(configuretView, (int)pararms.page, (int)pararms.rows)); } /// /// 教师信息查询 /// /// /// /// [HttpPost] public ActionResult GetDepartmentStaffDataBind(DropdownListBindType? bindType, Guid? departmentID) { List list = new List(); list = staffServices.Value.GetStaffViewList(new ConfiguretView(), null, null, departmentID, null, null, null, null, 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); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid userID) { StaffView staffView = new StaffView(); staffView = staffServices.Value.GetStaffView(userID); return View("Edit", staffView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(StaffView staffView) { staffView.UserID = Guid.Empty; return this.Edit(staffView); } /// /// 编辑、复制新增(新增、修改,业务主键:教职工号或证件号码) /// /// /// /// [HttpGet] public ActionResult Edit(Guid? newUserID, string type) { StaffView staffView = new StaffView(); if (newUserID.HasValue && newUserID != Guid.Empty) { staffView = staffServices.Value.GetStaffView(newUserID); if (type == "copyAdd") { staffView.UserID = Guid.Empty; staffView.StaffCode = null; staffView.Name = null; staffView.CertificatesType = (int)CF_CertificatesType.IdCrad; staffView.CertificatesNum = null; staffView.CollegeID = null; staffView.DepartmentID = null; staffView.PhotoUrl = null; } } else { staffView.NationID = (int)CF_Nation.Han; staffView.PoliticsID = (int)CF_Politics.YouthLeague; staffView.CertificatesType = (int)CF_CertificatesType.IdCrad; staffView.TeacherTypeID = (int)CF_TeacherType.Internal; staffView.IncumbencyState = (int)CF_IncumbencyState.Incumbency; staffView.HealthStateID = (int)CF_HealthState.Healthy; } return View(staffView); } /// /// 编辑、复制新增(新增、修改,业务主键:教职工号或证件号码) /// /// /// [HttpPost] public ActionResult Edit(StaffView staffView) { try { var accepts = new List { ".jpg", ".jpeg", ".png", ".bmp" }; var postedFile = Request.Files["PhotoUrl"]; if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower())) { throw new Exception("只允许上传.jpg、.jpeg、.png、.bmp格式的文件。"); } string photoUrl = FileUploadHelper.UploadFile(postedFile); staffServices.Value.StaffEdit(staffView, photoUrl); return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = "保存成功。", url = Url.Action("List").AddMenuParameter() }); } catch (Exception ex) { return RedirectToAction("MsgShowAndOpen", "Common", new { WindowID = Request["WindowID"], msg = "保存失败,原因:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string userIDs) { try { List list = userIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); staffServices.Value.StaffDelete(list); return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" }); } 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(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge }); } } /// /// 验证 /// /// /// /// [HttpPost] public ActionResult Verification(Guid? collegeID, Guid? departmentID) { return Json(staffServices.Value.GetVerification(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 }); } } /// /// 删除照片(批量删除) /// /// /// [HttpPost] public ActionResult PicDelete(string userIDs) { try { List list = userIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); staffServices.Value.PicDelete(list); return Json(new ReturnMessage() { IsSuccess = true, Message = "删除照片成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "删除照片失败:" + ex.Message }); } } /// /// 导入照片 /// /// [HttpGet] public ActionResult PicImport() { return View(); } /// /// 导入照片 /// /// /// /// [HttpPost] public ActionResult PicImport(HttpPostedFileBase file, string importPicType) { try { if (file.ContentLength <= 0) { throw new Exception("请选择你要上传的照片(注:格式为zip或rar的压缩包文件)。"); } var acceptFileExtensions = new[] { ".zip", ".rar" }; var p = Path.GetExtension(file.FileName); if (!acceptFileExtensions.Contains(p)) { throw new Exception("格式错误,只允许上传zip或rar格式的压缩包文件。"); } var photoPaths = FileUploadHelper.UploadFileAndExtractFile(file); if (photoPaths.Count <= 0) { throw new Exception("压缩包中没有相关格式的文件。"); } List listphotoPaths = new List(); var acceptPicExtensions = new[] { ".jpg", ".jpeg", ".png", ".bmp" }; foreach (var path in photoPaths) { string pathName = Path.GetExtension(path).ToLower(); if (acceptPicExtensions.Contains(pathName)) { listphotoPaths.Add(path); } //{ // throw new Exception("压缩包中含有不支持的照片格式。"); //} //if (!acceptPicExtensions.Contains(Path.GetExtension(path))) //{ // throw new Exception("压缩包中含有不支持的照片格式。"); //} } staffServices.Value.StaffPicImport(listphotoPaths, importPicType); return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = "导入照片成功。", url = Url.Action("List").AddMenuParameter() }); } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { WindowID = "none", msg = "导入照片失败,原因:" + ex.Message, url = Url.Action("PicImport").AddMenuParameter() + "&WindowID=" + Request["WindowID"] }); } } /// /// Excel导入 /// /// /// /// [HttpGet] public ActionResult Import(string errorFile, string operationTips) { ViewBag.ErrorFile = errorFile; if (string.IsNullOrEmpty(operationTips)) { operationTips = "点击查看失败原因..."; } ViewBag.operationTips = operationTips; return View(); } /// /// Excel导入 /// /// /// [HttpPost] public ActionResult Import(HttpPostedFileBase file) { try { if (!NpoiExcelHelper.GetIsCompatible(file.FileName)) { throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。"); } Dictionary cellheader = new Dictionary { { "StaffCode", "教职工号" }, { "Name", "姓名" }, { "UsedName", "曾用名" }, { "SexStr", "性别" }, { "BirthDateStr", "出生日期" }, { "NationStr", "民族" }, { "PoliticsStr", "政治面貌" }, { "CollegeName", RSL.Get("College") }, { "DepartmentName", "所属教研室" }, { "CertificatesTypeStr", "证件类型" }, { "CertificatesNum", "证件号码" }, { "TeacherTypeStr", "教师类型" }, { "IncumbencyStateStr", "在职状态" }, { "SituationStr", "任课状况" }, { "TitleStr", "职称" }, { "LiteracyLevelStr", "文化程度" }, { "LearnPositionStr", "学位" }, { "IsDualTeacherStr", "是否双师型" }, { "PaymentLevelStr", "课酬级别" }, { "Nationality", "国籍" }, { "Place", "籍贯" }, { "WorkDateStr", "参加工作年月" }, { "ComeSchoolDateStr", "来校年月" }, { "Email", "电子邮箱" }, { "ZIPCode", "邮政编码" }, { "WeChatNum", "微信号" }, { "QQ", "QQ" }, { "Telephone", "家庭电话" }, { "OfficeTelephone", "办公电话" }, { "HousePhone", "住宅电话" }, { "Mobile", "移动电话" }, { "HealthStateStr", "健康状况" }, { "ReligionStr", "宗教信仰" }, { "Speciality", "特长" }, { "Account", "银行卡号" }, { "Residence", "户口所在地" }, { "HomeAddress", "家庭住址" }, { "Address", "通信地址" }, { "NowAddress", "现住地址" }, { "Profile", "简介" }, { "Remark", "备注" }, { "ErrorMessage", "未导入原因" } }; StringBuilder errorMsg = new StringBuilder(); // 错误信息 string sourceWebPath = FileUploadHelper.UploadFile(file); var sourcePhysicalPath = Server.MapPath(sourceWebPath); List errList = new List(); List dataList = new List(); int? inCount = 0; //导入个数 int? upCount = 0; //更新个数 int? errCount = 0; //失败个数 //导入 staffServices.Value.StaffImport(cellheader, out inCount, out upCount, out errList, out errCount, 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}条教师信息更新成功,{2}条教师信息导入失败,点击查看。", inCount, upCount, errCount); ViewBag.operationTips = Errinfo; return RedirectToAction("MsgShow", "Common", new { WindowID = "none", msg = Errinfo, url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"] }); } else { string successInfo = string.Format("提示:{0}条教师信息导入成功,{1}条教师信息更新成功。", inCount, upCount); return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = successInfo, url = Url.Action("List").AddMenuParameter() }); } } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { WindowID = "none", msg = "导入失败,原因:" + ex.Message, url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"] }); } } /// /// 教师对应的角色信息 /// /// public ActionResult RoleList() { return View(); } /// /// 教师对应的角色信息 /// /// /// [HttpPost] public ActionResult RoleList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var userID = Request["userID"].ParseStrTo(); var roleID = pararms.getExtraGuid("RoleDropdown"); var dataRange = pararms.getExtraInt("DictionaryDataRange") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryDataRange"); var roleStatus = pararms.getExtraInt("DictionaryRoleStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryRoleStatus"); return base.Json(staffServices.Value.GetRoleListViewGrid(configuretView, userID, roleID, dataRange, roleStatus, (int)pararms.page, (int)pararms.rows)); } /// /// 教师对应的角色信息Excel导出 /// /// [HttpPost] public ActionResult RoleListExcel() { return null; } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var campusID = Request.Form["CampusDropdown"].ParseStrTo(); var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo(); var isPhotoUrl = Request.Form["IsPhotoUrlDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsPhotoUrlDropdown"].ParseStrTo(); var teacherTypeID = Request.Form["DictionaryTeacherType"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryTeacherType"].ParseStrTo(); var incumbencyState = Request.Form["DictionaryIncumbencyState"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIncumbencyState"].ParseStrTo(); var titleID = Request.Form["DictionaryTitle"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryTitle"].ParseStrTo(); var isDualTeacher = Request.Form["IsDualTeacherDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsDualTeacherDropdown"].ParseStrTo(); var dt = staffServices.Value.GetStaffViewList(configuretView, campusID, collegeID, departmentID, isPhotoUrl, teacherTypeID, incumbencyState, titleID, isDualTeacher) .Select(x => new { x.StaffCode, x.Name, x.UsedName, x.SexName, BirthDate = x.BirthDate.HasValue ? x.BirthDate.Value.ToString("yyyy-MM-dd") : "", x.NationName, x.PoliticsName, x.CampusCode, x.CampusName, x.CollegeNo, x.CollegeName, x.DepartmentCode, x.DepartmentName, x.CertificatesTypeName, x.CertificatesNum, x.TeacherTypeName, x.IncumbencyStateName, x.SituationName, x.TitleName, x.LiteracyLevelName, x.LearnPositionName, x.IsDualTeacherName, x.PaymentLevelName, x.Nationality, x.Place, WorkDate = x.WorkDate.HasValue ? x.WorkDate.Value.ToString("yyyy-MM") : "", ComeSchoolDate = x.ComeSchoolDate.HasValue ? x.ComeSchoolDate.Value.ToString("yyyy-MM") : "", x.Email, x.ZIPCode, x.WeChatNum, x.QQ, x.Telephone, x.OfficeTelephone, x.HousePhone, x.Mobile, x.HealthStateName, x.ReligionName, x.Speciality, x.Account, x.Residence, x.HomeAddress, x.Address, x.NowAddress, x.PhotoUrl, x.Profile, x.RoleCount, x.AccountStatusName, x.Remark }).ToTable(); string[] liststring = { "教职工号", "姓名", "曾用名", "性别", "出生日期", "民族", "政治面貌", RSL.Get("CampusCode"), RSL.Get("Campus"), RSL.Get("CollegeCode"), RSL.Get("College"), "所属教研室代码", "所属教研室", "证件类型", "证件号码", "教师类型", "在职状态", "任课状况", "职称", "文化程度", "学位", "是否双师型", "课酬级别", "国籍", "籍贯", "参加工作年月", "来校年月", "电子邮箱", "邮政编码", "微信号", "QQ", "家庭电话", "办公电话", "住宅电话", "移动电话", "健康状况", "宗教信仰", "特长", "银行卡号", "户口所在地", "家庭住址", "通信地址", "现住地址", "照片地址", "简介", "角色数", "帐号状态", "备注" }; neh.Export(dt, liststring, "教职工信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }