private void ControlKeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (sender == SearchProduct && SearchProduct.EditValue != null) { spLength.Focus(); } else if (sender == spPrice) { spLength.Focus(); } else if (sender == spLength) { spWidth.Focus(); } else if (sender == spWidth) { spQuantity.Focus(); } else if (sender == spQuantity) { spDiscount.Value = (spPrice.Value * spLength.Value * spWidth.Value * spQuantity.Value) - (int)(spPrice.Value * spLength.Value * spWidth.Value * spQuantity.Value); spDiscount.Focus(); } else if (sender == spDiscount) { ProductView.AddNewRow(); SearchProduct.EditValue = null; SearchProduct.Focus(); } } else if (e.KeyCode == Keys.Delete) { if (sender == ProductView) { if (ProductView.RowCount > 0) { SpInvoiceDiscount.Value = SpInvoiceDiscount.Value - decimal.Parse(ProductView.GetRowCellValue(ProductView.FocusedRowHandle, ProductView.Columns[9]).ToString()); spInvoiceTotal.Value = spInvoiceTotal.Value - decimal.Parse(ProductView.GetRowCellValue(ProductView.FocusedRowHandle, ProductView.Columns[10]).ToString()); ProductView.DeleteRow(ProductView.FocusedRowHandle); SearchProduct.Focus(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnAddNew_Click(object sender, EventArgs e) { try { SearchProduct.Focus(); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn { ColumnName = "v1", DataType = typeof(string) }); //PCode dt.Columns.Add(new DataColumn { ColumnName = "v2", DataType = typeof(string) }); //PName dt.Columns.Add(new DataColumn { ColumnName = "v3", DataType = typeof(string) }); //UCode dt.Columns.Add(new DataColumn { ColumnName = "v4", DataType = typeof(string) }); //UName dt.Columns.Add(new DataColumn { ColumnName = "v5", DataType = typeof(string) }); //Price dt.Columns.Add(new DataColumn { ColumnName = "v6", DataType = typeof(string) }); //Length dt.Columns.Add(new DataColumn { ColumnName = "v7", DataType = typeof(string) }); //Width dt.Columns.Add(new DataColumn { ColumnName = "v8", DataType = typeof(string) }); //Quantity dt.Columns.Add(new DataColumn { ColumnName = "v9", DataType = typeof(string) }); //Total Quantity dt.Columns.Add(new DataColumn { ColumnName = "v10", DataType = typeof(string) }); //Discount dt.Columns.Add(new DataColumn { ColumnName = "v11", DataType = typeof(string) }); //Line Total ProductGrid.DataSource = dt; ProductGrid.DataMember = dt.TableName; SpInvoiceDiscount.Value = spInvoiceTotal.Value = spInvoicePaied.Value = 0; } catch (Exception ex) { MessageBox.Show(ex.Message); } }