Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- introducir el código aquí
- private void Cmb_Cancelar_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void Frm_Agregar_Nuevos_Load(object sender, EventArgs e)
- {
- //Bloquer controles
- Interface_Inicial();
- }
- private void Interface_Inicial()
- {
- Lab_Id.Enabled = true;
- Tex_id.Enabled = true;
- Cmb_Buscar.Enabled = true;
- Cmb_Cancelar.Enabled = true;
- lab_Nombre.Enabled = false;
- lab_Direccion.Enabled = false;
- lab_Edad.Enabled = false;
- Tex_Nombre.Enabled = false;
- Tex_Direccion.Enabled = false;
- Tex_Edad.Enabled = false;
- Cmb_Guardar.Enabled = false;
- Tex_id.Focus();
- }
- private void Cmb_Buscar_Click(object sender, EventArgs e)
- {
- if (Buscar_Registro(Tex_id.Text) == false)
- {
- Interface_Datos();
- }
- else
- {
- MessageBox.Show("El registro ya existe");
- Tex_id.Focus();
- }
- }
- private bool Buscar_Registro(string Codigo)
- {
- // Convertir Cadena A Numero
- int Cod = Convert.ToInt32(Codigo);
- //Conexion a la base de datos acces
- OleDbConnection conexion = new OleDbConnection();
- conexion.ConnectionString = " Provider=Microsoft.ACE,ALEDB.12.0; Data Source= c:\BBDDEmpres.accdb; Persist Security Info=false ";
- // Cadena sql
- String CadenaSQL = "SELECT * FROM Personal WHERE id= "+ Cod;
- //Adaptador
- OleDbDataAdapter Adaptador = new OleDbDataAdapter(CadenaSQL,conexion);
- //Dataset contenedor
- DataSet ds = new DataSet();
- //Llenar el dataset
- conexion.Open();
- Adaptador.Fill(ds);
- conexion.Close();
- //Contar registro
- if (ds.Tables[0].Rows.Count == 0)
- {
- return false;//El registro no fue encontrado
- }
- else
- {
- return true;//El registro existe
- }
- }
- private void Interface_Datos()
- {
- Lab_Id.Enabled = false;
- Tex_id.Enabled = false;
- Cmb_Buscar.Enabled = false;
- Cmb_Cancelar.Enabled = true;
- lab_Nombre.Enabled = true;
- lab_Direccion.Enabled = true;
- lab_Edad.Enabled = true;
- Tex_Nombre.Enabled = true;
- Tex_Direccion.Enabled = true;
- Tex_Edad.Enabled = true;
- Cmb_Guardar.Enabled =true;
- Tex_Nombre.Focus();
- }
- private void Cmb_Guardar_Click(object sender, EventArgs e)
- {
- Limpiar_Formulario();//Permite limpiar el formulario
- Interface_Inicial();//Prepara la interfaz antes de abrir los datos
- }
- private void Limpiar_Formulario()
- {
- Tex_Nombre.Clear();
- Tex_Direccion.Clear();
- Tex_Edad.Clear();
- }
- }
Add Comment
Please, Sign In to add comment