using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient ;
namespace Gst_Stg_insertion
{
public partial class FrmGSTFULL : Form
{
public FrmGSTFULL()
{
InitializeComponent();
}
int i = 0;
DataSet ds = new DataSet();
SqlDataAdapter sqlda = new SqlDataAdapter("select * from stagiaire", "data source=.;initial catalog = ecole; integrated security = true");
private void FrmGSTFULL_Load(object sender, EventArgs e)
{
//sqlda.DeleteCommand = new SqlCommand();
//sqlda.DeleteCommand.Connection = sqlda.SelectCommand.Connection;
//sqlda.DeleteCommand.CommandText = "Delete from stagiaire where code=@code";
//SqlParameter par1 = new SqlParameter();
//par1.ParameterName ="@code";
//par1.Direction=ParameterDirection.Input ;
//par1.DbType=DbType.Int32;
//sqlda.DeleteCommand.Parameters.Add(par1);
//sqlda.Fill(ds, "Stagiaire");
//MessageBox.Show(ds.Tables["Stagiaire"].Rows.Count.ToString());
//////SqlCommandBuilder sqlcb = new SqlCommandBuilder(sqlda);
//////MessageBox.Show(sqlcb.GetUpdateCommand().CommandText);
}
//private Boolean Rechercher(int co)
//{
// Boolean b = false;
// int i;
// DataRow dr;
// for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
// {
// dr = ds.Tables["Stagiaire"].Rows[i];
// if (dr[0].Equals(co) == true) b = true;
// }
// return b;
//}
private void btnvider_Click(object sender, EventArgs e)
{
this.txtCode.Clear();
this.txtNom.Clear();
this.txtPrenom.Clear();
this.txtcodesp.Clear();
this.txtrow.Clear();
}
private void btnajout_Click(object sender, EventArgs e)
{
DataRow drw;
int b = Rechercher(int.Parse(this.txtCode.Text));
if (b == -1)
{
drw = ds.Tables["Stagiaire"].NewRow();
drw[0] = int.Parse(txtCode.Text);
drw[1] = this.txtNom.Text;
drw[2] = this.txtPrenom.Text;
drw[3] = this.txtcodesp.Text;
ds.Tables["Stagiaire"].Rows.Add(drw);
MessageBox.Show("Ajoute(e) avec Success");
}
else
MessageBox.Show("exist");
}
private void btnprem_Click(object sender, EventArgs e)
{
i = 0;
if (ds.Tables["Stagiaire"].Rows[i].RowState.ToString() != "Deleted")
{
txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
}
else
this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
}
private void btnprec_Click(object sender, EventArgs e)
{
if (i > 0)
{
i--;
txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
}
}
private void btndern_Click(object sender, EventArgs e)
{
i = ds.Tables["Stagiaire"].Rows.Count - 1;
txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
}
private void bntsuiv_Click(object sender, EventArgs e)
{
if (i < ds.Tables["Stagiaire"].Rows.Count - 1)
{
i++;
txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
}
}
private int Rechercher(int co)
{
int pos = -1;
int i;
DataRow dr;
for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
{
dr = ds.Tables["Stagiaire"].Rows[i];
if (dr[0].Equals(co) == true) pos = i;
}
return pos;
}
private void btnupgrd_Click(object sender, EventArgs e)
{
SqlCommandBuilder sqlBd = new SqlCommandBuilder(sqlda);
sqlda.Update(ds,"Stagiaire");
MessageBox.Show("Mise A jour Avec Success");
}
private void btnmodif_Click(object sender, EventArgs e)
{
int p = Rechercher(int.Parse(this.txtCode.Text));
if (p != -1)
{
ds.Tables["Stagiaire"].Rows[p][0] = this.txtCode.Text;
ds.Tables["Stagiaire"].Rows[p][1] = this.txtNom.Text;
ds.Tables["Stagiaire"].Rows[p][2] = this.txtPrenom.Text;
ds.Tables["Stagiaire"].Rows[p][3] = this.txtcodesp.Text;
MessageBox.Show("Modifie(é) avec Success");
}
else
MessageBox.Show("Non Trouve(e)");
}
private void btnsupp_Click_1(object sender, EventArgs e)
{
int posi = Rechercher(int.Parse(this.txtCode.Text));
if (posi != -1)
{
ds.Tables["Stagiaire"].Rows[posi].Delete();
MessageBox.Show("Suppression avec Success");
}
else MessageBox.Show("Stagiaire(e) Non Trouve(e)");
}
}
}