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;
            }
        }
        private void InitializeViewModels()
        {
            WarehouseRootViewModel = new WarehouseRootViewModel(CMContext);
            foreach (var warehouse in CMContext.Warehouse.Local)
            {
                WarehouseViewModel bufferWarehouseViewModel = new WarehouseViewModel(CMContext);
                bufferWarehouseViewModel.Warehouse = warehouse;
                foreach (var plane in warehouse.Planes)
                {
                    PlaneViewModel bufferPlaneViewModel = new PlaneViewModel(CMContext);
                    bufferPlaneViewModel.Plane = plane;
                    foreach (var block in plane.Blocks)
                    {
                        BlockViewModel bufferBlockViewModel = new BlockViewModel(CMContext);
                        bufferBlockViewModel.Block = block;
                        foreach (var cargoCollection in block.CargoCollections)
                        {
                            CargoCollectionViewModel bufferCargoCollectionViewModel = new CargoCollectionViewModel(CMContext)
                            {
                                CargoCollectionViewModels = CargoCollectionViewModels
                            };
                            bufferCargoCollectionViewModel.CargoCollection           = cargoCollection;
                            bufferCargoCollectionViewModel.BlockViewModel            = bufferBlockViewModel;
                            bufferCargoCollectionViewModel.SelectedPurchasePrizeDic  = bufferCargoCollectionViewModel.CargoCollection.PurchasePrizeDics[0];
                            bufferCargoCollectionViewModel.CargoCollectionViewModels = CargoCollectionViewModels;

                            bufferBlockViewModel.CargoCollectionViewModels.Add(bufferCargoCollectionViewModel);
                            CargoCollectionViewModels.Add(bufferCargoCollectionViewModel);
                        }
                        bufferBlockViewModel.PlaneViewModel = bufferPlaneViewModel;
                        bufferPlaneViewModel.BlockViewModels.Add(bufferBlockViewModel);
                    }
                    bufferPlaneViewModel.WarehouseViewModel = bufferWarehouseViewModel;
                    bufferWarehouseViewModel.PlaneViewModels.Add(bufferPlaneViewModel);
                }
                bufferWarehouseViewModel.WarehouseRootViewModel = WarehouseRootViewModel;
                WarehouseRootViewModel.WarehouseViewModels.Add(bufferWarehouseViewModel);
            }
            foreach (var cargo in CMContext.Cargo.Local)
            {
                CargoViewModel bufferCargoViewModel = new CargoViewModel(CMContext);
                bufferCargoViewModel.Cargo                     = cargo;
                bufferCargoViewModel.CargoViewModels           = CargoViewModels;
                bufferCargoViewModel.CargoCollectionViewModels = CargoCollectionViewModels;
                CargoViewModels.Add(bufferCargoViewModel);
            }
            PurchaseOrderCollectionViewModels = new ObservableCollection <PurchaseOrderCollectionViewModel>();
            foreach (var purchaseOrderCollection in CMContext.PurchaseOrderCollection.Local)
            {
                PurchaseOrderCollectionViewModel pocvm = new PurchaseOrderCollectionViewModel(CMContext)
                {
                    PurchaseOrderCollection = purchaseOrderCollection, PurchaseOrderCollectionViewModels = PurchaseOrderCollectionViewModels
                };
                foreach (var purchaseOrder in purchaseOrderCollection.PurchaseOrders)
                {
                    PurchaseOrderViewModel povm = new PurchaseOrderViewModel(CMContext)
                    {
                        PurchaseOrder = purchaseOrder, PurchaseOrderCollectionViewModel = pocvm
                    };
                    pocvm.PurchaseOrderViewModels.Add(povm);
                }
                PurchaseOrderCollectionViewModels.Add(pocvm);
            }
            SellOrderCollectionViewModels = new ObservableCollection <SellOrderCollectionViewModel>();
            foreach (var sellOrderCollection in CMContext.SellOrderCollection.Local)
            {
                SellOrderCollectionViewModel socvm = new SellOrderCollectionViewModel(CMContext)
                {
                    SellOrderCollection = sellOrderCollection, SellOrderCollectionViewModels = SellOrderCollectionViewModels
                };
                foreach (var sellOrder in sellOrderCollection.SellOrders)
                {
                    SellOrderViewModel sovm = new SellOrderViewModel(CMContext, new CargoCollectionViewModel())
                    {
                        SellOrder = sellOrder
                    };
                    socvm.SellOrderViewModels.Add(sovm);
                }
                SellOrderCollectionViewModels.Add(socvm);
            }
        }