public void refreshData() { listBox1.Items.Clear(); products = new Products(SQL); List<Product> tbl = products.getList(); foreach (Product collumn in tbl) { listBox1.Items.Add(collumn); } button3.Enabled = false; HandleSecurity(); }
private void button1_Click(object sender, EventArgs e) { productItems.Clear(); materialItems.Clear(); Compositions compositions = new Compositions(SQL); Products products = new Products(SQL); List<Product> allProducts = products.getList(); foreach (DataGridViewRow row in dataGridView1.Rows) { if ((row.Cells[0].Value == null) || (row.Cells[1].Value == null)) continue; Product p = allProducts.Where(a => row.Cells[0].Value.ToString() == a.ToString()).First<Product>(); int amount = 0; if (!int.TryParse(row.Cells[1].Value.ToString(), out amount)) { row.Cells[1].ErrorText = "Zadaná hodnota není číslo!"; return; } row.Cells[1].ErrorText = ""; List<Composition> c = compositions.getList(p.ID); c.ForEach(a=>{ MaterialUnitPair pair = new MaterialUnitPair(a.MaterialType, a.Unit); if(materialItems.ContainsKey(pair)){ materialItems[pair] += a.Amount * amount; } else{ materialItems.Add(pair, a.Amount * amount); } }); if (productItems.ContainsKey(p)) { productItems[p] += amount; } else { productItems.Add(p, amount); } } dataGridView2.Rows.Clear(); dataGridView2.Refresh(); foreach (MaterialUnitPair m in materialItems.Keys) { dataGridView2.Rows.Add(m.MaterialType, materialItems[m], m.Unit); } }