You are on page 1of 3

internal class Class1

{
public SqlConnection cnx =new SqlConnection ();
public SqlCommand cmd=new SqlCommand ();
public SqlDataReader dr;
public DataTable dt = new DataTable ();

public void conneter()


{
if (cnx.State == ConnectionState.Closed )
{
cnx.ConnectionString = "Data Source=.;Initial
Catalog=TPADO;Integrated Security=True";
cnx.Open();
}

}
public void deconneter()
{
if (cnx.State == ConnectionState.Open)
{

cnx.Close();
}
}
}

public int nombre() {


d.conneter();
int cpt;
d.cmd.CommandText = " select count (NumEmployé) from Employé where
NumEmployé =" + textBox1.Text + "";
d.cmd.Connection = d.cnx;
cpt = (int)d.cmd.ExecuteScalar();
return cpt;

}
public bool Ajouter()
{
if(nombre() == 0)
{
d.cmd.CommandText="insert into Employé values('"+textBox1.Text +
"','" + textBox2.Text+ "','" + textBox3.Text + "','" + textBox4.Text + "','" +
textBox5.Text + "','"+dateTimePicker1.Value +"')";
d.cmd.Connection=d.cnx;
d.cmd.ExecuteNonQuery();
return true;
}

return false;
}
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" ||
textBox4.Text == "" || textBox5.Text == ""|| textBox6.Text== "")
{
MessageBox.Show("remplir");
return;
}
if (Ajouter() == true)
{
MessageBox.Show("ajouter avec succes");

}
else
{
MessageBox.Show("existe deja");
}

public void remplir()


{
d.conneter();
d.cmd.CommandText = "select * from Employé";
d.cmd.Connection = d.cnx;
d.dr = d.cmd.ExecuteReader();
d.dt.Load(d.dr);
dataGridView1.DataSource = d.dt;
d.dr.Close();
}
public void loadform(object form)
{
if (this.panel2.Controls.Count > 0)
this.panel2.Controls.RemoveAt(0);
Form f = new Form();
f.TopLevel = false;
f.Dock = DockStyle.Fill;
this.panel2.Controls.Add(f);
this.panel2.Tag = f;
f.Show();
}

Form3 f3 = new Form3();


f3.TopLevel=false;
panel2.Controls.Add(f3);
f3.BringToFront();
f3.Show();

You might also like