Example #1
0
 //InternetGetConnectedState(out Des, 0).ToString()
 private void btnLogin_Click(object sender, EventArgs e)
 {
     if (InternetConnection.getConnection() == false)
     {
         //validate inputs
         try
         {
             if (string.IsNullOrEmpty(txtusername.Text) || txtusername.Text == "Username")
             {
                 throw new Exception("Enter Username");
             }
             if (string.IsNullOrEmpty(txtPassword.Text) || txtPassword.Text == "Password")
             {
                 throw new Exception("Enter Password");
             }
             else if (txtPassword.Text.Length == 12 && txtPassword.Text.Substring(0, 8) == UserLogin.GET_UserPass)
             {
                 UserInfor.setUser(txtusername.Text);
                 this.Hide();
                 var Test = new QuickTestFrm();
                 Test.Show();
                 this.Close();
             }
             else
             {
                 throw new Exception("Incorrect Username or Password ");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         try
         {
             ///CODE THE ONLINE LOGIN HERE
             if (string.IsNullOrEmpty(txtusername.Text) || txtusername.Text == "Username")
             {
                 throw new Exception("Enter Username");
             }
             if (string.IsNullOrEmpty(txtPassword.Text) || txtPassword.Text == "Password")
             {
                 throw new Exception("Enter Password");
             }
             else if (string.IsNullOrEmpty(txtusername.Text) == false && string.IsNullOrEmpty(txtPassword.Text) == false)
             {
                 //if (UserInfor.Passwords.Contains(txtPassword.Text) && UserInfor.Users.Contains(txtusername.Text) )
                 //UserInfor.setUser(txtusername.Text);
                 if (InternetConnection.getConnection() == false)
                 {
                     throw new Exception("No Internet Connection");
                 }
                 string           LoginUser = "******" + txtusername.Text + "' AND userslogin.Password ='******'";
                 MySqlDataAdapter adapter   = new MySqlDataAdapter(LoginUser, con);
                 DataTable        dt        = new DataTable();
                 adapter.Fill(dt);
                 int x = dt.Rows.Count;
                 if (x < 2 && x > 0)
                 {
                     foreach (DataRow dr in dt.Rows)
                     {
                         Online_Exam_Answers.UserID = Int32.Parse(dr[0].ToString());
                         UserInfor.setUser(dr[1].ToString());
                     }
                     this.Hide();
                     DName();
                     var Test = new QuickTestFrm();
                     Test.Show();
                     this.Close();
                 }
                 else
                 {
                     throw new Exception("Incorrect Username or Password ");
                 }
             }
             else
             {
                 throw new Exception("Incorrect Username or Password ");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Example #2
0
 private void txtPassword_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyValue == (char)Keys.Enter)
     {
         if (InternetConnection.getConnection() == false)
         {
             try
             {
                 if (string.IsNullOrEmpty(txtusername.Text) || txtusername.Text == "Username")
                 {
                     throw new Exception("Enter Username");
                 }
                 if (string.IsNullOrEmpty(txtPassword.Text) || txtPassword.Text == "Password")
                 {
                     throw new Exception("Enter Password");
                 }
                 else if (txtPassword.Text.Length == 12 && txtPassword.Text.Substring(0, 8) == UserLogin.GET_UserPass)
                 {
                     UserInfor.setUser(txtusername.Text);
                     this.Hide();
                     DName();
                     var Test = new QuickTestFrm();
                     Test.Show();
                     this.Close();
                 }
                 else
                 {
                     throw new Exception("Incorrect Username or Password ");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             try
             {
                 //CODE THE ONLINE LOGIN HERE
                 if (string.IsNullOrEmpty(txtusername.Text) || txtusername.Text == "Username")
                 {
                     throw new Exception("Enter Username");
                 }
                 if (string.IsNullOrEmpty(txtPassword.Text) || txtPassword.Text == "Password")
                 {
                     throw new Exception("Enter Password");
                 }
                 else if (UserInfor.Passwords.Contains(txtPassword.Text) && UserInfor.Users.Contains(txtusername.Text))
                 {
                     UserInfor.setUser(txtusername.Text);
                     this.Hide();
                     var Test = new QuickTestFrm();
                     Test.Show();
                     this.Close();
                 }
                 else
                 {
                     throw new Exception("Incorrect Username or Password ");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }