Ejemplo n.º 1
0
        /// <summary>
        /// Returns nurse
        /// </summary>
        /// <param name="userName">The UserName</param>
        /// <param name="password">The Password</param>
        /// <returns>Nurse Object</returns>
        public static Nurse GetNurse( string userName, string password)
        {
            Nurse nurse = null;

            String selectStatement = " SELECT n.UserName, u.Password, n.NurseID " +
                " FROM Nurses n JOIN UserSecurity u ON n.UserName = u.UserName "+
                " WHERE n.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())
                            {
                                nurse = new Nurse();
                                nurse.UserName = reader["UserName"].ToString();
                                nurse.Password = reader["Password"].ToString();
                                nurse.NurseID = (int)reader["NurseID"];
                            }
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return nurse;
        }
Ejemplo n.º 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);
         }
     }
 }