private void add_product_btn_Click_1(object sender, RoutedEventArgs e) { int price; if (name_add_product.Text != "" && price_add_product.Text != "" && kind_add_product.SelectedItem != null && (add_sell.IsChecked == true || add_buy.IsChecked == true) && add_prd_pack_lsb.SelectedItem != null) { if (checking_name(name_add_product.Text)) { string name = name_add_product.Text; price = Convert.ToInt32(price_add_product.Text); kind_product kp = db1.kind_product.ToArray()[kind_add_product.SelectedIndex]; client_or_supplier cl_or_sp = new client_or_supplier(); int i = 0; if (add_sell.IsChecked == true) { if (add_buy.IsChecked == true) { i = 2; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } else { i = 0; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } } else { if (add_buy.IsChecked == true) { i = 1; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } } products p = new products { name = name, price = price, kind_product = kp, kind_product_id = kind_add_product.SelectedIndex + 1, pack = add_prd_pack_lsb.SelectedItem.ToString().Substring(37), client_or_supplier = cl_or_sp, c_or_s_id = i + 1 }; db1.products.Add(p); db1.SaveChanges(); MessageBox.Show("The product has been added", "Succes", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else { MessageBox.Show("The name of the product is already exist in the system", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Fill all the fields", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void product_change_btn_Click(object sender, RoutedEventArgs e) { int price; if (pro != null && name_chnge_product.Text != "" && price_chnge_product.Text != "" && kind_chnge_product.SelectedItem != null && (chnge_sell.IsChecked == true || chnge_buy.IsChecked == true) && change_prd_pack_lsb.SelectedItem != null) { string name = name_chnge_product.Text; price = Convert.ToInt32(price_chnge_product.Text); kind_product kp = db1.kind_product.ToArray()[kind_chnge_product.SelectedIndex]; client_or_supplier cl_or_sp = new client_or_supplier(); int i = 0; if (chnge_sell.IsChecked == true) { if (chnge_buy.IsChecked == true) { i = 2; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } else { i = 0; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } } else { if (chnge_buy.IsChecked == true) { i = 1; cl_or_sp = db1.client_or_supplier.ToArray()[i]; } } pro.name = name; pro.price = price; pro.kind_product = kp; pro.kind_product_id = kind_chnge_product.SelectedIndex + 1; pro.pack = change_prd_pack_lsb.SelectedItem.ToString().Substring(37); pro.client_or_supplier = cl_or_sp; pro.c_or_s_id = i + 1; db1.SaveChanges(); MessageBox.Show("The product has been changed", "Succes", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else { MessageBox.Show("Fill all the fields", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }