예제 #1
0
        public ResultModel Close(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
                Model.FundsLog fundsLog = null;
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = cashInAllotDAL.Get(user, allotId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    //关闭付款分配
                    result = cashInAllotDAL.Close(user, cashInAllot);
                    if (result.ResultStatus != 0)
                        return result;

                    result = cashinstcokDAL.LoadByAllot(user, allotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInStcok> cashInStcoks = result.ReturnValue as List<Model.CashInStcok>;
                    if (cashInStcoks == null || !cashInStcoks.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取明细失败";
                        return result;
                    }

                    foreach (Model.CashInStcok cashInStcok in cashInStcoks)
                    {
                        //关闭明细
                        result = cashinstcokDAL.Close(user, cashInStcok);
                        if (result.ResultStatus != 0)
                            return result;

                        result = cashInContractDAL.Get(user, cashInStcok.ContractRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                        if (cashInContract == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        result = cashInContractDAL.Close(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        result = cashInCorpDAL.Get(user, cashInContract.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        result = cashInCorpDAL.Close(user, cashInCorp);
                        if (result.ResultStatus != 0)
                            return result;

                        result = fundsLogDAL.Get(user, cashInStcok.FundsLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        fundsLog = result.ReturnValue as Model.FundsLog;
                        if (fundsLog == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取资金流水失败";
                            return result;
                        }

                        //关闭流水
                        result = fundsLogDAL.Close(user, fundsLog);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
예제 #2
0
        public ResultModel Close_NewVersion(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();
            DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
            DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
            DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL();
            DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
            DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //获取主收款分配
                    result = cashinallotDAL.Get(user, allotId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配失败";
                        return result;
                    }

                    //完成主收款分配
                    result = cashinallotDAL.Close(user, cashInAllot);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取收款分配至公司
                    result = cashInCorpDAL.Load(user, cashInAllot.AllotId, NFMT.Common.StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInCorp> cashInCorps = result.ReturnValue as List<Model.CashInCorp>;
                    if (cashInCorps == null || !cashInCorps.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配至公司失败";
                        return result;
                    }

                    Model.CashInCorp cashInCorp = cashInCorps.FirstOrDefault(a => a.RefId > 0);

                    //完成收款分配至公司
                    result = cashInCorpDAL.Close(user, cashInCorp);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取收款分配至合约
                    result = cashInContractDAL.LoadDetail(user, cashInAllot.AllotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInContract> cashInContracts = result.ReturnValue as List<Model.CashInContract>;
                    if (cashInContracts == null || !cashInContracts.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配至合约失败";
                        return result;
                    }

                    Model.CashInContract cashInContract = cashInContracts.FirstOrDefault(a => a.RefId > 0);

                    //完成收款分配至合约
                    result = cashInContractDAL.Close(user, cashInContract);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取收款分配至库存
                    result = cashInStcokDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInStcok> cashInStcoks = result.ReturnValue as List<Model.CashInStcok>;
                    if (cashInStcoks == null || !cashInStcoks.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配至库存失败";
                        return result;
                    }

                    foreach (Model.CashInStcok cashInStcok in cashInStcoks)
                    {
                        //完成收款分配至库存
                        result = cashInStcokDAL.Close(user, cashInStcok);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取收款分配至库存
                    result = cashInInvoiceDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInInvoice> cashInInvoices = result.ReturnValue as List<Model.CashInInvoice>;
                    if (cashInInvoices == null || !cashInInvoices.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配至发票失败";
                        return result;
                    }

                    foreach (Model.CashInInvoice cashInInvoice in cashInInvoices)
                    {
                        //完成收款分配至库存
                        result = cashInInvoiceDAL.Close(user, cashInInvoice);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取资金流水
                    result = fundsLogDAL.Get(user, cashInCorp.FundsLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.FundsLog fundsLog = result.ReturnValue as Model.FundsLog;
                    if (fundsLog == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取资金流水失败";
                        return result;
                    }

                    //资金流水完成
                    result = fundsLogDAL.Close(user, fundsLog);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }