Example #1
0
        private TREA_OPEN_REC MappingTableForInsert(SpecifiedTimeTreasuryApplyViewModel data, string currentUserId)
        {
            //取得流水號
            SysSeqDao sysSeqDao = new SysSeqDao();
            string    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
            var       cId       = sysSeqDao.qrySeqNo("W", qPreCode).ToString().PadLeft(2, '0');
            //統一取系統時間
            DateTime dt = DateTime.Now;

            return(new TREA_OPEN_REC()
            {
                TREA_REGISTER_ID = $@"W{qPreCode}{cId}", //申請單號 W+系統日期YYYMMDD(民國年)+2碼流水號,
                OPEN_TREA_TYPE = "2",                    //開庫類型: 指定時間開庫
                OPEN_TREA_REASON = string.Join(";", data.vOPEN_TREA_REASON_ID),
                OPEN_TREA_TIME = data.vOPEN_TREA_TIME,
                EXEC_TIME_B = data.vEXEC_TIME_B,
                EXEC_TIME_E = data.vEXEC_TIME_E,
                MEMO = data.vMEMO,
                APPR_STATUS = "1",   //覆核狀態: 表單申請
                REGI_STATUS = "C02", // 登記簿狀態
                CREATE_UID = currentUserId,
                CREATE_DT = dt,
                LAST_UPDATE_UID = currentUserId,
                LAST_UPDATE_DT = dt,
                OPEN_TREA_DATE = Convert.ToDateTime(data.vOPEN_TREA_DATE),
                CREATE_UNIT = GetUserInfo(currentUserId).DPT_ID
            });
        }
Example #2
0
        /// <summary>
        /// 共用存檔 申請單紀錄檔 回傳參數1 (APLY_NO) 回傳參數2 (log訊息)
        /// </summary>
        /// <param name="db">Entity</param>
        /// <param name="taData">viewModel</param>
        /// <param name="logStr">紀錄訊息</param>
        /// <param name="dt">修改時間</param>
        /// <returns></returns>
        protected Tuple <string, string> SaveTREA_APLY_REC(TreasuryDBEntities db, TreasuryAccessViewModel taData, string logStr, DateTime dt)
        {
            //取得流水號
            SysSeqDao sysSeqDao = new SysSeqDao();
            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
            var       cId       = sysSeqDao.qrySeqNo("G6", qPreCode).ToString().PadLeft(3, '0');

            if (logStr.IsNullOrWhiteSpace())
            {
                logStr = string.Empty;
            }

            #region 申請單紀錄檔
            var _TAR = new TREA_APLY_REC()
            {
                APLY_NO              = $@"G6{qPreCode}{cId}",                                      //申請單號 G6+系統日期YYYMMDD(民國年)+3碼流水號
                APLY_FROM            = Ref.AccessProjectStartupType.M.ToString(),                  //人工
                ITEM_ID              = taData.vItem,                                               //申請項目
                ACCESS_TYPE          = taData.vAccessType,                                         //存入(P) or 取出(G)
                ACCESS_REASON        = taData.vAccessReason,                                       //申請原因
                APLY_STATUS          = Ref.AccessProjectFormStatus.A01.ToString(),                 //表單申請
                EXPECTED_ACCESS_DATE = TypeTransfer.stringToDateTimeN(taData.vExpectedAccessDate), //預計存取日期
                APLY_UNIT            = taData.vAplyUnit,                                           //申請單位
                APLY_UID             = taData.vAplyUid,                                            //申請人
                APLY_DT              = dt,
                CREATE_UNIT          = taData.vCreateUnit,                                         //新增單位
                CREATE_UID           = taData.vCreateUid,                                          //新增人
                CREATE_DT            = dt,
                LAST_UPDATE_UID      = taData.vCreateUid,
                LAST_UPDATE_DT       = dt
            };
            if (taData.vAplyUid != taData.vCreateUid) //當申請人不是新增人(代表為保管單位代申請)
            {
                _TAR.CUSTODY_UID = taData.vCreateUid; //保管單位直接帶 新增人
                _TAR.CUSTODY_DT  = dt;
            }
            logStr += _TAR.modelToString(logStr);
            db.TREA_APLY_REC.Add(_TAR);
            #endregion

            #region 申請單歷程檔
            var _ARH = new APLY_REC_HIS()
            {
                APLY_NO     = _TAR.APLY_NO,
                APLY_STATUS = _TAR.APLY_STATUS,
                PROC_DT     = dt,
                PROC_UID    = _TAR.CREATE_UID
            };
            logStr += _ARH.modelToString(logStr);
            db.APLY_REC_HIS.Add(_ARH);
            #endregion

            return(new Tuple <string, string>(_TAR.APLY_NO, logStr));
        }
Example #3
0
        /// <summary>
        /// 共用存檔 資料庫異動申請單紀錄檔 回傳參數1 (APLY_NO) 回傳參數2 (log訊息)
        /// </summary>
        /// <param name="db">Entity</param>
        /// <param name="data">viewModel</param>
        /// <param name="logStr">紀錄訊息</param>
        /// <param name="dt">時間</param>
        /// <param name="CHG_AUTH_UNIT">權責單位異動</param>
        /// <returns></returns>
        protected Tuple <string, string> SaveINVENTORY_CHG_APLY(TreasuryDBEntities db, CDCSearchViewModel data, string logStr, DateTime dt, string CHG_AUTH_UNIT = "N")
        {
            //取得流水號
            SysSeqDao sysSeqDao = new SysSeqDao();
            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
            var       cId       = sysSeqDao.qrySeqNo("G8", qPreCode).ToString().PadLeft(3, '0');

            #region 資料庫異動申請單紀錄檔
            var ICA = new INVENTORY_CHG_APLY()
            {
                APLY_NO       = $@"G8{qPreCode}{cId}", //申請單號 G8+系統日期YYYMMDD(民國年)+3碼流水號
                ITEM_ID       = data.vJobProject,
                APPR_STATUS   = "1",                   //表單申請
                CHG_AUTH_UNIT = CHG_AUTH_UNIT,         //權責單位異動
                CREATE_UID    = data.vCreate_Uid,
                CREATE_Date   = dt.Date,
                CREATE_Time   = dt.TimeOfDay
            };
            db.INVENTORY_CHG_APLY.Add(ICA);
            logStr += ICA.modelToString(logStr);
            #endregion
            return(new Tuple <string, string>(ICA.APLY_NO, logStr));
        }
Example #4
0
        /// <summary>
        /// 申請覆核 電子憑證
        /// </summary>
        /// <param name="insertDatas">資料</param>
        /// <param name="taData">申請單資料</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITreaItem> > ApplyAudit(IEnumerable <ITreaItem> insertDatas, TreasuryAccessViewModel taData)
        {
            var result = new MSGReturnModel <IEnumerable <ITreaItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (insertDatas != null)
                {
                    var datas = (List <CAViewModel>)insertDatas;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            string    logStr    = string.Empty; //log
                            var       item_Seq  = "E5";         //電子憑證流水號開頭編碼

                            String qPreCode = DateUtil.getCurChtDateTime().Split(' ')[0];

                            var _TAR         = new TREA_APLY_REC();                        //申請單號
                            var _APLY_STATUS = Ref.AccessProjectFormStatus.A01.ToString(); //表單申請

                            if (!taData.vAplyNo.IsNullOrWhiteSpace())                      //修改已存在申請單
                            {
                                #region 申請單紀錄檔
                                _TAR = db.TREA_APLY_REC.First(x => x.APLY_NO == taData.vAplyNo);
                                if (CustodyAppr.Contains(_TAR.APLY_STATUS))
                                {
                                    _APLY_STATUS     = CustodyConfirmStatus;
                                    _TAR.CUSTODY_UID = AccountController.CurrentUserId; //保管單位直接帶使用者
                                    _TAR.CUSTODY_DT  = dt;
                                }
                                else
                                {
                                    if (_TAR.APLY_STATUS != _APLY_STATUS)                          //申請紀錄檔狀態不是在表單申請狀態
                                    {
                                        _APLY_STATUS = Ref.AccessProjectFormStatus.A05.ToString(); //為重新申請案例
                                    }
                                }
                                _TAR.APLY_STATUS    = _APLY_STATUS;
                                _TAR.LAST_UPDATE_DT = dt;

                                logStr += _TAR.modelToString(logStr);
                                #endregion

                                #region 申請單歷程檔
                                var _ARH = new APLY_REC_HIS()
                                {
                                    APLY_NO     = taData.vAplyNo,
                                    APLY_STATUS = _APLY_STATUS,
                                    PROC_DT     = dt,
                                    PROC_UID    = taData.vCreateUid
                                };
                                logStr += _ARH.modelToString(logStr);
                                db.APLY_REC_HIS.Add(_ARH);
                                #endregion

                                #region 電子憑證庫存資料檔

                                var            _dept         = intra.getDept_Sect(taData.vAplyUnit);
                                List <string>  oldItemIds    = db.OTHER_ITEM_APLY.Where(x => x.APLY_NO == taData.vAplyNo).Select(x => x.ITEM_ID).ToList(); //原有 itemId
                                List <string>  updateItemIds = new List <string>();                                                                        //更新 itemId
                                List <string>  cancelItemIds = new List <string>();                                                                        //取消 itemId
                                List <ITEM_CA> inserts       = new List <ITEM_CA>();                                                                       //新增資料

                                //抓取有修改註記的
                                foreach (var item in datas)
                                {
                                    var _IC_Item_Id = string.Empty;
                                    if (taData.vAccessType == Ref.AccessProjectTradeType.P.ToString()) //存入
                                    {
                                        //只抓取預約存入
                                        if (item.vStatus == Ref.AccessInventoryType._3.GetDescription())
                                        {
                                            var _IC = new ITEM_CA();

                                            if (item.vItemId.StartsWith(item_Seq)) //舊有資料
                                            {
                                                _IC = db.ITEM_CA.FirstOrDefault(x => x.ITEM_ID == item.vItemId);
                                                if (_IC.LAST_UPDATE_DT > item.vLast_Update_Time)
                                                {
                                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                                    return(result);
                                                }
                                                _IC.CA_DESC   = item.vCA_Desc;   //電子憑證品項
                                                _IC.CA_USE    = item.vCA_Use;    //電子憑證用途
                                                _IC.BANK      = item.vBank;      //銀行/廠商
                                                _IC.CA_NUMBER = item.vCA_Number; //電子憑證號碼
                                                _IC.MEMO      = item.vMemo;      //備註說明
                                                updateItemIds.Add(item.vItemId);
                                                logStr += _IC.modelToString(logStr);
                                            }
                                            else
                                            {
                                                var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                                _IC = new ITEM_CA()
                                                {
                                                    ITEM_ID          = $@"{item_Seq}{item_id}", //物品編號
                                                    INVENTORY_STATUS = "3",                     //預約存入
                                                    CA_DESC          = item.vCA_Desc,           //電子憑證品項
                                                    CA_USE           = item.vCA_Use,            //電子憑證用途
                                                    BANK             = item.vBank,              //銀行/廠商
                                                    CA_NUMBER        = item.vCA_Number,         //電子憑證號碼
                                                    MEMO             = item.vMemo,              //備註說明
                                                    APLY_DEPT        = _dept.Item1,             //申請人部門
                                                    APLY_SECT        = _dept.Item2,             //申請人科別
                                                    APLY_UID         = taData.vAplyUid,         //申請人
                                                    CHARGE_DEPT      = _dept.Item1,             //權責部門
                                                    CHARGE_SECT      = _dept.Item2,             //權責科別
                                                                                                //PUT_DATE = dt, //存入日期時間
                                                    LAST_UPDATE_DT = dt,                        //最後修改時間
                                                };
                                                _IC_Item_Id = _IC.ITEM_ID;
                                                inserts.Add(_IC);
                                                logStr += _IC.modelToString(logStr);
                                            }
                                        }
                                    }
                                    else if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString() && (_APLY_STATUS != CustodyConfirmStatus))//取出
                                    {
                                        var _IC = db.ITEM_CA.FirstOrDefault(x => x.ITEM_ID == item.vItemId);
                                        if (_IC.LAST_UPDATE_DT > item.vLast_Update_Time)
                                        {
                                            result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                            return(result);
                                        }
                                        //預約取出
                                        if (item.vtakeoutFlag)
                                        {
                                            if (_IC.INVENTORY_STATUS == "1") //原先為在庫
                                            {
                                                _IC.INVENTORY_STATUS = "4";  //預約取出
                                                _IC.LAST_UPDATE_DT   = dt;   //最後修改時間
                                                updateItemIds.Add(_IC.ITEM_ID);
                                            }
                                            else if (_IC.INVENTORY_STATUS == "4") //原先為預約取出
                                            {
                                                updateItemIds.Add(_IC.ITEM_ID);
                                            }
                                        }
                                        else
                                        {
                                            if (_IC.INVENTORY_STATUS == "4") //原先為在庫
                                            {
                                                _IC.INVENTORY_STATUS = "1";  //預約取出
                                                _IC.LAST_UPDATE_DT   = dt;   //最後修改時間
                                            }
                                        }
                                    }
                                }

                                if (taData.vAccessType == Ref.AccessProjectTradeType.P.ToString()) //存入
                                {
                                    var delItemId = oldItemIds.Where(x => !updateItemIds.Contains(x)).ToList();
                                    db.OTHER_ITEM_APLY.RemoveRange(db.OTHER_ITEM_APLY.Where(x => x.APLY_NO == taData.vAplyNo && delItemId.Contains(x.ITEM_ID)).ToList());
                                    db.ITEM_CA.RemoveRange(db.ITEM_CA.Where(x => delItemId.Contains(x.ITEM_ID)).ToList());
                                    db.OTHER_ITEM_APLY.AddRange(inserts.Select(x => new OTHER_ITEM_APLY()
                                    {
                                        APLY_NO = taData.vAplyNo,
                                        ITEM_ID = x.ITEM_ID
                                    }));
                                    db.ITEM_CA.AddRange(inserts);
                                }
                                else if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString() && (_APLY_STATUS != CustodyConfirmStatus))//取出
                                {
                                    db.OTHER_ITEM_APLY.RemoveRange(db.OTHER_ITEM_APLY.Where(x => x.APLY_NO == taData.vAplyNo).ToList());
                                    db.OTHER_ITEM_APLY.AddRange(updateItemIds.Select(x => new OTHER_ITEM_APLY()
                                    {
                                        APLY_NO = taData.vAplyNo,
                                        ITEM_ID = x
                                    }));
                                }
                                #endregion
                            }
                            else
                            {
                                #region 申請單紀錄檔 & 申請單歷程檔

                                var data = SaveTREA_APLY_REC(db, taData, logStr, dt);
                                _TAR.APLY_NO = data.Item1;
                                logStr       = data.Item2;

                                #endregion

                                #region 電子憑證庫存資料檔
                                var _dept = intra.getDept_Sect(taData.vAplyUnit);
                                //抓取有修改註記的
                                foreach (var item in datas)
                                {
                                    var _IC_Item_Id = string.Empty;
                                    if (taData.vAccessType == Ref.AccessProjectTradeType.P.ToString()) //存入
                                    {
                                        //只抓取預約存入
                                        if (item.vStatus == Ref.AccessInventoryType._3.GetDescription())
                                        {
                                            var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                            var _IC     = new ITEM_CA()
                                            {
                                                ITEM_ID          = $@"{item_Seq}{item_id}", //物品編號
                                                INVENTORY_STATUS = "3",                     //預約存入
                                                CA_DESC          = item.vCA_Desc,           //電子憑證品項
                                                CA_USE           = item.vCA_Use,            //電子憑證用途
                                                BANK             = item.vBank,              //銀行/廠商
                                                CA_NUMBER        = item.vCA_Number,         //電子憑證號碼
                                                MEMO             = item.vMemo,              //備註說明
                                                APLY_DEPT        = _dept.Item1,             //申請人部門
                                                APLY_SECT        = _dept.Item2,             //申請人科別
                                                APLY_UID         = taData.vAplyUid,         //申請人
                                                CHARGE_DEPT      = _dept.Item1,             //權責部門
                                                CHARGE_SECT      = _dept.Item2,             //權責科別
                                                                                            //PUT_DATE = dt, //存入日期時間
                                                LAST_UPDATE_DT = dt,                        //最後修改時間
                                            };
                                            _IC_Item_Id = _IC.ITEM_ID;
                                            db.ITEM_CA.Add(_IC);
                                            logStr += _IC.modelToString(logStr);
                                        }
                                    }
                                    else if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString())//取出
                                    {
                                        //只抓取預約取出
                                        if (item.vStatus == Ref.AccessInventoryType._4.GetDescription())
                                        {
                                            var _IC = db.ITEM_CA.FirstOrDefault(x => x.ITEM_ID == item.vItemId);
                                            _IC_Item_Id = _IC.ITEM_ID;
                                            if (_IC.LAST_UPDATE_DT > item.vLast_Update_Time)
                                            {
                                                result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                                return(result);
                                            }
                                            _IC.INVENTORY_STATUS = "4"; //預約取出
                                                                        //_IRE.GET_DATE = dt; //取出日期時間
                                            _IC.LAST_UPDATE_DT = dt;    //最後修改時間
                                        }
                                    }


                                    #region 其它存取項目申請資料檔
                                    if (!_IC_Item_Id.IsNullOrWhiteSpace())
                                    {
                                        db.OTHER_ITEM_APLY.Add(
                                            new OTHER_ITEM_APLY()
                                        {
                                            APLY_NO = _TAR.APLY_NO,
                                            ITEM_ID = _IC_Item_Id
                                        });
                                    }
                                    #endregion
                                }
                                #endregion
                            }

                            #region Save Db
                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, taData.vCreateUid);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_TAR.APLY_NO}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #5
0
        //public List<SelectOption> GetTreaItem()
        //{
        //    List<SelectOption> treaItem = new List<SelectOption>();

        //    using (TreasuryDBEntities db = new TreasuryDBEntities())
        //    {
        //        treaItem = db.TREA_ITEM.AsNoTracking()
        //    }
        //}

        /// <summary>
        /// 金庫進出管理作業-申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (ItemMaintainSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var datas = (List <ItemMaintainSearchDetailViewModel>)saveData;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            var       cId       = sysSeqDao.qrySeqNo("G1", qPreCode).ToString().PadLeft(3, '0');
                            string    _Aply_No  = string.Empty;
                            _Aply_No = $@"G1{qPreCode}{cId}"; //申請單號 G1+系統日期YYYMMDD(民國年)+3碼流水號
                            string logStr = string.Empty;     //log

                            foreach (var item in datas)
                            {
                                var _Trea_Item_Id = string.Empty;
                                var _TI           = new TREA_ITEM();
                                # region 金庫存取作業設定檔
                                //判斷執行功能
                                switch (item.vEXEC_ACTION)
                                {
                                case "A":    //新增
                                    _Trea_Item_Id = "";
                                    //_Trea_Item_Id = sysSeqDao.qrySeqNo("D1", string.Empty).ToString().PadLeft(3, '0');
                                    //_Trea_Item_Id = $@"D1{_Trea_Item_Id}";
                                    //_TI = new TREA_ITEM()
                                    //{
                                    //    ITEM_ID = _Trea_Item_Id,
                                    //    ITEM_DESC = item.vITEM_DESC,
                                    //    IS_TREA_ITEM = item.vIS_TREA_ITEM,
                                    //    TREA_ITEM_NAME = item.vTREA_ITEM_NAME,
                                    //    TREA_ITEM_TYPE = item.vTREA_ITEM_TYPE,
                                    //    ITEM_OP_TYPE = item.vITEM_OP_TYPE,
                                    //    DAILY_FLAG = item.vISDO_PERDAY,
                                    //    IS_DISABLED = item.vIS_DISABLED,
                                    //    MEMO = item.vMEMO,
                                    //    DATA_STATUS = "2",//凍結中
                                    //    CREATE_DT = dt,
                                    //    CREATE_UID = searchData.vCUSER_ID,
                                    //    LAST_UPDATE_DT =dt,
                                    //    LAST_UPDATE_UID = searchData.vCUSER_ID,
                                    //    FREEZE_UID = searchData.vCUSER_ID,
                                    //    FREEZE_DT = dt
                                    //};
                                    //db.TREA_ITEM.Add(_TI);
                                    //logStr += "|";
                                    //logStr += _TI.modelToString();
                                    break;

                                case "U":    //修改
                                    _TI = db.TREA_ITEM.FirstOrDefault(x => x.ITEM_ID == item.vITEM_ID);
                                    if (_TI.LAST_UPDATE_DT != null && _TI.LAST_UPDATE_DT > item.vLAST_UPDATE_DT)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _Trea_Item_Id       = item.vITEM_ID;
                                    _TI.DATA_STATUS     = "2";//凍結中
                                    _TI.LAST_UPDATE_UID = searchData.vCUSER_ID;
                                    _TI.LAST_UPDATE_DT  = dt;
                                    _TI.FREEZE_UID      = searchData.vCUSER_ID;
                                    _TI.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _TI.modelToString();
                                    break;

                                case "D":    //刪除
                                    _TI = db.TREA_ITEM.FirstOrDefault(x => x.ITEM_ID == item.vITEM_ID);
                                    if (_TI.LAST_UPDATE_DT != null && _TI.LAST_UPDATE_DT > item.vLAST_UPDATE_DT)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _Trea_Item_Id       = item.vITEM_ID;
                                    _TI.DATA_STATUS     = "2";//凍結中
                                    _TI.LAST_UPDATE_UID = searchData.vCUSER_ID;
                                    _TI.LAST_UPDATE_DT  = dt;
                                    _TI.FREEZE_UID      = searchData.vCUSER_ID;
                                    _TI.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _TI.modelToString();
                                    break;

                                default:
                                    break;
                                }
                                #endregion
                                #region 金庫存取作業異動檔
                                var _TI_Data = db.TREA_ITEM.FirstOrDefault(x => x.ITEM_ID == item.vITEM_ID);
                                if (_TI_Data == null)
                                {
                                    var _TIH = new TREA_ITEM_HIS()
                                    {
                                        APLY_NO        = _Aply_No,
                                        ITEM_ID        = _Trea_Item_Id,
                                        EXEC_ACTION    = item.vEXEC_ACTION,
                                        ITEM_DESC      = item.vITEM_DESC,
                                        IS_TREA_ITEM   = item.vIS_TREA_ITEM,
                                        TREA_ITEM_NAME = item.vTREA_ITEM_NAME,
                                        TREA_ITEM_TYPE = item.vTREA_ITEM_TYPE,
                                        ITEM_OP_TYPE   = item.vITEM_OP_TYPE,
                                        DAILY_FLAG     = item.vISDO_PERDAY,
                                        IS_DISABLED    = item.vIS_DISABLED,
                                        MEMO           = item.vMEMO,
                                        APLY_DATE      = dt,
                                        APLY_UID       = searchData.vCUSER_ID,
                                        APPR_STATUS    = "1" //表單申請
                                    };
                                    db.TREA_ITEM_HIS.Add(_TIH);
                                    logStr += "|";
                                    logStr += _TIH.modelToString();
                                }
                                else
                                {
                                    var _TIH = new TREA_ITEM_HIS()
                                    {
                                        APLY_NO          = _Aply_No,
                                        ITEM_ID          = _Trea_Item_Id,
                                        EXEC_ACTION      = item.vEXEC_ACTION,
                                        ITEM_DESC        = item.vITEM_DESC,
                                        IS_TREA_ITEM     = item.vIS_TREA_ITEM,
                                        TREA_ITEM_NAME   = item.vTREA_ITEM_NAME,
                                        TREA_ITEM_TYPE   = item.vTREA_ITEM_TYPE,
                                        ITEM_OP_TYPE     = item.vITEM_OP_TYPE,
                                        DAILY_FLAG       = item.vISDO_PERDAY,
                                        IS_DISABLED      = item.vIS_DISABLED,
                                        MEMO             = item.vMEMO,
                                        APLY_DATE        = dt,
                                        APLY_UID         = searchData.vCUSER_ID,
                                        APPR_STATUS      = "1", //表單申請
                                        DAILY_FLAG_B     = _TI_Data.DAILY_FLAG,
                                        IS_DISABLED_B    = _TI_Data.IS_DISABLED,
                                        IS_TREA_ITEM_B   = _TI_Data.IS_TREA_ITEM,
                                        TREA_ITEM_TYPE_B = _TI_Data.TREA_ITEM_TYPE,
                                        TREA_ITEM_NAME_B = _TI_Data.TREA_ITEM_NAME,
                                        MEMO_B           = _TI_Data.MEMO
                                    };
                                    db.TREA_ITEM_HIS.Add(_TIH);
                                    logStr += "|";
                                    logStr += _TIH.modelToString();
                                }
                                #endregion
                            }
                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.vCUSER_ID);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
Example #6
0
        /// <summary>
        /// 金庫進出管理作業-申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (TreasuryMaintainSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var datas = (List <TreasuryMaintainViewModel>)saveData;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            string    _Aply_No  = string.Empty;
                            var       cId       = sysSeqDao.qrySeqNo("G2", qPreCode).ToString().PadLeft(3, '0');
                            _Aply_No = $@"G2{qPreCode}{cId}"; //申請單號 G2+系統日期YYYMMDD(民國年)+3碼流水號
                            string logStr = string.Empty;     //log

                            foreach (var item in datas)
                            {
                                var _Trea_Equip_Id = string.Empty;
                                var _TE            = new TREA_EQUIP();

                                #region 金庫設備設定檔

                                //判斷執行功能
                                switch (item.vExec_Action)
                                {
                                case "A":    //新增
                                    _Trea_Equip_Id = "";
                                    //_Trea_Equip_Id = sysSeqDao.qrySeqNo("D2", string.Empty).ToString().PadLeft(3, '0');
                                    //_Trea_Equip_Id = $@"D2{_Trea_Equip_Id}";
                                    //_TE = new TREA_EQUIP()
                                    //{
                                    //    TREA_EQUIP_ID = _Trea_Equip_Id,
                                    //    EQUIP_NAME = item.vEquip_Name,
                                    //    CONTROL_MODE = item.vControl_Mode,
                                    //    NORMAL_CNT = item.vNormal_Cnt,
                                    //    RESERVE_CNT = item.vReserve_Cnt,
                                    //    MEMO = item.vMemo,
                                    //    IS_DISABLED = "N",
                                    //    DATA_STATUS = "2",//凍結中
                                    //    CREATE_UID = searchData.vLast_Update_Uid,
                                    //    CREATE_DT = dt,
                                    //    LAST_UPDATE_UID = searchData.vLast_Update_Uid,
                                    //    LAST_UPDATE_DT = dt,
                                    //    FREEZE_UID = searchData.vLast_Update_Uid,
                                    //    FREEZE_DT = dt
                                    //};
                                    //db.TREA_EQUIP.Add(_TE);
                                    //logStr += "|";
                                    //logStr += _TE.modelToString();
                                    break;

                                case "U":    //修改
                                    _TE = db.TREA_EQUIP.FirstOrDefault(x => x.TREA_EQUIP_ID == item.vTrea_Equip_Id);
                                    if (_TE.LAST_UPDATE_DT != null && _TE.LAST_UPDATE_DT > item.vLast_Update_Dt)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _Trea_Equip_Id      = item.vTrea_Equip_Id;
                                    _TE.DATA_STATUS     = "2";//凍結中
                                    _TE.LAST_UPDATE_UID = searchData.vLast_Update_Uid;
                                    _TE.LAST_UPDATE_DT  = dt;
                                    _TE.FREEZE_UID      = searchData.vLast_Update_Uid;
                                    _TE.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _TE.modelToString();
                                    break;

                                case "D":    //刪除
                                    _TE = db.TREA_EQUIP.FirstOrDefault(x => x.TREA_EQUIP_ID == item.vTrea_Equip_Id);
                                    if (_TE.LAST_UPDATE_DT != null && _TE.LAST_UPDATE_DT > item.vLast_Update_Dt)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _Trea_Equip_Id      = item.vTrea_Equip_Id;
                                    _TE.DATA_STATUS     = "2";//凍結中
                                    _TE.LAST_UPDATE_UID = searchData.vLast_Update_Uid;
                                    _TE.LAST_UPDATE_DT  = dt;
                                    _TE.FREEZE_UID      = searchData.vLast_Update_Uid;
                                    _TE.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _TE.modelToString();
                                    break;

                                default:
                                    break;
                                }

                                #endregion 金庫設備設定檔

                                #region 金庫設備異動檔

                                var _TE_Data = db.TREA_EQUIP.FirstOrDefault(x => x.TREA_EQUIP_ID == item.vTrea_Equip_Id);
                                if (_TE_Data == null)
                                {
                                    var _TEH = new TREA_EQUIP_HIS()
                                    {
                                        APLY_NO       = _Aply_No,
                                        TREA_EQUIP_ID = _Trea_Equip_Id,
                                        EXEC_ACTION   = item.vExec_Action,
                                        EQUIP_NAME    = item.vEquip_Name,
                                        CONTROL_MODE  = item.vControl_Mode,
                                        NORMAL_CNT    = item.vNormal_Cnt,
                                        RESERVE_CNT   = item.vReserve_Cnt,
                                        MEMO          = item.vMemo,
                                        IS_DISABLED   = item.vIs_Disabled,
                                        APPR_STATUS   = "1",//表單申請
                                        APLY_UID      = searchData.vLast_Update_Uid,
                                        APLY_DATE     = dt
                                    };
                                    db.TREA_EQUIP_HIS.Add(_TEH);
                                    logStr += "|";
                                    logStr += _TEH.modelToString();
                                }
                                else
                                {
                                    var _TEH = new TREA_EQUIP_HIS()
                                    {
                                        APLY_NO        = _Aply_No,
                                        TREA_EQUIP_ID  = _Trea_Equip_Id,
                                        EXEC_ACTION    = item.vExec_Action,
                                        EQUIP_NAME     = item.vEquip_Name,
                                        CONTROL_MODE   = item.vControl_Mode,
                                        NORMAL_CNT     = item.vNormal_Cnt,
                                        RESERVE_CNT    = item.vReserve_Cnt,
                                        MEMO           = item.vMemo,
                                        IS_DISABLED    = item.vIs_Disabled,
                                        APPR_STATUS    = "1",//表單申請
                                        EQUIP_NAME_B   = _TE_Data.EQUIP_NAME,
                                        CONTROL_MODE_B = _TE_Data.CONTROL_MODE,
                                        NORMAL_CNT_B   = _TE_Data.NORMAL_CNT,
                                        RESERVE_CNT_B  = _TE_Data.RESERVE_CNT,
                                        MEMO_B         = _TE_Data.MEMO,
                                        IS_DISABLED_B  = _TE_Data.IS_DISABLED,
                                        APLY_UID       = searchData.vLast_Update_Uid,
                                        APLY_DATE      = dt
                                    };
                                    db.TREA_EQUIP_HIS.Add(_TEH);
                                    logStr += "|";
                                    logStr += _TEH.modelToString();
                                }

                                #endregion 金庫設備異動檔
                            }

                            #region Save Db

                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.vLast_Update_Uid);

                                    #endregion LOG

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }

                            #endregion Save Db
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #7
0
        public void Routine(TreasuryDBEntities db, string dateTime, DateTime _dtn, string MAIL_TIME_ID)
        {
            var       _split     = dateTime.Split(':');
            var       hh         = _split[0];
            var       mm         = _split.Length > 1 ? _split[1] : string.Empty;
            var       dt         = new DateTime(_dtn.Year, _dtn.Month, _dtn.Day, Convert.ToInt32(hh), Convert.ToInt32(mm), 0);
            SysSeqDao sysSeqDao  = new SysSeqDao();
            String    qPreCode   = DateUtil.getCurChtDateTime().Split(' ')[0];
            var       _Mail_Time = db.MAIL_TIME.ToList()
                                   .FirstOrDefault(x =>
                                                   x.MAIL_TIME_ID == MAIL_TIME_ID &&
                                                   x.SEND_TIME != null &&
                                                   x.SEND_TIME == dateTime &&
                                                   x.IS_DISABLED != "Y" &&
                                                   x.SCHEDULER_UPDATE_DT == _dtn);

            if (_Mail_Time != null)
            {
                string errorMsg = string.Empty;

                var MailTId      = sysSeqDao.qrySeqNo("MailT", qPreCode).ToString().PadLeft(3, '0');
                var _JOB_ITEM_ID = $@"{qPreCode}W{MailTId}";
                try
                {
                    #region 新增排程工作紀錄檔
                    Extension.NlogSet($"新增排程工作紀錄檔");
                    db.SYS_JOB_REC.Add(new SYS_JOB_REC()
                    {
                        JOB_ITEM_ID = _JOB_ITEM_ID,
                        JOB_ID      = _Mail_Time.MAIL_TIME_ID,
                        CREATE_TIME = dt,
                        STATUS      = "2",
                        START_TIME  = _dtn,
                    });

                    var test = db.GetValidationErrors().getValidateString();
                    if (!test.IsNullOrWhiteSpace())
                    {
                        Extension.NlogSet($"{test}");
                    }
                    db.SaveChanges();
                    #endregion

                    #region 新增 開庫紀錄檔
                    Extension.NlogSet($"新增開庫紀錄檔");
                    db.TREA_OPEN_REC.RemoveRange(
                        db.TREA_OPEN_REC.Where(x =>
                                               x.OPEN_TREA_TYPE == "1" &&
                                               x.OPEN_TYPE == "Y" &&
                                               x.REGI_STATUS == "C02"));

                    var _TORId = sysSeqDao.qrySeqNo("W", qPreCode).ToString().PadLeft(2, '0');
                    var _TOR   = new TREA_OPEN_REC()
                    {
                        TREA_REGISTER_ID = $"W{qPreCode}{_TORId}",    //開庫工作單號(金庫登記簿單號)
                        OPEN_TREA_TYPE   = "1",                       //開庫類型
                        OPEN_TREA_REASON = "例行性開庫",                   //開庫原因
                        OPEN_TREA_TIME   = _Mail_Time.TREA_OPEN_TIME, //開庫時間
                        EXEC_TIME_B      = _Mail_Time.EXEC_TIME_B,    //系統區間(起)
                        EXEC_TIME_E      = _Mail_Time.EXEC_TIME_E,    //系統區間(迄)
                        OPEN_TREA_DATE   = _dtn,
                        APPR_STATUS      = "2",
                        REGI_STATUS      = "C02",
                        CREATE_DT        = _dtn,
                        OPEN_TYPE        = "Y" //Y為例行性
                    };
                    db.TREA_OPEN_REC.Add(_TOR);

                    #endregion

                    #region 取得例行出入庫作業項目

                    #region 自【金庫存取作業設定檔】查詢例行出入庫作業項目
                    Extension.NlogSet($"自【金庫存取作業設定檔】查詢例行出入庫作業項目");
                    var _Trea_Item = db.TREA_ITEM.AsNoTracking()
                                     .Where(x =>
                                            x.DAILY_FLAG == "Y" &&
                                            x.IS_DISABLED == "N").ToList();
                    #endregion

                    #region 清空【申請單紀錄暫存檔】
                    Extension.NlogSet($" 清空【申請單紀錄暫存檔】");
                    db.TREA_APLY_TEMP.RemoveRange(db.TREA_APLY_TEMP);
                    #endregion

                    var _MAIL_CONTENT = db.MAIL_CONTENT.AsNoTracking()
                                        .First(x => x.MAIL_CONTENT_ID == _Mail_Time.MAIL_CONTENT_ID);
                    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();
                    List <string> _userIdList     = new List <string>();
                    var           emps            = GetEmps();
                    //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 _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();
                    _userIdList.AddRange(_CODE_USER.Where(x => _UserId.Contains(x.USER_ID) && x.IS_MAIL == "Y").Select(x => x.USER_ID));

                    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));
                            });
                        }
                    }

                    var str = _MAIL_CONTENT.MAIL_CONTENT1;

                    str = str.Replace("@_TREA_OPEN_TIME_", _Mail_Time.TREA_OPEN_TIME);
                    str = str.Replace("@_EXEC_TIME_E_", _Mail_Time.EXEC_TIME_E);

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(str);
//                    sb.AppendLine(
//$@"您好,
//通知今日金庫開關庫時間為:{_Mail_Time.TREA_OPEN_TIME},請準時至金庫門口集合。
//為配合金庫大門之啟閉,請有權人在:{_Mail_Time.EXEC_TIME_E} 前進入「金庫進出管理系統」完成入庫確認作業,謝謝。
//");
                    int num = 1;

                    #region 將例行作業項目寫入【申請單紀錄暫存檔】
                    Extension.NlogSet($" 將例行作業項目寫入【申請單紀錄暫存檔】");
                    _Trea_Item.ForEach(x =>
                    {
                        db.TREA_APLY_TEMP.Add(new TREA_APLY_TEMP()
                        {
                            ITEM_ID = x.ITEM_ID
                        });
                        //sb.AppendLine($"{num}. {x.ITEM_DESC}");
                        num += 1;
                    });
                    #endregion

                    #endregion

                    #region 寄送mail給保管人
                    Extension.NlogSet($" 寄送mail給保管人");
                    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();
                        Extension.NlogSet($" 寄送mail內容 : {sb.ToString()}");
                        sms.Mail_Send(
                            new Tuple <string, string>(sms.mailAccount, "金庫管理系統"),
                            _mailTo,
                            _ccTo,
                            _MAIL_CONTENT?.MAIL_SUBJECT ?? "金庫每日例行開庫通知",
                            sb.ToString()
                            );
                    }
                    catch (Exception ex)
                    {
                        Extension.NlogSet($" 寄送mail給保管人 錯誤 : {ex.exceptionMessage()}");
                    }


                    #endregion
                    test = db.GetValidationErrors().getValidateString();
                    if (!test.IsNullOrWhiteSpace())
                    {
                        Extension.NlogSet($"{test}");
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    errorMsg = ex.exceptionMessage();
                    Extension.NlogSet($"錯誤 : {errorMsg}");
                }
                #region 異動【排程工作紀錄檔】資料(工作結束)
                var _SJR = db.SYS_JOB_REC
                           .FirstOrDefault(x => x.JOB_ITEM_ID == _JOB_ITEM_ID);
                if (_SJR != null)
                {
                    if (!errorMsg.IsNullOrWhiteSpace())
                    {
                        _SJR.STATUS = "4"; //執行失敗
                        _SJR.MEMO   = errorMsg;
                    }
                    else
                    {
                        _SJR.STATUS = "3"; //執行成功
                        _SJR.MEMO   = null;
                    }
                    _SJR.END_TIME = DateTime.Now;
                    var test = db.GetValidationErrors().getValidateString();
                    if (!test.IsNullOrWhiteSpace())
                    {
                        Extension.NlogSet($"{test}");
                    }
                    db.SaveChanges();
                }
                #endregion
            }
            //db.MAIL_TIME
        }
Example #8
0
        public void RemindClose(TreasuryDBEntities db, string dateTime, DateTime _dtn, int?_INTERVAL_MIN)
        {
            //bool result = true;
            var       _split    = dateTime.Split(':');
            var       hh        = _split[0];
            var       mm        = _split.Length > 1 ? _split[1] : string.Empty;
            var       dt        = new DateTime(_dtn.Year, _dtn.Month, _dtn.Day, Convert.ToInt32(hh), Convert.ToInt32(mm), 0);
            SysSeqDao sysSeqDao = new SysSeqDao();
            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];

            //var _TREA_OPEN_REC = db.TREA_OPEN_REC.AsNoTracking()
            //    .Where(x => x.REGI_STATUS.Trim()[0] == 'D' && x.LAST_UPDATE_DT < _dtn.AddMinutes(Convert.ToDouble(-_INTERVAL_MIN)));


            var _TREA_OPEN_REC = db.TREA_OPEN_REC.AsNoTracking().AsEnumerable()
                                 .FirstOrDefault(x => x.REGI_STATUS != "E01" && x.APPR_STATUS != "4" && x.LAST_UPDATE_DT < _dtn.AddMinutes(Convert.ToDouble(-_INTERVAL_MIN)));

            if (_TREA_OPEN_REC != null)
            {
                //result = false;

                var _TREA_APLY_REC = db.TREA_APLY_REC.AsNoTracking().FirstOrDefault(x => x.TREA_REGISTER_ID == _TREA_OPEN_REC.TREA_REGISTER_ID);

                var _Mail_Time = db.MAIL_TIME.AsNoTracking().FirstOrDefault(x => x.MAIL_TIME_ID == "3" && x.IS_DISABLED == "N");
                if (_Mail_Time != null)
                {
                    var    _MAIL_CONTENT = db.MAIL_CONTENT.AsNoTracking().FirstOrDefault(x => x.MAIL_CONTENT_ID == _Mail_Time.MAIL_CONTENT_ID && x.IS_DISABLED == "N");
                    string errorMsg      = string.Empty;

                    Extension.NlogSet($"MAIL_TIME 有找到未完成關庫覆核的金庫登記簿");
                    Extension.NlogSet($"DateTime : {_dtn}");

                    var MailTId      = sysSeqDao.qrySeqNo("MailT", qPreCode).ToString().PadLeft(3, '0');
                    var _JOB_ITEM_ID = $@"{qPreCode}W{MailTId}";

                    try
                    {
                        #region 新增排程工作紀錄檔
                        Extension.NlogSet($"新增排程工作紀錄檔");
                        db.SYS_JOB_REC.Add(new SYS_JOB_REC()
                        {
                            JOB_ITEM_ID = _JOB_ITEM_ID,
                            JOB_ID      = _Mail_Time.MAIL_TIME_ID,
                            CREATE_TIME = dt,
                            STATUS      = "2",
                            START_TIME  = _dtn,
                        });
                        var test = db.GetValidationErrors().getValidateString();
                        if (!test.IsNullOrWhiteSpace())
                        {
                            Extension.NlogSet($"{test}");
                        }
                        db.SaveChanges();
                        #endregion

                        //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           _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();
                        List <string> _userIdList = new List <string>();
                        var           emps        = GetEmps();

                        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();
                        _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));
                                });
                            }
                        }


                        StringBuilder sb = new StringBuilder();

                        string str = _MAIL_CONTENT.MAIL_CONTENT1;
                        str = str.Replace("@_TREA_REGISTER_ID_", _TREA_OPEN_REC.TREA_REGISTER_ID);
                        var status = string.Empty;

                        switch (_TREA_OPEN_REC.REGI_STATUS)
                        {
                        case "C02":
                            if (_TREA_OPEN_REC.APPR_STATUS == "3")
                            {
                                status = "【指定開庫申請作業】";
                            }
                            else if (_TREA_OPEN_REC.APPR_STATUS == "1")
                            {
                                status = "【指定開庫覆核作業】";
                            }
                            else if (_TREA_OPEN_REC.APPR_STATUS == "2")
                            {
                                if (_TREA_APLY_REC == null)
                                {
                                    status = "【入庫人員確認作業】";
                                }
                                else
                                {
                                    status = "【金庫登記簿執行作業(開庫前)】";
                                }
                            }
                            break;

                        case "D01":
                            status = "【金庫登記簿執行作業(開庫後)】";
                            break;

                        case "D02":
                        case "D04":
                            status = "【金庫登記簿覆核作業】";
                            break;
                        }

                        str = str.Replace("@_STATUS_", status);
                        sb.AppendLine(str);

                        #region 寄送mail給相關人員
                        Extension.NlogSet($" 寄送mail給相關人員");
                        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();
                            Extension.NlogSet($" 寄送mail內容 : {sb.ToString()}");
                            sms.Mail_Send(
                                new Tuple <string, string>(sms.mailAccount, "金庫管理系統"),
                                _mailTo,
                                _ccTo,
                                _MAIL_CONTENT?.MAIL_SUBJECT ?? "金庫登記簿開庫流程尚完成通知",
                                sb.ToString()
                                );
                        }
                        catch (Exception ex)
                        {
                            Extension.NlogSet($" 寄送mail給相關人員 錯誤 : {ex.exceptionMessage()}");
                        }
                        test = db.GetValidationErrors().getValidateString();
                        if (!test.IsNullOrWhiteSpace())
                        {
                            Extension.NlogSet($"{test}");
                        }
                        db.SaveChanges();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        errorMsg = ex.exceptionMessage();
                        Extension.NlogSet($"錯誤 : {errorMsg}");
                    }

                    #region 異動【排程工作紀錄檔】資料(工作結束)
                    var _SJR = db.SYS_JOB_REC
                               .FirstOrDefault(x => x.JOB_ITEM_ID == _JOB_ITEM_ID);
                    if (_SJR != null)
                    {
                        if (!errorMsg.IsNullOrWhiteSpace())
                        {
                            _SJR.STATUS = "4"; //執行失敗
                            _SJR.MEMO   = errorMsg;
                        }
                        else
                        {
                            _SJR.STATUS = "3"; //執行成功
                            _SJR.MEMO   = null;
                        }
                        _SJR.END_TIME = DateTime.Now;
                        var test = db.GetValidationErrors().getValidateString();
                        if (!test.IsNullOrWhiteSpace())
                        {
                            Extension.NlogSet($"{test}");
                        }
                        db.SaveChanges();
                    }
                    #endregion
                }
            }
            //return result;
        }
Example #9
0
        /// <summary>
        /// 金庫進出管理作業-覆核
        /// </summary>
        /// <param name="db">Entities</param>
        /// <param name="aplyNos">覆核的申請單號</param>
        /// <param name="logStr">log</param>
        /// <param name="dt">執行時間</param>
        /// <param name="userId">覆核人ID</param>
        /// <returns></returns>
        public Tuple <bool, string> TinApproved(TreasuryDBEntities db, List <string> aplyNos, string logStr, DateTime dt, string userId)
        {
            foreach (var aplyNo in aplyNos)
            {
                var MCH = db.MAIL_CONTENT_HIS.First(x => x.APLY_NO == aplyNo);
                MCH.APPR_UID    = userId;
                MCH.APPR_DATE   = dt;
                MCH.APPR_STATUS = "2"; //覆核完成
                var _MAIL_CONTENT_ID    = string.Empty;
                List <MAIL_RECEIVE> MRS = new List <MAIL_RECEIVE>();
                if (!MCH.MAIL_CONTENT_ID.IsNullOrWhiteSpace())
                {
                    logStr += MCH.modelToString(logStr);
                    var MC = db.MAIL_CONTENT.First(x => x.MAIL_CONTENT_ID == MCH.MAIL_CONTENT_ID);
                    MC.FREEZE_DT     = null;
                    MC.FREEZE_UID    = null;
                    MC.APPR_UID      = userId;
                    MC.APPR_DT       = dt;
                    MC.DATA_STATUS   = "1"; //可異動
                    MC.MAIL_SUBJECT  = MCH.MAIL_SUBJECT;
                    MC.MAIL_CONTENT1 = MCH.MAIL_CONTENT;
                    MC.IS_DISABLED   = MCH.IS_DISABLED;
                    _MAIL_CONTENT_ID = MC.MAIL_CONTENT_ID;
                    logStr          += MC.modelToString(logStr);
                    MRS = db.MAIL_RECEIVE.Where(x => x.MAIL_CONTENT_ID == MCH.MAIL_CONTENT_ID).ToList();
                }
                else
                {
                    SysSeqDao sysSeqDao = new SysSeqDao();
                    _MAIL_CONTENT_ID    = $@"{sysSeqDao.qrySeqNo("D4", string.Empty).ToString().PadLeft(2, '0')}";
                    MCH.MAIL_CONTENT_ID = _MAIL_CONTENT_ID;
                    logStr += MCH.modelToString(logStr);
                    var MC = new MAIL_CONTENT()
                    {
                        MAIL_CONTENT_ID = _MAIL_CONTENT_ID,
                        MAIL_SUBJECT    = MCH.MAIL_SUBJECT,
                        MAIL_CONTENT1   = MCH.MAIL_CONTENT,
                        IS_DISABLED     = MCH.IS_DISABLED,
                        CREATE_UID      = MCH.APLY_UID,
                        CREATE_DT       = MCH.APLY_DATE,
                        LAST_UPDATE_UID = MCH.APLY_UID,
                        LAST_UPDATE_DT  = dt,
                        APPR_UID        = userId,
                        APPR_DT         = dt,
                        DATA_STATUS     = "1" //可異動
                    };
                    db.MAIL_CONTENT.Add(MC);
                    logStr += MC.modelToString(logStr);
                }
                foreach (var subitem in db.MAIL_RECEIVE_HIS
                         .Where(x => x.APLY_NO == aplyNo &&
                                x.EXEC_ACTION != null))
                {
                    MAIL_RECEIVE _MR = new MAIL_RECEIVE();
                    switch (subitem.EXEC_ACTION)
                    {
                    case "A":
                        _MR = new MAIL_RECEIVE()
                        {
                            MAIL_CONTENT_ID = _MAIL_CONTENT_ID,
                            FUNC_ID         = subitem.FUNC_ID,
                            DATA_STATUS     = "1", //可異動
                            CREATE_UID      = MCH.APLY_UID,
                            CREATE_DT       = MCH.APLY_DATE,
                            APPR_UID        = userId,
                            APPR_DT         = dt,
                            LAST_UPDATE_UID = MCH.APLY_UID,
                            LAST_UPDATE_DT  = MCH.APLY_DATE
                        };
                        logStr += _MR.modelToString(logStr);
                        db.MAIL_RECEIVE.Add(_MR);
                        break;

                    case "D":
                        _MR = MRS.FirstOrDefault(x => x.FUNC_ID == subitem.FUNC_ID);
                        if (_MR != null)
                        {
                            db.MAIL_RECEIVE.Remove(_MR);
                        }
                        break;
                    }
                }
            }
            return(new Tuple <bool, string>(true, logStr));
        }
Example #10
0
        public ActionResult updateRole(RoleMgrModel roleMgrModel, String authFunc
                                       , List <CodeRoleEquipModel> equipData, List <CodeRoleItemModel> itemData, List <CodeRoleItemModel> formAplyData)
        {
            string roleId       = StringUtil.toString(roleMgrModel.cRoleID);
            bool   bChgRole     = false;
            bool   bChgFunc     = false;
            bool   bChgEquip    = false;
            bool   bChgItem     = false;
            bool   bChgFormAply = false;
            bool   bNewRole     = false;


            CodeRoleDao codeRoleDao = new CodeRoleDao();
            CODE_ROLE   codeRoleO   = new CODE_ROLE();

            bool bDupRoleName = codeRoleDao.dupRoleName(StringUtil.toString(roleMgrModel.cRoleID),
                                                        StringUtil.toString(roleMgrModel.roleAuthType), StringUtil.toString(roleMgrModel.cRoleName));

            if (bDupRoleName)
            {
                return(Json(new { success = false, errors = "相同角色群組下,不能建置相同的角色名稱!!" }, JsonRequestBehavior.AllowGet));
            }


            //比對是否有異動"角色資訊"
            if ("".Equals(roleId))
            {
                bNewRole = true;
                bChgRole = true;
                SysSeqDao sysSeqDao = new SysSeqDao();

                var cId = sysSeqDao.qrySeqNo("F1", "").ToString();
                roleId = "F1" + cId.ToString().PadLeft(8, '0');
            }
            else
            {
                codeRoleO = codeRoleDao.qryRoleByKey(roleId);
                if (!(
                        StringUtil.toString(roleMgrModel.cRoleName).Equals(StringUtil.toString(codeRoleO.ROLE_NAME)) &&
                        StringUtil.toString(roleMgrModel.isDisabled).Equals(StringUtil.toString(codeRoleO.IS_DISABLED)) &&
                        StringUtil.toString(roleMgrModel.vMemo).Equals(StringUtil.toString(codeRoleO.MEMO))
                        ))
                {
                    bChgRole = true;
                }
            }



            //比對是否有異動"授權功能"
            List <FuncRoleModel> funcList = new List <FuncRoleModel>();

            string[] funcData = authFunc.Split('|');

            if ("F".Equals(roleMgrModel.roleAuthType))
            {
                CodeRoleFunctionDao  CodeRoleFunctionDao = new CodeRoleFunctionDao();
                List <FuncRoleModel> roleFuncListO       = CodeRoleFunctionDao.qryForRoleMgr(roleId);
                foreach (string item in funcData)
                {
                    if (!"".Equals(StringUtil.toString(item)))
                    {
                        FuncRoleModel funcRoleModel = new FuncRoleModel();
                        funcRoleModel.cRoleId     = roleId;
                        funcRoleModel.cFunctionID = item;
                        if (roleFuncListO.Exists(x => x.cFunctionID == item))
                        {
                            funcRoleModel.execAction = "";
                        }

                        else
                        {
                            bChgFunc = true;
                            funcRoleModel.execAction = "A";
                        }
                        funcList.Add(funcRoleModel);
                    }
                }

                foreach (FuncRoleModel oItem in roleFuncListO)
                {
                    if (!funcList.Exists(x => x.cFunctionID == oItem.cFunctionID))
                    {
                        bChgFunc = true;
                        FuncRoleModel funcRoleModel = new FuncRoleModel();
                        funcRoleModel.cRoleId     = roleId;
                        funcRoleModel.cFunctionID = oItem.cFunctionID;
                        funcRoleModel.execAction  = "D";
                        funcList.Add(funcRoleModel);
                    }
                }
            }



            //比對是否有異動"金庫設備權限"
            List <CodeRoleEquipModel> equipList           = new List <CodeRoleEquipModel>();
            CodeRoleTreaItemDao       codeRoleTreaItemDao = new CodeRoleTreaItemDao();

            if ("E".Equals(roleMgrModel.roleAuthType))
            {
                List <CodeRoleEquipModel> roleEquipListO = codeRoleTreaItemDao.qryForRoleMgr(roleId);

                if (equipData != null)
                {
                    foreach (CodeRoleEquipModel item in equipData)
                    {
                        CodeRoleEquipModel codeRoleEquipModel = new CodeRoleEquipModel();
                        codeRoleEquipModel.roleId      = roleId;
                        codeRoleEquipModel.treaEquipId = StringUtil.toString(item.treaEquipId);
                        //codeRoleEquipModel.controlMode = StringUtil.toString(item.controlMode);
                        codeRoleEquipModel.custodyMode   = StringUtil.toString(item.custodyMode);
                        codeRoleEquipModel.custodyOrder  = StringUtil.toString(item.custodyOrder);
                        codeRoleEquipModel.custodyModeB  = "";
                        codeRoleEquipModel.custodyOrderB = "";
                        codeRoleEquipModel.execAction    = "";
                        if (roleEquipListO.Exists(x => x.treaEquipId == item.treaEquipId))
                        {
                            CodeRoleEquipModel itemO = roleEquipListO.Find(x => x.treaEquipId == item.treaEquipId);

                            if (!(
                                    //item.controlMode.Equals(itemO.controlMode) &&
                                    item.custodyMode.Equals(itemO.custodyMode) && item.custodyOrder.Equals(itemO.custodyOrder)))
                            {
                                codeRoleEquipModel.execAction    = "U";
                                codeRoleEquipModel.custodyModeB  = itemO.custodyMode;
                                codeRoleEquipModel.custodyOrderB = itemO.custodyOrder;
                                bChgEquip = true;
                            }
                        }
                        else
                        {
                            codeRoleEquipModel.execAction = "A";
                            bChgEquip = true;
                        }
                        equipList.Add(codeRoleEquipModel);
                    }
                }


                foreach (CodeRoleEquipModel oItem in roleEquipListO)
                {
                    if (equipList != null)
                    {
                        if (!equipList.Exists(x => x.treaEquipId == oItem.treaEquipId))
                        {
                            bChgEquip = true;
                            CodeRoleEquipModel codeRoleEquipModel = new CodeRoleEquipModel();
                            codeRoleEquipModel.roleId       = roleId;
                            codeRoleEquipModel.treaEquipId  = StringUtil.toString(oItem.treaEquipId);
                            codeRoleEquipModel.controlMode  = StringUtil.toString(oItem.controlMode);
                            codeRoleEquipModel.custodyMode  = StringUtil.toString(oItem.custodyMode);
                            codeRoleEquipModel.custodyOrder = StringUtil.toString(oItem.custodyOrder);
                            codeRoleEquipModel.execAction   = "D";
                            equipList.Add(codeRoleEquipModel);
                        }
                    }
                    else
                    {
                        bChgEquip = true;
                        CodeRoleEquipModel codeRoleEquipModel = new CodeRoleEquipModel();
                        codeRoleEquipModel.roleId       = roleId;
                        codeRoleEquipModel.treaEquipId  = StringUtil.toString(oItem.treaEquipId);
                        codeRoleEquipModel.controlMode  = StringUtil.toString(oItem.controlMode);
                        codeRoleEquipModel.custodyMode  = StringUtil.toString(oItem.custodyMode);
                        codeRoleEquipModel.custodyOrder = StringUtil.toString(oItem.custodyOrder);
                        codeRoleEquipModel.execAction   = "D";
                        equipList.Add(codeRoleEquipModel);
                    }
                }
            }


            //比對是否有異動"存取項目權限"
            CodeRoleItemDao          codeRoleItemDao = new CodeRoleItemDao();
            List <CodeRoleItemModel> itemList        = new List <CodeRoleItemModel>();

            if ("I".Equals(roleMgrModel.roleAuthType))
            {
                List <CodeRoleItemModel> itemDataO = codeRoleItemDao.qryForRoleMgr(roleId, "1");

                if (itemData != null)
                {
                    foreach (CodeRoleItemModel item in itemData)
                    {
                        CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                        codeRoleItemModel.roleId   = roleId;
                        codeRoleItemModel.itemId   = StringUtil.toString(item.itemId);
                        codeRoleItemModel.authType = "1";

                        if (itemDataO.Exists(x => x.itemId == item.itemId))
                        {
                            codeRoleItemModel.execAction = "";
                        }
                        else
                        {
                            bChgItem = true;
                            codeRoleItemModel.execAction = "A";
                        }
                        itemList.Add(codeRoleItemModel);
                    }
                }


                foreach (CodeRoleItemModel oItem in itemDataO)
                {
                    if (itemList != null)
                    {
                        if (!itemList.Exists(x => x.itemId == oItem.itemId))
                        {
                            bChgItem = true;
                            CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                            codeRoleItemModel.roleId     = roleId;
                            codeRoleItemModel.itemId     = StringUtil.toString(oItem.itemId);
                            codeRoleItemModel.authType   = "1";
                            codeRoleItemModel.execAction = "D";
                            itemList.Add(codeRoleItemModel);
                        }
                    }
                    else
                    {
                        bChgItem = true;
                        CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                        codeRoleItemModel.roleId     = roleId;
                        codeRoleItemModel.itemId     = StringUtil.toString(oItem.itemId);
                        codeRoleItemModel.authType   = "1";
                        codeRoleItemModel.execAction = "D";
                        itemList.Add(codeRoleItemModel);
                    }
                }
            }



            //比對是否有異動"表單申請權限"

            List <CodeRoleItemModel> formAplyList = new List <CodeRoleItemModel>();

            if ("A".Equals(roleMgrModel.roleAuthType))
            {
                List <CodeRoleItemModel> formAplyDataO = codeRoleItemDao.qryForRoleMgr(roleId, "2");
                if (formAplyData != null)
                {
                    foreach (CodeRoleItemModel item in formAplyData)
                    {
                        CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                        codeRoleItemModel.roleId   = roleId;
                        codeRoleItemModel.itemId   = StringUtil.toString(item.itemId);
                        codeRoleItemModel.authType = "2";

                        if (formAplyDataO.Exists(x => x.itemId == item.itemId))
                        {
                            codeRoleItemModel.execAction = "";
                        }
                        else
                        {
                            bChgFormAply = true;
                            codeRoleItemModel.execAction = "A";
                        }
                        formAplyList.Add(codeRoleItemModel);
                    }
                }


                foreach (CodeRoleItemModel oItem in formAplyDataO)
                {
                    if (formAplyList != null)
                    {
                        if (!formAplyList.Exists(x => x.itemId == oItem.itemId))
                        {
                            bChgFormAply = true;
                            CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                            codeRoleItemModel.roleId     = roleId;
                            codeRoleItemModel.itemId     = StringUtil.toString(oItem.itemId);
                            codeRoleItemModel.authType   = "2";
                            codeRoleItemModel.execAction = "D";
                            formAplyList.Add(codeRoleItemModel);
                        }
                    }
                    else
                    {
                        bChgFormAply = true;
                        CodeRoleItemModel codeRoleItemModel = new CodeRoleItemModel();
                        codeRoleItemModel.roleId     = roleId;
                        codeRoleItemModel.itemId     = StringUtil.toString(oItem.itemId);
                        codeRoleItemModel.authType   = "2";
                        codeRoleItemModel.execAction = "D";
                        formAplyList.Add(codeRoleItemModel);
                    }
                }
            }



            if (bChgRole == false && bChgFunc == false && bChgEquip == false && bChgItem == false && bChgFormAply == false)
            {
                return(Json(new { success = false, errors = "未異動畫面資料,將不進行修改覆核作業!!" }, JsonRequestBehavior.AllowGet));
            }



            /*------------------ DB處理   begin------------------*/
            string strConn = DbUtil.GetDBTreasuryConnStr();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                SqlTransaction transaction = conn.BeginTransaction("Transaction");
                try
                {
                    roleMgrModel.cRoleID = roleId;

                    AuthApprDao authApprDao = new AuthApprDao();
                    AUTH_APPR   authAppr    = new AUTH_APPR();
                    authAppr.AUTH_APLY_TYPE   = "R";
                    authAppr.APPR_STATUS      = "1";
                    authAppr.APPR_MAPPING_KEY = roleId;
                    authAppr.CREATE_UID       = Session["UserID"].ToString();


                    //新增"覆核資料檔"
                    string aplyNo = authApprDao.insert(authAppr, conn, transaction);


                    //異動"角色資料檔"覆核狀態
                    if (bNewRole == false)
                    {
                        updateRole(roleMgrModel, codeRoleO, conn, transaction);
                    }


                    //處理角色資料檔的異動
                    if (bChgRole)
                    {
                        //新增"角色資料異動檔"
                        CodeRoleHisDao codeRoleHisDao = new CodeRoleHisDao();
                        CODE_ROLE_HIS  codeRoleHis    = new CODE_ROLE_HIS();
                        codeRoleHis.APLY_NO        = aplyNo;
                        codeRoleHis.ROLE_ID        = StringUtil.toString(roleMgrModel.cRoleID);
                        codeRoleHis.ROLE_NAME      = StringUtil.toString(roleMgrModel.cRoleName);
                        codeRoleHis.ROLE_AUTH_TYPE = StringUtil.toString(roleMgrModel.roleAuthType);
                        codeRoleHis.IS_DISABLED    = StringUtil.toString(roleMgrModel.isDisabled);
                        codeRoleHis.MEMO           = StringUtil.toString(roleMgrModel.vMemo);

                        if (codeRoleO != null)
                        {
                            codeRoleHis.ROLE_NAME_B   = StringUtil.toString(codeRoleO.ROLE_NAME);
                            codeRoleHis.IS_DISABLED_B = StringUtil.toString(codeRoleO.IS_DISABLED);
                            codeRoleHis.MEMO_B        = StringUtil.toString(codeRoleO.MEMO);
                        }
                        else
                        {
                            codeRoleHis.ROLE_NAME_B   = "";
                            codeRoleHis.IS_DISABLED_B = "";
                            codeRoleHis.MEMO_B        = "";
                        }


                        if (bNewRole)
                        {
                            codeRoleHis.EXEC_ACTION = "A";
                        }
                        else
                        {
                            codeRoleHis.EXEC_ACTION = "U";
                        }

                        codeRoleHisDao.insert(codeRoleHis, conn, transaction);
                    }



                    //處理功能角色資料檔的異動
                    if (bChgFunc)
                    {
                        CodeRoleFuncHisDao codeRoleFuncHisDao = new CodeRoleFuncHisDao();
                        foreach (FuncRoleModel func in funcList)
                        {
                            codeRoleFuncHisDao.insert(aplyNo, "Treasury", func, conn, transaction);

                            //if (!"".Equals(func.execAction)) {
                            //    codeRoleFuncHisDao.insert(aplyNo, "Treasury", func, conn, transaction);
                            //}
                        }
                    }


                    //處理角色金庫設備資料檔的異動
                    if (bChgEquip)
                    {
                        CodeRoleTreaItemHisDao codeRoleTreaItemHisDao = new CodeRoleTreaItemHisDao();
                        foreach (CodeRoleEquipModel equip in equipList)
                        {
                            codeRoleTreaItemHisDao.insert(aplyNo, equip, conn, transaction);
                            //if (!"".Equals(equip.execAction))
                            //{
                            //    codeRoleTreaItemHisDao.insert(aplyNo, equip, conn, transaction);
                            //}
                        }
                    }


                    //處理角色存取項目資料檔的異動(存取項目)
                    if (bChgItem)
                    {
                        CodeRoleItemHisDao codeRoleItemHisDao = new CodeRoleItemHisDao();
                        foreach (CodeRoleItemModel item in itemList)
                        {
                            codeRoleItemHisDao.insert(aplyNo, item, conn, transaction);
                            //if (!"".Equals(item.execAction))
                            //{
                            //    codeRoleItemHisDao.insert(aplyNo, item, conn, transaction);
                            //}
                        }
                    }


                    //處理角色存取項目資料檔的異動(表單申請)
                    if (bChgFormAply)
                    {
                        CodeRoleItemHisDao codeRoleItemHisDao = new CodeRoleItemHisDao();
                        foreach (CodeRoleItemModel item in formAplyList)
                        {
                            codeRoleItemHisDao.insert(aplyNo, item, conn, transaction);
                            //if (!"".Equals(item.execAction))
                            //{
                            //    codeRoleItemHisDao.insert(aplyNo, item, conn, transaction);
                            //}
                        }
                    }


                    transaction.Commit();

                    /*------------------ DB處理   end------------------*/
                    return(Json(new { success = true, aplyNo = aplyNo }));
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    logger.Error("[updateRole]其它錯誤:" + e.ToString());

                    return(Json(new { success = false, errors = "其它錯誤,請洽系統管理員!!" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Example #11
0
        /// <summary>
        /// 金庫進出管理作業-申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (TreasuryMailTimeSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var datas = (List <TreasuryMailTimeViewModel>)saveData;
                    if (datas.Any(x => x.updateFlag))
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            string logStr = string.Empty; //log

                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            string    _Aply_No  = $@"G3{qPreCode}{sysSeqDao.qrySeqNo("G3", qPreCode).ToString().PadLeft(3, '0')}"; //申請單號 G3+系統日期YYYMMDD(民國年)+3碼流水號

                            foreach (var data in datas.Where(x => x.updateFlag))
                            {
                                var _MT = db.MAIL_TIME.First(x => x.MAIL_TIME_ID == data.vMAIL_TIME_ID);

                                if (_MT.DATA_STATUS != "1")
                                {
                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                    return(result);
                                }
                                _MT.DATA_STATUS     = "2"; //凍結中
                                _MT.LAST_UPDATE_UID = searchData.userId;
                                _MT.LAST_UPDATE_DT  = dt;
                                _MT.FREEZE_DT       = dt;
                                _MT.FREEZE_UID      = searchData.userId;

                                var MTH = new MAIL_TIME_HIS()
                                {
                                    APLY_NO           = _Aply_No,
                                    MAIL_TIME_ID      = _MT.MAIL_TIME_ID,
                                    EXEC_ACTION       = "U", //只有修改
                                    FUNC_ID           = data.vFUNC_ID,
                                    FUNC_ID_B         = _MT.FUNC_ID,
                                    SEND_TIME         = data.vSEND_TIME,
                                    SEND_TIME_B       = _MT.SEND_TIME,
                                    INTERVAL_MIN      = TypeTransfer.stringToIntN(data.vINTERVAL_MIN),
                                    INTERVAL_MIN_B    = _MT.INTERVAL_MIN,
                                    TREA_OPEN_TIME    = data.vTREA_OPEN_TIME,
                                    TREA_OPEN_TIME_B  = _MT.TREA_OPEN_TIME,
                                    EXEC_TIME_B       = data.vEXEC_TIME_B,
                                    EXEC_TIME_B_B     = _MT.EXEC_TIME_B,
                                    EXEC_TIME_E       = data.vEXEC_TIME_E,
                                    EXEC_TIME_E_B     = _MT.EXEC_TIME_E,
                                    MAIL_CONTENT_ID   = data.vMAIL_CONTENT_ID,
                                    MAIL_CONTENT_ID_B = _MT.MAIL_CONTENT_ID,
                                    MEMO          = data.vMEMO,
                                    MEMO_B        = _MT.MEMO,
                                    IS_DISABLED   = data.vIS_DISABLED,
                                    IS_DISABLED_B = _MT.IS_DISABLED,
                                    APLY_UID      = searchData.userId,
                                    APLY_DATE     = dt,
                                    APPR_STATUS   = "1", //表單申請
                                };

                                logStr += MTH.modelToString(logStr);
                                db.MAIL_TIME_HIS.Add(MTH);
                            }

                            #region Save Db
                            var validateMessage = db.GetValidationErrors().getValidateString();
                            if (validateMessage.Any())
                            {
                                result.DESCRIPTION = validateMessage;
                            }
                            else
                            {
                                try
                                {
                                    db.SaveChanges();

                                    #region LOG
                                    //新增LOG
                                    Log log = new Log();
                                    log.CFUNCTION = "申請覆核-mail發送內文設定檔";
                                    log.CACTION   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.userId);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #12
0
        /// <summary>
        /// 金庫進出管理作業-順序調整申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinOrderApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (DepChkItemSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var datas = (List <DepChkItemViewModel>)saveData;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            string    _Aply_No  = string.Empty;
                            var       cId       = sysSeqDao.qrySeqNo("G9", qPreCode).ToString().PadLeft(3, '0');
                            _Aply_No = $@"G9{qPreCode}{cId}"; //申請單號 G9+系統日期YYYMMDD(民國年)+3碼流水號
                            string logStr = string.Empty;     //log

                            foreach (var item in datas)
                            {
                                #region 定存檢核表項目設定異動檔
                                var _DCI_Data = db.DEP_CHK_ITEM.FirstOrDefault(x => x.ACCESS_TYPE == item.vAccess_Type && x.ISORTBY == item.vIsortby);
                                var _DCIH     = new DEP_CHK_ITEM_HIS()
                                {
                                    APLY_NO             = _Aply_No,
                                    ACCESS_TYPE         = item.vAccess_Type,
                                    ISORTBY             = item.vIsortby,
                                    EXEC_ACTION         = "O",
                                    DEP_CHK_ITEM_DESC   = _DCI_Data.DEP_CHK_ITEM_DESC,
                                    IS_DISABLED         = _DCI_Data.IS_DISABLED,
                                    ITEM_ORDER          = item.vItem_Order,
                                    REPLACE             = _DCI_Data.REPLACE,
                                    APPR_STATUS         = "1",//表單申請
                                    DEP_CHK_ITEM_DESC_B = _DCI_Data.DEP_CHK_ITEM_DESC,
                                    IS_DISABLED_B       = _DCI_Data.IS_DISABLED,
                                    ITEM_ORDER_B        = _DCI_Data.ITEM_ORDER,
                                    REPLACE_B           = _DCI_Data.REPLACE,
                                    APLY_UID            = searchData.vLast_Update_Uid,
                                    APLY_DATE           = dt
                                };
                                db.DEP_CHK_ITEM_HIS.Add(_DCIH);
                                logStr += "|";
                                logStr += _DCIH.modelToString();
                                #endregion
                            }

                            #region Save Db
                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.vLast_Update_Uid);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #13
0
        /// <summary>
        /// 申請刪除 & 作廢 空白票據資料庫要復原的事件
        /// </summary>
        /// <param name="db"></param>
        /// <param name="aply_No"></param>
        /// <param name="logStr"></param>
        /// <param name="dt"></param>
        /// <param name="deleFlag"></param>
        /// <returns></returns>
        public Tuple <bool, string> Recover(TreasuryDBEntities db, string aply_No, string logStr, DateTime dt, bool deleFlag)
        {
            var _changeFlag = false;
            //以「申請單號」為鍵項讀取【空白票據申請資料檔】
            var _BLANK_NOTE_APLY = db.BLANK_NOTE_APLY.Where(x => x.APLY_NO == aply_No).ToList();

            _BLANK_NOTE_APLY
            .ForEach(x =>
            {
                var _CHECK_NO_E = TypeTransfer.stringToInt(x.CHECK_NO_E) + 1;
                //依【空白票據申請資料檔】的「ITEM_BLANK_NOTE_ITEM_ID」查【空白票據庫存資料檔】
                //異動欄位:「庫存狀態」= 1在庫
                //最後異動日期時間:系統時間
                var _ITEM_BLANK_NOTE = db.ITEM_BLANK_NOTE.FirstOrDefault(y => y.ITEM_ID == x.ITEM_BLANK_NOTE_ITEM_ID);
                if (_ITEM_BLANK_NOTE != null)
                {
                    if (_ITEM_BLANK_NOTE.INVENTORY_STATUS == "1" &&
                        TypeTransfer.stringToInt(_ITEM_BLANK_NOTE.CHECK_NO_B) == _CHECK_NO_E) //在庫 且 申請資料的迄號(+1) = 庫存起號
                    {
                        _ITEM_BLANK_NOTE.CHECK_NO_B     = x.CHECK_NO_B;
                        _ITEM_BLANK_NOTE.LAST_UPDATE_DT = dt;
                        logStr += _ITEM_BLANK_NOTE.modelToString(logStr);
                    }
                    else if (
                        _ITEM_BLANK_NOTE.INVENTORY_STATUS == "4" &&
                        _ITEM_BLANK_NOTE.CHECK_NO_B == x.CHECK_NO_B &&
                        _ITEM_BLANK_NOTE.CHECK_NO_E == x.CHECK_NO_E) //全部都被預約取出 且 起訖號相同
                    {
                        _ITEM_BLANK_NOTE.INVENTORY_STATUS = "1";
                        _ITEM_BLANK_NOTE.LAST_UPDATE_DT   = dt;
                        logStr += _ITEM_BLANK_NOTE.modelToString(logStr);
                    }
                    else     //其他情形 須新增一筆 空白票據庫存資料檔
                    {
                        SysSeqDao sysSeqDao                  = new SysSeqDao();
                        var cId                              = sysSeqDao.qrySeqNo("E2", string.Empty).ToString().PadLeft(8, '0');
                        var _newITEM_BLANK_NOTE              = _ITEM_BLANK_NOTE.ModelConvert <ITEM_BLANK_NOTE, ITEM_BLANK_NOTE>();
                        _newITEM_BLANK_NOTE.ITEM_ID          = $@"E2{cId}";
                        _newITEM_BLANK_NOTE.INVENTORY_STATUS = "1";
                        _newITEM_BLANK_NOTE.CHECK_NO_B       = x.CHECK_NO_B;
                        _newITEM_BLANK_NOTE.CHECK_NO_E       = x.CHECK_NO_E;
                        _newITEM_BLANK_NOTE.CREATE_DT        = dt;
                        _newITEM_BLANK_NOTE.LAST_UPDATE_DT   = dt;
                        db.ITEM_BLANK_NOTE.Add(_newITEM_BLANK_NOTE);
                        logStr += _newITEM_BLANK_NOTE.modelToString(logStr);
                    }
                }
                else
                {
                    _changeFlag = true;
                }
            });
            if (_changeFlag)
            {
                return(new Tuple <bool, string>(false, logStr));
            }
            else
            {
                if (deleFlag)
                {
                    db.BLANK_NOTE_APLY.RemoveRange(_BLANK_NOTE_APLY);
                }
                return(new Tuple <bool, string>(true, logStr));
            }
        }
Example #14
0
        /// <summary>
        /// 申請覆核動作
        /// </summary>
        /// <param name="insertDatas"></param>
        /// <param name="taData"></param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITreaItem> > ApplyAudit(IEnumerable <ITreaItem> insertDatas, TreasuryAccessViewModel taData)
        {
            var result = new MSGReturnModel <IEnumerable <ITreaItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (insertDatas != null)
                {
                    //取得流水號
                    SysSeqDao sysSeqDao = new SysSeqDao();
                    String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                    var       datas     = (List <BillViewModel>)insertDatas;
                    string    logStr    = string.Empty;       //log
                    var       item_Seq  = "E2";               //空白票卷流水號開頭編碼
                    if (!taData.vAplyNo.IsNullOrWhiteSpace()) //修改已存在申請單
                    {
                        if (datas.Any())
                        {
                            using (TreasuryDBEntities db = new TreasuryDBEntities())
                            {
                                var _APLY_STATUS = Ref.AccessProjectFormStatus.A01.ToString(); //表單申請

                                #region 申請單紀錄檔
                                var _TAR = db.TREA_APLY_REC.First(x => x.APLY_NO == taData.vAplyNo);
                                if (CustodyAppr.Contains(_TAR.APLY_STATUS))
                                {
                                    _APLY_STATUS     = CustodyConfirmStatus;
                                    _TAR.CUSTODY_UID = AccountController.CurrentUserId; //保管單位直接帶使用者
                                    _TAR.CUSTODY_DT  = dt;
                                }
                                else
                                {
                                    if (_TAR.APLY_STATUS != _APLY_STATUS)                          //申請紀錄檔狀態不是在表單申請狀態
                                    {
                                        _APLY_STATUS = Ref.AccessProjectFormStatus.A05.ToString(); //為重新申請案例
                                    }
                                }
                                _TAR.APLY_STATUS    = _APLY_STATUS;
                                _TAR.LAST_UPDATE_DT = dt;
                                logStr += _TAR.modelToString(logStr);
                                #endregion

                                #region 申請單歷程檔
                                var _ARH = new APLY_REC_HIS()
                                {
                                    APLY_NO     = taData.vAplyNo,
                                    APLY_STATUS = _APLY_STATUS,
                                    PROC_DT     = dt,
                                    PROC_UID    = taData.vCreateUid
                                };
                                logStr += _ARH.modelToString(logStr);
                                db.APLY_REC_HIS.Add(_ARH);
                                #endregion

                                #region 空白票據申請資料檔
                                List <BLANK_NOTE_APLY> updates = new List <BLANK_NOTE_APLY>();
                                List <BLANK_NOTE_APLY> inserts = new List <BLANK_NOTE_APLY>();

                                foreach (var item in datas)
                                {
                                    if (item.vItemId.StartsWith(item_Seq)) // 舊有資料
                                    {
                                        var _BNA = db.BLANK_NOTE_APLY.First(
                                            x => x.ITEM_ID == item.vItemId &&
                                            x.APLY_NO == taData.vAplyNo);
                                        _BNA.CHECK_TYPE     = item.vCheckType;
                                        _BNA.ISSUING_BANK   = item.vIssuingBank;
                                        _BNA.CHECK_NO_TRACK = item.vCheckNoTrack;
                                        _BNA.CHECK_NO_B     = item.vCheckNoB;
                                        _BNA.CHECK_NO_E     = item.vCheckNoE;
                                        updates.Add(_BNA);
                                        logStr += _BNA.modelToString(logStr);
                                    }
                                    else
                                    {
                                        var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                        var _BNA    = new BLANK_NOTE_APLY()
                                        {
                                            APLY_NO        = _TAR.APLY_NO,
                                            ITEM_ID        = $@"{item_Seq}{item_id}",
                                            CHECK_TYPE     = item.vCheckType,
                                            ISSUING_BANK   = item.vIssuingBank,
                                            CHECK_NO_TRACK = item.vCheckNoTrack,
                                            CHECK_NO_B     = item.vCheckNoB,
                                            CHECK_NO_E     = item.vCheckNoE
                                        };
                                        inserts.Add(_BNA);
                                        logStr += _BNA.modelToString(logStr);
                                    }
                                }

                                var ups = updates.Select(x => x.ITEM_ID).ToList();

                                db.BLANK_NOTE_APLY.RemoveRange(
                                    db.BLANK_NOTE_APLY.Where(x => x.APLY_NO == taData.vAplyNo && !ups.Contains(x.ITEM_ID)).ToList());
                                db.BLANK_NOTE_APLY.AddRange(inserts);

                                #endregion

                                #region Save Db

                                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  = logStr;
                                        LogDao.Insert(log, _TAR.CREATE_UID);
                                        #endregion

                                        result.RETURN_FLAG = true;
                                        result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_TAR.APLY_NO}");
                                    }
                                    catch (DbUpdateException ex)
                                    {
                                        result.DESCRIPTION = ex.exceptionMessage();
                                    }
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                        }
                    }
                    else //新增申請單
                    {
                        //取出只抓狀態為預約取出的資料
                        if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString())
                        {
                            datas = datas.Where(x => x.vStatus == Ref.AccessInventoryType._4.GetDescription()).ToList();
                        }
                        if (datas.Any())
                        {
                            using (TreasuryDBEntities db = new TreasuryDBEntities())
                            {
                                #region 申請單紀錄檔 & 申請單歷程檔

                                var data = SaveTREA_APLY_REC(db, taData, logStr, dt);

                                logStr = data.Item2;

                                #endregion

                                string _ITEM_BLANK_NOTE_ITEM_ID = null; //紀錄空白票據申請資料檔 對應空白票據庫存資料檔 物品編號

                                bool _changFlag = false;
                                datas.ForEach(x =>
                                {
                                    #region 取出時要把空白票據資料 做切段動作
                                    if (taData.vAccessType == Ref.AccessProjectTradeType.G.ToString()) //取出時要把空白票據資料 做切段動作
                                    {
                                        var _blank_Note = db.ITEM_BLANK_NOTE.FirstOrDefault(y => y.ITEM_ID == x.vItemId);
                                        if (_blank_Note != null)
                                        {
                                            if (_blank_Note.LAST_UPDATE_DT > x.vLast_Update_Time || _blank_Note.INVENTORY_STATUS != "1")
                                            {
                                                _changFlag = true;
                                            }
                                            else
                                            {
                                                _ITEM_BLANK_NOTE_ITEM_ID = _blank_Note.ITEM_ID;
                                                //全部取出
                                                if (x.vTakeOutE == _blank_Note.CHECK_NO_E)
                                                {
                                                    _blank_Note.INVENTORY_STATUS = "4"; //預約取出
                                                }
                                                //分段取出
                                                else
                                                {
                                                    _blank_Note.CHECK_NO_B = (TypeTransfer.stringToInt(x.vTakeOutE) + 1).ToString().PadLeft(7, '0');
                                                }
                                                _blank_Note.LAST_UPDATE_DT = dt;
                                            }
                                        }
                                        else
                                        {
                                            _changFlag = true;
                                        }
                                    }
                                    #endregion

                                    #region 空白票據申請資料檔
                                    var item_id = sysSeqDao.qrySeqNo(item_Seq, string.Empty).ToString().PadLeft(8, '0');
                                    var _BNA    = new BLANK_NOTE_APLY()
                                    {
                                        APLY_NO                 = data.Item1,
                                        ITEM_ID                 = $@"{item_Seq}{item_id}",
                                        CHECK_TYPE              = x.vCheckType,
                                        ISSUING_BANK            = x.vIssuingBank,
                                        CHECK_NO_TRACK          = x.vCheckNoTrack,
                                        CHECK_NO_B              = x.vCheckNoB,
                                        CHECK_NO_E              = taData.vAccessType == Ref.AccessProjectTradeType.P.ToString() ? x.vCheckNoE : x.vTakeOutE,
                                        ITEM_BLANK_NOTE_ITEM_ID = _ITEM_BLANK_NOTE_ITEM_ID
                                    };
                                    db.BLANK_NOTE_APLY.Add(_BNA);
                                    logStr += _BNA.modelToString(logStr);
                                    #endregion
                                });
                                if (_changFlag)
                                {
                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                    return(result);
                                }
                                #region Save Db

                                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   = "A";
                                        log.CCONTENT  = logStr;
                                        LogDao.Insert(log, taData.vCreateUid);
                                        #endregion

                                        result.RETURN_FLAG = true;
                                        result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{data.Item1}");
                                    }
                                    catch (DbUpdateException ex)
                                    {
                                        result.DESCRIPTION = ex.exceptionMessage();
                                    }
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                        }
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #15
0
        public MSGReturnModel <string> ApplyCompData(List <RctCompDetailViewModel> saveData, RctCompSearchViewModel searchModel)
        {
            MSGReturnModel <string> result = new MSGReturnModel <string>();

            result.RETURN_FLAG = false;
            DateTime now      = DateTime.Now;
            string   _aply_no = string.Empty;

            try
            {
                if (saveData.Any())
                {
                    using (dbFGLEntities db = new dbFGLEntities())
                    {
                        //取得流水號
                        SysSeqDao sysSeqDao = new SysSeqDao();
                        string    qPreCode  = DateUtil.getCurChtDateTime(now.Year.ToString().Length);
                        var       cId       = sysSeqDao.qrySeqNo("RCT", "M1", qPreCode).ToString().PadLeft(3, '0');
                        _aply_no = $@"M1{qPreCode}{cId}";//M1 + 系統日期YYYMMDD(民國年) + 3碼流水號

                        foreach (var rowData in saveData)
                        {
                            var _relationId = string.Empty;
                            var _RCR        = new RCT_COMPANY_RELATION();
                            #region 收據類別與公司別主檔
                            //判斷執行功能
                            switch (rowData.vExec_action_code)
                            {
                            case "A":    //新增
                                _relationId = "";
                                break;

                            case "U":     //修改
                                _RCR = db.RCT_COMPANY_RELATION.FirstOrDefault(y => y.relation_id == rowData.vRelation_id);
                                if (_RCR.update_datetime != null && _RCR.update_datetime > rowData.vUpdateTime)
                                {
                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                    return(result);
                                }
                                _relationId          = rowData.vRelation_id;
                                _RCR.reciept_type    = rowData.vRct_type_code;
                                _RCR.company_code    = rowData.vCompany_code;
                                _RCR.payment_type    = rowData.vPayment_code;
                                _RCR.currency_code   = rowData.vCurrency_code;
                                _RCR.update_datetime = now;
                                _RCR.update_id       = searchModel.vCurrent_Uid;
                                _RCR.data_status     = "2"; //凍結中
                                //logStr += "|";
                                //logStr += _RCR.modelToString();
                                break;

                            default:
                                break;
                            }
                            #endregion
                            #region 收據類別與公司別異動檔
                            switch (rowData.vExec_action_code)
                            {
                            case "A":    //新增
                                var _RCRH = new RCT_COMPANY_RELATION_HIS()
                                {
                                    aply_no         = _aply_no,
                                    relation_id     = _relationId,
                                    exec_action     = rowData.vExec_action_code,
                                    a_reciept_type  = rowData.vRct_type_code,
                                    a_company_code  = rowData.vCompany_code,
                                    a_payment_type  = rowData.vPayment_code,
                                    a_currency_code = rowData.vCurrency_code,
                                    a_is_disabled   = rowData.vIsDisabled_code,
                                    apply_status    = "1",  //表單申請
                                    apply_id        = searchModel.vCurrent_Uid,
                                    apply_datetime  = now
                                };
                                db.RCT_COMPANY_RELATION_HIS.Add(_RCRH);
                                break;

                            case "U":     //修改
                                var db_RCR = db.RCT_COMPANY_RELATION.AsNoTracking().FirstOrDefault(y => y.relation_id == rowData.vRelation_id);
                                if (db_RCR != null)
                                {
                                    var _RCRHU = new RCT_COMPANY_RELATION_HIS()
                                    {
                                        aply_no         = _aply_no,
                                        relation_id     = rowData.vRelation_id,
                                        exec_action     = rowData.vExec_action_code,
                                        b_reciept_type  = db_RCR.reciept_type,
                                        b_company_code  = db_RCR.company_code,
                                        b_payment_type  = db_RCR.payment_type,
                                        b_currency_code = db_RCR.currency_code,
                                        b_is_disabled   = db_RCR.is_disabled,
                                        a_reciept_type  = rowData.vRct_type_code,
                                        a_company_code  = rowData.vCompany_code,
                                        a_payment_type  = rowData.vPayment_code,
                                        a_currency_code = rowData.vCurrency_code,
                                        a_is_disabled   = rowData.vIsDisabled_code,
                                        apply_datetime  = now,
                                        apply_id        = searchModel.vCurrent_Uid,
                                        apply_status    = "1"  //表單申請
                                    };
                                    db.RCT_COMPANY_RELATION_HIS.Add(_RCRHU);
                                    //logStr += "|";
                                    //logStr += _RCRHU.modelToString();
                                }
                                break;
                            }
                            #endregion
                        }
                        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 = "A";
                                //log.CCONTENT = logStr;
                                //LogDao.Insert(log, searchModel.vCurrent_Uid);
                                #endregion

                                result.RETURN_FLAG = true;
                                result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_aply_no}");
                            }
                            catch (DbUpdateException ex)
                            {
                                result.DESCRIPTION = ex.exceptionMessage();
                            }
                        }
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }
            return(result);
        }
Example #16
0
        /// <summary>
        /// 保管資料發送維護作業-申請覆核
        /// </summary>
        /// <param name="saveData"></param>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (ItemChargeUnitSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            //return result;
            try
            {
                if (saveData != null)
                {
                    var datas = (List <ItemChargeUnitSearchDetailViewModel>)saveData;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            string    _Aply_No  = string.Empty;
                            var       cId       = sysSeqDao.qrySeqNo("G8", qPreCode).ToString().PadLeft(3, '0');
                            _Aply_No = $@"G8{qPreCode}{cId}"; //G8 + 系統日期YYYMMDD(民國年) + 3碼流水號
                            string logStr = string.Empty;     //log

                            foreach (var item in datas)
                            {
                                var _CHARGE_UNIT_ID = string.Empty;
                                var _ICU            = new ITEM_CHARGE_UNIT();
                                # region 保管單位設定檔
                                //判斷執行功能
                                switch (item.vEXEC_ACTION)
                                {
                                case "A":    //新增
                                    _CHARGE_UNIT_ID = "";
                                    //_CHARGE_UNIT_ID = sysSeqDao.qrySeqNo("D5", string.Empty).ToString().PadLeft(3, '0');
                                    //_CHARGE_UNIT_ID = $@"D5{_CHARGE_UNIT_ID}";
                                    //_ICU = new ITEM_CHARGE_UNIT()
                                    //{
                                    //    CHARGE_UNIT_ID = _CHARGE_UNIT_ID,
                                    //    ITEM_ID = item.vTREA_ITEM_NAME,
                                    //    CHARGE_DEPT = item.vCHARGE_DEPT,
                                    //    CHARGE_SECT = item.vCHARGE_SECT,
                                    //    CHARGE_UID = item.vCHARGE_UID,
                                    //    IS_MAIL_DEPT_MGR = item.vIS_MAIL_DEPT_MGR,
                                    //    IS_MAIL_SECT_MGR = item.vIS_MAIL_SECT_MGR,
                                    //    IS_DISABLED = "N",
                                    //    DATA_STATUS = "2",//凍結中
                                    //    CREATE_DT = dt,
                                    //    CREATE_UID = searchData.vCUSER_ID,
                                    //    LAST_UPDATE_DT = dt,
                                    //    LAST_UPDATE_UID = searchData.vCUSER_ID,
                                    //    FREEZE_UID = searchData.vCUSER_ID,
                                    //    FREEZE_DT = dt
                                    //};
                                    //db.ITEM_CHARGE_UNIT.Add(_ICU);
                                    //logStr += "|";
                                    //logStr += _ICU.modelToString();
                                    break;

                                case "U":    //修改
                                    _ICU = db.ITEM_CHARGE_UNIT.FirstOrDefault(x => x.CHARGE_UNIT_ID == item.vCHARGE_UNIT_ID);
                                    if (_ICU.LAST_UPDATE_DT != null && _ICU.LAST_UPDATE_DT > item.vLAST_UPDATE_DT)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _CHARGE_UNIT_ID      = item.vCHARGE_UNIT_ID;
                                    _ICU.DATA_STATUS     = "2"; //凍結中
                                    _ICU.LAST_UPDATE_UID = searchData.vCUSER_ID;
                                    _ICU.LAST_UPDATE_DT  = dt;
                                    _ICU.FREEZE_UID      = searchData.vCUSER_ID;
                                    _ICU.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _ICU.modelToString();
                                    break;

                                case "D":    //刪除
                                    _ICU = db.ITEM_CHARGE_UNIT.FirstOrDefault(x => x.CHARGE_UNIT_ID == item.vCHARGE_UNIT_ID);
                                    if (_ICU.LAST_UPDATE_DT != null && _ICU.LAST_UPDATE_DT > item.vLAST_UPDATE_DT)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _CHARGE_UNIT_ID      = item.vCHARGE_UNIT_ID;
                                    _ICU.DATA_STATUS     = "2";//凍結中
                                    _ICU.LAST_UPDATE_UID = searchData.vCUSER_ID;
                                    _ICU.LAST_UPDATE_DT  = dt;
                                    _ICU.FREEZE_UID      = searchData.vCUSER_ID;
                                    _ICU.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _ICU.modelToString();
                                    break;

                                default:
                                    break;
                                }
                                #endregion
                                #region 保管單位設定異動檔
                                var _ICU_Data = db.ITEM_CHARGE_UNIT.FirstOrDefault(x => x.CHARGE_UNIT_ID == item.vCHARGE_UNIT_ID);
                                if (_ICU_Data == null)
                                {
                                    var _ICUH = new ITEM_CHARGE_UNIT_HIS()
                                    {
                                        APLY_NO          = _Aply_No,
                                        CHARGE_UNIT_ID   = _CHARGE_UNIT_ID,
                                        EXEC_ACTION      = item.vEXEC_ACTION,
                                        ITEM_ID          = item.vTREA_ITEM_NAME,
                                        CHARGE_DEPT      = item.vCHARGE_DEPT,
                                        CHARGE_SECT      = item.vCHARGE_SECT,
                                        CHARGE_UID       = item.vCHARGE_UID,
                                        IS_MAIL_DEPT_MGR = item.vIS_MAIL_DEPT_MGR,
                                        IS_MAIL_SECT_MGR = item.vIS_MAIL_SECT_MGR,
                                        IS_DISABLED      = item.vIS_DISABLED,
                                        APLY_DATE        = dt,
                                        APLY_UID         = searchData.vCUSER_ID,
                                        APPR_STATUS      = "1" //表單申請
                                    };
                                    db.ITEM_CHARGE_UNIT_HIS.Add(_ICUH);
                                    logStr += "|";
                                    logStr += _ICUH.modelToString();
                                }
                                else
                                {
                                    var _ICUH = new ITEM_CHARGE_UNIT_HIS()
                                    {
                                        APLY_NO            = _Aply_No,
                                        CHARGE_UNIT_ID     = _CHARGE_UNIT_ID,
                                        EXEC_ACTION        = item.vEXEC_ACTION,
                                        ITEM_ID            = item.vTREA_ITEM_NAME,
                                        CHARGE_DEPT        = item.vCHARGE_DEPT,
                                        CHARGE_SECT        = item.vCHARGE_SECT,
                                        CHARGE_UID         = item.vCHARGE_UID,
                                        IS_MAIL_DEPT_MGR   = item.vIS_MAIL_DEPT_MGR,
                                        IS_MAIL_SECT_MGR   = item.vIS_MAIL_SECT_MGR,
                                        IS_DISABLED        = item.vIS_DISABLED,
                                        CHARGE_UID_B       = _ICU_Data.CHARGE_UID,
                                        IS_MAIL_DEPT_MGR_B = _ICU_Data.IS_MAIL_DEPT_MGR,
                                        IS_MAIL_SECT_MGR_B = _ICU_Data.IS_MAIL_SECT_MGR,
                                        IS_DISABLED_B      = _ICU_Data.IS_DISABLED,
                                        APLY_DATE          = dt,
                                        APLY_UID           = searchData.vCUSER_ID,
                                        APPR_STATUS        = "1" //表單申請
                                    };
                                    db.ITEM_CHARGE_UNIT_HIS.Add(_ICUH);
                                    logStr += "|";
                                    logStr += _ICUH.modelToString();
                                }
                                #endregion
                            }
                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.vCUSER_ID);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
Example #17
0
        /// <summary>
        /// 金庫進出管理作業-覆核
        /// </summary>
        /// <param name="db">Entities</param>
        /// <param name="aplyNos">覆核的申請單號</param>
        /// <param name="logStr">log</param>
        /// <param name="dt">執行時間</param>
        /// <param name="userId">覆核人ID</param>
        /// <returns></returns>
        public Tuple <bool, string> TinApproved(TreasuryDBEntities db, List <string> aplyNos, string logStr, DateTime dt, string userId)
        {
            SysSeqDao sysSeqDao = new SysSeqDao();

            foreach (var aplyNo in aplyNos)
            {
                var _TreaEquipHisList = db.TREA_EQUIP_HIS.AsNoTracking().Where(x => x.APLY_NO == aplyNo).ToList();
                if (_TreaEquipHisList.Any())
                {
                    foreach (var TreaEquipHis in _TreaEquipHisList)
                    {
                        var _Trea_Equip_Id = string.Empty;
                        //金庫設備設定檔
                        var _TreaEquip = db.TREA_EQUIP.FirstOrDefault(x => x.TREA_EQUIP_ID == TreaEquipHis.TREA_EQUIP_ID);
                        if (_TreaEquip != null)
                        {
                            _TreaEquip.DATA_STATUS  = "1";//可異動
                            _TreaEquip.EQUIP_NAME   = TreaEquipHis.EQUIP_NAME;
                            _TreaEquip.CONTROL_MODE = TreaEquipHis.CONTROL_MODE;
                            _TreaEquip.NORMAL_CNT   = TreaEquipHis.NORMAL_CNT;
                            _TreaEquip.RESERVE_CNT  = TreaEquipHis.RESERVE_CNT;
                            _TreaEquip.MEMO         = TreaEquipHis.MEMO;
                            _TreaEquip.IS_DISABLED  = TreaEquipHis.IS_DISABLED;
                            _TreaEquip.FREEZE_DT    = null;
                            _TreaEquip.FREEZE_UID   = null;
                            _TreaEquip.APPR_UID     = userId;
                            _TreaEquip.APPR_DT      = dt;

                            logStr += _TreaEquip.modelToString(logStr);
                        }
                        else
                        {
                            _Trea_Equip_Id = $@"D2{sysSeqDao.qrySeqNo("D2", string.Empty).ToString().PadLeft(3, '0')}";
                            //新增至TREA_EQUIP
                            var _TE = new TREA_EQUIP()
                            {
                                TREA_EQUIP_ID   = _Trea_Equip_Id,
                                EQUIP_NAME      = TreaEquipHis.EQUIP_NAME,
                                CONTROL_MODE    = TreaEquipHis.CONTROL_MODE,
                                NORMAL_CNT      = TreaEquipHis.NORMAL_CNT,
                                RESERVE_CNT     = TreaEquipHis.RESERVE_CNT,
                                MEMO            = TreaEquipHis.MEMO,
                                IS_DISABLED     = TreaEquipHis.IS_DISABLED,
                                DATA_STATUS     = "1",//可異動
                                CREATE_UID      = TreaEquipHis.APLY_UID,
                                CREATE_DT       = dt,
                                LAST_UPDATE_UID = TreaEquipHis.APLY_UID,
                                LAST_UPDATE_DT  = dt,
                                APPR_UID        = userId,
                                APPR_DT         = dt
                            };
                            logStr += _TE.modelToString();
                            db.TREA_EQUIP.Add(_TE);
                        }

                        //金庫設備異動檔
                        var _TreaEquipHis = db.TREA_EQUIP_HIS.FirstOrDefault(x => x.APLY_NO == TreaEquipHis.APLY_NO && x.HIS_ID == TreaEquipHis.HIS_ID);
                        if (_TreaEquipHis != null)
                        {
                            if (_TreaEquipHis.TREA_EQUIP_ID.IsNullOrWhiteSpace())
                            {
                                _TreaEquipHis.TREA_EQUIP_ID = _Trea_Equip_Id;
                            }
                            _TreaEquipHis.APPR_STATUS = "2";//覆核完成
                            _TreaEquipHis.APPR_DATE   = dt;
                            _TreaEquipHis.APPR_UID    = userId;

                            logStr = _TreaEquipHis.modelToString(logStr);
                        }
                        else
                        {
                            return(new Tuple <bool, string>(false, logStr));
                        }
                    }
                }
                else
                {
                    return(new Tuple <bool, string>(false, logStr));
                }
            }
            return(new Tuple <bool, string>(true, logStr));
        }
Example #18
0
        /// <summary>
        /// 金庫進出管理作業-申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (TreasuryMailContentSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var data = ((List <TreasuryMailContentUpdateViewModel>)saveData).FirstOrDefault();
                    if (data != null)
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];

                            string logStr = string.Empty; //log

                            var          _MAIL_CONTENT_ID = string.Empty;
                            MAIL_CONTENT _MC = null;
                            if (!data.vMAIL_CONTENT_ID.IsNullOrWhiteSpace()) //現有資料修改
                            {
                                _MAIL_CONTENT_ID = data.vMAIL_CONTENT_ID;
                                _MC = db.MAIL_CONTENT.First(x => x.MAIL_CONTENT_ID == _MAIL_CONTENT_ID);
                                if (_MC.DATA_STATUS != "1")
                                {
                                    result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                    return(result);
                                }
                                _MC.DATA_STATUS     = "2"; //凍結中
                                _MC.LAST_UPDATE_UID = data.UserID;
                                _MC.LAST_UPDATE_DT  = dt;
                                _MC.FREEZE_DT       = dt;
                                _MC.FREEZE_UID      = data.UserID;
                            }
                            else
                            {
                                //目前只加入異動檔
                            }

                            string _Aply_No = $@"G4{qPreCode}{sysSeqDao.qrySeqNo("G4", qPreCode).ToString().PadLeft(3, '0')}";  //申請單號 G4+系統日期YYYMMDD(民國年)+3碼流水號

                            var MCH = new MAIL_CONTENT_HIS()
                            {
                                APLY_NO         = _Aply_No,
                                MAIL_CONTENT_ID = _MAIL_CONTENT_ID,
                                IS_DISABLED     = data.vIS_DISABLED,
                                IS_DISABLED_B   = _MC?.IS_DISABLED,
                                MAIL_SUBJECT    = data.vMAIL_SUBJECT,
                                MAIL_SUBJECT_B  = _MC?.MAIL_SUBJECT,
                                MAIL_CONTENT    = data.vMAIL_CONTENT,
                                MAIL_CONTENT_B  = _MC?.MAIL_CONTENT1,
                                APLY_UID        = data.UserID,
                                APLY_DATE       = dt,
                                APPR_STATUS     = "1", //表單申請
                                EXEC_ACTION     = (data.vMAIL_CONTENT_ID != null) ? "U" : "A"
                            };

                            logStr += MCH.modelToString(logStr);
                            db.MAIL_CONTENT_HIS.Add(MCH);

                            foreach (var item in data.subData)
                            {
                                var _MRH = new MAIL_RECEIVE_HIS()
                                {
                                    APLY_NO         = _Aply_No,
                                    MAIL_CONTENT_ID = _MAIL_CONTENT_ID,
                                    FUNC_ID         = item.FUNC_ID,
                                    EXEC_ACTION     = item.vStatus
                                };
                                logStr += _MRH.modelToString(logStr);
                                db.MAIL_RECEIVE_HIS.Add(_MRH);
                            }
                            #region Save Db
                            var validateMessage = db.GetValidationErrors().getValidateString();
                            if (validateMessage.Any())
                            {
                                result.DESCRIPTION = validateMessage;
                            }
                            else
                            {
                                try
                                {
                                    db.SaveChanges();

                                    #region LOG
                                    //新增LOG
                                    Log log = new Log();
                                    log.CFUNCTION = "申請覆核-mail發送內文設定檔";
                                    log.CACTION   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, data.UserID);
                                    #endregion
                                    result.Datas       = GetSearchData(searchModel);
                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }
Example #19
0
        /// <summary>
        /// 金庫進出管理作業-申請覆核
        /// </summary>
        /// <param name="saveData">申請覆核的資料</param>
        /// <param name="searchModel">查詢ViwModel</param>
        /// <returns></returns>
        public MSGReturnModel <IEnumerable <ITinItem> > TinApplyAudit(IEnumerable <ITinItem> saveData, ITinItem searchModel)
        {
            var searchData = (DepChkItemSearchViewModel)searchModel;
            var result     = new MSGReturnModel <IEnumerable <ITinItem> >();

            result.RETURN_FLAG = false;
            DateTime dt = DateTime.Now;

            try
            {
                if (saveData != null)
                {
                    var datas = (List <DepChkItemViewModel>)saveData;
                    if (datas.Any())
                    {
                        using (TreasuryDBEntities db = new TreasuryDBEntities())
                        {
                            //取得流水號
                            SysSeqDao sysSeqDao = new SysSeqDao();
                            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];
                            string    _Aply_No  = string.Empty;
                            var       cId       = sysSeqDao.qrySeqNo("G9", qPreCode).ToString().PadLeft(3, '0');
                            _Aply_No = $@"G9{qPreCode}{cId}"; //申請單號 G9+系統日期YYYMMDD(民國年)+3碼流水號
                            string logStr = string.Empty;     //log

                            foreach (var item in datas)
                            {
                                int _Isortby = 0, _Item_Order = 0;
                                var _DCI = new DEP_CHK_ITEM();
                                #region 定存檢核表項目設定檔
                                //判斷執行功能
                                switch (item.vExec_Action)
                                {
                                case "A":    //新增
                                    //判斷交易別
                                    if (item.vAccess_Type == "P")
                                    {
                                        _Isortby = sysSeqDao.qrySeqNo("DCI_P", string.Empty);
                                        //_Item_Order = GetItem_Order("P");
                                    }
                                    else if (item.vAccess_Type == "G")
                                    {
                                        _Isortby = sysSeqDao.qrySeqNo("DCI_G", string.Empty);
                                        //_Item_Order = GetItem_Order("G");
                                    }
                                    //_DCI = new DEP_CHK_ITEM()
                                    //{
                                    //    ACCESS_TYPE=item.vAccess_Type,
                                    //    ISORTBY= _Isortby,
                                    //    DEP_CHK_ITEM_DESC=item.vDep_Chk_Item_Desc,
                                    //    IS_DISABLED=item.vIs_Disabled,
                                    //    ITEM_ORDER= _Item_Order,
                                    //    REPLACE=item.vReplace,
                                    //    DATA_STATUS = "2",//凍結中
                                    //    CREATE_UID = searchData.vLast_Update_Uid,
                                    //    CREATE_DT = dt,
                                    //    LAST_UPDATE_UID = searchData.vLast_Update_Uid,
                                    //    LAST_UPDATE_DT = dt,
                                    //    FREEZE_UID = searchData.vLast_Update_Uid,
                                    //    FREEZE_DT = dt
                                    //};
                                    //db.DEP_CHK_ITEM.Add(_DCI);
                                    //logStr += "|";
                                    //logStr += _DCI.modelToString();
                                    break;

                                case "U":    //修改
                                    _DCI = db.DEP_CHK_ITEM.FirstOrDefault(x => x.ACCESS_TYPE == item.vAccess_Type && x.ISORTBY == item.vIsortby);
                                    if (_DCI.LAST_UPDATE_DT != null && _DCI.LAST_UPDATE_DT > item.vLast_Update_Dt)
                                    {
                                        result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
                                        return(result);
                                    }
                                    _Isortby             = item.vIsortby;
                                    _Item_Order          = _DCI.ITEM_ORDER;
                                    _DCI.DATA_STATUS     = "2";//凍結中
                                    _DCI.LAST_UPDATE_UID = searchData.vLast_Update_Uid;
                                    _DCI.LAST_UPDATE_DT  = dt;
                                    _DCI.FREEZE_UID      = searchData.vLast_Update_Uid;
                                    _DCI.FREEZE_DT       = dt;
                                    logStr += "|";
                                    logStr += _DCI.modelToString();
                                    break;

                                default:
                                    break;
                                }
                                #endregion

                                #region 定存檢核表項目設定異動檔
                                var _DCI_Data = db.DEP_CHK_ITEM.FirstOrDefault(x => x.ACCESS_TYPE == item.vAccess_Type && x.ISORTBY == item.vIsortby);
                                if (_DCI_Data == null)
                                {
                                    var _DCIH = new DEP_CHK_ITEM_HIS()
                                    {
                                        APLY_NO           = _Aply_No,
                                        ACCESS_TYPE       = item.vAccess_Type,
                                        ISORTBY           = _Isortby,
                                        EXEC_ACTION       = item.vExec_Action,
                                        DEP_CHK_ITEM_DESC = item.vDep_Chk_Item_Desc,
                                        IS_DISABLED       = item.vIs_Disabled,
                                        ITEM_ORDER        = _Item_Order,
                                        REPLACE           = item.vReplace,
                                        APPR_STATUS       = "1",//表單申請
                                        APLY_UID          = searchData.vLast_Update_Uid,
                                        APLY_DATE         = dt
                                    };
                                    db.DEP_CHK_ITEM_HIS.Add(_DCIH);
                                    logStr += "|";
                                    logStr += _DCIH.modelToString();
                                }
                                else
                                {
                                    var _DCIH = new DEP_CHK_ITEM_HIS()
                                    {
                                        APLY_NO             = _Aply_No,
                                        ACCESS_TYPE         = item.vAccess_Type,
                                        ISORTBY             = _Isortby,
                                        EXEC_ACTION         = item.vExec_Action,
                                        DEP_CHK_ITEM_DESC   = item.vDep_Chk_Item_Desc,
                                        IS_DISABLED         = item.vIs_Disabled,
                                        ITEM_ORDER          = _Item_Order,
                                        REPLACE             = item.vReplace,
                                        APPR_STATUS         = "1",//表單申請
                                        DEP_CHK_ITEM_DESC_B = _DCI_Data.DEP_CHK_ITEM_DESC,
                                        IS_DISABLED_B       = _DCI_Data.IS_DISABLED,
                                        ITEM_ORDER_B        = _DCI_Data.ITEM_ORDER,
                                        REPLACE_B           = _DCI_Data.REPLACE,
                                        APLY_UID            = searchData.vLast_Update_Uid,
                                        APLY_DATE           = dt
                                    };
                                    db.DEP_CHK_ITEM_HIS.Add(_DCIH);
                                    logStr += "|";
                                    logStr += _DCIH.modelToString();
                                }
                                #endregion
                            }

                            #region Save Db
                            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   = "A";
                                    log.CCONTENT  = logStr;
                                    LogDao.Insert(log, searchData.vLast_Update_Uid);
                                    #endregion

                                    result.RETURN_FLAG = true;
                                    result.DESCRIPTION = Ref.MessageType.Apply_Audit_Success.GetDescription(null, $@"單號為{_Aply_No}");
                                }
                                catch (DbUpdateException ex)
                                {
                                    result.DESCRIPTION = ex.exceptionMessage();
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                    }
                }
                else
                {
                    result.DESCRIPTION = Ref.MessageType.not_Find_Audit_Data.GetDescription();
                }
            }
            catch (Exception ex)
            {
                result.DESCRIPTION = ex.exceptionMessage();
            }

            return(result);
        }