예제 #1
0
 /// <summary>
 /// Interacts with usersecurity on behalf of Administators
 /// </summary>
 /// <param name="userName">the username</param>
 /// <param name="password">the password</param>
 /// <returns>An Administrator</returns>
 public static Administrator GetAdmin(string userName, string password)
 {
     Administrator admin = null;
     String selectStatement = " SELECT a.UserName, u.Password, a.AdminID " +
         " FROM Administrators a JOIN UserSecurity u ON a.UserName = u.UserName " +
         " WHERE a.UserName = @UserName AND u.Password = @Password ";
     try
     {
         using (SqlConnection connection = MedassistDB.GetConnection())
         {
             connection.Open();
             using (SqlCommand cmnd = new SqlCommand(selectStatement, connection))
             {
                 cmnd.Parameters.AddWithValue("@UserName", userName);
                 cmnd.Parameters.AddWithValue("@Password", password);
                 using (SqlDataReader reader = cmnd.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         admin = new Administrator();
                         admin.UserName = reader["UserName"].ToString();
                         admin.Password = reader["Password"].ToString();
                         admin.AdminID = (int)reader["AdminID"];
                     }
                 }
             }
         }
     }
     catch (SqlException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return admin;
 }
예제 #2
0
 /// <summary>
 /// The method manages a nurse login, so that he/she can get access to other 
 /// applications after login button is clicked 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void button1_Click(object sender, EventArgs e)
 {
     string userName = textBoxUserName.Text;
     string password = MD5Hash(textBoxPassword.Text);
     if (Validator.IsPresent(textBoxUserName) &&
         Validator.IsPresent(textBoxPassword));
     {
         try
         {
             this.nurse = this.controllerNurse.GetNurse(userName, password);
             this.admin = this.adminController.GetAdmin(userName, password);
             UserSecurityController.AdminLoggedIn = this.admin;
             UserSecurityController.NurseLoggedIn = this.nurse;
             if (this.nurse != null || this.admin != null)
             {
                 this.mainForm = new MainForm();
                 this.mainForm.Text = "You are logged in as  " + userName;
                 if (this.mainForm.ShowDialog() == DialogResult.OK)
                 {
                     this.mainForm.Show();
                 }
                 else
                 {
                     this.Close();
                 }
             }
             else
             {
                 MessageBox.Show("Invalid user name or password.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }