public void NewProductOrdered(ProductOrdered pror) { if (ProductsOrdered.FirstOrDefault(p => p.ProductId == pror.ProductId) == null) { ProductsOrdered.Add(pror); } else { ProductsOrdered.FirstOrDefault(p => p.ProductId == pror.ProductId).aantal += 1; } dgvOrderProducten.DataSource = null; dgvOrderProducten.Columns.Clear(); dgvOrderProducten.DataSource = ProductsOrdered; DataGridViewButtonColumn EditButtonColumn = new DataGridViewButtonColumn(); EditButtonColumn.Name = "Aantal Bewerken"; EditButtonColumn.Text = "Bewerk Aantal"; EditButtonColumn.UseColumnTextForButtonValue = true; DataGridViewButtonColumn DeleteButtonColumn = new DataGridViewButtonColumn(); DeleteButtonColumn.Name = "Verwijderen"; DeleteButtonColumn.Text = "Verwijder"; DeleteButtonColumn.UseColumnTextForButtonValue = true; dgvOrderProducten.Columns.Insert(dgvOrderProducten.Columns.Count, EditButtonColumn); dgvOrderProducten.Columns.Insert(dgvOrderProducten.Columns.Count, DeleteButtonColumn); dgvOrderProducten.Columns["Verwijderen"].DisplayIndex = 7; dgvOrderProducten.Columns["Aantal Bewerken"].DisplayIndex = 6; deleteindex = dgvOrderProducten.Columns["Verwijderen"].Index; editindex = dgvOrderProducten.Columns["Aantal Bewerken"].Index; if (dgvOrderProducten.Height < 250) { dgvOrderProducten.Height = dgvOrderProducten.Rows.GetRowsHeight(DataGridViewElementStates.None) + dgvOrderProducten.ColumnHeadersHeight + 2; } }
private void cmbProducten_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmb = (ComboBox)sender; Product p = cmb.SelectedItem as Product; ProductOrdered po = new ProductOrdered(); po.ProductId = p.ProductId; po.ProductNaam = p.ProductNaam; po.levrancier = p.levrancier; po.UnitPrice = p.UnitPrice; po.Omschrijving = p.Omschrijving; po.aantal = 1; NewProductOrdered(po); }
private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { Product p = new Product(); using (var ctx = new ProjectContext()) p = ctx.Products.FirstOrDefault(P => P.BarCode == txtBarcode.Text); if (p != null) { ProductOrdered po = new ProductOrdered(); po.ProductId = p.ProductId; po.ProductNaam = p.ProductNaam; po.levrancier = p.levrancier; po.UnitPrice = p.UnitPrice; po.Omschrijving = p.Omschrijving; po.aantal = 1; NewProductOrdered(po); } } }