コード例 #1
0
        /// <summary>
        /// Checks if a username password combination exists
        /// Still needs to record login times to database
        /// Need to make a session/login class to record session data
        /// </summary>
        /// <param name="userName">username to find in database</param>
        /// <param name="password">password to check</param>
        /// <returns>True for match found, false for no match found</returns>
        public static bool LogUserIn(string userName, string password)
        {
            // commented out so code is still present
            //string connStr = Properties.Settings.Default.DBconnection;

            //// It allows comunication between the Database's source and the application
            //System.Data.SqlClient.SqlConnection dbConnection = new SqlConnection(connStr);  // @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\EAHT - Monitor - App\Application\EAHT - Application\EAHT - Engine\EAHT - Database.mdf; Integrated Security = True; Connect Timeout = 30");

            ////SQL query.
            //SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM Staff WHERE First_Name = ' " + userName + " 'AND Password_Hash = ' " + password + "'", dbConnection);
            //DataTable data = new DataTable();
            //dataAdapter.Fill(data);



            // Fixed and refactored to simplify

            // Checks input for conditions that would cause errors
            // not null and 1 character or more
            if (!(userName is null) && userName.Length > 1)
            {
                // Get password hash from database where first name matches
                DataSet dataset = SqlQueryExecutor.SelectColumnsFromTable(new string[1] {
                    "Password_Hash"
                }, "Staff", "First_Name=\'" + userName + "\'");
                DataTableReader reader = dataset.CreateDataReader();

                // If there is a result
                if (reader.Read())
                {
                    // If the hashed password entered matches the stored hash
                    if (reader.GetString(0) == PasswordCryptography.ComputeSha256Hash(password))
                    {
                        // Password matches
                        user = userName;
                        return(true);
                    }
                    // Password doesn't match
                    return(false);
                }
                // Username not found or
            }
            // Input is invalid
            return(false);
        }
コード例 #2
0
ファイル: Bed.cs プロジェクト: aliasmaus/EAHT-Monitor-App
        private int[] GetMonitorConfigurationFromDatabase()
        {
            string  AND         = ") AND ";
            DataSet monitorData = SqlQueryExecutor.SelectColumnsFromTable(new string[2] {
                "Monitor_Number", "Monitor_Type"
            }, "Monitors_In_Beds", "(Ward=" + wardRef.Id + AND + "(Bay=" + BayID + AND + "(Bed=" + bedNumber + AND + "(Monitor_Number<" + monitors.Length + ")");
            DataTableReader reader = monitorData.CreateDataReader();

            int[] types = new int[monitors.Length];
            for (int monitor = 0; monitor < types.Length; monitor++)
            {
                types[monitor] = -1;
            }
            while (reader.Read())
            {
                types[reader.GetInt32(0)] = reader.GetInt32(1);
            }
            return(types);
        }
コード例 #3
0
ファイル: Monitor.cs プロジェクト: aliasmaus/EAHT-Monitor-App
        /// <summary>
        /// Constructs a monitor for use in a bed
        /// </summary>
        /// <param name="monitorType">The type of monitor to create</param>
        /// <param name="ward"></param>
        /// <param name="bay"></param>
        /// <param name="bed"></param>
        /// <param name="number"></param>
        public Monitor(int monitorType, Ward ward, int bay, int bed, int number)
        {
            DataSet         monitorTypeInfo = SqlQueryExecutor.SelectAllFromTable("Monitors");
            DataTableReader reader          = monitorTypeInfo.CreateDataReader();

            this.ward = ward;
            this.bay  = bay;
            this.bed  = bed;
            while (reader.Read())
            {
                sensorTypes.Add(reader.GetString(1));
                defaultValues.Add(reader.GetDouble(5));
                defaultMinValues.Add(reader.GetDouble(3));
                defaultMaxValues.Add(reader.GetDouble(4));
                readRanges.Add(reader.GetDouble(6));
                readFrequencies.Add(reader.GetInt32(2));
                readRounds.Add(2);
            }
            this.name = sensorTypes[monitorType];
            sensor    = new MonitorSensor(readFrequencies[monitorType], defaultValues[monitorType], readRanges[monitorType], defaultMaxValues[monitorType], defaultMinValues[monitorType]);
            round     = readRounds[monitorType];
        }
コード例 #4
0
        /// <summary>
        /// Initializes the ward by retrieving ward data from the database
        /// </summary>
        /// <param name="ID"></param>
        public Ward(int ID)
        {
            this.id = ID;
            //Load info from database
            DataSet wardInfo;

            wardInfo = SqlQueryExecutor.SelectAllFromTable("Ward_Settings", "Id = " + ID.ToString());
            DataTableReader reader = wardInfo.CreateDataReader();

            reader.Read();
            //Load data from reader
            name = reader.GetString(1);
            int nBays     = reader.GetInt32(2);
            int nBeds     = reader.GetInt32(3);
            int nMonitors = reader.GetInt32(4);

            //Load bays
            bays = new Bay[nBays];
            for (int bay = 0; bay < nBays; bay++)
            {
                bays[bay] = new Bay(bay, nBeds, nMonitors, this);
            }
        }