Ejemplo n.º 1
0
        public int qrySeqNo(string sysCd, string cType, string cPreCode)
        {
            int intseq = 0;
            int cnt    = 0;

            //using (new TransactionScope(
            //       TransactionScopeOption.Required,
            //       new TransactionOptions
            //       {
            //           IsolationLevel = IsolationLevel.ReadUncommitted
            //       }))
            //{

            using (dbFGLEntities db = new dbFGLEntities())
            {
                try
                {
                    if ("".Equals(cPreCode))
                    {
                        SYS_SEQ sysDeq = db.SYS_SEQ.Where(x => x.SYS_CD == sysCd & x.SEQ_TYPE == cType).FirstOrDefault <SYS_SEQ>();
                        //sysDeq.SYS_CD = sysCd;
                        if (sysDeq == null)
                        {
                            sysDeq            = new SYS_SEQ();
                            intseq            = 1;
                            sysDeq.SYS_CD     = sysCd;
                            sysDeq.SEQ_TYPE   = cType;
                            sysDeq.PRECODE    = "";
                            sysDeq.CURR_VALUE = intseq + 1;

                            db.SYS_SEQ.Add(sysDeq);
                            cnt = db.SaveChanges();
                        }
                        else
                        {
                            intseq = sysDeq.CURR_VALUE;

                            sysDeq.CURR_VALUE = intseq + 1;

                            cnt = db.SaveChanges();
                        }
                    }
                    else
                    {
                        SYS_SEQ sysDeq = db.SYS_SEQ.Where(x => x.SYS_CD == sysCd & x.SEQ_TYPE == cType & x.PRECODE == cPreCode).FirstOrDefault <SYS_SEQ>();

                        if (sysDeq == null)
                        {
                            sysDeq            = new SYS_SEQ();
                            intseq            = 1;
                            sysDeq.SYS_CD     = sysCd;
                            sysDeq.SEQ_TYPE   = cType;
                            sysDeq.PRECODE    = cPreCode;
                            sysDeq.CURR_VALUE = intseq + 1;

                            db.SYS_SEQ.Add(sysDeq);
                            cnt = db.SaveChanges();
                        }
                        else
                        {
                            intseq            = sysDeq.CURR_VALUE;
                            sysDeq.CURR_VALUE = intseq + 1;
                            cnt = db.SaveChanges();
                        }
                    }

                    return(intseq);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            //}
        }
Ejemplo n.º 2
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);
        }