Exemplo n.º 1
0
        /// <summary>
        /// 刪除申請 (刪除資料)
        /// </summary>
        /// <param name="searchData">金庫物品存取主畫面查詢ViewModel</param>
        /// <param name="data">申請表單查詢顯示區塊ViewModel</param>
        /// <returns></returns>
        public MSGReturnModel <List <TreasuryAccessSearchDetailViewModel> > Cancel(TreasuryAccessSearchViewModel searchData, TreasuryAccessSearchDetailViewModel data)
        {
            var result = new MSGReturnModel <List <TreasuryAccessSearchDetailViewModel> >();

            result.RETURN_FLAG = false;
            result.DESCRIPTION = Ref.MessageType.already_Change.GetDescription();
            DateTime dt     = DateTime.Now;
            string   logStr = string.Empty;
            //取得流水號
            SysSeqDao sysSeqDao = new SysSeqDao();
            String    qPreCode  = DateUtil.getCurChtDateTime().Split(' ')[0];

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var _TREA_APLY_REC = db.TREA_APLY_REC.FirstOrDefault(x => x.APLY_NO == data.vAPLY_NO);
                if (_TREA_APLY_REC != null)
                {
                    if (_TREA_APLY_REC.LAST_UPDATE_DT > data.vLast_Update_Time)
                    {
                        return(result);
                    }
                    logStr += _TREA_APLY_REC.modelToString();


                    #region 刪除申請
                    var sampleFactory = new SampleFactory();
                    var getAgenct     = sampleFactory.GetAgenct(EnumUtil.GetValues <Ref.TreaItemType>().First(x => x.ToString() == _TREA_APLY_REC.ITEM_ID));
                    if (getAgenct != null)
                    {
                        var _recover = getAgenct.CancelApply(db, _TREA_APLY_REC.APLY_NO, _TREA_APLY_REC.ACCESS_TYPE, logStr, dt);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr = _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                    #endregion

                    #region 刪除 申請單歷程檔
                    db.APLY_REC_HIS.RemoveRange(db.APLY_REC_HIS.Where(x => x.APLY_NO == _TREA_APLY_REC.APLY_NO));
                    #endregion

                    #region 刪除 申請單紀錄檔
                    db.TREA_APLY_REC.Remove(_TREA_APLY_REC);
                    #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   = "D";
                            log.CCONTENT  = logStr;
                            LogDao.Insert(log, searchData.vCreateUid);
                            #endregion

                            result.RETURN_FLAG = true;
                            result.DESCRIPTION = $@"單號{data.vAPLY_NO} 已刪除!";
                        }
                        catch (DbUpdateException ex)
                        {
                            result.DESCRIPTION = ex.exceptionMessage();
                        }
                    }
                }
                if (result.RETURN_FLAG)
                {
                    result.Datas = GetSearchDetail(searchData);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public MSGReturnModel <List <TDAApprSearchDetailViewModel> > Reject(TDAApprSearchViewModel searchData, List <TDAApprSearchDetailViewModel> viewModels, string apprDesc)
        {
            var result = new MSGReturnModel <List <TDAApprSearchDetailViewModel> >();

            result.RETURN_FLAG = false;
            result.DESCRIPTION = Ref.MessageType.not_Find_Any.GetDescription();
            List <string> TREA_ITEM_APLY        = new List <string>();
            List <string> TREA_EQUIP_APLY       = new List <string>();
            List <string> MAIL_CONTENT_APLY     = new List <string>();
            List <string> MAIL_TIME_APLY        = new List <string>();
            List <string> ITEM_CHARGE_UNIT_APLY = new List <string>();
            List <string> DEP_CHK_ITEM_APLY     = new List <string>();
            DateTime      dt     = DateTime.Now;
            string        logStr = string.Empty;

            using (TreasuryDBEntities db = new TreasuryDBEntities())
            {
                var aplynos = new List <string>();
                foreach (var item in viewModels.Where(x => x.vCheckFlag))
                {
                    switch (item.vTDA_Id)
                    {
                    case "TREA_ITEM":
                        TREA_ITEM_APLY.Add(item.vAply_No);
                        break;

                    case "TREA_EQUIP":
                        TREA_EQUIP_APLY.Add(item.vAply_No);
                        break;

                    case "MAIL_CONTENT":
                        MAIL_CONTENT_APLY.Add(item.vAply_No);
                        break;

                    case "MAIL_TIME":
                        MAIL_TIME_APLY.Add(item.vAply_No);
                        break;

                    case "ITEM_CHARGE_UNIT":
                        ITEM_CHARGE_UNIT_APLY.Add(item.vAply_No);
                        break;

                    case "DEP_CHK_ITEM":
                        DEP_CHK_ITEM_APLY.Add(item.vAply_No);
                        break;
                    }
                    aplynos.Add(item.vAply_No);
                }
                #region  應資料檔-駁回
                var sampleFactory = new SampleFactory();

                if (TREA_ITEM_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "TREA_ITEM"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, TREA_ITEM_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                if (TREA_EQUIP_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "TREA_EQUIP"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, TREA_EQUIP_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                if (MAIL_CONTENT_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "MAIL_CONTENT"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, MAIL_CONTENT_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                if (MAIL_TIME_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "MAIL_TIME"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, MAIL_TIME_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                if (ITEM_CHARGE_UNIT_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "ITEM_CHARGE_UNIT"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, ITEM_CHARGE_UNIT_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                if (DEP_CHK_ITEM_APLY.Any())
                {
                    var getTDAAction = sampleFactory.GetTDAAction(EnumUtil.GetValues <Ref.DefinitionType>().First(x => x.ToString() == "DEP_CHK_ITEM"));
                    if (getTDAAction != null)
                    {
                        var _recover = getTDAAction.TinReject(db, DEP_CHK_ITEM_APLY, logStr, dt, searchData.vCreateUid, apprDesc);
                        if (!_recover.Item1) //失敗
                        {
                            return(result);
                        }
                        logStr += _recover.Item2;
                    }
                    else
                    {
                        return(result);
                    }
                }
                #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   = "U";
                        log.CCONTENT  = logStr;
                        LogDao.Insert(log, searchData.vCreateUid);
                        #endregion

                        result.RETURN_FLAG = true;
                        result.DESCRIPTION = $"申請單號 : {string.Join(",", aplynos)} 已駁回!";
                        result.Datas       = GetApprSearchDetail(searchData);
                    }
                    catch (DbUpdateException ex)
                    {
                        result.DESCRIPTION = ex.exceptionMessage();
                    }
                }
            }
            return(result);
        }