private void btnAceptar_Click(object sender, EventArgs e) { try { clsEmpleado nuevoEmpleado; if (rbMasculino.Checked == true) { nuevoEmpleado = new clsEmpleado(LosCargos[cmbCargo.SelectedIndex], txtNombres.Text, txtApellidos.Text, txtDNI.Text, txtTelefono.Text, 'M', Convert.ToDateTime(dtpFechaNacimiento.Value.Date)); } else { nuevoEmpleado = new clsEmpleado(LosCargos[cmbCargo.SelectedIndex], txtNombres.Text, txtApellidos.Text, txtDNI.Text, txtTelefono.Text, 'F', Convert.ToDateTime(dtpFechaNacimiento.Value.Date)); } nuevoEmpleado.EmailEmp = txtEmail.Text; nuevoEmpleado.InsertarEmpleado(); MessageBox.Show("Empleado Registrado"); } catch (Exception ErrorRegEm) { MessageBox.Show(ErrorRegEm.Message); } }
public static List <clsEmpleado> Listar() { List <clsEmpleado> x = new List <clsEmpleado>(); SqlConnection conexion = new SqlConnection(mdlVariables.CadenaDeConexion); SqlCommand cmd = new SqlCommand("usp_Empleado_Listar_Todos", conexion); cmd.CommandType = System.Data.CommandType.StoredProcedure; conexion.Open(); SqlDataReader contenedor; contenedor = cmd.ExecuteReader(); while (contenedor.Read() == true) { clsEmpleado MiObjeto; MiObjeto = new clsEmpleado(Convert.ToInt32(contenedor["IdEmpleado"]), contenedor["Nombres_Emp"].ToString(), contenedor["Apellidos_Emp"].ToString(), contenedor["DNI_Emp"].ToString(), contenedor["Telefono_Emp"].ToString(), Convert.ToChar(contenedor["Genero_Emp"]), contenedor["Email_Emp"].ToString(), Convert.ToDateTime(contenedor["Fecha_Nac_Emp"]), Convert.ToInt32(contenedor["IdCargo"])); x.Add(MiObjeto); } conexion.Close(); return(x); }