コード例 #1
0
        private void bt_adduser_Click(object sender, EventArgs e)
        {
            dato_erroneo_nombre.Visible      = false;
            dato_erroneo_apellido.Visible    = false;
            dato_erroneo_email.Visible       = false;
            dato_erroneo_contrasenia.Visible = false;
            dato_erroneo_verificar.Visible   = false;
            dato_erroneo_cedula.Visible      = false;
            dato_erroneo_telefono.Visible    = false;
            dato_erroneo_user.Visible        = false;
            if (txt_nombre.Text.Length != 0 && txt_apellido.Text.Length != 0 && txt_correo.Text.Length != 0 &&
                txt_v_contra.Text.Length != 0 && comboBox_cargo.SelectedItem != null && txt_cedula.Text.Length != 0)
            {
                //Verifica que los campos no estén vacios -- Codigo traido de Felipe Riaño
                if (verficarNombre_Apell(txt_nombre.Text) && verficarNombre_Apell(txt_apellido.Text) &&
                    verificarEmail(txt_correo.Text) && verficarPassWordL(txt_contrasenia.Text) && verificarIgualdadContra(txt_contrasenia.Text, txt_v_contra.Text))
                {
                    if (!addUser.Add_user(txt_cedula.Text, txt_nombre.Text, txt_apellido.Text, Convert.ToDateTime(pick_fecha_nacimiento.Text), txt_telefono.Text, comboBox_genero.SelectedItem.ToString(), txt_correo.Text, txt_contrasenia.Text, comboBox_cargo.SelectedItem.ToString(), txt_usuario.Text, comboBox_pais.SelectedItem.ToString()))
                    {
                        MessageBox.Show("El correo registrado ya se encuentra registrado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("El usuario ha sido registrado\n" + "Se ha enviado un correo al usuario para el acceso.\n", "Registro exitoso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        String nombre   = txt_nombre.Text + " " + txt_apellido.Text;
                        String messageB = "Hola\n\n"
                                          + nombre + "\n"
                                          + "Te damos la bienvenida a YMCA-BOTSERVICE\n"
                                          + "Recuerda tus datos:"
                                          + "\n\t- Correo de acceso:\t" + txt_correo.Text + "\n"
                                          + "\t- Contraseña:\t" + txt_contrasenia.Text + "\n\n"
                                          + "Gracias!\n"
                                          + "YMCA Colombia";
                        String subject = "Bienvenido a YMCA-BOTSERVICE";

                        String email = txt_correo.Text;

                        sendEmail(email, messageB, subject);

                        //Reiniciar valores para otro registro

                        /*
                         * txt_nombre.Text = "NOMBRE";
                         * txt_apellido.Text = "APELLIDO";
                         * txt_correo.Text = "CORREO";
                         * txt_usuario.Text = "USUARIO";
                         * pick_fecha_nacimiento.Value = DateTime.Parse("01-01-2000");
                         * txt_contrasenia.UseSystemPasswordChar = false;
                         * txt_v_contra.UseSystemPasswordChar = false;
                         * txt_contrasenia.Text = "CONTRASEÑA";
                         * txt_v_contra.Text = "VERIFICACIÓN";
                         */
                        this.Close();
                    }
                }
                else
                {
                    if (!verficarNombre_Apell(txt_nombre.Text))
                    {
                        dato_erroneo_nombre.Visible = true;
                    }
                    if (!verficarNombre_Apell(txt_apellido.Text))
                    {
                        dato_erroneo_apellido.Visible = true;
                    }
                    if (!verificarEmail(txt_correo.Text))
                    {
                        dato_erroneo_email.Visible = true;
                    }
                    if (!verficarPassWordL(txt_contrasenia.Text))
                    {
                        dato_erroneo_contrasenia.Visible = true;
                    }
                    if (!verificarIgualdadContra(txt_contrasenia.Text, txt_v_contra.Text))
                    {
                        dato_erroneo_verificar.Visible = true;
                    }
                    DialogResult datos = MessageBox.Show("Algunos datos ingresados son incorrectos", "Datos erroneos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show(messageData, "Tener en cuenta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                DialogResult datos = MessageBox.Show("Completa los campos", "Datos erroneos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }