private void valider_Click(object sender, RoutedEventArgs e) { SqlCommand cmd; SqlDataReader dr = null; SqlConnection cn = new SqlConnection(@"Data source =.\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=true; "); try { bool exist = false; int id = 0; cn.Open(); marque = marquetextbox.Text; type = typetextbox.Text; comp = comptextbox.Text; quant = Int32.Parse(quanttextbox.Text); cmd = new SqlCommand("Select * From Bien_etre where Marque='" + marque + "' and Type='" + type + "' and Gout='" + comp + "' ORDER BY DateDePeremption ASC", cn); dr = cmd.ExecuteReader(); //exist = false; if (dr.Read()) { id = Convert.ToInt32(dr[0].ToString()); } dr.Close(); if (id != 0) { foreach (Listview_content element in Window1.list_inf) { if ((element.id == id) && (element.Medicament == false)) { exist = true; break; } } if (!exist) { prix = Window1.db.Stock_suffi_bien(marque, type, comp, quant); if (prix != -1) { if (Saisir_facture.modifier) { foreach (Listview_content elem in Window1.list_inf) { if ((elem.ID == Saisir_facture.id_mod) && (elem.Medicament == true)) { Window1.list_inf.Remove(elem); break; } } } //list_stock.Add(new Up_Del_bien(id, quant, false)); prix = Window1.db.Stock_suffi_bien(marque, type, comp, quant); Listview_content med_inf = new Listview_content(); med_inf.marque = marque; med_inf.type = type; med_inf.prix = prix; med_inf.quant = quant; med_inf.id = id; med_inf.comp = comp; med_inf.medicament = false; Window1.list_inf.Add(med_inf); } else { MessageBox.Show("Quantité insuffisante !!"); } } else { MessageBox.Show("Vous avez déjà insérer ce produit !!! "); } } else { MessageBox.Show("produit n'existe pas !!"); } } catch (Exception ex) { MessageBox.Show("ERREUR !!"); } finally { if (dr != null) { dr.Close(); } cn.Close(); } }
private void valider_Click(object sender, RoutedEventArgs e) { SqlCommand cmd; SqlDataReader dr = null; SqlConnection cn = new SqlConnection(@"Data source =.\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=true; "); try { bool exist = false, choix = true; int id = 0; cn.Open(); DCI = DCItextbox.Text; marque = Marquetextbox.Text; dosage = Int32.Parse(Dosagetextbox.Text); quant = Int32.Parse(Quanttextbox.Text); foreach (var kvp in ((Dictionary <int, String>)map)) { if ((kvp.Value != null) && (kvp.Value.Equals(Forme_combobox.SelectedValue.ToString()))) { forme = kvp.Key; break; } } if (restit.SelectedItem.ToString().Equals(rest.ToString())) { restitue = true; } if (restit.SelectedItem.ToString().Equals(non_rest.ToString())) { restitue = false; } if (restit.SelectedItem.ToString().Equals(none.ToString())) { choix = false; restitue = false; } cmd = new SqlCommand("Select * From Tab_med where DCI='" + DCI + "' and marque='" + marque + "' and forme=" + forme + " and dosage=" + dosage, cn); dr = cmd.ExecuteReader(); exist = false; if (dr.Read()) { id = Convert.ToInt32(dr[0].ToString()); } dr.Close(); if (id != 0) { foreach (Listview_content element in Window1.list_inf) { if ((element.id == id) && (element.Medicament == true)) { exist = true; break; } } if (!exist) { if (choix) { if (!restitue) { prix = Window1.db.Stock_suffi("Tab_NEW", id, quant); } else { prix = Window1.db.Stock_suffi("TabRestitue", id, quant); } if (prix != -1) { if (Saisir_facture.modifier) { //foreach (Up_Del elem in list_stock) //{ // if (elem.Id == Saisir_facture.id_mod) // { // list_stock.Remove(elem); // break; // } //} foreach (Listview_content elem in Window1.list_inf) { if ((elem.ID == Saisir_facture.id_mod) && (elem.Medicament == true)) { Window1.list_inf.Remove(elem); break; } } } //list_stock.Add(new Up_Del(id, quant, restitue)); Listview_content med_inf = new Listview_content(); med_inf.marque = marque; med_inf.prix = prix; med_inf.quant = quant; med_inf.medicament = true; med_inf.restitue = restitue; med_inf.id = id; Window1.list_inf.Add(med_inf); } else { MessageBox.Show("Quantité insuffisante !!"); } } else { prix = Window1.db.Stock_suffi("Tab_NEW", id, quant); if (prix != -1) { if (Saisir_facture.modifier) { Window1.list_inf.Remove(Saisir_facture.a_modifie); } Listview_content med_inf = new Listview_content(); med_inf.marque = marque; med_inf.prix = prix; med_inf.quant = quant; med_inf.medicament = true; med_inf.id = id; med_inf.restitue = false; Window1.list_inf.Add(med_inf); } else { prix = Window1.db.Stock_suffi("TabRestitue", id, quant); if (prix != -1) { if (Saisir_facture.modifier) { Window1.list_inf.Remove(Saisir_facture.a_modifie); } //list_stock.Add(new Up_Del(id, quant, restitue)); Listview_content med_inf = new Listview_content(); med_inf.marque = marque; med_inf.prix = prix; med_inf.quant = quant; med_inf.medicament = true; med_inf.id = id; med_inf.restitue = true; Window1.list_inf.Add(med_inf); } else { MessageBox.Show("Quantité insuffisante !!"); } } } } else { MessageBox.Show("Vous avez déjà insérer ce médicament !!! "); } } else { MessageBox.Show("Médicament n'existe pas !!"); } } catch (Exception ex) { MessageBox.Show("ERREUR !!"); } finally { if (dr != null) { dr.Close(); } cn.Close(); } }