public void ShowProductsToProductgroup(object sender, EventArgs e) { var button = sender as CustomButton; if (button != null) { var progroup = button.Obj as Productgroup; if (progroup != null) { flowLayoutPanelProducts.Controls.Clear(); Productgroup pg = new Productgroup(progroup.Id); pg.GetAllProducts(); foreach (var item in pg.Products) { //flowLayoutPanelProducts CustomButton buttonProduct = new CustomButton(); buttonProduct.Obj = item; buttonProduct.Size = new Size(100, 50); buttonProduct.FlatStyle = FlatStyle.Flat; buttonProduct.BackColor = Color.LightGray; buttonProduct.Text = $@"{item.Description} {Environment.NewLine} {item.Price}€"; buttonProduct.Click += buttonProduct_Click; flowLayoutPanelProducts.Controls.Add(buttonProduct); } } } }
private void Form1_Load(object sender, EventArgs e) { Hide(); using (FormLogin login = new FormLogin()) { login.ShowDialog(); if (login.LoginScuccess) { _employee = login.Employee; Show(); WindowState = FormWindowState.Maximized; _shoppingCart = new ShoppingCart(textBoxTotalAmount); panel3.Visible = false; labelMwst.Text = ""; radioButtonLocal.Checked = true; var productgroups = Productgroup.GetAll(); int i = 0; foreach (var item in productgroups) { CustomButton b = new CustomButton(); b.Obj = item; b.FlatStyle = FlatStyle.Flat; b.Text = item.Description; b.Size = new Size(150, 75); b.Location = new Point(175 * i, 0); b.Click += ShowProductsToProductgroup; panelProductgroups.Controls.Add(b); i++; } } else { Close(); } } }