123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Bowin.Common.Data;
- using Bowin.Common.Utility;
- using Bowin.Web.Controls.Mvc;
- using EMIS.Web.Controls;
- using EMIS.Utility;
- using EMIS.Utility.FormValidate;
- using EMIS.ViewModel;
- using EMIS.ViewModel.SystemView;
- using EMIS.ViewModel.UniversityManage.TeacherManage;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.CommonLogic.UniversityManage.TeacherManage;
- namespace EMIS.Web.Controllers.UserManagement
- {
- [Authorization]
- public class UserController : Controller
- {
- public IUserServices UserServices { get; set; }
- public IUserInfoChangeServices UserInfoChangeServices { get; set; }
- public IParameterServices parameterServices { get; set; }
- public Lazy<IStaffServices> staffServices { get; set; }
- public object staffView { 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 campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var departmentID = pararms.getExtraGuid("DepartmentDropdown");
- var roleID = pararms.getExtraGuid("Role");
- var dataRange = pararms.getExtraInt("DataRange");
- var stauts = pararms.getExtraInt("Stauts");
- if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
- if (stauts == DropdownList.SELECT_ALL) stauts = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(UserServices.GetUserViewList(configuretView, campusID, collegeID, departmentID, roleID, dataRange, stauts, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 学生用户页面
- /// </summary>
- /// <returns></returns>
- public ActionResult StudentList()
- {
- return View();
- }
- /// <summary>
- /// 学生列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var educationID = pararms.getExtraInt("Education");
- var schoolYearID = pararms.getExtraInt("SchoolYear");
- var standardID = pararms.getExtraInt("Standard");
- var learnFormID = pararms.getExtraInt("Learningform");
- var classID = pararms.getExtraGuid("ClassmajorDropdown");
- var LearnSystem = pararms.getExtraString("DictionaryLearnSystem");
- if (educationID == DropdownList.SELECT_ALL) educationID = null;
- if (schoolYearID == DropdownList.SELECT_ALL) schoolYearID = null;
- if (standardID == DropdownList.SELECT_ALL) standardID = null;
- if (learnFormID == DropdownList.SELECT_ALL) learnFormID = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(UserServices.GetStudentUserViewList(configuretView, campusID, collegeID, educationID, schoolYearID, standardID, learnFormID, classID,LearnSystem, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- ///
- /// </summary>
- /// <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 roleID = Request.Form["Role"].ParseStrTo<Guid>();
- var dataRange = Request.Form["DataRange"].ParseStrTo<int>();
- if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- var dt = UserServices.GetUserViewList(configuretView, campusID, collegeID, departmentID, roleID, dataRange)
- .Select(x => new
- {
- x.LoginID,
- x.Name,
- x.SexName,
- x.CollegeName,
- x.RoleName,
- x.DataRangeName,
- x.RecordStatusName,
- x.CreateTime,
- x.ModifyTime
- }).ToTable();
- string[] liststring = { "用户名", "姓名", "性别", "院系所", "角色名称", "数据范围", "允许登录", "创建时间", "修改时间" };
- neh.Export(dt, liststring, "用户信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/User/List").AddMenuParameter()
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentExcel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- //避开全选值
- var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
- var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
- var educationID = Request.Form["Education"].ParseStrTo<int>();
- var schoolYearID = Request.Form["SchoolYear"].ParseStrTo<int>();
- var standardID = Request.Form["Standard"].ParseStrTo<int>();
- var learnFormID = Request.Form["Learningform"].ParseStrTo<int>();
- var classID = Request.Form["ClassmajorDropdown"].ParseStrTo<Guid>();
- var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString();
- if (educationID == DropdownList.SELECT_ALL) educationID = null;
- if (schoolYearID == DropdownList.SELECT_ALL) schoolYearID = null;
- if (standardID == DropdownList.SELECT_ALL) standardID = null;
- if (learnFormID == DropdownList.SELECT_ALL) learnFormID = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- var dt = UserServices.GetStudentUserViewList(configuretView, campusID, collegeID, educationID, schoolYearID,
- standardID, learnFormID, classID, LearnSystem)
- .Select(x => new
- {
- x.LoginID,
- x.Name,
- x.RoleName,
- x.ClassmajorName,
- x.RecordStatusDesc,
- x.Remarks,
- x.CreateTime,
- x.CreateUserName
- }).ToTable();
- string[] liststring = { "用户名", "用户名称", "角色类型", "在校班级", "是否可用", "备注", "创建时间", "创建人" };
- neh.Export(dt, liststring, "学生用户信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/User/StudentList").AddMenuParameter()
- });
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult BatchInitPassword(string userID,int type)
- {
- BatchInitPasswordView batchInitPasswordView = new BatchInitPasswordView();
- batchInitPasswordView.User = userID;
- var parameter=parameterServices.GetParameterValue(ViewModel.CF_ParameterType.TeacherInitPassword);
- if(type==1){
- parameter = parameterServices.GetParameterValue(ViewModel.CF_ParameterType.StudentInitPassword);
- }
- if (parameter == null)
- {
- batchInitPasswordView.BatchInt = false;
- }
- else
- {
- batchInitPasswordView.BatchInt = true;
- }
- batchInitPasswordView.type = type;
- return View(batchInitPasswordView);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="batchInitPasswordView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult BatchInitPassword(string userID, BatchInitPasswordView batchInitPasswordView)
- {
- //由于历史原因,目前先采取这种做法,后期再调整
- //batchInitPasswordView.User = userID;
- if (batchInitPasswordView.User != null && batchInitPasswordView.User != "student" && batchInitPasswordView.User != "staff")
- {
- try
- {
- List<Guid?> userid = batchInitPasswordView.User.SplitIDString();
- bool isChange = false;
- if (batchInitPasswordView.BatchInt == true)
- {
- isChange = true;
- }
- var pwd = batchInitPasswordView.Password;
- UserServices.BatchInitPassword(userid, isChange, pwd);
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "初始化成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "初始化失败!" + ex.Message
- });
- }
- }
- else
- {
- try
- {
- string pwd = batchInitPasswordView.Password;
- if (pwd != null && batchInitPasswordView.BatchInt == true)
- {
- pwd = pwd.MD5();
- }
- if (batchInitPasswordView.type == 0)
- {
- parameterServices.SaveTo(ViewModel.CF_ParameterType.TeacherInitPassword, pwd);
- }
- if (batchInitPasswordView.type == 1)
- {
- parameterServices.SaveTo(ViewModel.CF_ParameterType.StudentInitPassword, pwd);
- }
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存失败,原因:" + ex.Message + "!"
- });
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userIDList"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Usable(string userIDList)
- {
- try
- {
- UserServices.Usable(userIDList.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "启用成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "启用失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userIDList"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult UnUsable(string userIDList)
- {
- try
- {
- UserServices.UnUsable(userIDList.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "禁用成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "禁用失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <returns></returns>
- public ActionResult ModifyRole(Guid userID)
- {
- return View();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <returns></returns>
- public ActionResult DataRange(Guid userID)
- {
- return View();
- }
- /// <summary>
- /// 教师用户页面修改角色
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="roleIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult SaveRoles(Guid userID, string roleIDs)
- {
- try
- {
- UserServices.SaveUserRoles(userID, roleIDs.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="campusIDList"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult SaveUserCampus(Guid userID, string campusIDList)
- {
- try
- {
- UserServices.SaveUserCampus(userID, campusIDList.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="collegeIDList"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult SaveUserCollege(Guid userID, string collegeIDList)
- {
- try
- {
- UserServices.SaveUserCollege(userID, collegeIDList.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="departmentIDList"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult SaveUserDepartment(Guid userID, string departmentIDList)
- {
- try
- {
- UserServices.SaveUserDepartment(userID, departmentIDList.SplitIDString());
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetUserRoleList(Guid userID)
- {
- var roleViewList = UserServices.GetUserRolesView(userID);
- return Json(new JsonDataGridResult<RoleView> { rows = roleViewList, total = roleViewList.Count });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetUserRoleDropdownList(DropdownListBindType? bindType)
- {
- var user = CustomPrincipal.Current;
- var list = UserServices.GetUserRolesView(user.UserID).Select(x => new DropdownListItem { Text = x.RoleName, Value = x.RoleID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult UserInfoChange()
- {
- Guid? userID = null;
- var query = UserInfoChangeServices.GetStaffView(userID);
- return View(query);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="staffView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult UserInfoChange(StaffView staffView)
- {
- try
- {
- //string photoUrl = FileUploadHelper.UploadFile(Request.Files["PhotoUrl"]);
- staffServices.Value.StaffEdit(staffView, null);
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = "保存成功!",
- url = Url.Action("UserInfoChange").AddMenuParameter()
- });
- }
- catch (Exception ex)
- {
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = "保存失败,原因:" + ex.Message + "!",
- url = Url.Action("UserInfoChange").AddMenuParameter()
- });
- }
- }
- }
- }
|