Пример #1
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            SQLCONN.Open();
            SQLCMD = new SqlCommand("SELECT tildeltRettighed FROM Brugere WHERE brugernavn = '" + Bruger.Text + "' AND Kodeord = '" + adgangskode.Password + "'", SQLCONN);
            SQLDR  = SQLCMD.ExecuteReader();
            if (SQLDR.HasRows)
            {
                SQLDR.Read();
                if (SQLDR[0].ToString() == "Administrator")
                {
                    Administrator Admin = new Administrator();
                    Admin.Show();
                    MessageBox.Show("Din rettighed er Admnistrator");
                }
                else if (SQLDR[0].ToString() == "Superbruger")
                {
                    Superbruger SB = new Superbruger();
                    SB.Show();
                    MessageBox.Show("Din rettighed er Superbruger");
                }
            }
            else
            {
                MessageBox.Show("Bruger findes ikke");
            }

            SQLCONN.Close();
        }
Пример #2
0
 private void button1_Click(object sender, EventArgs ex)
 {
     try //tests the code for any errors
     {
         SQLiteConnection  Con    = new SQLiteConnection(@"Data Source=.\UsersDB.db;Version=3");
         SQLiteCommand     SqlCmd = new SQLiteCommand("select * from Users where Username = '******' and [Password]='" + textBox2.Text + "'", Con); //selects all database entries that match the username and password entered
         SQLiteDataAdapter SqlDA  = new SQLiteDataAdapter(SqlCmd);
         DataTable         DT     = new DataTable();
         SqlDA.Fill(DT);                                                //fills the "DT" datatable with the data selected
         string cmbItemValue = comboBox1.SelectedItem.ToString();       //saves the usertype selected, from the usertype drop down menu, into "cmbItemValue"
         if (DT.Rows.Count > 0)                                         //if there is data in the datatable, the code will run
         {
             for (int i = 0; i < DT.Rows.Count; i++)                    //scans through the rows in the datatable
             {
                 if (DT.Rows[i]["usertype"].ToString() == cmbItemValue) //if the usertype selected is in the datatable, the code will run
                 {
                     if (comboBox1.SelectedIndex == 0)                  //if you selected the "Bruger" usertype, the "Bruger.cs" window will pop up, and the current window will be hidden
                     {
                         Bruger f = new Bruger();
                         f.Show();
                         this.Hide();
                     }
                     else if (comboBox1.SelectedIndex == 1) //if you selected the "Superbruger" usertype, the "Superbruger.cs" window will pop up, and the current window will be hidden
                     {
                         Superbruger ff = new Superbruger();
                         this.Hide();
                         ff.Show();
                     }
                     else if (comboBox1.SelectedIndex == 2) //if you selected the "Administrator" usertype, the "Administrator.cs" window will pop up, and the current window will be hidden
                     {
                         Administrator fff = new Administrator();
                         this.Hide();
                         fff.Show();
                     }
                 }
                 break; //breaks out of the current scope
             }
         }
         else //clears the boxes and shows a general error message, if a non-detectable error(i.e. human error) occurs
         {
             textBox1.Clear();
             textBox2.Clear();
             MessageBox.Show("                               Error \n    Login and/or Password were incorrect");
         }
     }
     catch (Exception exc) { MessageBox.Show(exc.Message); } //shows the error message if the code has any errors
 }