Exemplo n.º 1
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            if (txtContraseña.Text.Length == 0)
            {
                MessageBox.Show("Introduce una contraseña");
            }
            else
            {
                if (Utilidades.ComprobarCorreo(txtCorreo.Text))
                {
                    try
                    {
                        if (ConexionBD.AbrirConexion())
                        {
                            if (Utilidades.IniciarSesion(ConexionBD.Conexion, txtCorreo.Text, txtContraseña.Text))
                            {
                                this.Hide();
                                Categorias categorias = new Categorias(txtCorreo.Text);
                                categorias.Show();
                            }
                            else
                            {
                                MessageBox.Show("El correo o la contraseña no son correctos.");
                                txtContraseña.Clear();
                            }

                            ConexionBD.CerrarConexion();
                        }
                        else
                        {
                            MessageBox.Show("No se ha podido abrir la conexión con la Base de Datos");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                    }
                    finally
                    {
                        ConexionBD.CerrarConexion();
                    }
                }
                else
                {
                    MessageBox.Show("Correo incorrecto");
                }
            }
        }
Exemplo n.º 2
0
        //Metodo para validar que todos los datos son correctos
        public bool ValidarDatos()
        {
            bool ok = true;

            if (txtNombre.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtNombre, "Introduce un nombre");
            }
            else
            {
                errorProvider1.SetError(txtNombre, null);
            }

            if (txtApellidos.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtApellidos, "Introduce apellidos");
            }
            else
            {
                errorProvider1.SetError(txtApellidos, null);
            }

            if (!Utilidades.NifCorrecto(txtDNI.Text))
            {
                ok = false;
                errorProvider1.SetError(txtDNI, "El DNI no es valido");
            }
            else
            {
                errorProvider1.SetError(txtDNI, null);
            }

            if (Utilidades.ComprobarCorreo(txtCorreo.Text) == false)
            {
                ok = false;
                errorProvider1.SetError(txtCorreo, "Correo incorrecto");
            }
            else
            {
                errorProvider1.SetError(txtCorreo, null);
            }

            if (txtPass1.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtPass1, "Introduce contraseña");
            }
            else
            {
                errorProvider1.SetError(txtPass1, null);
            }

            if (txtPass2.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtPass2, "Introduce contraseña");
            }
            else
            {
                errorProvider1.SetError(txtPass2, null);
            }

            if (txtDireccion.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtDireccion, "Introduce dirección");
            }
            else
            {
                errorProvider1.SetError(txtDireccion, null);
            }

            if (txtProvincia.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtProvincia, "Introduce una provincia");
            }
            else
            {
                errorProvider1.SetError(txtProvincia, null);
            }

            if (txtLocalidad.Text.Length == 0)
            {
                ok = false;
                errorProvider1.SetError(txtLocalidad, "Introduce una localidad");
            }
            else
            {
                errorProvider1.SetError(txtLocalidad, null);
            }

            int cantidad;

            if (!int.TryParse(txtCodigoPostal.Text, out cantidad) || txtCodigoPostal.Text.Length != 5)
            {
                ok = false;
                errorProvider1.SetError(txtCodigoPostal, "El codigo postal no es correcto");
            }
            else
            {
                errorProvider1.SetError(txtCodigoPostal, null);
            }

            if (!int.TryParse(txtTelefono.Text, out cantidad) || txtTelefono.Text.Length != 9)
            {
                ok = false;
                errorProvider1.SetError(txtTelefono, "El teléfono no es correcto");
            }
            else
            {
                errorProvider1.SetError(txtTelefono, null);
            }

            if (!int.TryParse(txtNum.Text, out cantidad) || txtNum.Text.Length > 3)
            {
                ok = false;
                errorProvider1.SetError(txtNum, "El número de portal no es correcto");
            }
            else
            {
                errorProvider1.SetError(txtNum, null);
            }

            if (!int.TryParse(txtPiso.Text, out cantidad) || txtPiso.Text.Length > 2)
            {
                ok = false;
                errorProvider1.SetError(txtPiso, "El número de piso no es correcto");
            }
            else
            {
                errorProvider1.SetError(txtPiso, null);
            }

            if (!int.TryParse(txtPuerta.Text, out cantidad) || txtPuerta.Text.Length > 3)
            {
                ok = false;
                errorProvider1.SetError(txtPuerta, "El número de puerta no es correcto");
            }
            else
            {
                errorProvider1.SetError(txtPuerta, null);
            }

            if (chkTerminos.Checked == false)
            {
                ok = false;
                errorProvider1.SetError(chkTerminos, "Acepta los términos.");
            }
            else
            {
                errorProvider1.SetError(chkTerminos, null);
            }

            return(ok);
        }