private void BtnGuardar_Click(object sender, EventArgs e)
        {
            if (TxtPassword.Text == TxtPassword2.Text)
            {
                if (TxtUsuario.Text != "" || TxtPassword.Text != "" || TxtPassword2.Text != "")
                {
                    Usuarios n    = new Usuarios(TxtUsuario.Text, TxtPassword.Text, TxtNombre.Text, TxtEmail.Text, "11", Convert.ToInt32(CmbTipoCuenta.SelectedValue));
                    Boolean  resp = n.Guardar();

                    if (resp)
                    {
                        MessageBox.Show("Se ha guardado el usuario con exito", "Guardado con exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        TxtEmail.Clear();
                        TxtNombre.Clear();
                        TxtPassword.Clear();
                        TxtPassword2.Clear();
                        TxtUsuario.Clear();
                    }
                    else
                    {
                        MessageBox.Show("Error al guardar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("No se permiten campos vacios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Las contraseñas no coinciden", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        //button register
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(rezult);
            if (TxtPassword.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtPassword.Focus();
                return;
            }
            if (TxtPassword2.Text == "")
            {
                MessageBox.Show("Please enter confirm password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtPassword.Focus();
                return;
            }
            if (TxtUsername.Text == "")
            {
                MessageBox.Show("Please enter username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtPassword.Focus();
                return;
            }
            try
            {
                SqlConnection myConnection = default(SqlConnection);
                myConnection = new SqlConnection(@"Data Source=DESKTOP-NP1RDM2\BAZALUIMARIAN;Initial Catalog=task;Persist Security Info=True;User ID=sa; Password = 0299");



                if (TxtPassword.Text == TxtPassword2.Text)
                {
                    String query = "INSERT INTO dbo.Users (NameUser,PasswordUser) VALUES (@UserName,@Password)";

                    using (SqlCommand command = new SqlCommand(query, con))
                    {
                        command.Parameters.AddWithValue("@UserName", TxtUsername.Text);
                        command.Parameters.AddWithValue("@Password", TxtPassword.Text);
                        MessageBox.Show("Register successfully !", "Register Successfully", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        con.Open();
                        int result = command.ExecuteNonQuery();

                        // Check Error
                        if (result < 0)
                        {
                            Console.WriteLine("Error inserting data into Database!");
                        }
                        Close();
                    }
                }



                else
                {
                    MessageBox.Show("Register Denied", "Register Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TxtUsername.Clear();
                    TxtPassword.Clear();
                    TxtPassword2.Clear();
                    TxtUsername.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }