Ejemplo n.º 1
0
        public void LoadViewModel()
        {
            ObjStatus = new ObjectStatus {
                IsNew = true
            };
            Client         = new CRUD_ManagerServiceClient();
            WarehousesList = new ObservableCollection <V_Warehouse>();
            WarehousesList.CollectionChanged += WarehousesList_CollectionChanged;
            CreationDate = DateTime.Now;
            Client.GetAllWarehousesByCompanyNameCompleted += (s, e) =>
            {
                foreach (var item in e.Result)
                {
                    WarehousesList.Add(item);
                }
            };
            Client.GetAllWarehousesByCompanyNameAsync("CCR");
            PurchaseOrderDetails = new ObservableCollection <NewRfqPurchasOrderDetailsViewModel>();

            PurchaseOrderDetails.CollectionChanged += (s, e) =>
            {
                if (e.NewItems != null)
                {
                    foreach (NewRfqPurchasOrderDetailsViewModel item in e.NewItems)
                    {
                        item.PropertyChanged
                            += (s1, e1) =>
                            {
                            RaisePropertyChanged(e1.PropertyName);
                            if (e1.PropertyName == "RowTotal")
                            {
                                GrandTotal = PurchaseOrderDetails.Sum(x => x.RowTotal);
                            }
                            };

                        var item1 = item;
                        item.DeletePurchLine += (ss, ee) =>
                        {
                            var res = MessageBox.Show("Delete?", "", MessageBoxButton.OKCancel);
                            if (res == MessageBoxResult.Cancel)
                            {
                                return;
                            }
                            PurchaseOrderDetails.Remove(item1);
                        };
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (NewRfqPurchasOrderDetailsViewModel item in e.OldItems)
                    {
                        item.PropertyChanged
                            -= ((s1, e1) => RaisePropertyChanged(e1.PropertyName));
                        var item1 = item;
                        item.DeletePurchLine -= ((ss, ee) =>
                        {
                            if (item1.ObjStatus.IsSavedDBItem)
                            {
                                PurchaseOrderDeletedDetails.Add(item1);
                            }
                            PurchaseOrderDetails.Remove(item1);
                        });
                    }
                }
            };

            Client.PostPoToAxCompleted += (s, e)
                                          =>
            {
                MessageBox
                .Show(e.Error == null ? "PO Successfully Posted" : "PO Was not posted");
                IsPosted = e.Error == null;
            };
        }