コード例 #1
0
        private void btnAgregarU_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text.Equals("") || txtApellido.Text.Equals("") || txtUsuario.Text.Equals(""))
            {
                MessageBox.Show("Hay campos vacíos");
            }
            else
            {
                try
                {
                    AppUser nuevo = new AppUser();
                    nuevo.fullname = txtNombre.Text + " " + txtApellido.Text;
                    nuevo.username = txtUsuario.Text;
                    nuevo.password = txtUsuario.Text;
                    nuevo.admin    = radAdmin.Checked;
                    AppUserQuery.newUser(nuevo);

                    MessageBox.Show("Usuario creado con los datos: \nNombre de usuario: " + txtUsuario.Text +
                                    ", contraseña: " + txtUsuario.Text);

                    txtNombre.Text   = "";
                    txtApellido.Text = "";
                    txtUsuario.Text  = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ocurrió un error");
                }
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <AppUser> lista = PrepararLista();

            if (textBox1.Text.Equals("") || textBox2.Text.Equals("") || textBox3.Text.Equals("") ||
                textBox4.Text.Equals("") || textBox5.Text.Equals(""))
            {
                MessageBox.Show("Hay campos vacíos");
            }
            else
            {
                bool flag = true;
                try
                {
                    foreach (AppUser au in lista)
                    {
                        if (textBox3.Text.Equals(au.username))
                        {
                            flag = false;
                            break;
                        }
                    }

                    if (flag)
                    {
                        AppUser nuevo = new AppUser();
                        nuevo.fullname = textBox1.Text + " " + textBox2.Text;
                        nuevo.username = textBox3.Text;
                        nuevo.password = textBox4.Text;

                        if (textBox4.Text.Equals(textBox5.Text))
                        {
                            AppUserQuery.newUser(nuevo);
                            MessageBox.Show("Registro completo");
                            textBox1.Text = "";
                            textBox2.Text = "";
                            textBox3.Text = "";
                            textBox4.Text = "";
                            textBox5.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("Las contraseñas no coinciden");
                        }
                    }
                    else
                    {
                        MessageBox.Show("El nombre de usuario ya existe");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ocurrió un error");
                }
            }
        }