private bool VerificarIdSeleccionado()
 {
     errorProvider.InitializeError();//Limpia los errores pasados.
     if (String.IsNullOrWhiteSpace(id))
     {
         errorProvider.SetError(dgvTerritorios, "Seleccionar ID dando clic en fila.");
     }
     if (errorProvider.GetError())
     {
         MessageBox.Show("Seleccionar un ID primero");
         return(true);
     }
     return(false);
 }
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     errorProvider.InitializeError();//Limpia los errores pasados.
     if (_accion.Equals("Nuevo"))
     {
         AgregarTerritorio();
     }
     else
     {
         EditarTerritorio();
     }
 }
 /// <summary>
 /// Realiza la operación de inserción o actualización segun la acción del formulario.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     //Limpiar errores pasados.
     errorProvider.InitializeError();
     //Condicional de Id vacío.
     errorProvider.HasError(String.IsNullOrWhiteSpace(txtID.Text), txtID, "Rellenar campo de Id");
     //Condicional de Producto vacío.
     errorProvider.HasError(String.IsNullOrWhiteSpace(txtNombre.Text), txtNombre, "Rellenar campo de Nombre del producto");
     if (errorProvider.GetError(this))
     {
         return;
     }
     //Condicional de Id númerico.
     errorProvider.HasError(!int.TryParse(txtID.Text, out var id), txtID, "Ingrese código númerico de maximo 10 dígitos.");
     if (Accion.Equals(AccionPopup.Nuevo))
     {
         if (errorProvider.GetError(this))
         {
             return;
         }
         //Condicional de Id repetido.
         var existeID = db.Products.Any(p => p.ProductID.Equals(txtID.Text));
         errorProvider.HasError(existeID, txtID, "El Id ya está registrado.");
         //Condicional de Producto repetido.
         var existeProducto = db.Products.Any(p => p.ProductName.Equals(txtNombre.Text));
         errorProvider.HasError(existeProducto, txtNombre, "El producto ya está registrado.");
         if (errorProvider.GetError(this))
         {
             return;
         }
         //Agregar Recurso.
         AgregarRecurso();
     }
     else
     {
         //Condicional de Producto repetido.
         var existeProducto = db.Products.Any(p => p.ProductName == txtNombre.Text && p.ProductID != id);
         errorProvider.HasError(existeProducto, txtNombre, "El producto ya está registrado.");
         if (errorProvider.GetError(this))
         {
             return;
         }
         //Editar el recurso.
         EditarRecurso();
     }
 }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            errorProvider.InitializeError();//Lia errores pasados.
            if (string.IsNullOrWhiteSpace(txtCódigo.Text))
            {
                errorProvider.SetError(txtCódigo, "Ingrese código");
            }
            if (!int.TryParse(txtCódigo.Text, out var n))
            {
                errorProvider.SetError(txtCódigo, "Ingrese código númerico de maximo 10 dígitos.");
            }
            if (string.IsNullOrWhiteSpace(txtNombre.Text))
            {
                errorProvider.SetError(txtNombre, "Ingrese nombre del empleado");
            }
            if (string.IsNullOrWhiteSpace(txtApellidos.Text))
            {
                errorProvider.SetError(txtApellidos, "Ingrese apellidos del empleado");
            }
            if (string.IsNullOrWhiteSpace(txtTitulo.Text))
            {
                errorProvider.SetError(txtTitulo, "Ingrese título del empleado");
            }
            if (errorProvider.GetError())
            {
                this.DialogResult = DialogResult.None;
                return;
            }
            //Insertar un nuevo dato.
            int      Código    = Convert.ToInt32(txtCódigo.Text);
            string   Nombre    = txtNombre.Text;
            string   Apellidos = txtApellidos.Text;
            string   Dirección = txtDirección.Text;
            string   Título    = txtTitulo.Text;
            DateTime Fecha     = txtFecha.Value;

            if (accion.Equals("Nuevo"))
            {
                Employees empleado = new Employees
                {
                    EmployeeID    = Código,
                    FirstName     = Nombre,
                    LastName      = Apellidos,
                    Address       = Dirección,
                    BirthDate     = Fecha,
                    Title         = Título,
                    bitHabilitado = true
                };
                try
                {
                    //Agregar
                    db.Employees.InsertOnSubmit(empleado);
                    //Actualizar en base de datos
                    db.SubmitChanges();
                    MessageBox.Show("Empleado agregado correctamente.", "Insertar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Ocurrió un error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                var empleado = db.Employees.Where(em => em.EmployeeID.Equals(id)).Single();
                empleado.FirstName = Nombre;
                empleado.LastName  = Apellidos;
                empleado.Address   = Dirección;
                empleado.BirthDate = Fecha;
                empleado.Title     = Título;
                try
                {
                    //Actualizar en base de datos
                    db.SubmitChanges();
                    MessageBox.Show("Empleado actualizado correctamente.", "Actualizar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Ocurrió un error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }