// <summary>
        // Checks if user exists in the database and the password is correct
        // </summary>
        // <return>True if user exists</return>
        public static bool User_Exists(string user, string pass)
        {
            string _inputCommand = "SELECT * FROM NEWUsers WHERE UserName = '******' and Password = '******'";

            Console.WriteLine(_inputCommand);
            MySqlCommand _command = new MySqlCommand();

            if (_MySQL.OpenConnection() == true)
            {
                _command.CommandText = _inputCommand;
                _command.Parameters.AddWithValue("@user", user);
                _command.Parameters.AddWithValue("@password", pass);
                _command.Connection = _MySQL.connection;
                MySqlDataReader login = _command.ExecuteReader();

                if (login.Read())
                {
                    login.Close();
                    _MySQL.CloseConnection();
                    return(true);
                }
                else
                {
                    login.Close();
                    _MySQL.CloseConnection();
                    return(false);
                }
            }
            return(false);
        }
        /// <summary>
        /// Add an incident to the database
        /// </summary>
        /// <param name="IncidentDesc">String describing the incident that occured</param>
        public static void Add_Incident(string uid, string IncidentDesc)
        {
            MySqlCommand _command = new MySqlCommand();

            if (_mysql.OpenConnection())
            {
                _mysql.Change_Timezone(_command); // Change time zone to match Melb

                //Add parameters and execute the command to MySQL database
                _command.CommandText = "" +
                                       "INSERT INTO Incidents (UID, DateOfIncident, TimeOfIncident, IncidentDescription) " +
                                       "VALUES (@UID, CURDATE(), CURTIME(), @IncidentDescription);";
                _command.Parameters.AddWithValue("@UID", uid);
                _command.Parameters.AddWithValue("IncidentDescription", IncidentDesc);

                _command.ExecuteNonQuery(); // Execute the command
            }
            _mysql.CloseConnection();
        }
Exemple #3
0
        /// <summary>
        /// Show all food requests that aren't completed
        /// </summary>
        public static void Show_Requests()
        {
            if (_MySQL.OpenConnection())
            {
                MySqlDataAdapter mySqlDataAdapter_Food = new MySqlDataAdapter(
                    // "SELECT U.UID, U.FirstName, U.LastName, Res.Room, Res.Section, Req.MealType, Req.HotOrCold, Req.MealName, Req.DateOfRequest, Req.TimeOfRequest, Req.Completed FROM NEWUsers U " +

                    "SELECT U.FirstName, U.LastName, Res.Room, Res.Section, Req.MealType, Req.HotOrCold, Req.MealName, Req.Completed, Req.DateOfRequest, Req.TimeOfRequest, U.UID FROM NEWUsers U " +
                    "INNER JOIN NEWResidents Res ON U.UID = Res.UID " +
                    "INNER JOIN NEWFoodRequests Req ON Res.UID = Req.UID " +
                    "WHERE Completed != 'y' OR Completed IS NULL;" // Only show uncompleted requests
                    , _MySQL.connection);
                DataTable = new DataTable();
                mySqlDataAdapter_Food.Fill(DataTable);

                _MySQL.CloseConnection();
            }
            else
            {
                Console.WriteLine("Could not open connection");
            }
        }
Exemple #4
0
 public void test_mysql_conn_close()
 {
     valid = _conn.CloseConnection();
     Assert.AreEqual(valid, true);
 }