You are on page 1of 5

public

public
public
public
public
public
string

SqlConnection cnx;
SqlCommand cmd;
SqlDataReader dr;
DataTable dt;
DataRow row;
int pos = -1;
rqtremplissage;

public Gestion(string cn,string commandeselect)


this.cnx = new SqlConnection(cn);
this.rqtremplissage = commandeselect;
remplissage(rqtremplissage);
}
public void remplissage(string commande)
cnx.Open();
cmd = new SqlCommand(commande, cnx);
dr = cmd.ExecuteReader();
dt = new DataTable();
for (int i = 0; i < dr.FieldCount; i++)
{dt.Columns.Add(new DataColumn(dr.GetName(i)));}
while (dr.Read())
{row = dt.NewRow();
for (int i = 0; i < dr.FieldCount; i++)
{row[i] = dr[i];}
dt.Rows.Add(row);}
cnx.Close();}
public bool miseajour(string commande)
cnx.Open();
SqlCommand c = new SqlCommand(commande, cnx);
int count = c.ExecuteNonQuery();
c.Dispose();
cnx.Close();
remplissage(rqtremplissage);
if (count == 0)
return false;
return true;
}
public bool GetData(int P)
{
if(P>=0 && P< dt.Rows.Count)
{
pos = P;
row = dt.Rows[pos];
return true;
}
return false;
}

GESTION

AJOUTER
if (GQ.miseajour("insert into Quartie values(" + quartier.Text + ",'" + nom.Text + "','" +
population.Text + "'," + ville.SelectedValue + ",'" +total.Text + "')"))
{
MessageBox.Show("Quartie ajouter avec succes", "Confirmation", MessageBoxButtons.OK,
MessageBoxIcon.Information);
GQ.pos = GQ.dt.Rows.Count - 1;
afiicher();
}
else
{
MessageBox.Show("Erreur lors de l'ajout", "Erreur", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

Modifier
if (GQ.miseajour("update Quartie set nomQ='" + nom.Text + "' , populationQ='" +
population.Text + "' , codev=" + ville.SelectedValue + " , totalQ =" + total.Text + " where
codeQ=" + quartier.Text))
{
MessageBox.Show("Quartie bien modifier", "Confirmation", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Erreur lors de la modification", "Erreur", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

Supprimer
if (GQ.miseajour("delete from Quartie where codeQ = " + quartier.Text))
{
MessageBox.Show("Quartie suppression avec succes", "Confirmation", MessageBoxButtons.OK,
MessageBoxIcon.Information);
if (GQ.pos > GQ.dt.Rows.Count - 1)
{
GQ.pos = GQ.dt.Rows.Count - 1;
}
afiicher();
}
else
{
MessageBox.Show("Erreur lors de suppression", "Erreur", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

Afficher
void afiicher()
{
label6.Text = (GQ.pos + 1) + "/" + (GQ.dt.Rows.Count);
if(GQ.pos>=0 && GQ.pos< GQ.dt.Rows.Count)
{
GQ.GetData(GQ.pos);
quartier.Text = GQ.row[0].ToString();
nom.Text = GQ.row[1].ToString();
population.Text = GQ.row[2].ToString();
ville.SelectedValue = GQ.row[3].ToString();
total.Text = GQ.row[4].ToString();
}
else
{
quartier.Text = "";
nom.Text = "";
population.Text = "";
ville.SelectedIndex = -1;
total.Text = "";
}

Navigation
<
GQ.pos = 0;
afiicher() ;

>>
if (GQ.pos < GQ.dt.Rows.Count - 1)
{
GQ.pos++;
afiicher();

<<
if (GQ.pos > 0)
{
GQ.pos--;
afiicher();
}

>
GQ.pos = GQ.dt.Rows.Count - 1;
afiicher();

AFFICHAGE
Load == Combobox
comboBox1.DisplayMember = "nomCir";
comboBox1.ValueMember = "idCirconscription";
comboBox1.DataSource = cir.dt;

comboBox1_SelectedIndexChanged
gp.remplissage("select ca.idParti,nomparti,COUNT(CINcandidat) as 'nbr condidat' from Parti i,
Circonscription ci, Candidat ca where i.idParti = ca.idParti and ci.idCirconscription =
ca.idCirconscription and ci.idCirconscription ="+comboBox1.SelectedValue + "group by
ca.idParti,nomparti");
dataGridView1.DataSource = p.dt;

supprimer =checbox=datagrid
gestion GS = new gestion(@"Data Source=DESKTOP-U9487CR\SQLEXPRESS;Initial
Catalog=variante11_2012;Integrated Security=True", "select * from parti");
for(int i = 0; i < p.dt.Rows.Count; i++)
if (dataGridView1.Rows[i].Cells[0].Value!=null)
if (dataGridView1.Rows[i].Cells[0].Value == "1")
GS.miseajour("delete from candidat where idparti=" + dataGridView1.Rows[i].Cells[1].Value);
if (GS.miseajour("delete from parti where idparti=" + dataGridView1.Rows[i].Cells[1].Value))
MessageBox.Show("ID Parti supprimer : " +
dataGridView1.Rows[i].Cells[1].Value);

AFFICHER
c.remplissage("select * from candidat where idCirconscription =" +
comboBox2.SelectedValue + "and idPArti=" +
comboBox1.SelectedValue);
dataGridView1.DataSource = c.dt;

OU
LOAD == combobox1
comboBox1.DisplayMember = "Nom";
comboBox1.ValueMember = "Num_Agence";
comboBox1.DataSource = GA.Table;

combobox2=comboBox1_SelectedIndexChang
ed
GC.Remplissage("select * from compte where
num_agence=" + comboBox1.SelectedValue);
comboBox2.DisplayMember = "Solde";
comboBox2.ValueMember = "Num_Compte";
comboBox2.DataSource = GC.Table;

afficher=comboBox2_SelectedIndexChanged
GCl.Remplissage("select * from client where num_client in (select num_client from compte where
num_compte=" + comboBox2.SelectedValue+")");
dataGridView1.DataSource = GCl.Table;

You might also like