Esempio n. 1
0
        public AgregarEmpleado(int IdEmpleado)
        {
            try
            {
                InitializeComponent();
                idEmpleado       = IdEmpleado;
                lblEmpleado.Text = "Modificar Empleado";
                btnAgregar.Text  = "Modificar";

                tblEmpleadoTableAdapter empleadoAdapter = new tblEmpleadoTableAdapter();
                tblEmpleadoRow          empleadoFila    = empleadoAdapter.EmpleadoPorId(idEmpleado)[0];

                txtCedula.Text          = empleadoFila.Cedula;
                txtNombre.Text          = empleadoFila.Nombre;
                txtApellidos.Text       = empleadoFila.Apellidos;
                txtSalario.Text         = empleadoFila.Salario.ToString();
                txtTelefono.Text        = empleadoFila.Telefono;
                idTipoEmpleado          = empleadoFila.idTipoEmpleado;
                txtDireccion.Text       = empleadoFila.Direccion;
                cboEstado.SelectedIndex = empleadoFila.Activo == true ? 0 : 1;

                txtCedula.Enabled = false;
                cboEstado.Enabled = false;

                log.Debug($"Se abrió la ventana Modificar Empleado para modificar al empleado con el ID: {idEmpleado}");
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtCedula.MaskFull && txtNombre.Text != "" && txtApellidos.Text != "" && txtSalario.Text != "")
                {
                    string cedula   = txtCedula.Text.Remove(3, 1).Remove(10, 1);
                    string telefono = txtTelefono.MaskFull == true?txtTelefono.Text.Remove(3, 1).Remove(6, 1) : "";

                    decimal salario        = Convert.ToDecimal(txtSalario.Text);
                    bool    estado         = cboEstado.SelectedIndex == 0 ? true : false;
                    int     idTipoEmpleado = Convert.ToInt32(cboTipoEmpleado.SelectedValue);

                    tblEmpleadoTableAdapter empleadoAdapter = new tblEmpleadoTableAdapter();
                    if (btnAgregar.Text == "Agregar")
                    {
                        empleadoAdapter.InsertarEmpleado(idTipoEmpleado, cedula, txtNombre.Text.Trim(), txtApellidos.Text.Trim(),
                                                         salario, estado, telefono, txtDireccion.Text.Trim());

                        MessageBox.Show($"{txtNombre.Text} {txtApellidos.Text} ha sido agregado como empleado", "Empleado agregado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        log.Info($"Se agregó un nuevo empleado con la cédula {cedula} y el nombre {txtNombre.Text} {txtApellidos.Text}");
                        LimpiarAgregar();
                    }
                    else
                    {
                        empleadoAdapter.ActualizarEmpleado(idEmpleado, idTipoEmpleado, txtNombre.Text.Trim(), txtApellidos.Text.Trim(),
                                                           salario, telefono, txtDireccion.Text.Trim());
                        log.Info($"Se modificó al empleado con el ID: {idEmpleado}");
                        MessageBox.Show($"{txtNombre.Text} {txtApellidos.Text} ha sido actualizado", "Empleado actualizado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtNombre.Focus();
                    }

                    agregoEmpleados = true;
                }
                else
                {
                    string mensaje = "Falta por completar los siguientes datos:";

                    if (!txtCedula.MaskFull)
                    {
                        mensaje += "\nCédula";
                    }
                    if (txtNombre.Text == "")
                    {
                        mensaje += "\nNombre";
                    }
                    if (txtApellidos.Text == "")
                    {
                        mensaje += "\nApellidos";
                    }
                    if (txtSalario.Text == "")
                    {
                        mensaje += "\nSalario";
                    }

                    MessageBox.Show(mensaje, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }