private void Other_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { this.CalculateOtherCharges(); GrossAmount.Focus(); } }
private void SalesInvoiceDataGrid_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { e.Handled = true; DataGrid grid = (DataGrid)sender; int col = grid.CurrentCell.Column.DisplayIndex; DataGridCellInfo cell = PurchaseInvoiceDataGrid.SelectedCells[0]; int rowIndex = PurchaseInvoiceDataGrid.Items.IndexOf(cell.Item); int row = rowIndex; List <SalesInvoiceCollectionViewModel> salesInvoiceCollectionViewModels = (List <SalesInvoiceCollectionViewModel>)PurchaseInvoiceDataGrid.ItemsSource; if (col < grid.Columns.Count - 1) { if (!string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].name)) { ProductViewModel productmodel = GetProductById(Convert.ToInt32(salesInvoiceCollectionViewModels[row - 1].name)); if (string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].rate)) { salesInvoiceCollectionViewModels[row - 1].rate = productmodel.MRP; } salesInvoiceCollectionViewModels[row - 1].per = productmodel.Unit; if (string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].grossnet) && string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].less)) { salesInvoiceCollectionViewModels[row - 1].netweight = "00.00 " + productmodel.Unit; } else if (!string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].grossnet) && string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].less)) { salesInvoiceCollectionViewModels[row - 1].netweight = salesInvoiceCollectionViewModels[row - 1].grossnet + productmodel.Unit; } else if (!string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].grossnet) && !string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].less)) { salesInvoiceCollectionViewModels[row - 1].netweight = (Convert.ToDouble(salesInvoiceCollectionViewModels[row - 1].grossnet) - Convert.ToDouble(salesInvoiceCollectionViewModels[row - 1].less)) + productmodel.Unit; } else { salesInvoiceCollectionViewModels[row - 1].netweight = "00.00 " + productmodel.Unit; } salesInvoiceCollectionViewModels[row - 1].amount = ((Convert.ToDecimal(salesInvoiceCollectionViewModels[row - 1].rate)) * (Convert.ToDecimal(salesInvoiceCollectionViewModels[row - 1].netweight.Replace(productmodel.Unit, "")))).ToString(); double sum = 0; for (int i = 0; i < PurchaseInvoiceDataGrid.Items.Count - 1; i++) { sum += Convert.ToDouble(salesInvoiceCollectionViewModels[i].amount); } GrossAmount.Text = sum.ToString(); this.CalculateNetAmount(); salesInvoiceCollectionViewModels[row - 1].sr = row; PurchaseInvoiceDataGrid.ItemsSource = salesInvoiceCollectionViewModels; PurchaseInvoiceDataGrid.Items.Refresh(); } if (col == 4) { grid.CurrentCell = new DataGridCellInfo( grid.Items[row - 1], grid.Columns[6]); grid.BeginEdit(); } else { grid.CurrentCell = new DataGridCellInfo( grid.Items[row - 1], grid.Columns[col + 1]); grid.BeginEdit(); } } else if (col == grid.Columns.Count - 1) { if (!string.IsNullOrEmpty(salesInvoiceCollectionViewModels[row - 1].name)) { grid.CurrentCell = new DataGridCellInfo( grid.Items[rowIndex++], grid.Columns[1]); grid.BeginEdit(); } else { GrossAmount.Focus(); } } } }