You are on page 1of 54

Pseudocode

//Structure that has members to use in worksheet reference


Record worksheet
Begin
Declare
name, namePerson, address, email, date, contact person, as string
records, jobNumber, telephone as integer
End worksheet

//Structure that has members to use in jobsheet reference


Record jobsheet
Begin
Declare
name as string
telephone as string
address as string
date as string
contactPerson as string
services as string
records as integer
subService as string
subServiceAmount as integer
serviceType as integer
serviceQuery as string
End jobsheet

//Structure that has members to use in gathering the inputs from users in regards to different
databases
Record databaseInputs
Begin
Declare
databaseInput,databaseInputTable as Integer
databaseInputName as string
End databaseInputs

//Structure that has a member to use in creating a name for the databases
Reocrd databaseName
Begin
Declare
name as string
End databaseName

//Structure that has members to use in creating a database table


Record databaseTables
Begin
Declare
name,columnName,datatype as string
columnDataType,columnDataString as string
alterTableQuery as string
columns,columnDataSize,columnDataInt as integer
End databaseTables

//Structure that has members to use in creating user fields in a database table
Record userInformation
Begin
Declare
userFirstName as string
userSurname as string
userDOB as string
userEmail as string
userID as integer
numberOfUsers as integer
End userInformation
//Structure that has members that holds login information for users
Record userCredentails
Begin
Declare
userName as string
password as string
menuInput as integer
End userCredentials

//Structure that has members to use in the admin option selection menu
Record adminControls
Begin
Declare
adminInput as integer
adminInputDB as integer
adminInputUsers as integer
adminInputUsersDatabase as integer
adminInputUsersTable as integer
End adminControls

Record userControls
Begin
Declare
userInput, userInputDB as integer
userDBName,userdbtName as string
End userControls

wk as worksheet Record
jobsheet as jobsheet Record
dBI as databaseInputs Record
db as databaseName Record
dbt as databaseTables Record
userInfo as userInformation Record
user as userCredentials Record
admin as adminControls Record
u as userControls Record

//A function that prompts the user to enter a name to create a database
FUNCTION createDatabaseName
Begin
Print "Enter a name for the Database: "
Read db.name
End

//A function that prompts the user to enter a name to create a database table
FUNCTION createDatabaseTableName
Begin
Print "Enter a name for the table: "
Read dbt.name
End

//A function that checks to see if a mySQL query was executed with errors
FUNCTION finish_with_error(MYSQL * con)
Begin
Print mysql_error(con)
mysql_close(con)
End

FUNCTION mysqlConnection
Begin
if (con == NULL) then
Print mysql
l_error(con)
exit(1))
Endif
if (mysql_real_connect(con, "localhost", "root", "root", NULL, 0, NULL, 0) == NULL) then
then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif
End

FUNCTION mysqlConnectionDatabase
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then


Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root", dBI.databaseInputName, 0, NULL, 0)
== NULL) then
finish_with_error(con)
Endif
End

//A function that returns the list of available databases specifically for users, after hiding the
default mySQL databases
FUNCTION showDatabasesForUsers
Begin
MYSQL* con = mysql_init(NULL) then

if (con == NULL) then then


Print stderr,mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
NULL, 0, NULL, 0) == NULL) then then

Print stderr, mysql_error(con)


mysql_close(con)
exit(1)
Endif
query as string
Print query, "SELECT `schema_name` from INFORMATION_SCHEMA.SCHEMATA
WHERE `schema_name` NOT IN('information_schema', 'mysql', 'performance_schema', 'sys',",
u.userDBName)
if (mysql_query(con, query)) then

Print stderr,mysql_error(con)
mysql_close(con)
exit(1)
Endif
MYSQL_RES* result = mysql_store_result(con)

num_fields as integer
num_fields = mysql_num_fields(result)

MYSQL_ROW row

if (result == NULL) then

finish_with_error(con)
Endif
Print "List of Databases"
Print " "
while ((row = mysql_fetch_row(result))) do

Print " "


for 1 to num_fields do
Print row[i] ? row[i] : "NULL"
Endfor

Print " "


Endwhile
Print " "

mysql_free_result(result)
mysql_close(con)
End

//A function that shows the list of available databases for the admin
FUNCTION showDatabases
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then


Print mysql_error(con
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root", NULL, 0, NULL, 0) == NULL) then


l_error(con
mysql_close(con)
exit(1)
Endif

query as string
Print(query, "SHOW SCHEMAS")

if (mysql_query(con, query)) then


Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

MYSQL_RES* result = mysql_store_result(con)

int num_fields = mysql_num_fields(result)

MYSQL_ROW row

while ((row = mysql_fetch_row(result))) do

for 1 to num_fields do

Print( row[i] ? row[i] )

Endfor

Print " "


Endwhile

Print " "

mysql_free_result(result)
mysql_close(con)
End
FUNCTION

//A function that returns the list of available tables in a database


FUNCTION showDatabaseTables
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then


Print mysql_error(con)
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
Print "SHOW TABLES"
if (mysql_query(con, query)) Then
Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

MYSQL_RES* result = mysql_store_result(con)

int num_fields = mysql_num_fields(result)

MYSQL_ROW row

while ((row = mysql_fetch_row(result))) do

for 1 to num_field do

Print row[i] ? row[i] : "NULL"


Endfor

Print " "


Endwhile

Print " "


mysql_free_result(result)
mysql_close(con)

End

//A function that prompts the user to enter the name of a database that will be used in mySQL
queries
FUNCTION selectDatabase
Begin
Print "Select the name of the database to use ")
Read dBI.databaseInputName
End

//A function that prompts the user to enter the name of a database table that will be used in
mySQL queries
FUNCTION selectDatabaseTables
Begin
Print "Select the name of the Worksheet to use "
Read dbt.name

End

//A function that deletes a database table that was provided by the user
FUNCTION deleteDatabaseTables
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then then
finish_with_error(con)
Endif
query as string
Print(query, "DROP TABLE " dbt.name)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that shows the data of a database table that was provided by the user
FUNCTION showDatabaseTableData
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then then

finish_with_error(con)
Endif

query as string
Print query, "SELECT * FROM" dbt.name
if (mysql_query(con), query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

MYSQL_RES* result = mysql_store_result(con)

if (result == NULL) then then

finish_with_error(con)
Endif

int num_fields = mysql_num_fields(result)

MYSQL_ROW row
MYSQL_FIELD* field

while ((row = mysql_fetch_row(result))) do

for 1 to num_field do

if (i == 0) then
while (field = mysql_fetch_field(result)) do

Print field->name
Endwhile

Print " "


Endif

Print row[i] ? row[i] : "NULL"


Endfor
Endwhile
Print " "

mysql_free_result(result)

mysql_close(con)

End

//A function that deletes a database that was provided by the user
FUNCTION deleteDatabase
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


NULL, 0, NULL, 0) == NULL) then then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

query as string
Print(query, "DROP DATABASE ", dBI.databaseInputName)
if (mysql_query(con, query)) then
Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that creates a database using a name provided by the user
FUNCTION createDatabase
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then then

Print mysql_error(con)
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


NULL, 0, NULL, 0) == NULL) then then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

query as string
Print(query, "CREATE DATABASE ", db.name)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that creates a database table using a name provided by the user
FUNCTION createTables
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then then

finish_with_error(con)
Endif

query as string
sPrint(query, "CREATE TABLE ", dbt.name, dbt.columnName, dbt.dataType)
if (mysql_query(con, query))

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)
End

//A function that returns the names of the columns from a database table
FUNCTION showColumns
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
Print(query, "SHOW COLUMNS FROM ", dbt.name)

if (mysql_query(con, query)) then


Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

MYSQL_RES* result = mysql_store_result(con)

if (result == NULL) then


finish_with_error(con)
Endif
int num_fields = mysql_num_fields(result)

MYSQL_ROW row
MYSQL_FIELD* field

while ((row = mysql_fetch_row(result))) do


for 1 to num_feild do
if (i == 0) then
while (field = mysql_fetch_field(result)) do

if field->name == "field" then


Print field->name
Endif

Endwhile

Print " "


Endif

Print row[i] ? row[i] : "NULL"

Endfor
Endwhile
Print " "

mysql_free_result(result)

mysql_close(con)
End
End

//A function that creates a database table with column names and data types
FUNCTION createTablesInput
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then


Print mysql_error(con)
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

Print "Enter the name of the Table: "


Read dbt.name
Print "Enter how many columns you want in the table: ")
Read dbt.columns
Print("Enter the name of the column: "
Read dbt.columnName
Print "Enter the Data type of the column INT() , VARCHAR() , DATE , DECIMAL: "
Read dbt.columnDataType
if (strcmp(dbt.columnDataType, "INT") == 0) then
Begin
Print("Enter the size for : ", dbt.columnName
Read dbt.columnDataSize
sPrint(dbt.dataType, "INT(%i)", dbt.columnDataSize
createTables(

end
else if (strcmp(dbt.columnDataType, "VARCHAR") == 0) then
Begin
Print("Enter the size for", dbt.columnName,":"
Read dbt.columnDataSize
sPrint(dbt.dataType, "VARCHAR ", dbt.columnDataSize
createTables(

end
else if (strcmp(dbt.columnDataType, "DATE") == 0) then
sPrint(dbt.dataType, "DATE"
createTables(

Endif
mysql_close(con)

End

//A function that allows the user to add database tables


FUNCTION addTables
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
sPrint(query, "ADD ", dbt.columnName, dbt.columnDataType
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that is called to insert the second column in a requested table
FUNCTION insertTableColumns2
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
sPrint(query, "ALTER TABLE ADD COLUMN ", dbt.name, dbt.columnName, dbt.dataType
if (mysql_query(con, query)) then
Print mysql_error(con)
mysql_close(con)
exit(1
Endif

mysql_close(con)

End

//A function that allows the user to make modifications to a database table
FUNCTION alterTables
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
Print("Enter the modification to make to the table's column ADD, MODIFY, DROP: ")
Read dbt.alterTableQuery
if (strcmp(dbt.alterTableQuery, "ADD") == 0) then
Print("Enter the name of the column: "
Read dbt.columnName
Print("Enter the Data type of the column INT() , VARCHAR() , DATE , DECIMAL: "
Read dbt.columnDataType
if (strcmp(dbt.columnDataType, "INT") == 0) then
Begin
Print("Enter the size for : ", dbt.columnName
Read dbt.columnDataSize
sPrint(dbt.dataType, "INT(%i)", dbt.columnDataSize
end

else if (strcmp(dbt.columnDataType, "VARCHAR") == 0) then


Begin
Print("Enter the size for : ", dbt.columnName)
Read dbt.columnDataSize)
sPrint(dbt.dataType, "VARCHAR(%i)", dbt.columnDataSize)

end
else if (strcmp(dbt.columnDataType, "DATE") == 0) then
Begin
sPrint(dbt.dataType, "DATE")

end
Endif
sPrint(query, "ALTER TABLE ADD", dbt.name, dbt.columnName, dbt.dataType)
if (mysql_query(con, query)) then
begin
Print mysql_error(con)
mysql_close(con)
exit(1)
end

else if (dbt.alterTableQuery == "DROP") then


begin
showColumns()
Print("Enter the name of the column: ")
Read dbt.columnName)
sPrint(query, "ALTER TABLE , DROP COLUMN ", dbt.name, dbt.columnName)
if (mysql_query(con, query)) then
begin
Print mysql_error(con)
mysql_close(con)
exit(1)
end

else if (dbt.alterTableQuery == "MODIFY") then


begin
Print("Enter the name of the column: ")
Read dbt.columnName)
Print("Enter the Data type of the column INT() , VARCHAR() , DATE , DECIMAL: ")
Read dbt.columnDataType)
if (strcmp(dbt.columnDataType, "INT") == 0) then
begin
Print("Enter the size for : ", dbt.columnName)
Read dbt.columnDataSize)
sPrint(dbt.dataType, "INT ", dbt.columnDataSize)
end

else if (dbt.columnDataType =="VARCHAR") then


begin
Print("Enter the size for : ", dbt.columnName)
Read dbt.columnDataSize)
sPrint(dbt.dataType, "VARCHAR ", dbt.columnDataSize)
end

else if (dbt.columnDataType == "DATE") then


begin
sPrint(dbt.dataType, "DATE")

End
Endif
sPrint(query, "ALTER TABLE MODIFY ", dbt.name, dbt.columnName, dbt.dataType)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that allows the user to add columns to a table


FUNCTION insertTableColumns
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
endif

for 1 to dbt.columns - 1 do
Print("Enter the name of the column: ")
Read dbt.columnName)
Print("Enter the Data type of the column INT() , VARCHAR() , DATE , DECIMAL: ")
Read dbt.columnDataType)
if (dbt.columnDataType == "INT") then
begin
Print("Enter the size for : ", dbt.columnName)
Read dbt.columnDataSize)
sPrint(dbt.dataType, "INT("dbt.columnDataSize")"
FUNCTION insertTableColumns2()
end

else if (strcmp(dbt.columnDataType, "VARCHAR") == 0) then


Begin
Print("Enter the size for : ", dbt.columnName)
Read dbt.columnDataSize)
sPrint(dbt.dataType, "VARCHAR(%i)", dbt.columnDataSize)
FUNCTION insertTableColumns2()
end

else if (strcmp(dbt.columnDataType, "DATE") == 0) then

sPrint(dbt.dataType, "DATE")
FUNCTION insertTableColumns2()

Endif
Endfor
mysql_close(con)

End

//A function that gathers input from the user regarding the database table values to be passed
into a worksheet
FUNCTION insertTableValues
Begin
Print "Enter the amount of records you want to insert: "
Read wk.records
for 1 to wk.records do
Print "Enter the name of the person: "
Read wk.namePerson
Print "Enter the address of the person: "
Read wk.address
Print "Enter the telephone number of the person: "
Read wk.telephone
Print "Enter the date: "
Read wk.date
Print "Enter the email of the person: "
Read wk.email
Print "Enter the Job Number of the person: "
Read wk.jobNumber
Print "Enter the Contact Person: "
Read wk.contactPerson

Endfor

End

//A function that gathers input from the user regarding the database table values to be passed
into a worksheet
FUNCTION insertTableValues2
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then
finish_with_error(con)
Endfor

query as string

Print "Enter the amount of records you want to insert: "


Read &wk.records
for for 1 to wk.records do do
Print "Enter the name of the person: "
Read wk.namePerson
Print "Enter the address of the person: "
Read wk.address
Print "Enter the telephone number of the person: "
Read wk.telephone
Print "Enter the date: "
Read wk.date
Print "Enter the email of the person: "
Read wk.email
Print "Enter the Job Number of the person: "
Read wk.jobNumber
Print "Enter the Contact Person: "
Read wk.contactPerson
sPrint(query, "INSERT INTO VALUES(' ', ' ', ' ', ' ', ' ', ' ', ‘ ')", dbt.name, wk.namePerson,
wk.address, wk.telephone, wk.date, wk.email, wk.jobNumber, wk.contactPerson)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
endif

Endfor
mysql_close(con)

End

//A function that gathers input from the user regarding the database table values to be passed
into the user table that will hold the login credentials
FUNCTION insertTableValuesUsers
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string

Print "Enter the amount of records you want to insert: "


Read &userInfo.numberOfUsers
for 1 to userInfo.numberOfUsers do
Print "Enter your id number: "
Read userInfo.userID
Print "Enter your first name: "
Read userInfo.userFirstName
Print "Enter your last name: "
Read userInfo.userSurname
Print "Enter your Date of birth: "
Read userInfo.userDOB
Print "Enter your email: "
Read userInfo.userEmail
Print "Enter a password: "
Read user.password
sPrint(query, "INSERT INTO VALUES( ‘ ’ , ' ', ' ', ' ', ' ', ' ')", dbt.name, userInfo.userID,
userInfo.userFirstName, userInfo.userSurname, userInfo.userEmail, userInfo.userDOB,
user.password)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif
Endfor

mysql_close(con)

End

//A function that searches the user login table and selects the password based on the ID
number provided
//it then stores the password inside of a variable that is authenticated with the password
provided
//by the user

FUNCTION userAuthentication()
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then


Print mysql_error(con)
exit(1)
endif

if (mysql_real_connect(con, "localhost", "root", "root",


"userdatabase", 0, NULL, 0) == NULL) then

finish_with_error(con)
endif

query as string
sPrint(query, "SELECT PASSWORD FROM userinformation WHERE ID = ",
user.userName)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
Endif

MYSQL_RES* result = mysql_store_result(con)

Num_fields as integer
num_fields = mysql_num_fields(result)

MYSQL_ROW row

while ((row = mysql_fetch_row(result))) do

for (int i = 0 i < num_fields i++) do

res = row[i] ? row[i] : "NULL"


Endfor
Print " "
Endwhile

Print " "


if (strcmp(user.userName, "admin") == 0) then
begin
adminWelcomeScreen()
end
else if (strcmp(user.password, res) == 0) then
begin
welcomeScreen()
end
else
Print("Incorrect UserName or password")
loginScreen()

Endif

mysql_free_result(result)
mysql_close(con)

End

//A function that gather the information that will be used to update the records in a database
table
FUNCTION updateTableValuesQuery()
Begin
Print "Enter the number of columns that will be used to update the records: "
Read dbt.columnNumber
for int i = 0 i < dbt.columnNumber ++i do
Print "Enter the name of the Column to use for updating the records: "
Read dbt.columnName
system "cls"
showDatabaseTableData
Print " "
Print "Enter the record value to update: "
Read dbt.query
Endfor

End

//A function that updates records in a database table


FUNCTION updateTableValues()
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Fprint (mysql_error(con))
exit(1)
endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
endif

query as string
if (strcmp(dbt.columnName, "JobNumber") == 0) then
Sprint (query, "UPDATE SET WHERE = ")

else
Sprint (query, "UPDATE SET = '' WHERE ID = ", dbt.name, dbt.columnName, dbt.query)
Endif

if (mysql_query(con, query)) then


FPrint (mysql_error(con))
mysql_close(con)
exit(1)
Endif

mysql_close(con)

End

//A function that gathers the input from the user to use in deleting values from a database table
FUNCTION deleteTableValuesQuery()
Begin
Print "Enter the name of the Column to use for deletion: "
Read dbt.columnName
Print "Enter the name of the person to delete their record: "
Read wk.namePerson

End

//A function that deletes records in a database table


FUNCTION deleteTableValues
Begin
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print mysql_error(con)
exit(1)
Endif
if (mysql_real_connect(con, "localhost", "root", "root",
dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif

query as string
sPrint(query, "DELETE FROM WHERE = ", dbt.name, dbt.columnName,
wk.namePerson)
if (mysql_query(con, query)) then

Print mysql_error(con)
mysql_close(con)
exit(1)
endif

mysql_close(con)

End

//A function that creates a files that will store the services provided in a jobsheet
FUNCTION servicesFileCreation()
Begin

FILE* filePointer

filePointer = fopen("services.txt", "w")

if (filePointer == NULL) then


Print "Error!")
exit(1)
Endif
if (jb.subServiceAmount < 2) then
Fprint (filePointer, " ", jb.subService)

else
Fprint (filePointer, " ,", jb.subService)
Endif

fclose(filePointer)

End

//A function that appends to a file that will store the services provided in a jobsheet
FUNCTION servicesFileAppend()
Begin
FILE* filePointer

filePointer = fopen("services.txt", "a")

if (filePointer == NULL) then


Print("Error!")
exit(1)
Endif

if (jb.subServiceAmount < 2) then


Fprint (filePointer, " " , jb.subService)

else
Fprint (filePointer, " " ," ", jb.subService)
Endif

fclose(filePointer)

End
//A function that stores the services provided
FUNCTION servicesFileStorage()
Begin

FILE* filePointer

filePointer = fopen("services.txt", "r")

if (filePointer == NULL) then


Print ("Error!")
exit(1)
Endif

fRead(filePointer, " ", jb.services)


fclose(filePointer)

End

//A function that presents the different types of jobsheet sub-services for the installation service
FUNCTION installationCase()
Begin
for 1 to 1 do
Print ("Carpet")
Print " "
Print ("Drapery")
Print " "
Print ("Blinds/Roller Shades")
Print " "
Print ("Enter Sub-Service : ")
Read (jb.subService)
servicesFileCreation()
Endfor
for 1 to jb.subServiceAmount - 1 do
Print ( "Carpet")
Print " "
Print ("Drapery")
Print " "
Print ("Blinds/Roller Shades")
Print " "
Print ("Enter Sub-Service : ")
Read ( jb.subService)
servicesFileAppend()
servicesFileStorage()
Sprint (jb.servicesQuery, "Installation of ", jb.services)
Endfor

End

//A function that presents the different types of jobsheet sub-services for the repair service
FUNCTION repairCase()
Begin

for 1 to 1 do
Print "Carpet"
Print " "
Print "Drapery"
Print " "
Print "Blinds/Roller Shades"
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileCreation()
endfor
for 1 to jb.subServiceAmount - 1 do
Print "Carpet"
Print " "
Print "Drapery"
Print " "
print "Blinds/Roller Shades"
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileAppend()
servicesFileStorage()
sPrint (jb.servicesQuery, "Repair of ", jb.services)
Endfor
End

//A function that presents the different types of jobsheet sub-services for the pest control service
FUNCTION pestControlCase()
Begin

For 1 to 1 do
Print "Spraying"
Print " "
Print "Bait/Paste "
Print " "
Print "Termite Treatment"
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileCreation()
Endfor

for 1 to (jb.subServiceAmount - 1) do
Print "Spraying"
Print " "
Print "Bait/Paste"
Print " "
Print "Termite Treatment "
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileAppend()
servicesFileStorage()
sPrint (jb.servicesQuery, "Pest Control of ", jb.services)
Endfor

End

//A function that presents the different types of jobsheet sub-services for the sanitation service
FUNCTION sanitationCase()
Begin
For 1 to 1 do
Print "Rug"
Print " "
Print "Carpet"
Print " "
Print "Drapery"
Print " "
Print "Blinds/Roller Shades"
Print " "
Print "Deep Clean"
Print " "
Print "Windows"
Print " "
Print "Vehicle Interior"
Print " "
Print "Tile Stipping "
Print " "
Print "Sofa/Settee"
Print " "
Print "Sanitization"
Print " "
Print "Partitions"
Print " "
Print "Office Chairs"
Print " "
Print "Dining Chairs"
Print " "
Print "Mattress"
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileCreation()
Endfor

for 1 to jb.subServiceAmount - 1 do
Print "Rug"
Print " "
Print "Carpet"
Print " "
Print "Drapery"
Print " "
Print "Blinds/Roller Shades"
Print " "
Print "Deep Clean"
Print " "
Print "Windows "
Print " "
Print "Vehicle Interior "
Print " "
Print "Tile Stipping "
Print " "
Print "Sofa/Settee "
Print " "
Print "Sanitization "
Print " "
Print "Partitions "
Print " "
Print "Office Chairs "
Print " "
Print "Dining Chairs "
Print " "
Print "Mattress "
Print " "
Print "Enter Sub-Service : "
Read jb.subService
servicesFileAppend()
servicesFileStorage()
sPrint(jb.servicesQuery, "Cleaning/Sanitization of ", jb.services)
Endfor

End

//A function that gathers information that will be stored in a jobsheet


FUNCTION insertTableValuesJobsheet()

MYSQL* con = mysql_init(NULL)

if (con == NULL) then

fPrint(stderr, , mysql_error(con))
exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


dBI.databaseInputName, 0, NULL, 0) == NULL) then

finish_with_error(con)
Endif
query as string

Print "Enter the amount of records you want to insert: "


Read &jb.records
for 1 to jb.records do
Print "Enter the name of the person: "
Read jb.name
Print "Enter the telephone number of the person: "
Read jb.telephone
Print"Enter the address of the person: "
Read jb.address
Print"Enter the date: "
Read jb.date
Print"Enter the Contact Person: "
Read jb.contactPerson
system"cls"
Print"1) Installation"
Print " "
Print"2) Repair"
Print " "
Print"3) Pest Control"
Print " "
Print"4) Cleaning/Sanitization"
Print " "
Print"Enter the type of Service: "
Print " "
Read jb.serviceType
insertTableValuesJobsheet2()
sPrint(query, "INSERT INTO VALUES(' ', ' ', ' ', ' ', ' ', ' ')", dbt.name, jb.name, jb.telephone,
jb.address, jb.date, jb.contactPerson, jb.servicesQuery)
if (mysql_query(con, query)) then

fPrint(stderr, "", mysql_error(con))


mysql_close(con)
exit(1)
Endif
Endfor

mysql_close(con)
End

//A function that prompts the user for the number of subservices, then calles the respective
function based on the service type
FUNCTION insertTableValuesJobsheet2()

Print "Enter the amount of Sub-Services: "


Read jb.subServiceAmount
if (jb.serviceType == 1) then
begin
installationCase()

end
else if (jb.serviceType == 2) then
begin
repairCase()
end
else if (jb.serviceType == 3) then
begin
pestControlCase()
end
else if (jb.serviceType == 4) then
begin
sanitationCase()
Endif
End

//A function that creates a files that will store the user database name provided by the admin
FUNCTION userDatabaseNameFileCreation()

FILE* filePointer

filePointer = fopen("userdatabasename.txt", "w")

if (filePointer == NULL) then


Print("Error!")
exit(1)
Endif

fPrint(filePointer, " ", db.name)


fclose(filePointer)
End

//A function that stores the userdatabase name


FUNCTION userDatabaseNameFileStorage()

FILE* filePointer

filePointer = fopen("userdatabasename.txt", "r")

if (filePointer == NULL) then


Print("Error!")
exit(1)
Endif

fRead(filePointer, " ", u.userDBName)


fclose(filePointer)
End

//A function that creates a files that will store the user database table name provided by the
admin
FUNCTION userTableNameFileCreation()

FILE* filePointer

filePointer = fopen("usertablename.txt", "w")

if (filePointer == NULL) then


Print("Error!")
exit(1)
Endif

fPrint(filePointer, " ", dbt.name)


fclose(filePointer)
End

//A function that stores the userdatabase table name


FUNCTION userTableNameFileStorage()

FILE* filePointer

filePointer = fopen("usertablename.txt", "r")

if (filePointer == NULL) then


Print("Error!")
exit(1)
Endif

fRead(filePointer, " ", u.userdbtName)


fclose(filePointer)
End

//A function that authenticates the password provided by the user and calls the specific function
FUNCTION loginScreen()
Begin
Print "Username: "
Read user.userNAme
Print " "
Print "Password: "
Read user.password
if user.password = admin then
Print adminWelcomeScreen()
else
Print welcomescreen()
Endif
End

//A function that presents the different options for the admin
FUNCTION adminWelcomeScreenOption2()

Print"1) Create a Worksheet")


Print " "
Print"2) Edit a Worksheet")
Print " "
Print"3) Delete a Worksheet")
Print " "
Print"4) Previous Page ")

End

//A function that presents the different options for the user
FUNCTION userEditWorksheetScreenOptions
Print"1) Add records "
Print " "
Print"2) Delete records"
Print " "
Print"3) Show Table Data"
Print " "
Print"4) Previous Page"

End

//A function that presents the different options for the user
FUNCTION userWelcomeScreenOption
Begin

Print "Welcome ", user.userName


Print "1) Worksheets"
Print " "
Print "2) Jobsheets"
Print " "
Print "3) Log Out"
Print " "
End

FUNCTION CreateAccount()
Begin
system "cls"
Print "Account Creation"
Print "Enter your first name: "
Read userInfo.userFirstName
Print " "
Print "Enter your last name: "
Read userInfo.userSurname
Print " "
Print " Enter your Date of birth: "
Read userInfo.userDOB
Print " "
Print " Enter your email: "
Read userInfo.userEmail
End

FUNCTION welcomeScreen()
Begin
system "cls"
menu()
Print "Welcome", user.userName
Print "1) Create a worksheet"
Print "2) Edit a worksheet"
Print "3) Delete a worksheet"
Print "4) Create a jobsheet"
Print "5) Edit a jobsheet"
Print "6) Delete a jobsheet"
End
//A function that presents the different options for the admin
void adminWelcomeScreenOption1() {
system "cls"
print "1) Create a Database"
print "2) Delete Database "
print "3) View Databases "
print "4) Previous Page "

}
//A function that presents the different options for the admin
void adminWelcomeScreenOptions() {

print "Welcome", user.userName


print "1) Databases"
print "2) Worksheets"
print "3) Jobsheets"
print "4) Users")
print "5) Log Out"

//A function that presents the different options for the admin
void adminEditWorksheetScreenOptions() {

print "1) Add records "


print "2) Delete records"
print "3) Update records"
print "4) Show colums "
print "5) Alter Columns "
print "6) Show Table Data "
print "7) Previous Page "

FUNCTION adminWelcomeScreen ()
Begin
system "cls"
menu()
Print "Welcome ", user.userName
Print "1) Modify Worksheets"
Print "2) Modify Jobsheets"
Print "3) Modify Users"
Read admin.adminInput
switch (admin.adminInput) {
case(1):
system"cls"
Print "1) Create a worksheet"
Print "2) Edit a worksheet"
Print "3) Delete a worksheet"
case (2):
Print "4) Create a jobsheet"
Print "5) Edit a jobsheet"
Print "6) Delete a jobsheet"
case (3):
Print "4) Create a User"
Print "5) Edit a User"
Print "6) Delete a User"
Endif
End

FUNCTION mainMenu()
Begin
system("cls")
startupMenu()
Print "MAIN MENU"
Print "1) Sign in"
Print "2) Sign up"
Print "3) EXIT"
Print "Enter your input here: "
Read &user.menuInput
switch(user.menuInput)
case(1):
loginScreen()
break
case(2):
createAccount()
case(3):
Print "Have A Nice Day!"
exit(0)
End

FUNCTION adminWelcomeScreen()
Begin
system"cls"
menu()
Print "Welcome", user.userName
Print "1) Modify Worksheets"
Print "2) Modify Jobsheets"
Print "3) Modify Users"
Read &admin.adminInput
switch (admin.adminInput)
case(1):
system("cls")
Print "1) Create a worksheet"
Print "2) Edit a worksheet"
Print "3) Delete a worksheet"
case (2):
Print "4) Create a jobsheet"
Print "5) Edit a jobsheet"
Print "6) Delete a jobsheet"
case (3):
Print "4) Create a User"
Print "5) Edit a User"
Print "6) Delete a User"
End

FUNCTION startupMenu ()
Begin
Declare comp_name as string
length as integer
length = sizeof(comp_name)/ sizeof(comp_name[0])

Print
"************************************************************************************************************
******************"
Print " ___ ___ ___ ___ ___ ________ ________ _______ ________
________ ________ _______"
sleep(200)
Print " | | || || || | | |___ ___| |___ ___| | ____| | | | | ______ | |
______| | ____|"
Sleep(200)
Print " || || | | | |____| | | | | | | |____ | _____| | | | | | |_____ ||
____ "
Sleep(200)
Print " || || | | | |____| | | | | | | ____| | | \\ \\ || | | |_____ | |
____|"
Sleep(200)
Print " | |____| |____| | | | | | ___| |___ | | | |____ | | \\ \\ | |____| |
_____| | | |____"
Sleep(200)
Print " |_______________| |_| |_| |________| |__| |______| |_| \\_\\ |
_______ | |_______ | |______|"

Print
"************************************************************************************************************
******************"
For i 1 to length do
Print comp_name[i]
Sleep(50)
Print " "
End
End
FUNCTION menu()
Begin
declare comp_name as string
length,i as integer
length = sizeof(comp_name)/sizeof(comp_name[0])
Print
"************************************************************************************************************
******************"
Print " ___ ___ ___ ___ ___ ________ ________ _______
________ ________ ________ _______ "
Print " || || || || | | |___ ___| |___ ___| | ____| | | | | ______ | |
______| | ____| "
Print " || || | | | |____| | | | | | | |____ | _____| | | | | | |_____ ||
____ "
Print " || || | | | |____| | | | | | | ____| | | \\ \\ || | | |_____ | |
____|"
Print " | |____| |____| | | | | | ___| |___ | | | |____ | | \\ \\ | |____| |
_____| | | |____"
Print " |_______________| |_| |_| |________| |__| |______| |_| \\_\\ |
_______ | |_______ | |______|"

Print
"************************************************************************************************************
******************"

for i to length do
Print comp_name[i]

Print " "


End

FUNCTION main
Begin
Callup mainMenu
MYSQL* con = mysql_init(NULL)

if (con == NULL) then

Print(stderr, "", mysql_error(con))


exit(1)
Endif

if (mysql_real_connect(con, "localhost", "root", "root",


NULL, 0, NULL, 0) == NULL) then

Print stderr, mysql_error(con)


mysql_close(con)
exit(1)
Endif

mysql_close(con)
exit(0)

End

You might also like