예제 #1
0
        /// <summary>
        ///     插入新订单行
        /// </summary>
        /// <param name="order">订单</param>
        /// <param name="dto">订单DTO</param>
        /// <param name="line">订单行DTO</param>
        /// <param name="importType">引进方式</param>
        /// <param name="supplierId">供应商ID</param>
        private void InsertOrderLine(EnginePurchaseOrder order, EnginePurchaseOrderDTO dto,
            EnginePurchaseOrderLineDTO line, ActionCategory importType, int supplierId)
        {
            // 获取飞机物料机型
            var material =
                _materialRepository.GetFiltered(m => m.Id == line.EngineMaterialId)
                    .OfType<EngineMaterial>()
                    .FirstOrDefault();
            var pnReg = _pnRegRepository.GetFiltered(p => p.Pn == material.Pn).FirstOrDefault();
            if (material == null)
            {
                throw new ArgumentException("未能获取飞机物料!");
            }

            // 添加订单行
            var orderLine = order.AddNewEnginePurchaseOrderLine(line.UnitPrice, line.Amount,
                line.Discount,
                line.EstimateDeliveryDate);
            orderLine.SetEngineMaterial(line.EngineMaterialId);

            // 创建或引用合同发动机
            var persist = _contractEngineRepository.Get(line.ContractEngineId) as PurchaseContractEngine;
            var contractEngine = ContractEngineFactory.CreatePurchaseContractEngine(dto.Name,
                line.RankNumber);
            contractEngine.ChangeCurrentIdentity(line.ContractEngineId);
            contractEngine.SetImportCategory(importType);
            contractEngine.SetSerialNumber(line.SerialNumber);
            contractEngine.SetSupplier(supplierId);
            contractEngine.SetPart(pnReg);
            if (persist == null)
            {
                orderLine.SetContractEngine(contractEngine);
            }
            else
            {
                orderLine.SetContractEngine(persist);
                _contractEngineRepository.Merge(persist, contractEngine);
            }
        }
예제 #2
0
        public void InsertEnginePurchaseOrder(EnginePurchaseOrderDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentException("参数为空!");
            }

            // 获取版本号
            var id = dto.TradeId;
            var version = _orderRepository.GetFiltered(o => o.TradeId == id).Count() + 1;

            var date = DateTime.Now.Date;
            var seq = _orderRepository.GetFiltered(t => t.CreateDate > date).Count() + 1;

            // 创建订单
            var order = OrderFactory.CreateEnginePurchaseOrder(version, dto.OperatorName, dto.OrderDate);
            order.SetTrade(dto.TradeId);
            order.SetCurrency(dto.CurrencyId);
            order.SetContractNumber(seq);
            order.SetLinkman(dto.LinkmanId);
            order.SetSourceGuid(dto.SourceGuid);
            order.SetName(dto.Name);
            order.SetOrderStatus((OrderStatus) dto.Status);
            if (!string.IsNullOrWhiteSpace(dto.LogWriter))
            {
                order.SetNote(dto.LogWriter);
            }
            if (dto.ContractDocGuid != Guid.Empty)
            {
                order.SetContractDoc(dto.ContractDocGuid, dto.ContractName);
            }

            // 获取引进方式
            var importType =
                _actionCategoryRepository.GetFiltered(a => a.ActionType == "引进" && a.ActionName == "购买")
                    .FirstOrDefault();

            // 处理订单行
            dto.EnginePurchaseOrderLines.ToList()
                .ForEach(line => InsertOrderLine(order, dto, line, importType, dto.SupplierId));

            // 处理分解合同
            dto.ContractContents.ToList().ForEach(c => InsertContractContent(order, c));

            _orderRepository.Add(order);
        }
예제 #3
0
        public void UpdateEnginePurchaseOrder(EnginePurchaseOrderDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentException("参数为空!");
            }

            var order = _orderRepository.Get(dto.Id) as EnginePurchaseOrder;
            if (order != null)
            {
                // 更新当前记录
                order.SetCurrency(dto.CurrencyId);
                order.SetLinkman(dto.LinkmanId);
                order.SetName(dto.Name);
                order.SetOperatorName(dto.OperatorName);
                order.SetOrderStatus((OrderStatus) dto.Status);
                if (!string.IsNullOrWhiteSpace(dto.LogWriter))
                {
                    order.SetNote(dto.LogWriter);
                }
                if (dto.ContractDocGuid != Guid.Empty)
                {
                    order.SetContractDoc(dto.ContractDocGuid, dto.ContractName);
                }

                // 获取引进方式
                var importType =
                    _actionCategoryRepository.GetFiltered(a => a.ActionType == "引进" && a.ActionName == "购买")
                        .FirstOrDefault();

                var trade = _tradeRepository.Get(order.TradeId);

                // 处理订单行
                var dtoOrderLines = dto.EnginePurchaseOrderLines;
                var orderLines = order.OrderLines;
                DataHelper.DetailHandle(dtoOrderLines.ToArray(),
                    orderLines.OfType<EnginePurchaseOrderLine>().ToArray(),
                    c => c.Id, p => p.Id,
                    i => InsertOrderLine(order, dto, i, importType, trade.SupplierId),
                    UpdateOrderLine,
                    d => _orderRepository.RemoveOrderLine(d));

                // 处理分解合同
                var dtoContents = dto.ContractContents;
                var contents = order.ContractContents;
                DataHelper.DetailHandle(dtoContents.ToArray(), contents.ToArray(),
                    c => c.Id, p => p.Id,
                    i => InsertContractContent(order, i),
                    UpdateContractContent,
                    d => _orderRepository.RemoveContractContent(d));
            }
        }
예제 #4
0
        public void DeleteEnginePurchaseOrder(EnginePurchaseOrderDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentException("参数为空!");
            }

            var deleteEnginePurchaseOrder = _orderRepository.Get(dto.Id);
            if (deleteEnginePurchaseOrder != null)
            {
                _relatedDocRepository.GetFiltered(r => r.SourceId == deleteEnginePurchaseOrder.SourceGuid)
                    .ToList()
                    .ForEach(r => _relatedDocRepository.Remove(r));
                _orderRepository.Remove(deleteEnginePurchaseOrder);
            }
        }