private void ConfirmPurchaseOrderCollectionExecute(object parameter)
        {
            string       message       = "是否确认订单";
            string       detailMessage = "请检查进货订单中的每一个条目是否正确,确认订单后将无法修改";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                DateTime CurrentTime = DateTime.Now;
                PurchaseOrderCollectionViewModel.PurchaseOrderCollection.PurchaseTime = CurrentTime;
                foreach (var purchaseorderviewmodel in PurchaseOrderCollectionViewModel.PurchaseOrderViewModels)
                {
                    purchaseorderviewmodel.PurchaseOrder.PurchaseTime = CurrentTime;
                    CMContext.PurchaseOrder.Add(purchaseorderviewmodel.PurchaseOrder);
                    BlockViewModel blockViewModel             = purchaseorderviewmodel.BlockViewModel;
                    IEnumerable <CargoCollectionViewModel> cc = blockViewModel.CargoCollectionViewModels.Where <CargoCollectionViewModel>(item => item.CargoCollection.PreciseCargoName == purchaseorderviewmodel.PurchaseOrder.PreciseCargoName);
                    if (cc.Count() == 0)
                    {
                        CargoCollectionViewModel c = new CargoCollectionViewModel(CMContext, purchaseorderviewmodel)
                        {
                            BlockViewModel = blockViewModel, CargoCollectionViewModels = CargoCollectionViewModels
                        };
                        CargoCollectionViewModels.Add(c);
                        blockViewModel.CargoCollectionViewModels.Add(c);
                        CMContext.CargoCollection.Add(c.CargoCollection);
                        PurchasePrizeDic p1 = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder)
                        {
                            UnitPurchasePrize = -1
                        };
                        PurchasePrizeDic p2 = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder);
                        CMContext.PurchasePrizeDic.Add(p1);
                        CMContext.PurchasePrizeDic.Add(p2);
                        c.SelectedPurchasePrizeDic = p1;
                    }
                    else
                    {
                        CargoCollectionViewModel c = cc.First();
                        c.CargoCollection.Amount += purchaseorderviewmodel.PurchaseOrder.Amount;
                        c.CargoCollection.PurchasePrizeDics[0].Amount = c.CargoCollection.Amount;
                        IEnumerable <PurchasePrizeDic> pp = c.CargoCollection.PurchasePrizeDics.Where <PurchasePrizeDic>(item => item.UnitPurchasePrize == purchaseorderviewmodel.PurchaseOrder.UnitPurchasePrize);
                        if (pp.Count() == 0)
                        {
                            PurchasePrizeDic p = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder);
                            CMContext.PurchasePrizeDic.Add(p);
                        }
                        else
                        {
                            pp.First().Amount += purchaseorderviewmodel.PurchaseOrder.Amount;
                        }
                    }
                }
                CMContext.PurchaseOrderCollection.Add(PurchaseOrderCollectionViewModel.PurchaseOrderCollection);
                PurchaseOrderCollectionViewModels.Add(PurchaseOrderCollectionViewModel);
                CMContext.SaveChanges();
                PurchaseOrderCollectionViewModel = null;
                OutPurchaseOrderButtonIsEnabled  = false;
            }
        }
コード例 #2
0
 public SellOrderViewModel(CargoManagementContext cmContext, CargoCollectionViewModel cargoCollectionViewModel)
 {
     CMContext = cmContext;
     CargoCollectionViewModel = cargoCollectionViewModel;
     DeleteCommand            = new DelegateCommand()
     {
         ExecuteAction = new Action <object>(DeleteExecute)
     };
     ShowDetailCommand = new DelegateCommand()
     {
         ExecuteAction = new Action <object>(ShowDetailExecute)
     };
 }
        private void ConfirmSellOrderCollectionExecute(object parameter)
        {
            string       message       = "是否确认订单";
            string       detailMessage = "请检查卖货订单中的每一个条目是否正确,确认订单后将无法修改";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                DateTime CurrentTime = DateTime.Now;
                SellOrderCollectionViewModel.SellOrderCollection.SellTime = CurrentTime;
                foreach (var sellorderviewmodel in SellOrderCollectionViewModel.SellOrderViewModels)
                {
                    sellorderviewmodel.SellOrder.SellTime = CurrentTime;
                    CMContext.SellOrder.Add(sellorderviewmodel.SellOrder);
                    CargoCollectionViewModel cargoCollectionViewModel = sellorderviewmodel.CargoCollectionViewModel;
                    if (cargoCollectionViewModel.CargoCollection.Amount == sellorderviewmodel.SellOrder.Amount)
                    {
                        CMContext.CargoCollection.Remove(cargoCollectionViewModel.CargoCollection);
                        cargoCollectionViewModel.BlockViewModel.CargoCollectionViewModels.Remove(cargoCollectionViewModel);
                        cargoCollectionViewModel.CargoCollectionViewModels.Remove(cargoCollectionViewModel);
                    }
                    else
                    {
                        int BufferAmount = sellorderviewmodel.SellOrder.Amount;
                        cargoCollectionViewModel.CargoCollection.PurchasePrizeDics[0].Amount -= sellorderviewmodel.SellOrder.Amount;
                        cargoCollectionViewModel.CargoCollection.Amount -= sellorderviewmodel.SellOrder.Amount;
                        foreach (var dic in cargoCollectionViewModel.CargoCollection.PurchasePrizeDics)
                        {
                            if (dic.UnitPurchasePrize == -1)
                            {
                                continue;
                            }
                            else if (BufferAmount == 0)
                            {
                                break;
                            }
                            else if (dic.Amount == BufferAmount)
                            {
                                dic.Amount   = 0;
                                BufferAmount = 0;
                            }
                            else if (dic.Amount < BufferAmount)
                            {
                                BufferAmount -= dic.Amount;
                                dic.Amount    = 0;
                            }
                            else if (dic.Amount > BufferAmount)
                            {
                                dic.Amount  -= BufferAmount;
                                BufferAmount = 0;
                            }
                        }
                        var bufferresult = cargoCollectionViewModel.CargoCollection.PurchasePrizeDics.Where <PurchasePrizeDic>(item => item.Amount == 0).ToList();

                        for (int i = 0; i < bufferresult.Count(); i++)
                        {
                            cargoCollectionViewModel.CargoCollection.PurchasePrizeDics.Remove(bufferresult[i]);
                        }
                    }
                }
                CMContext.SellOrderCollection.Add(SellOrderCollectionViewModel.SellOrderCollection);
                SellOrderCollectionViewModels.Add(SellOrderCollectionViewModel);
                CMContext.SaveChanges();
                SellOrderCollectionViewModel = null;
                OutSellOrderButtonIsEnabled  = false;
            }
        }