void Ajouter() { try { IDetails_Sortie detail = new Detail_sortie_service(); int rowCount; if (idEnteteSortie == 0) { MessageBox.Show("Avant chaque opération d'enregistrement veuillez cliqué d'abord sur le bouton Nouveau en bas du formulaire", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (comboBox1.SelectedIndex == -1 || textBox3.Text == "" || textBox4.Text == "") { MessageBox.Show("Completez tous les champs svp !!!", "Champs Obligatiore", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } else if (stock <= 0 || stock < int.Parse(textBox3.Text)) { MessageBox.Show("Vérifiez votre stock avant d'effectuer cette opération!!!", "Attention", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } else { rowCount = dataGridView2.Rows.Count; if (rowCount == 0) { idDetailSortie = detail.Nouveau(); dataGridView2.Rows.Add(idDetailSortie.ToString(), comboBox1.Text, textBox3.Text, textBox4.Text, Convert.ToInt32(textBox3.Text) * Convert.ToInt32(textBox4.Text)); label8.Text = dataGridView2.Rows.Count.ToString() + " médicaments"; //idDetailSortie = 0; } else { idDetailSortie = idDetailSortie + 1; //for (int i = 0; i < dataGridView2.Rows.Count; i++) //{ // if (comboBox1.Text == dataGridView2.Rows[i].Cells[1].Value.ToString()) // { // MessageBox.Show("Ce médicament existe dans cette commande", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // } // else // { dataGridView2.Rows.Add(idDetailSortie.ToString(), comboBox1.Text, textBox3.Text, textBox4.Text, Convert.ToInt32(textBox3.Text) * Convert.ToInt32(textBox4.Text)); label8.Text = dataGridView2.Rows.Count.ToString() + " médicaments"; //idDetailSortie = 0; //} //} } } } catch (Exception ex) { MessageBox.Show("L'erreur suivant est survenue : " + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }