/// <summary> /// 根据UserId主键获取人员信息 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string GetPersonIdByUserId(string userId) { string personId = userId; var getPerson = GetPersonById(userId); if (getPerson == null) { var getUser = UserService.GetUserByUserId(userId); if (getUser != null) { getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.IdentityCard == getUser.IdentityCard); if (getPerson != null) { personId = getPerson.PersonId; } } } return(personId); }
/// <summary> /// 根据用户UnitId判断是否为本单位用户或管理员 /// </summary> /// <returns></returns> public static bool IsMainUnitOrAdmin(string userId) { bool result = false; if (userId == Const.sysglyId || userId == Const.hfnbdId || userId == Const.sedinId) { result = true; } else { var user = UserService.GetUserByUserId(userId); if (user != null) { Model.Base_Unit unit = UnitService.GetUnitByUnitId(user.UnitId); if (unit != null && unit.IsThisUnit == true) { result = true; } } } return(result); }
/// <summary> /// 根据用户UnitId判断是否为本单位用户或管理员 /// </summary> /// <returns></returns> public static bool IsLeaderOrManage(string userId) { bool result = false; if (userId == Const.sysglyId || userId == Const.hfnbdId || userId == Const.sedinId) { result = true; } else { var user = UserService.GetUserByUserId(userId); if (user != null && user.IsOffice == true) { var role = RoleService.GetRoleByRoleId(user.RoleId); if (role != null && (role.RoleType == "3" || role.RoleType == "2")) ////是管理、领导角色 { result = true; } } } return(result); }
/// <summary> /// 保存考生信息 /// </summary> /// <param name="testRecord">考试计划记录</param> public static Model.TestRecordItem SaveTestRecord(Model.TestRecordItem testRecord) { using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString)) { var getTestPlan = db.Test_TestPlan.FirstOrDefault(x => x.TestPlanId == testRecord.TestPlanId); if (getTestPlan != null) { testRecord.TestPlanName = getTestPlan.PlanName; testRecord.TestPlanStartTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", getTestPlan.TestStartTime); testRecord.TestPlanEndTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", getTestPlan.TestEndTime); Model.Test_TestRecord newTestRecord = new Model.Test_TestRecord { TestPlanId = testRecord.TestPlanId, TestManId = testRecord.TestManId, TestManName = testRecord.TestManName, IdentityCard = testRecord.IdentityCard, Telephone = testRecord.Telephone, ManType = testRecord.UserType, Duration = getTestPlan.Duration, }; if (!string.IsNullOrEmpty(testRecord.UnitId)) { newTestRecord.UnitId = testRecord.UnitId; } if (!string.IsNullOrEmpty(testRecord.DepartId)) { newTestRecord.DepartId = testRecord.DepartId; } if (!string.IsNullOrEmpty(testRecord.WorkPostId)) { newTestRecord.WorkPostId = testRecord.WorkPostId; } if (!string.IsNullOrEmpty(testRecord.ProjectId)) { newTestRecord.ProjectId = testRecord.ProjectId; } if (string.IsNullOrEmpty(newTestRecord.ManType)) { if (testRecord.TestManId == Const.sedinId) { newTestRecord.ManType = "2"; } else if (UserService.GetUserByUserId(testRecord.TestManId) != null) { newTestRecord.ManType = "1"; } else { newTestRecord.ManType = "3"; } } Model.Test_TestRecord getUpdateTestRecord = new Model.Test_TestRecord(); ; getUpdateTestRecord = db.Test_TestRecord.FirstOrDefault(x => x.TestRecordId == testRecord.TestRecordId); if (getUpdateTestRecord == null) { getUpdateTestRecord = db.Test_TestRecord.FirstOrDefault(x => x.TestPlanId == testRecord.TestPlanId && x.IdentityCard == testRecord.IdentityCard); } if (getUpdateTestRecord != null) { testRecord.TestRecordId = getUpdateTestRecord.TestRecordId; testRecord.TestEndTime = string.Format("{0:yyyy-MM:dd HH:mm:ss}", getUpdateTestRecord.TestEndTime); testRecord.TestStartTime = string.Format("{0:yyyy-MM:dd HH:mm:ss}", getUpdateTestRecord.TestStartTime); testRecord.TestScores = getUpdateTestRecord.TestScores ?? 0; if (string.IsNullOrEmpty(getUpdateTestRecord.ManType)) { getUpdateTestRecord.ManType = newTestRecord.ManType; } if (!getUpdateTestRecord.TestEndTime.HasValue && getTestPlan.TestEndTime < DateTime.Now) { getUpdateTestRecord.DepartId = newTestRecord.DepartId; getUpdateTestRecord.TestManName = newTestRecord.TestManName; getUpdateTestRecord.IdentityCard = newTestRecord.IdentityCard; getUpdateTestRecord.Telephone = newTestRecord.Telephone; db.SubmitChanges(); } } else { if (getTestPlan.TestEndTime > DateTime.Now) { var getTestPlanTraining = db.Test_TestPlanTraining.Where(x => x.TestPlanId == getTestPlan.TestPlanId && x.UserType == testRecord.UserType); if (getTestPlanTraining.Count() > 0) { int cout1 = getTestPlanTraining.Sum(x => x.TestType1Count ?? 0); int cout2 = getTestPlanTraining.Sum(x => x.TestType2Count ?? 0); int cout3 = getTestPlanTraining.Sum(x => x.TestType3Count ?? 0); newTestRecord.QuestionCount = cout1 + cout2 + cout3; newTestRecord.TotalScore = (getTestPlan.SValue ?? 0) * cout1 + (getTestPlan.MValue ?? 0) * cout2 + (getTestPlan.JValue ?? 0) * cout3; } testRecord.TestRecordId = newTestRecord.TestRecordId = SQLHelper.GetNewID(); db.Test_TestRecord.InsertOnSubmit(newTestRecord); db.SubmitChanges(); } } if (!string.IsNullOrEmpty(testRecord.TestEndTime)) { testRecord.TestStates = "3"; } else if (getTestPlan.States == Const.State_2 && getTestPlan.TestEndTime >= DateTime.Now) { testRecord.TestStates = "2"; } else if (getTestPlan.States != Const.State_2 || getTestPlan.TestStartTime < DateTime.Now) { testRecord.TestStates = "1"; } else if (getTestPlan.TestEndTime < DateTime.Now) { testRecord.TestStates = "0"; } } } return(testRecord); }
/// <summary> /// 获取当前人是否具有按钮操作权限 /// </summary> /// <param name="userId">用户id</param> /// <param name="menuId">按钮id</param> /// <param name="buttonName">按钮名称</param> /// <returns>是否具有权限</returns> public static bool GetAllButtonPowerList(string projectId, string userId, string menuId, string buttonName) { Model.SUBHSSEDB db = Funs.DB; bool isPower = false; ////定义是否具备按钮权限 if (userId == Const.sedinId) { return(isPower); } if (!isPower && (userId == Const.sysglyId || userId == Const.hfnbdId)) { isPower = true; } // 根据角色判断是否有按钮权限 if (!isPower) { if (string.IsNullOrEmpty(projectId)) { var user = UserService.GetUserByUserId(userId); ////用户 if (user != null) { if (!string.IsNullOrEmpty(user.RoleId)) { var buttonToMenu = from x in db.Sys_ButtonToMenu join y in db.Sys_ButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId join z in db.Sys_Menu on x.MenuId equals z.MenuId where y.RoleId == user.RoleId && y.MenuId == menuId && x.ButtonName == buttonName && x.MenuId == menuId select x; if (buttonToMenu.Count() > 0) { isPower = true; } } } } else { var pUser = BLL.ProjectUserService.GetProjectUserByUserIdProjectId(projectId, userId); ///项目用户 if (pUser != null) { if (!string.IsNullOrEmpty(pUser.RoleId)) { List <string> roleIdList = Funs.GetStrListByStr(pUser.RoleId, ','); var buttonToMenu = from x in db.Sys_ButtonToMenu join y in db.Sys_ButtonPower on x.ButtonToMenuId equals y.ButtonToMenuId join z in db.Sys_Menu on x.MenuId equals z.MenuId where roleIdList.Contains(y.RoleId) && y.MenuId == menuId && x.ButtonName == buttonName && x.MenuId == menuId select x; if (buttonToMenu.Count() > 0) { isPower = true; } } } } } if (isPower && !String.IsNullOrEmpty(projectId) && menuId != BLL.Const.ProjectShutdownMenuId) { var porject = BLL.ProjectService.GetProjectByProjectId(projectId); if (porject != null && (porject.ProjectState == BLL.Const.ProjectState_2 || porject.ProjectState == BLL.Const.ProjectState_3)) { isPower = false; } } if (!CommonService.GetIsBuildUnit()) { var menu = BLL.SysMenuService.GetSysMenuByMenuId(menuId); if (menu != null && menu.MenuType == BLL.Const.Menu_Resource) { if (buttonName == BLL.Const.BtnSaveUp || buttonName == BLL.Const.BtnUploadResources || buttonName == BLL.Const.BtnAuditing) { isPower = false; } } } return(isPower); }
/// <summary> /// 保存TrainingPlan /// </summary> /// <param name="trainingPlan">培训计划记录</param> /// <param name="trainingTasks">培训人员list</param> /// <param name="trainingPlanItems">培训教材类型list</param> public static void SaveTrainingPlan(Model.TrainingPlanItem trainingPlan) { using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString)) { Model.Training_Plan newTrainingPlan = new Model.Training_Plan { PlanId = trainingPlan.PlanId, PlanCode = trainingPlan.PlanCode, ProjectId = trainingPlan.ProjectId, DesignerId = trainingPlan.DesignerId, PlanName = trainingPlan.PlanName, TrainContent = trainingPlan.TrainContent, TrainStartDate = Funs.GetNewDateTime(trainingPlan.TrainStartDate), TeachHour = trainingPlan.TeachHour, TeachMan = trainingPlan.TeachMan, TeachAddress = trainingPlan.TeachAddress, TrainTypeId = trainingPlan.TrainTypeId, UnitIds = trainingPlan.UnitIds, WorkPostId = trainingPlan.WorkPostId, States = trainingPlan.States, }; if (!string.IsNullOrEmpty(trainingPlan.TrainLevelId)) { newTrainingPlan.TrainLevelId = trainingPlan.TrainLevelId; } if (newTrainingPlan.TrainStartDate.HasValue && newTrainingPlan.TeachHour.HasValue) { double dd = (double)((decimal)newTrainingPlan.TeachHour.Value); newTrainingPlan.TrainEndDate = newTrainingPlan.TrainStartDate.Value.AddHours(dd); } List <Model.TrainingTaskItem> trainingTasks = trainingPlan.TrainingTasks; List <Model.TrainingPlanItemItem> trainingPlanItems = trainingPlan.TrainingPlanItems; var isUpdate = db.Training_Plan.FirstOrDefault(x => x.PlanId == newTrainingPlan.PlanId); if (isUpdate == null) { newTrainingPlan.DesignerDate = DateTime.Now; string unitId = string.Empty; var user = UserService.GetUserByUserId(newTrainingPlan.DesignerId); if (user != null) { unitId = user.UnitId; } newTrainingPlan.PlanCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectTrainingPlanMenuId, newTrainingPlan.ProjectId, unitId); if (string.IsNullOrEmpty(newTrainingPlan.PlanId)) { newTrainingPlan.PlanId = SQLHelper.GetNewID(); } db.Training_Plan.InsertOnSubmit(newTrainingPlan); db.SubmitChanges(); CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectTrainingPlanMenuId, newTrainingPlan.ProjectId, null, newTrainingPlan.PlanId, newTrainingPlan.DesignerDate); } else { if (newTrainingPlan.States == "0" || newTrainingPlan.States == "1") { isUpdate.PlanName = newTrainingPlan.PlanName; isUpdate.TrainContent = newTrainingPlan.TrainContent; isUpdate.TrainStartDate = newTrainingPlan.TrainStartDate; isUpdate.TeachHour = newTrainingPlan.TeachHour; isUpdate.TrainEndDate = newTrainingPlan.TrainEndDate; isUpdate.TeachMan = newTrainingPlan.TeachMan; isUpdate.TeachAddress = newTrainingPlan.TeachAddress; isUpdate.TrainTypeId = newTrainingPlan.TrainTypeId; isUpdate.TrainLevelId = newTrainingPlan.TrainLevelId; isUpdate.UnitIds = newTrainingPlan.UnitIds; isUpdate.WorkPostId = newTrainingPlan.WorkPostId; isUpdate.States = newTrainingPlan.States; db.SubmitChanges(); } ////删除培训任务 var tasks = from x in db.Training_Task where x.PlanId == newTrainingPlan.PlanId select x; if (tasks.Count() > 0) { var taskItems = from x in db.Training_TaskItem where x.PlanId == newTrainingPlan.PlanId select x; if (tasks.Count() > 0) { db.Training_TaskItem.DeleteAllOnSubmit(taskItems); db.SubmitChanges(); } db.Training_Task.DeleteAllOnSubmit(tasks); db.SubmitChanges(); } ////删除培训教材类型 var planItem = (from x in db.Training_PlanItem where x.PlanId == newTrainingPlan.PlanId select x).ToList(); if (planItem.Count() > 0) { db.Training_PlanItem.DeleteAllOnSubmit(planItem); db.SubmitChanges(); } } if (trainingTasks.Count() > 0) { ////新增培训人员明细 foreach (var item in trainingTasks) { if (!string.IsNullOrEmpty(item.PersonId)) { Model.Training_Task newTrainDetail = new Model.Training_Task { TaskId = SQLHelper.GetNewID(), ProjectId = newTrainingPlan.ProjectId, PlanId = newTrainingPlan.PlanId, UserId = item.PersonId, TaskDate = DateTime.Now, States = Const.State_0, ////未生成培训教材明细 }; db.Training_Task.InsertOnSubmit(newTrainDetail); db.SubmitChanges(); } } } if (trainingPlanItems.Count() > 0) { ////新增培训教材类型明细 foreach (var item in trainingPlanItems) { if (!string.IsNullOrEmpty(item.CompanyTrainingId) || !string.IsNullOrEmpty(item.CompanyTrainingItemId)) { Model.Training_PlanItem newPlanItem = new Model.Training_PlanItem { PlanItemId = SQLHelper.GetNewID(), PlanId = newTrainingPlan.PlanId, }; if (!string.IsNullOrEmpty(item.CompanyTrainingId)) { newPlanItem.CompanyTrainingId = item.CompanyTrainingId; } if (!string.IsNullOrEmpty(item.CompanyTrainingItemId)) { newPlanItem.CompanyTrainingItemId = item.CompanyTrainingItemId; } db.Training_PlanItem.InsertOnSubmit(newPlanItem); db.SubmitChanges(); } } } } }