Important: STG "FULL3


SUBMITTED BY: Guest

DATE: Nov. 23, 2013, 9:54 p.m.

FORMAT: Text only

SIZE: 12.1 kB

HITS: 792

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient ;
  10. namespace Gst_Stg_insertion
  11. {
  12. public partial class FrmGSTFULL : Form
  13. {
  14. public FrmGSTFULL()
  15. {
  16. InitializeComponent();
  17. }
  18. int i = 0;
  19. DataSet ds = new DataSet();
  20. SqlDataAdapter sqlda = new SqlDataAdapter("select * from stagiaire", "data source=.;initial catalog = ecole; integrated security = true");
  21. private void FrmGSTFULL_Load(object sender, EventArgs e)
  22. {
  23. //sqlda.DeleteCommand = new SqlCommand();
  24. //sqlda.DeleteCommand.Connection = sqlda.SelectCommand.Connection;
  25. //sqlda.DeleteCommand.CommandText = "Delete from stagiaire where code=@code";
  26. //SqlParameter par1 = new SqlParameter();
  27. //par1.ParameterName ="@code";
  28. //par1.Direction=ParameterDirection.Input ;
  29. //par1.DbType=DbType.Int32;
  30. //sqlda.DeleteCommand.Parameters.Add(par1);
  31. //sqlda.Fill(ds, "Stagiaire");
  32. //MessageBox.Show(ds.Tables["Stagiaire"].Rows.Count.ToString());
  33. //////SqlCommandBuilder sqlcb = new SqlCommandBuilder(sqlda);
  34. //////MessageBox.Show(sqlcb.GetUpdateCommand().CommandText);
  35. }
  36. //private Boolean Rechercher(int co)
  37. //{
  38. // Boolean b = false;
  39. // int i;
  40. // DataRow dr;
  41. // for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
  42. // {
  43. // dr = ds.Tables["Stagiaire"].Rows[i];
  44. // if (dr[0].Equals(co) == true) b = true;
  45. // }
  46. // return b;
  47. //}
  48. private void btnvider_Click(object sender, EventArgs e)
  49. {
  50. this.txtCode.Clear();
  51. this.txtNom.Clear();
  52. this.txtPrenom.Clear();
  53. this.txtcodesp.Clear();
  54. this.txtrow.Clear();
  55. }
  56. private void btnajout_Click(object sender, EventArgs e)
  57. {
  58. DataRow drw;
  59. int b = Rechercher(int.Parse(this.txtCode.Text));
  60. if (b == -1)
  61. {
  62. drw = ds.Tables["Stagiaire"].NewRow();
  63. drw[0] = int.Parse(txtCode.Text);
  64. drw[1] = this.txtNom.Text;
  65. drw[2] = this.txtPrenom.Text;
  66. drw[3] = this.txtcodesp.Text;
  67. ds.Tables["Stagiaire"].Rows.Add(drw);
  68. MessageBox.Show("Ajoute(e) avec Success");
  69. }
  70. else
  71. MessageBox.Show("exist");
  72. }
  73. private void btnprem_Click(object sender, EventArgs e)
  74. {
  75. i = 0;
  76. if (ds.Tables["Stagiaire"].Rows[i].RowState.ToString() != "Deleted")
  77. {
  78. txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
  79. txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
  80. txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
  81. txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
  82. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  83. }
  84. else
  85. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  86. }
  87. private void btnprec_Click(object sender, EventArgs e)
  88. {
  89. if (i > 0)
  90. {
  91. i--;
  92. txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
  93. txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
  94. txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
  95. txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
  96. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  97. }
  98. }
  99. private void btndern_Click(object sender, EventArgs e)
  100. {
  101. i = ds.Tables["Stagiaire"].Rows.Count - 1;
  102. txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
  103. txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
  104. txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
  105. txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
  106. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  107. }
  108. private void bntsuiv_Click(object sender, EventArgs e)
  109. {
  110. if (i < ds.Tables["Stagiaire"].Rows.Count - 1)
  111. {
  112. i++;
  113. txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
  114. txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
  115. txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
  116. txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
  117. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  118. }
  119. }
  120. private int Rechercher(int co)
  121. {
  122. int pos = -1;
  123. int i;
  124. DataRow dr;
  125. for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
  126. {
  127. dr = ds.Tables["Stagiaire"].Rows[i];
  128. if (dr[0].Equals(co) == true) pos = i;
  129. }
  130. return pos;
  131. }
  132. private void btnupgrd_Click(object sender, EventArgs e)
  133. {
  134. SqlCommandBuilder sqlBd = new SqlCommandBuilder(sqlda);
  135. sqlda.Update(ds,"Stagiaire");
  136. MessageBox.Show("Mise A jour Avec Success");
  137. }
  138. private void btnmodif_Click(object sender, EventArgs e)
  139. {
  140. int p = Rechercher(int.Parse(this.txtCode.Text));
  141. if (p != -1)
  142. {
  143. ds.Tables["Stagiaire"].Rows[p][0] = this.txtCode.Text;
  144. ds.Tables["Stagiaire"].Rows[p][1] = this.txtNom.Text;
  145. ds.Tables["Stagiaire"].Rows[p][2] = this.txtPrenom.Text;
  146. ds.Tables["Stagiaire"].Rows[p][3] = this.txtcodesp.Text;
  147. MessageBox.Show("Modifie(é) avec Success");
  148. }
  149. else
  150. MessageBox.Show("Non Trouve(e)");
  151. }
  152. private void btnsupp_Click_1(object sender, EventArgs e)
  153. {
  154. int posi = Rechercher(int.Parse(this.txtCode.Text));
  155. if (posi != -1)
  156. {
  157. ds.Tables["Stagiaire"].Rows[posi].Delete();
  158. MessageBox.Show("Suppression avec Success");
  159. }
  160. else MessageBox.Show("Stagiaire(e) Non Trouve(e)");
  161. }
  162. }
  163. }
  164. public partial class frm_exr : Form
  165. {
  166. public frm_exr()
  167. {
  168. InitializeComponent();
  169. }
  170. string reqcmd="";
  171. SqlDataAdapter sqlda;
  172. DataSet ds = new DataSet();
  173. int i ;
  174. private void frm_exr_Load(object sender, EventArgs e)
  175. {
  176. opttous.Checked = true;
  177. }
  178. private void opttous_CheckedChanged(object sender, EventArgs e)
  179. {
  180. if (opttous.Checked == true)
  181. {
  182. lblgrp.Text = "";
  183. txtgrp.Enabled = false;
  184. reqcmd = "select * from stagiaire";
  185. sqlda = new SqlDataAdapter(reqcmd, "data source=.;initial catalog = ecole; integrated security = true");
  186. sqlda.Fill(ds, "Stagiaire");
  187. }
  188. }
  189. private void afficher()
  190. {
  191. txtCode.Text = ds.Tables["Stagiaire"].Rows[i][0].ToString();
  192. txtNom.Text = ds.Tables["Stagiaire"].Rows[i][1].ToString();
  193. txtPrenom.Text = ds.Tables["Stagiaire"].Rows[i][2].ToString();
  194. txtcodesp.Text = ds.Tables["Stagiaire"].Rows[i][3].ToString();
  195. this.txtrow.Text = ds.Tables["Stagiaire"].Rows[i].RowState.ToString();
  196. }
  197. private void btnprem_Click(object sender, EventArgs e)
  198. {
  199. i = 0;
  200. afficher();
  201. }
  202. private void btnprec_Click(object sender, EventArgs e)
  203. {
  204. if (i > 0)
  205. {
  206. i--;
  207. afficher();
  208. }
  209. }
  210. private void bntsuiv_Click(object sender, EventArgs e)
  211. {
  212. if (i < ds.Tables["Stagiaire"].Rows.Count - 1)
  213. {
  214. i++;
  215. afficher();
  216. }
  217. }
  218. private void btndern_Click(object sender, EventArgs e)
  219. {
  220. i = ds.Tables["Stagiaire"].Rows.Count - 1;
  221. afficher();
  222. }
  223. private int Rechercher(int co)
  224. {
  225. int pos = -1;
  226. int i;
  227. DataRow dr;
  228. for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
  229. {
  230. dr = ds.Tables["Stagiaire"].Rows[i];
  231. if (dr[0].Equals(co) == true) pos = i;
  232. }
  233. return pos;
  234. }
  235. private void optcode_CheckedChanged(object sender, EventArgs e)
  236. {
  237. if (optcode.Checked == true)
  238. {
  239. ds.Clear();
  240. lblgrp.Text = "Code";
  241. txtgrp.Enabled = true;
  242. }
  243. else
  244. lblgrp.Text = "";
  245. }
  246. private void btncharger_Click(object sender, EventArgs e)
  247. {
  248. if (optcode.Checked == true)
  249. {
  250. int var = int.Parse(txtgrp.Text);
  251. reqcmd = "select * from stagiaire where code=" + var;
  252. sqlda = new SqlDataAdapter(reqcmd, "data source=.;initial catalog = ecole; integrated security = true");
  253. sqlda.Fill(ds, "Stagiaire");
  254. if (ds.Tables["Stagiaire"].Rows.Count != 0)
  255. {
  256. i = 0;
  257. if (i == 0)
  258. {
  259. afficher();
  260. }
  261. }
  262. else MessageBox.Show("Non Trouve(e)");
  263. }
  264. if (optnom.Checked == true)
  265. {
  266. reqcmd = "select * from stagiaire where nom like '"+txtgrp.Text+"%'";
  267. sqlda = new SqlDataAdapter(reqcmd, "data source=.;initial catalog = ecole; integrated security = true");
  268. sqlda.Fill(ds, "Stagiaire");
  269. if (ds.Tables["Stagiaire"].Rows.Count != 0)
  270. {
  271. i = 0;
  272. afficher();
  273. }
  274. else MessageBox.Show("Non Trouve(e)");
  275. }
  276. }
  277. private void optnom_CheckedChanged(object sender, EventArgs e)
  278. {
  279. if (optnom.Checked == true)
  280. {
  281. ds.Clear();
  282. lblgrp.Text = "Nom";
  283. txtgrp.Enabled = true;
  284. }
  285. else
  286. lblgrp.Text = "";
  287. }
  288. }

comments powered by Disqus