コード例 #1
0
 public ResultForm( )
 {
     InitializeComponent();
     lblName.Text  = UserInfor.getUser();
     lblscore.Text = UserInfor.getUserScore().ToString();
     lblinfor.Text = UserInfor.UserFailed;
 }
コード例 #2
0
 /// <summary>
 /// get the Name of the user when they login successfully
 /// </summary>
 private void DName()
 {
     try
     {
         String query = "SELECT FirstName,LastName FROM users where UserID IN (SELECT UserID FROM userslogin where "
                        + "UserName ='******' and  Password='******')";
         con.Open();
         MySqlCommand    commdand = new MySqlCommand(query, con);
         MySqlDataReader reader   = commdand.ExecuteReader();
         if (reader.HasRows)
         {
             while (reader.Read())
             {
                 UserInfor.setName(reader.GetString(0) + " " + reader.GetString(1));
             }
         }
         con.Close();
     }
     catch (Exception)
     {
     }
 }
コード例 #3
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);
         }
     }
 }
コード例 #4
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);
             }
         }
     }
 }