コード例 #1
0
        /// <summary>
        /// 获取记录期初数据
        /// </summary>
        /// <param name="settlement">能源结算</param>
        /// <param name="record">能源结算记录</param>
        /// <returns>期初用量,期初金额</returns>
        private Tuple <decimal, decimal> GetBeginData(Settlement settlement, SettlementRecord record)
        {
            TargetRecordBusiness trBusiness = new TargetRecordBusiness();
            var targetRecord = trBusiness.FindByDepartment(settlement.TargetId, record.DepartmentId, record.EnergyType);

            decimal beginQuantum = 0;
            decimal beginAmount  = 0;

            if (string.IsNullOrEmpty(settlement.PreviousId))
            {
                if (targetRecord != null)
                {
                    beginQuantum = targetRecord.PlanQuantum;
                    beginAmount  = targetRecord.PlanAmount;
                }
                else
                {
                    beginQuantum = 0;
                    beginAmount  = 0;
                }
            }
            else
            {
                SettlementBusiness settlementBusiness = new SettlementBusiness();
                var previous = settlementBusiness.FindById(settlement.PreviousId);

                var dal            = this.baseDal as ISettlementRecordRepository;
                var previousRecord = dal.FindOne(previous.Id, record.DepartmentId, record.EnergyType);

                beginQuantum = previousRecord.BeginQuantum - previousRecord.Quantum;
                beginAmount  = previousRecord.BeginAmount - previousRecord.Amount;
            }

            return(new Tuple <decimal, decimal>(beginQuantum, beginAmount));
        }
コード例 #2
0
        /// <summary>
        /// 添加默认结算记录
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="user">操作用户</param>
        public void Create(SettlementRecord entity, LoginUser user)
        {
            var dal = this.baseDal as ISettlementRecordRepository;

            SettlementBusiness settlementBusiness = new SettlementBusiness();
            var settlement = settlementBusiness.FindById(entity.SettlementId);

            TargetRecordBusiness trBusiness = new TargetRecordBusiness();
            var targetRecord = trBusiness.FindByDepartment(settlement.TargetId, entity.DepartmentId, entity.EnergyType);

            DateTime now = DateTime.Now;

            entity.Quantum  = 0;
            entity.Amount   = 0;
            entity.Status   = 0;
            entity.CreateBy = new UpdateStamp
            {
                UserId = user.Id,
                Name   = user.Name,
                Time   = now
            };
            entity.UpdateBy = new UpdateStamp
            {
                UserId = user.Id,
                Name   = user.Name,
                Time   = now
            };

            var begin = GetBeginData(settlement, entity);

            entity.BeginQuantum = begin.Item1;
            entity.BeginAmount  = begin.Item2;

            dal.Create(entity);
            return;
        }