1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| private void button2_Click(object sender, EventArgs e)
{
SqlConnection connection1 = new SqlConnection(connectionString);
connection1.Open();
String reqt1 = "select numero_cpte from compte where numero_cpte=" + textBox1.Text + ";";
SqlCommand sql1 = new SqlCommand(reqt1, connection1);
int d = int.Parse(textBox1.Text);
int dd = Convert.ToInt32(sql1.ExecuteScalar());
if (d == dd)
{
int o1 = sql1.ExecuteNonQuery();
MessageBox.Show("Ce compte existe.Veuillez sasir un numéro de compte valide!!", "Fiche Comptes");
//DialogResult dialogResult = MessageBox.Show("La fiche Journaux a été modifiéé.Validez vous ces modifications?", "fiche journaux", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
connection1.Close();
return;
}
if (String.IsNullOrEmpty(textBox1.Text) == true)
{
MessageBox.Show("La saisie du numéro de compte est obligatoire!!", "Fiche Comptes", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand sql = new SqlCommand("insert into compte values(" + textBox1.Text + ",'" + textBox2.Text + "','" + type_cpteComboBox.SelectedItem.ToString() + "','" + textBox2.Text + "','" + comboBox1.SelectedItem.ToString() + "'," + comboBox2.SelectedItem.ToString() + ",'" + checkBox1.Checked.ToString() + "','" + checkBox2.Checked.ToString() + "','" + textBox5.Text + "','" + textBox6.Text + "');", connection);
int o = sql.ExecuteNonQuery();
MessageBox.Show(o + " Le compte a été ajouté avec succès", "Fiche Comptes");
connection.Close();
affich(); //pour afficher dans le dataGridView destination
}
} |
Partager