public Window_Add_Product(produkt p) { InitializeComponent(); _type = "Modyfication"; _p = p; Button_Add_Product.Text = "Zmień"; Add_Product_Information(); }
private void Adding() { produkt produkt = new produkt(); Boolean flag = false; try { produkt.Nazwa = textBox_Product_Name.Text.ToString(); produkt.Producent = textBox_Manufacturer.Text.ToString(); produkt.Numer_katalogowy = textBox_Catalog.Text.ToString(); produkt.Vat = System.Convert.ToDouble(ComboBox_Taxes.Text); produkt.Cena_brutto = System.Convert.ToDecimal(textBox_Price_Gross.Text); produkt.Kategoria = (int)comboBox_Product_Category.SelectedValue; produkt.Status = (int)comboBox_Product_Status.SelectedValue; try { produkt.Ilość = System.Convert.ToDouble(textBox_Quantity.Text); produkt.Jm = comboBox_Unit.Text.ToString(); try { produkt.Cena_netto = System.Convert.ToDecimal(textBox_Price_Net.Text); flag = true; } catch { MessageBox.Show("Cena musi być liczbą", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch { MessageBox.Show("Ilość musi być liczbą", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { MessageBox.Show("Wypełnij wszystkie dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); flag = false; } if (flag == true) { using (zlecenieEntities db = new zlecenieEntities()) { db.produkt.Add(produkt); db.SaveChanges(); MessageBox.Show("Produkt dodany", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_Product_Name.Clear(); textBox_Manufacturer.Clear(); textBox_Catalog.Clear(); textBox_Quantity.Clear(); textBox_Price_Net.Clear(); textBox_Price_Gross.Clear(); comboBox_Unit.Items.Clear(); ComboBox_Taxes.Items.Clear(); } } }
} // Open New Client Window #endregion #region buttons_modify private void button_Modify_Product_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = pW.getSelectedProduct(); if (ID != 0) { produkt pm = db.produkt.Find(ID); OpenChildForm(new Window_Add_Product(pm)); } } catch { } } } // Modify Product information
private void button_PStatus_withdrawn_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = pW.getSelectedProduct(); if (ID != 0) { produkt pm = db.produkt.Find(ID); pm.Status = 2; db.SaveChanges(); pW = new Product_Window(); OpenChildForm(pW); } } catch { } } }