Exemplo n.º 1
0
        private void CarregaFormPrincipal()
        {
            FormPrincipal FormPrincipal = new FormPrincipal();

            FormPrincipal.Show();
            this.Hide();
        }
Exemplo n.º 2
0
        public void Login()
        {
            try
            {
                using (var conn = new SQLiteConnection(@"Data Source=CaoMedor.db; Version = 3"))
                {
                    conn.Open();
                    using (var cmd = new SQLiteCommand("SELECT username,password FROM users WHERE username=@Username AND password=@Password", conn))
                    {
                        cmd.Parameters.AddWithValue("@Username", metroTextBoxUsuario.Text);
                        cmd.Parameters.AddWithValue("@Password", metroTextBoxSenha.Text);

                        using (var reader = cmd.ExecuteReader())
                        {
                            var count = 0;
                            while (reader.Read())
                            {
                                count = count + 1;
                            }
                            if (count == 1 && metroTextBoxSenha.Text == "admin")
                            {
                                FormAlteraSenha FormAlteraSenha = new FormAlteraSenha();
                                FormAlteraSenha.Show();
                                this.Hide();
                            }

                            else if (count == 1 && metroTextBoxSenha.Text != "admin")
                            {
                                FormPrincipal FormPrincipal = new FormPrincipal();
                                FormPrincipal.Show();
                                this.Hide();
                            }

                            else if (count == 0)
                            {
                                MessageBox.Show("Usuário e/ou senha inválidos!", "CãoMedor",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error,
                                                MessageBoxDefaultButton.Button1);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }