123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data;
- using System.Reflection;
- using System.Web.Mvc;
- using Autofac;
- using Bowin.Web.Controls.Mvc;
- using Bowin.Common;
- using Bowin.Common.Utility;
- using EMIS.Utility;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.WorkflowManage;
- using EMIS.ViewModel.AccountManage;
- using EMIS.CommonLogic.StudentManage.StudentProfile;
- using EMIS.CommonLogic.CalendarManage;
- using EMIS.CommonLogic.SystemServices;
- namespace EMIS.Web.Controls
- {
- public static class BaseExtensions
- {
- /// <summary>
- /// 查询用户字典信息
- /// </summary>
- public static void GetContextUser()
- {
- FormsAuthenticationHelper fahelper = new FormsAuthenticationHelper();
-
- var cookieName = EMIS.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- fahelper.AuthenticateRequest(HttpContext.Current, cookieName, Const.LOCAL_AUTH_EXCEPTURL);
- }
- /// <summary>
- /// 查询星期下拉列表
- /// </summary>
- public static List<DropdownListItem> WeekdayDropdownListItemList
- {
- get
- {
- return WeekHelper.WeekDictionary.OrderBy(x => (x.Key == 0 ? 7 : x.Key))
- .Select(x => new DropdownListItem
- {
- Text = x.Value,
- Value = x.Key
- }).ToList();
- }
- }
- /// <summary>
- /// 查询当前启用校历对应的学年学期ID(主键ID)
- /// </summary>
- /// <returns></returns>
- public static Guid GetCurrentSchoolYearID()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var schoolYearView = SchoolYearServices.GetCurrentSchoolYear();
- return schoolYearView.SchoolYearID.Value;
- }
- }
- /// <summary>
- /// 查询当前启用校历对应的学年学期Code(学年学期Code)
- /// </summary>
- /// <returns></returns>
- public static string GetCurrentSchoolYearCode()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var schoolYearView = SchoolYearServices.GetCurrentSchoolYear();
- return schoolYearView.Code;
- }
- }
- /// <summary>
- ///查询当前启用校历对应的下一个学年学期ID(主键ID)
- /// </summary>
- /// <returns></returns>
- public static Guid GetNextSchoolYearID()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var nextSchoolYear = SchoolYearServices.GetNextSchoolYear();
- return nextSchoolYear.SchoolYearID.Value;
- }
- }
- /// <summary>
- /// 查询当前启用校历对应的下一个学年学期Code(学年学期Code)
- /// </summary>
- /// <returns></returns>
- public static string GetNextSchoolYearCode()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var nextSchoolYear = SchoolYearServices.GetNextSchoolYear();
- return nextSchoolYear.Code;
- }
- }
- /// <summary>
- /// 查询当前启用校历对应的学年(学年)
- /// </summary>
- /// <returns></returns>
- public static int? GetCurrentYearID()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var schoolYear = SchoolYearServices.GetCurrentSchoolYear();
- return schoolYear.Years;
- }
- }
- /// <summary>
- /// 查询当前启用校历的对应的学年的下一学年(学年)
- /// </summary>
- /// <returns></returns>
- public static int? GetNextYearID()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var currentSchoolYear = SchoolYearServices.GetCurrentSchoolYear();
- var nextSchoolYear = SchoolYearServices.GetNextSchoolYear();
- if (nextSchoolYear.Years <= currentSchoolYear.Years)
- {
- return nextSchoolYear.Years + 1;
- }
- else
- {
- return nextSchoolYear.Years;
- }
- }
- }
- /// <summary>
- /// 查询当前启用的毕业学期ID(学年学期对应的ID)
- /// </summary>
- /// <returns></returns>
- public static Guid? GetGradSchoolYearID()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IParameterServices ParameterServices = scope.Resolve<IParameterServices>();
- //查询设置的毕业学期信息
- var graduationSchoolyear = ParameterServices.GetParameterValue(CF_ParameterType.GraduationSchoolyear);
- if (!string.IsNullOrEmpty(graduationSchoolyear))
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var schoolYearView = SchoolYearServices.GetSchoolYearView(Guid.Parse(graduationSchoolyear));
- if (schoolYearView != null)
- {
- return schoolYearView.SchoolYearID;
- }
- }
- return null;
- }
- }
- /// <summary>
- /// 查询当前启用的毕业学期Code(学年学期对应的Code)
- /// </summary>
- /// <returns></returns>
- public static string GetGradSchoolYearCode()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IParameterServices ParameterServices = scope.Resolve<IParameterServices>();
- //查询设置的毕业学期信息
- var graduationSchoolyear = ParameterServices.GetParameterValue(CF_ParameterType.GraduationSchoolyear);
- if (!string.IsNullOrEmpty(graduationSchoolyear))
- {
- ISchoolYearServices SchoolYearServices = scope.Resolve<ISchoolYearServices>();
- var schoolYearView = SchoolYearServices.GetSchoolYearView(Guid.Parse(graduationSchoolyear));
- if (schoolYearView != null)
- {
- return schoolYearView.Code;
- }
- }
- return null;
- }
- }
- /// <summary>
- /// 查询对应的工作流程中开始流程环节的状态Pid(根据对应的tableName)
- /// </summary>
- /// <param name="tableName"></param>
- /// <returns></returns>
- public static int? GetStartFlowStatus(string tableName)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetStartStatus(tableName);
- }
- }
- /// <summary>
- /// 查询对应的接入流程表已退回流程环节Pid(注:不包含开始环节、结束环节且为[BP]标识)
- /// </summary>
- /// <param name="tableName"></param>
- /// <returns></returns>
- public static int? GetSendBackFlowStatus(string tableName)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetSendBackStatus(tableName);
- }
- }
- /// <summary>
- /// 查询对应的接入流程表已通过流程环节Pid(注:不包含开始环节、结束环节且为[PASS]标识)
- /// </summary>
- /// <param name="tableName"></param>
- /// <returns></returns>
- public static int? GetPassNoEndFlowStatus(string tableName)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetPassNoEndStatus(tableName);
- }
- }
- /// <summary>
- /// 查询对应的工作流程中结束流程环节的状态Pid(根据对应的tableName,结束环节且不为[BP]标识的)
- /// </summary>
- /// <param name="tableName"></param>
- /// <returns></returns>
- public static int? GetEndFlowStatus(string tableName)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetCorrectEndStatus(tableName);
- }
- }
- /// <summary>
- /// 查询对应的接入流程表非正常结束的流程环节Pid(注:通常为结束环节且为[BP]标识的)
- /// </summary>
- /// <param name="tableName"></param>
- /// <returns></returns>
- public static List<int?> GetBackpointStatus(string tableName)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetBackpointStatus(tableName);
- }
- }
- /// <summary>
- /// 根据当前流程环节ID获取下一步审批动作
- /// </summary>
- /// <param name="tableName"></param>
- /// <param name="formID"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- public static List<ActionView> GetCurrentActionViewList(string tableName, Guid formID, Guid userID)
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IWorkflowServices WorkflowServices = scope.Resolve<IWorkflowServices>();
- return WorkflowServices.GetActionView(tableName, formID, userID);
- }
- }
- /// <summary>
- /// 登录成功
- /// </summary>
- /// <param name="controller"></param>
- /// <param name="model"></param>
- /// <param name="userName"></param>
- public static void LoginSureccessful(this ControllerBase controller, LogOnModel model, string userName)
- {
- FormsAuthenticationHelper fahelper = new FormsAuthenticationHelper();
- var cookieName = EMIS.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- List<string> userData = new List<string>();
- Sys_User userpageResult;
- Sys_Role defaultRole = null;
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IUserServices userServices = scope.Resolve<IUserServices>();
- userpageResult = userServices.GetUserByLoginID(userName, true);
- if (userpageResult == null)
- {
- throw new Exception("获取用户失败。");
- }
- //只要不是学生,就需要获取角色,如果实在没有角色,则不用选,依然允许进入系统,反正他什么都看不到
- if (userpageResult.CF_Student == null)
- {
- defaultRole = userServices.GetMaxPrivilegeRoleByUserID(userpageResult.UserID);
- }
- }
- if (model.RememberMe)
- {
- controller.RemeberUserCookies(model);
- }
- else
- {
- controller.RemoveUserCookies(model);
- }
- userData.Add(userpageResult.LoginID);
- userData.Add(userpageResult.UserID.ToString());
- userData.Add(userpageResult.Name);
- userData.Add((userpageResult.CF_Staff != null) ? userpageResult.UserID.ToString() : "");//教职工ID
- userData.Add((userpageResult.CF_Student != null) ? userpageResult.UserID.ToString() : "");//学生ID
- userData.Add((userpageResult.CF_Staff != null && userpageResult.CF_Staff.CF_Department != null) ? userpageResult.CF_Staff.DepartmentID.ToString() : "");//部门(教研室)ID
- userData.Add((userpageResult.CF_Staff != null && userpageResult.CF_Staff.CF_Department != null) ? userpageResult.CF_Staff.CF_Department.HierarchyID : "");//部门(教研室)树结构ID
- userData.Add((userpageResult.CF_Staff != null && userpageResult.CF_Staff.CF_Department != null) ? userpageResult.CF_Staff.CF_Department.Name : "");//部门(教研室)名称
- if (userpageResult.CF_Student == null)
- {
- if (userpageResult.CF_Staff != null && userpageResult.CF_Staff.CF_College != null)
- {
- userData.Add(userpageResult.CF_Staff.CollegeID.ToString());//学院ID
- userData.Add(userpageResult.CF_Staff.CF_College.CampusID.ToString());//校区ID
- userData.Add(userpageResult.CF_Staff.CF_College.CF_Campus.UniversityID.ToString());//学校ID
- }
- else
- {
- userData.Add("");
- userData.Add("");
- userData.Add("");
- }
- if (defaultRole != null)
- {
- userData.Add(defaultRole.RoleID.ToString());//默认角色ID
- }
- else
- {
- userData.Add("");
- }
- }
- else
- {
- //学生的后续再加
- userData.Add("");
- userData.Add("");
- userData.Add("");
- userData.Add("");
- }
- fahelper.loginFormsAuthentication(controller.ControllerContext.HttpContext, cookieName, userData);
- }
- /// <summary>
- /// 角色切换
- /// </summary>
- /// <param name="controller"></param>
- /// <param name="roleID"></param>
- public static void SwitchUserRole(this ControllerBase controller, Guid roleID)
- {
- FormsAuthenticationHelper fahelper = new FormsAuthenticationHelper();
- var userData = EMIS.Utility.FormValidate.CustomPrincipal.Current.GetUserData();
- var cookieName = EMIS.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- userData[11] = roleID.ToString();
- fahelper.loginFormsAuthentication(controller.ControllerContext.HttpContext, cookieName, userData);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="controller"></param>
- /// <param name="model"></param>
- public static void RemeberUserCookies(this ControllerBase controller, LogOnModel model)
- {
- HttpCookie cookie = new HttpCookie("username");
- cookie.Value = model.UserName;
- cookie.Expires = DateTime.Now.AddDays(1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie);
- HttpCookie cookie2 = new HttpCookie("password");
- cookie2.Value = model.Password;
- cookie2.Expires = DateTime.Now.AddDays(1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie2);
- HttpCookie cookie3 = new HttpCookie("rememberme");
- cookie3.Value = model.RememberMe.ToString();
- cookie3.Expires = DateTime.Now.AddDays(1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie3);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="controller"></param>
- /// <param name="model"></param>
- public static void RemoveUserCookies(this ControllerBase controller, LogOnModel model)
- {
- HttpCookie cookie = new HttpCookie("username");
- cookie.Value = model.UserName;
- cookie.Expires = DateTime.Now.AddDays(-1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie);
- HttpCookie cookie2 = new HttpCookie("password");
- cookie2.Value = model.Password;
- cookie2.Expires = DateTime.Now.AddDays(-1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie2);
- HttpCookie cookie3 = new HttpCookie("rememberme");
- cookie3.Value = model.RememberMe.ToString();
- cookie3.Expires = DateTime.Now.AddDays(-1);
- controller.ControllerContext.HttpContext.Response.AppendCookie(cookie3);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="controller"></param>
- /// <returns></returns>
- public static LogOnModel GetUserCookies(this ControllerBase controller)
- {
- LogOnModel model = new LogOnModel();
- HttpCookie cookie = controller.ControllerContext.HttpContext.Request.Cookies["username"];
- if (cookie != null)
- {
- model.UserName = cookie.Value;
- }
- HttpCookie cookie2 = controller.ControllerContext.HttpContext.Request.Cookies["password"];
- if (cookie2 != null)
- {
- model.Password = cookie2.Value;
- }
- HttpCookie cookie3 = controller.ControllerContext.HttpContext.Request.Cookies["rememberme"];
- if (cookie3 != null)
- {
- model.RememberMe = cookie3.Value.ToLower() == "true";
- }
- return model;
- }
- /// <summary>
- /// 查询默认的学习形式(个性化配置)
- /// 默认为全部
- /// </summary>
- /// <returns></returns>
- public static int? GetDefaultLearnformForList()
- {
- using (var scope = AutofacHelper.Container.BeginLifetimeScope())
- {
- IStudentServices studentServices = scope.Resolve<IStudentServices>();
- return studentServices.GetDefaultLearnformForList();
- }
- }
- /// <summary>
- /// 查询入学学期ID(Web.config)
- /// </summary>
- /// <returns></returns>
- public static int? GetEntranceSemesterID()
- {
- int? entranceSemesterID = null;
- if (!string.IsNullOrEmpty(EMIS.Utility.Const.LOCAL_SETTING_ENTRANCESEMESTERID))
- {
- entranceSemesterID = Convert.ToInt32(EMIS.Utility.Const.LOCAL_SETTING_ENTRANCESEMESTERID);
- }
- return entranceSemesterID;
- }
- /// <summary>
- /// List转换为DataTable
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="items"></param>
- /// <returns></returns>
- public static DataTable ToDataTable<T>(this List<T> items)
- {
- DataTable dataTable = new DataTable();
- PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
- foreach (PropertyInfo prop in Props)
- {
- dataTable.Columns.Add(prop.Name);
- }
- foreach (T obj in items)
- {
- var values = new object[Props.Length];
- for (int i = 0; i < Props.Length; i++)
- {
- values[i] = Props[i].GetValue(obj, null);
- }
- dataTable.Rows.Add(values);
- }
- return dataTable;
- }
- }
- }
|