Vous êtes sur la page 1sur 2

// FORM 3

//SUPPRIMER
private void btnSupL_Click(object sender, EventArgs e)
{
if(dataGridView1.Rows != null && dataGridView1.Rows.Count != 0)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);
sum();

}
else
{
MessageBox.Show("you cannot delete because it s already empty");

// ENREGISTRER
private void btnSave_Click(object sender, EventArgs e)
{
try
{

if (txtNumC.Text=="" && comboClient.Text=="" &&


(dataGridView1.Rows== null && dataGridView1.Rows.Count==0)) {
MessageBox.Show("there are empty fields", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{

this.mainForm.StartTimer1();
CmdMaj = new SqlCommand("insert into Commande values('" +
txtNumC.Text + "','" + dateTimePicker1.Value + "','" + comboClient.Text + "')",
con);
con.Open();
CmdMaj.ExecuteNonQuery();
con.Close();

for (int i = 0; i < dataGridView1.Rows.Count; i++)


{
CmdMaj = new SqlCommand("insert into D�taill values('" +
txtNumC.Text + "','" + dataGridView1.Rows[i].Cells[0].Value + "','" +
dataGridView1.Rows[i].Cells[3].Value + "')", con);
con.Open();
CmdMaj.ExecuteNonQuery();
con.Close();

CmdMaj = new SqlCommand("select * from Article where


CodeArt= '" + dataGridView1.Rows[i].Cells[0].Value + "'", con);
con.Open();
dr = CmdMaj.ExecuteReader();
while (dr.Read() == true)
{
qstock = int.Parse(dr.GetValue(3).ToString());
}
con.Close();
CmdMaj = new SqlCommand("update Article set QStock = '" +
(qstock - Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value)) + "' where CodeArt
='" + dataGridView1.Rows[i].Cells[0].Value + "'", con);
con.Open();
CmdMaj.ExecuteNonQuery();
con.Close();

}
catch (SqlException )
{
this.mainForm.StartTimer2();

}
finally {
if (con.State == ConnectionState.Open)
con.Close();
initialiser();

Vous aimerez peut-être aussi