private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            _vm = DataContext as AmmendSalesmanOrderLineItemViewModel;
            if (MessageBox.Show("Save these changes?", "Distributr: Ammending Order", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            if (!_vm.IsNew)
                txtQty_GotFocus(this, new RoutedEventArgs());

            decimal guardQty = 0;
            if (_vm.ProcessingBackOrder)
                guardQty = _vm.OriginalQty;
            else
                guardQty = _vm.Qty;

            bool isInvalid = false;
            if (cmbProducts.SelectedItem == null || cmbProducts.SelectedIndex == -1)
            //|| _vm.AwaitingStock+_vm.BackOrder+_vm.Qty+_vm.LostSale <= 0)
            {
                MessageBox.Show("Select a product in product dropdown list.",
                                "Distributr: Add Order Line Items", MessageBoxButton.OK);
                isInvalid = true;
            }

            if (!isInvalid)
            {
                _vm.AddOrUpdateProducts();
                this.DialogResult = true;
            }
        }
 private void cmbProducts_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     _vm = this.DataContext as AmmendSalesmanOrderLineItemViewModel;
     _vm.SelectedProduct = cmbProducts.SelectedItem as OrderLineItemProductLookupItem;
     _vm.ProductSelected.Execute(null);
 }
        private void txtApprove_TextChanged(object sender, TextChangedEventArgs e)
        {
            if(!isInitialised)
                return;
            if (_vm == null)
                _vm = DataContext as AmmendSalesmanOrderLineItemViewModel;

            if (txtApprove.Text == "")
                txtApprove.Text = "0";

             
            decimal guardQty = 0;
            decimal txtapprove = 0;
                Decimal.TryParse(txtApprove.Text,out txtapprove);
            if (_vm.ProcessingBackOrder)
                guardQty = _vm.OriginalQty;
            else
                Decimal.TryParse(txtQty.Text, out guardQty);
            ;
            if (txtapprove > guardQty && _vm.DocumentStatus == "Order Pending Dispatch")
            {
                MessageBox.Show("The quantity to approve must not be more than the quantity originally required.",
                                "Distribtr: Ammend Order", MessageBoxButton.OK);
                txtApprove.Text = txtQty.Text;
            }
            else
            {
                _vm.Approve = txtapprove;//Convert.ToInt32(txtApprove.Text);
                //_vm.RecalcTotal();
                if (_vm.SellInBulk)
                {
                    _vm.SellInBulkSelected.Execute(null);
                    //_vm.RecalcTotal();
                }
                else if (_vm.SellInUnits)
                {
                    _vm.SellInUnitsSelected.Execute(null);
                }

                _vm.txtApproveGotFocusCommand.Execute(null);
            }
        }
 private void txtApprove_GotFocus(object sender, RoutedEventArgs e)
 {
     _vm = DataContext as AmmendSalesmanOrderLineItemViewModel;
     _vm.txtApproveGotFocusCommand.Execute(null);
 }