public bool DeleteDatabaseManager(ManagerClass deleteManager)
        {
            bool isValid = false;

            //establish database connection
            MySqlConnection databaseConnection = new MySqlConnection(Global.ConnectionString);

            try
            {
                string       deleteManagerStatement = "DELETE FROM manager WHERE username=@username";
                MySqlCommand deleteManagerCommand   = new MySqlCommand(deleteManagerStatement, databaseConnection);
                deleteManagerCommand.Parameters.AddWithValue("@username", deleteManager.managerUsername);
                databaseConnection.Open();

                int rows = deleteManagerCommand.ExecuteNonQuery();
                if (rows > 0)
                {
                    isValid = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                databaseConnection.Close();
            }

            return(isValid);
        }
Exemple #2
0
        //insert data to database
        public bool InsertToDatabase(ManagerClass insertManager)
        {
            bool isValid = false;

            //establish database connection
            MySqlConnection databaseConnection = new MySqlConnection(Global.ConnectionString);

            try
            {
                //SQL query to insert items
                string insertManagerStatement = "INSERT INTO manager (username, password, firstName, lastName, dateOfBirth, accessLevel) VALUES (@username, @password, @firstName, @lastName, @dateOfBirth, @accessLevel)";

                //execute
                MySqlCommand insertManagerCommand = new MySqlCommand(insertManagerStatement, databaseConnection);

                insertManagerCommand.Parameters.AddWithValue("@username", insertManager.managerUsername);
                insertManagerCommand.Parameters.AddWithValue("@password", insertManager.managerPassword);
                insertManagerCommand.Parameters.AddWithValue("@firstName", insertManager.managerFName);
                insertManagerCommand.Parameters.AddWithValue("@lastName", insertManager.managerLName);
                insertManagerCommand.Parameters.AddWithValue("@dateOfBirth", insertManager.managerDOB);
                insertManagerCommand.Parameters.AddWithValue("@accessLevel", insertManager.managerAccessLvl);

                databaseConnection.Open();
                int rows = insertManagerCommand.ExecuteNonQuery();

                if (rows > 0)
                {
                    isValid = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                databaseConnection.Close();
            }

            return(isValid);
        }
Exemple #3
0
        public bool UpdateDatabaseManager(ManagerClass updateManager)
        {
            bool isValid = false;

            //establish database connection
            MySqlConnection databaseConnection = new MySqlConnection(Global.ConnectionString);

            try
            {
                string updateManagerStatement = "UPDATE manager SET username=@username, password=@password, firstName=@firstName, lastName=@lastName, dateOfBirth=@dateOfBirth, accessLevel=@accessLevel";
                //execute
                MySqlCommand updateManagerCommand = new MySqlCommand(updateManagerStatement, databaseConnection);
                updateManagerCommand.Parameters.AddWithValue("@username", updateManager.managerUsername);
                updateManagerCommand.Parameters.AddWithValue("@password", updateManager.managerPassword);
                updateManagerCommand.Parameters.AddWithValue("@firstName", updateManager.managerFName);
                updateManagerCommand.Parameters.AddWithValue("@lastName", updateManager.managerLName);
                updateManagerCommand.Parameters.AddWithValue("@dateOfBirth", updateManager.managerDOB);
                updateManagerCommand.Parameters.AddWithValue("@accessLevel", updateManager.managerAccessLvl);

                databaseConnection.Open();

                int rows = updateManagerCommand.ExecuteNonQuery();
                if (rows > 0)
                {
                    isValid = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                databaseConnection.Close();
            }

            return(isValid);
        }