Guest User

Untitled

a guest
Feb 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. introducir el código aquí
  2.  
  3. private void Cmb_Cancelar_Click(object sender, EventArgs e)
  4. {
  5. this.Close();
  6. }
  7.  
  8. private void Frm_Agregar_Nuevos_Load(object sender, EventArgs e)
  9. {
  10.  
  11. //Bloquer controles
  12. Interface_Inicial();
  13.  
  14.  
  15. }
  16.  
  17.  
  18. private void Interface_Inicial()
  19. {
  20.  
  21. Lab_Id.Enabled = true;
  22. Tex_id.Enabled = true;
  23. Cmb_Buscar.Enabled = true;
  24. Cmb_Cancelar.Enabled = true;
  25.  
  26. lab_Nombre.Enabled = false;
  27. lab_Direccion.Enabled = false;
  28. lab_Edad.Enabled = false;
  29.  
  30. Tex_Nombre.Enabled = false;
  31. Tex_Direccion.Enabled = false;
  32. Tex_Edad.Enabled = false;
  33.  
  34. Cmb_Guardar.Enabled = false;
  35.  
  36. Tex_id.Focus();
  37. }
  38.  
  39. private void Cmb_Buscar_Click(object sender, EventArgs e)
  40. {
  41. if (Buscar_Registro(Tex_id.Text) == false)
  42. {
  43. Interface_Datos();
  44. }
  45. else
  46. {
  47. MessageBox.Show("El registro ya existe");
  48. Tex_id.Focus();
  49. }
  50.  
  51.  
  52. }
  53.  
  54. private bool Buscar_Registro(string Codigo)
  55. {
  56. // Convertir Cadena A Numero
  57.  
  58. int Cod = Convert.ToInt32(Codigo);
  59.  
  60. //Conexion a la base de datos acces
  61. OleDbConnection conexion = new OleDbConnection();
  62. conexion.ConnectionString = " Provider=Microsoft.ACE,ALEDB.12.0; Data Source= c:\BBDDEmpres.accdb; Persist Security Info=false ";
  63.  
  64. // Cadena sql
  65.  
  66. String CadenaSQL = "SELECT * FROM Personal WHERE id= "+ Cod;
  67.  
  68. //Adaptador
  69. OleDbDataAdapter Adaptador = new OleDbDataAdapter(CadenaSQL,conexion);
  70.  
  71.  
  72. //Dataset contenedor
  73. DataSet ds = new DataSet();
  74.  
  75.  
  76. //Llenar el dataset
  77.  
  78. conexion.Open();
  79. Adaptador.Fill(ds);
  80.  
  81. conexion.Close();
  82.  
  83. //Contar registro
  84. if (ds.Tables[0].Rows.Count == 0)
  85. {
  86.  
  87. return false;//El registro no fue encontrado
  88.  
  89. }
  90. else
  91. {
  92. return true;//El registro existe
  93. }
  94.  
  95.  
  96.  
  97.  
  98. }
  99.  
  100.  
  101. private void Interface_Datos()
  102. {
  103.  
  104. Lab_Id.Enabled = false;
  105. Tex_id.Enabled = false;
  106. Cmb_Buscar.Enabled = false;
  107. Cmb_Cancelar.Enabled = true;
  108.  
  109. lab_Nombre.Enabled = true;
  110. lab_Direccion.Enabled = true;
  111. lab_Edad.Enabled = true;
  112.  
  113. Tex_Nombre.Enabled = true;
  114. Tex_Direccion.Enabled = true;
  115. Tex_Edad.Enabled = true;
  116.  
  117. Cmb_Guardar.Enabled =true;
  118.  
  119. Tex_Nombre.Focus();
  120.  
  121.  
  122. }
  123.  
  124. private void Cmb_Guardar_Click(object sender, EventArgs e)
  125. {
  126. Limpiar_Formulario();//Permite limpiar el formulario
  127. Interface_Inicial();//Prepara la interfaz antes de abrir los datos
  128.  
  129.  
  130. }
  131.  
  132. private void Limpiar_Formulario()
  133. {
  134. Tex_Nombre.Clear();
  135. Tex_Direccion.Clear();
  136. Tex_Edad.Clear();
  137. }
  138. }
Add Comment
Please, Sign In to add comment