/// <summary> /// 取得 人員基本資料 /// </summary> /// <param name="cUserID"></param> /// <returns></returns> public BaseUserInfoModel GetUserInfo(string cUserID) { BaseUserInfoModel user = new BaseUserInfoModel(); using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities()) { var _emply = dbINTRA.V_EMPLY2.AsNoTracking().FirstOrDefault(x => x.USR_ID == cUserID); if (_emply != null) { user.EMP_ID = cUserID; user.EMP_Name = _emply.EMP_NAME?.Trim(); user.DPT_ID = _emply.DPT_CD?.Trim(); user.DPT_Name = _emply.DPT_NAME?.Trim(); } } return(user); }
/// <summary> /// 金庫進出管理作業-金庫物品存取申請作業 初始畫面顯示 /// </summary> /// <param name="cUserID">userId</param> /// <param name="custodyFlag">管理科Flag</param> /// <param name="unit">科別指定</param> /// <returns></returns> public Tuple <List <SelectOption>, List <SelectOption>, List <SelectOption>, BaseUserInfoModel> TreasuryAccessDetail(string cUserID, bool custodyFlag, string unit = null) { List <SelectOption> applicationProject = new List <SelectOption>(); //申請項目 List <SelectOption> applicationUnit = new List <SelectOption>(); //申請單位 List <SelectOption> applicant = new List <SelectOption>(); //申請人 var empty = new SelectOption() { Text = string.Empty, Value = string.Empty }; BaseUserInfoModel user = GetUserInfo(cUserID); //填表人 資料 try { using (DB_INTRAEntities dbINTRA = new DB_INTRAEntities()) { var depts = dbINTRA.VW_OA_DEPT.AsNoTracking().ToList(); using (TreasuryDBEntities db = new TreasuryDBEntities()) { #region 保管科人員 if (custodyFlag) //是保管科人員 { applicationProject = db.TREA_ITEM.AsNoTracking() .Where(x => x.IS_DISABLED == "N" && x.ITEM_OP_TYPE == "3") //「入庫作業類型=3」且啟用中的存取項目 .OrderBy(x => x.ITEM_ID) .AsEnumerable() .Select(x => new SelectOption() { Value = x.ITEM_ID, Text = x.ITEM_DESC }).ToList(); var Units = new List <string>(); //自【保管單位設定檔】中挑出啟用中的單位 db.ITEM_CHARGE_UNIT.AsNoTracking() .Where(x => x.IS_DISABLED == "N").ToList() .ForEach(x => { if (!x.CHARGE_SECT.IsNullOrWhiteSpace()) { Units.Add(x.CHARGE_SECT.Trim()); } else { Units.Add(x.CHARGE_DEPT.Trim()); } }); applicationUnit = Units.Distinct().OrderBy(x => x) .AsEnumerable() .Select(x => new SelectOption() { Value = x, Text = depts.FirstOrDefault(y => y.DPT_CD.Trim() == x)?.DPT_NAME }).ToList(); if (applicationUnit.Any()) { if (unit != null) { var _first = applicationUnit.FirstOrDefault(x => x.Value == unit); if (_first != null) { applicant = dbINTRA.V_EMPLY2.AsNoTracking() .Where(x => x.DPT_CD == _first.Value) .AsEnumerable() .Select(x => new SelectOption() { Value = x.USR_ID, Text = $@"{x.USR_ID}({x.EMP_NAME})" }).ToList(); } } } if (!applicant.Any()) { applicant.Add(empty); } } #endregion #region 非保管科人員 else { applicationProject = db.CODE_USER_ROLE.AsNoTracking() .Where(x => x.USER_ID == cUserID) //登入者所擁有的角色 .Join(db.CODE_ROLE_ITEM.AsNoTracking() .Where(x => x.AUTH_TYPE == "2"), //表單申請權限=Y x => x.ROLE_ID, y => y.ROLE_ID, (x, y) => y ).Join(db.TREA_ITEM.AsNoTracking(), //金庫存取作業設定檔 x => x.ITEM_ID, y => y.ITEM_ID, (x, y) => y ).AsEnumerable() .Select(x => new SelectOption() { Value = x.ITEM_ID, Text = x.ITEM_DESC }).ToList(); if (user != null) { applicationUnit.Add(new SelectOption() { Value = user.DPT_ID, Text = user.DPT_Name }); applicant.Add(new SelectOption() { Value = user.EMP_ID, Text = $@"{user.EMP_ID}({user.EMP_Name})" }); } } #endregion } } } catch (Exception ex) { var message = ex.exceptionMessage(); throw ex; } return(new Tuple <List <SelectOption>, List <SelectOption>, List <SelectOption>, BaseUserInfoModel>(applicationProject, applicationUnit, applicant, user)); }