public JsonResult SearchAppr(SpecifiedTimeTreasuryApprSearchViewModel searchModel) { MSGReturnModel <string> result = new MSGReturnModel <string>(); result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription(); Cache.Invalidate(CacheList.SpecifiedTimeTreasuryApprSearchData); Cache.Set(CacheList.SpecifiedTimeTreasuryApprSearchData, searchModel); var datas = SpecifiedTimeTreasury.GetApprSearchData(searchModel); if (datas.Any()) { Cache.Invalidate(CacheList.SpecifiedTimeTreasuryApprSearchDetailViewData); Cache.Set(CacheList.SpecifiedTimeTreasuryApprSearchDetailViewData, datas); result.RETURN_FLAG = true; } return(Json(result)); }
/// <summary> /// 駁回 /// </summary> /// <param name="RegisterNo"></param> /// <param name="RejectReason"></param> /// <param name="ViewModel"></param> /// <param name="SearchData"></param> /// <returns></returns> public MSGReturnModel <List <SpecifiedTimeTreasuryApprSearchDetailViewModel> > RejectData(List <string> RegisterNo, string RejectReason, List <SpecifiedTimeTreasuryApprSearchDetailViewModel> ViewModel, SpecifiedTimeTreasuryApprSearchViewModel SearchData) { var result = new MSGReturnModel <List <SpecifiedTimeTreasuryApprSearchDetailViewModel> >(); result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription(); DateTime dt = DateTime.Now; string logStrC = string.Empty; //combin Log using (TreasuryDBEntities db = new TreasuryDBEntities()) { foreach (var item in ViewModel.Where(x => RegisterNo.Contains(x.vTREA_REGISTER_ID))) { var _TREA_OPEN_REC = db.TREA_OPEN_REC.FirstOrDefault(x => x.TREA_REGISTER_ID == item.vTREA_REGISTER_ID); if (_TREA_OPEN_REC == null) //找不到該單號 { result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription(null, $"單號:{item.vTREA_REGISTER_ID}"); return(result); } if (_TREA_OPEN_REC.LAST_UPDATE_DT > item.vLAST_UPDATE_DT) //資料已被更新 { result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription(null, $"單號:{item.vTREA_REGISTER_ID}"); return(result); } var applyStatus = ((int)Ref.ApplyStatus._3).ToString(); // 狀態: 退回 string logStrB = string.Empty; //修改前 Log string logStrA = string.Empty; //修改後 Log logStrB += _TREA_OPEN_REC.modelToString(logStrB); _TREA_OPEN_REC.APPR_STATUS = applyStatus; _TREA_OPEN_REC.LAST_UPDATE_UID = SearchData.vCreateUid; _TREA_OPEN_REC.LAST_UPDATE_DT = dt; _TREA_OPEN_REC.APPR_DESC = RejectReason; _TREA_OPEN_REC.APPR_UID = SearchData.vCreateUid; _TREA_OPEN_REC.APPR_DT = dt; logStrA += _TREA_OPEN_REC.modelToString(logStrA); logStrC += string.Format("修改前{0}^^修改後{1}", logStrB, logStrA); } //檢核欄位 var validateMessage = db.GetValidationErrors().getValidateString(); if (validateMessage.Any()) { result.DESCRIPTION = validateMessage; } else { try { db.SaveChanges(); #region LOG //新增LOG Log log = new Log(); log.CFUNCTION = "駁回-指定開庫覆核作業"; log.CACTION = "U"; log.CCONTENT = logStrC; LogDao.Insert(log, SearchData.vCreateUid); #endregion result.RETURN_FLAG = true; result.DESCRIPTION = $"申請單號 : {string.Join(",", RegisterNo)} 已駁回"; result.Datas = GetApprSearchData(SearchData); } catch (DbUpdateException ex) { result.DESCRIPTION = ex.exceptionMessage(); } } } return(result); }
/// <summary> /// 覆核 /// </summary> /// <param name="RegisterNo"></param> /// <param name="ViewModel"></param> /// <param name="SearchData"></param> /// <returns></returns> public MSGReturnModel <List <SpecifiedTimeTreasuryApprSearchDetailViewModel> > ApproveData(List <string> RegisterNo, List <SpecifiedTimeTreasuryApprSearchDetailViewModel> ViewModel, SpecifiedTimeTreasuryApprSearchViewModel SearchData) { var result = new MSGReturnModel <List <SpecifiedTimeTreasuryApprSearchDetailViewModel> >(); result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription(); if (!ViewModel.Any()) { return(result); } DateTime dt = DateTime.Now; string logStrC = string.Empty; //combin Log List <TREA_OPEN_REC> TORs = new List <TREA_OPEN_REC>(); using (TreasuryDBEntities db = new TreasuryDBEntities()) { var _TREA_ITEM = db.TREA_ITEM.Where(x => x.ITEM_OP_TYPE == "3").Select(x => x.ITEM_ID).ToList(); foreach (var item in ViewModel.Where(x => RegisterNo.Contains(x.vTREA_REGISTER_ID))) { var _TREA_OPEN_REC = db.TREA_OPEN_REC.FirstOrDefault(x => x.TREA_REGISTER_ID == item.vTREA_REGISTER_ID); if (_TREA_OPEN_REC == null) //找不到該單號 { result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription(null, $"單號:{item.vTREA_REGISTER_ID}"); return(result); } if (_TREA_OPEN_REC.LAST_UPDATE_DT > item.vLAST_UPDATE_DT) //資料已備更新 { result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription(null, $"單號:{item.vTREA_REGISTER_ID}"); return(result); } TORs.Add(_TREA_OPEN_REC); var applyStatus = ((int)Ref.ApplyStatus._2).ToString(); // 狀態: 覆核完成 string logStrB = string.Empty; //修改前 Log string logStrA = string.Empty; //修改後 Log logStrB += _TREA_OPEN_REC.modelToString(logStrB); _TREA_OPEN_REC.APPR_STATUS = applyStatus; _TREA_OPEN_REC.LAST_UPDATE_UID = SearchData.vCreateUid; _TREA_OPEN_REC.LAST_UPDATE_DT = dt; _TREA_OPEN_REC.APPR_UID = SearchData.vCreateUid; _TREA_OPEN_REC.APPR_DT = dt; logStrA += _TREA_OPEN_REC.modelToString(logStrA); //#region 申請單紀錄檔 ////取得流水號 //List<string> workList = _TREA_OPEN_REC.OPEN_TREA_REASON.Split(';').ToList(); //foreach (var workItem in workList) //{ // if (!_TREA_ITEM.Contains(workItem)) // { // SysSeqDao sysSeqDao = new SysSeqDao(); // string qPreCode = DateUtil.getCurChtDateTime().Split(' ')[0]; // var cId = sysSeqDao.qrySeqNo("G6", qPreCode).ToString().PadLeft(3, '0'); // var _TREA_APLY_REC = db.TREA_APLY_REC // .Add(new TREA_APLY_REC() // { // APLY_NO = $@"G6{qPreCode}{cId}", ////申請單號 G6+系統日期YYYMMDD(民國年)+3碼流水號 // APLY_FROM = "S", // TREA_REGISTER_ID = item.vTREA_REGISTER_ID, // ITEM_ID = workItem, // APLY_STATUS = "C01", // EXPECTED_ACCESS_DATE = _TREA_OPEN_REC.OPEN_TREA_DATE, // APLY_UNIT = _TREA_OPEN_REC.CREATE_UNIT, // APLY_UID = _TREA_OPEN_REC.CREATE_UID, // APLY_DT = _TREA_OPEN_REC.CREATE_DT, // APLY_APPR_UID = SearchData.vCreateUid, // APLY_APPR_DT = dt, // CREATE_UID = SearchData.vCreateUid, // CREATE_DT = dt, // LAST_UPDATE_UID = SearchData.vCreateUid, // LAST_UPDATE_DT = dt, // CREATE_UNIT = SearchData.vCreateUnit // }); // logStrA += _TREA_APLY_REC.modelToString(logStrA); // } //} //#endregion #region 申請單暫存檔 //取得流水號 List <string> workList = _TREA_OPEN_REC.OPEN_TREA_REASON.Split(';').ToList(); if (workList.Count != 0) { var data = (from n in db.TREA_APLY_TEMP select n); db.TREA_APLY_TEMP.RemoveRange(data); } foreach (var workItem in workList) { if (!_TREA_ITEM.Contains(workItem)) { var _TREA_APLY_TEMP = db.TREA_APLY_TEMP .Add(new TREA_APLY_TEMP() { ITEM_ID = workItem, }); } } #endregion logStrC += string.Format("修改前{0}^^修改後{1}", logStrB, logStrA); } var validateMessage = db.GetValidationErrors().getValidateString(); if (validateMessage.Any()) { result.DESCRIPTION = validateMessage; } else { try { db.SaveChanges(); #region 寄信 //List<Tuple<string, string>> _mailTo = new List<Tuple<string, string>>() { new Tuple<string, string>("*****@*****.**", "測試帳號-glsisys") }; List <Tuple <string, string> > _mailTo = new List <Tuple <string, string> >(); List <Tuple <string, string> > _ccTo = new List <Tuple <string, string> >(); var emps = GetEmps(); var _MAIL_CONTENT = db.MAIL_CONTENT.AsNoTracking().FirstOrDefault(x => x.MAIL_CONTENT_ID == "01" && x.IS_DISABLED == "N"); var _MAIL_RECEIVE = db.MAIL_RECEIVE.AsNoTracking(); var _CODE_ROLE_FUNC = db.CODE_ROLE_FUNC.AsNoTracking(); var _CODE_USER_ROLE = db.CODE_USER_ROLE.AsEnumerable(); var _CODE_USER = db.CODE_USER.AsNoTracking(); foreach (var TOR in TORs) { if (_MAIL_CONTENT != null) { string _content = _MAIL_CONTENT.MAIL_CONTENT1; _content = _content.Replace("@_TREA_OPEN_TIME_", TOR.OPEN_TREA_TIME); _content = _content.Replace("@_EXEC_TIME_E_", TOR.EXEC_TIME_E); StringBuilder sb = new StringBuilder(); sb.AppendLine(_content); // sb.AppendLine( // $@"您好, //通知今日金庫開關庫時間為:{TOR.OPEN_TREA_TIME},請準時至金庫門口集合。 //為配合金庫大門之啟閉,請有權人在:{TOR.EXEC_TIME_E} 前進入「金庫進出管理系統」完成入庫確認作業,謝謝。 //"); var _FuncId = _MAIL_RECEIVE.Where(x => x.MAIL_CONTENT_ID == _MAIL_CONTENT.MAIL_CONTENT_ID).Select(x => x.FUNC_ID); var _RoleId = _CODE_ROLE_FUNC.Where(x => _FuncId.Contains(x.FUNC_ID)).Select(x => x.ROLE_ID); var _UserId = _CODE_USER_ROLE.Where(x => _RoleId.Contains(x.ROLE_ID)).Select(x => x.USER_ID).Distinct(); List <string> _userIdList = new List <string>(); _userIdList.AddRange(_CODE_USER.Where(x => _UserId.Contains(x.USER_ID) && x.IS_MAIL == "Y").Select(x => x.USER_ID).ToList()); if (_userIdList.Any()) { //人名 EMAIl var _EMP = emps.Where(x => _userIdList.Contains(x.USR_ID)).ToList(); if (_EMP.Any()) { _EMP.ForEach(x => { _mailTo.Add(new Tuple <string, string>(x.EMAIL, x.EMP_NAME)); }); } } try { var sms = new SendMail.SendMailSelf(); sms.smtpPort = 25; sms.smtpServer = Properties.Settings.Default["smtpServer"]?.ToString(); sms.mailAccount = Properties.Settings.Default["mailAccount"]?.ToString(); sms.mailPwd = Properties.Settings.Default["mailPwd"]?.ToString(); sms.Mail_Send( new Tuple <string, string>(sms.mailAccount, "金庫管理系統"), _mailTo, _ccTo, _MAIL_CONTENT?.MAIL_SUBJECT ?? "入庫人員確認作業通知", sb.ToString() ); } catch (Exception ex) { result.DESCRIPTION = $"Email 發送失敗請人工通知。"; } } } #endregion #region LOG //新增LOG Log log = new Log(); log.CFUNCTION = "覆核-指定開庫覆核作業"; log.CACTION = "U"; log.CCONTENT = logStrC; LogDao.Insert(log, SearchData.vCreateUid); #endregion result.RETURN_FLAG = true; result.DESCRIPTION = $"申請單號 : {string.Join(",", RegisterNo)} 覆核成功"; result.Datas = GetApprSearchData(SearchData); } catch (Exception ex) { result.DESCRIPTION = ex.exceptionMessage(); } } } return(result); }
/// <summary> /// 覆核作業查詢 /// </summary> /// <param name="data"></param> /// <returns></returns> public List <SpecifiedTimeTreasuryApprSearchDetailViewModel> GetApprSearchData(SpecifiedTimeTreasuryApprSearchViewModel data) { List <SpecifiedTimeTreasuryApprSearchDetailViewModel> result = new List <SpecifiedTimeTreasuryApprSearchDetailViewModel>(); using (TreasuryDBEntities db = new TreasuryDBEntities()) { var depts = GetDepts(); var emps = GetEmps(); DateTime?_vAPLY_DT_S = TypeTransfer.stringToDateTimeN(data.vAPLY_DT_S); DateTime?_vAPLY_DT_E = TypeTransfer.stringToDateTimeN(data.vAPLY_DT_E).DateToLatestTime(); result = db.TREA_OPEN_REC.AsNoTracking() .Where(x => x.OPEN_TREA_TYPE == "2") .Where(x => x.CREATE_DT >= _vAPLY_DT_S, _vAPLY_DT_S != null) //申請日期(起) .Where(x => x.CREATE_DT <= _vAPLY_DT_E, _vAPLY_DT_E != null) //申請日期(迄) .Where(x => x.TREA_REGISTER_ID == data.vTREA_REGISTER_ID, !data.vTREA_REGISTER_ID.IsNullOrWhiteSpace()) //工作單號 //.Where(x => x.CREATE_UNIT == data.vCreateUnit) //相同部門 .Where(x => x.APPR_STATUS == "1") .AsEnumerable() .Select(x => new SpecifiedTimeTreasuryApprSearchDetailViewModel() { vCREATE_DT = x.CREATE_DT?.ToString("yyyy/MM/dd"), vTREA_REGISTER_ID = x.TREA_REGISTER_ID, vCREATE_UID = x.CREATE_UID, vCREATE_NAME = emps.FirstOrDefault(y => y.USR_ID == x.CREATE_UID)?.EMP_NAME, vOPEN_TREA_DATE = x.OPEN_TREA_DATE.ToString("yyyy/MM/dd"), vEXEC_TIME_B = x.EXEC_TIME_B, vEXEC_TIME_E = x.EXEC_TIME_E, vOPEN_TREA_TIME = x.OPEN_TREA_TIME, vMEMO = x.MEMO, vOPEN_TREA_REASON_ID = x.OPEN_TREA_REASON, vLAST_UPDATE_DT = x.LAST_UPDATE_DT, vAPPR_FLAG = x.CREATE_UID != data.vCreateUid }).ToList(); } return(result); }