Skip to content

Commit

Permalink
Commented code further
Browse files Browse the repository at this point in the history
  • Loading branch information
babeyjack committed Mar 4, 2024
1 parent aec1df3 commit 8131d38
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Scripts/.vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file not shown.
Empty file.
Binary file added Scripts/.vs/Scripts/v17/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions Scripts/.vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ExpandedNodes": [
"",
"\\Admin",
"\\Data Classes",
"\\Databases",
"\\Networking",
"\\Till Functions"
],
"SelectedNode": "\\Till Functions\\StockLookup.cs",
"PreviewInSolutionExplorer": false
}
Binary file added Scripts/.vs/slnx.sqlite
Binary file not shown.
4 changes: 3 additions & 1 deletion Scripts/Admin/StaffAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public void ConfirmInputs()
DateTime dobDT;
DateTime startDT;
DateTime endDT;
// Validate that none of the data fields are left blank
if(idInput.text == "" || firstNameInput.text == "" || lastNameInput.text == "" || dateOfBirthInput.text == "" || startDateInput.text == "" || endDateInput.text == "" || permissionsLevelInput.text == "")
{
return;
}else if(!DateTime.TryParse(dateOfBirthInput.text, out dobDT) || !DateTime.TryParse(startDateInput.text, out startDT) || !DateTime.TryParse(endDateInput.text, out endDT))
}else if(!DateTime.TryParse(dateOfBirthInput.text, out dobDT) || !DateTime.TryParse(startDateInput.text, out startDT) || !DateTime.TryParse(endDateInput.text, out endDT)) // Validate that a correct date has been entered
{
return;
}
// Format a server query with the data and add the the send queue
string q_toSend = "&STAFFWR|" + idInput.text + "|" + firstNameInput.text + "|" + lastNameInput.text + "|" + dobDT.ToString("s") + "|" + startDT.ToString("s") + "|" + endDT.ToString("s") + "|" + permissionsLevelInput.text;
FindObjectOfType<Client>().instance.toSend.AddLast(q_toSend);
CloseWindow();
Expand Down
4 changes: 4 additions & 0 deletions Scripts/Admin/StockItemAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ public class StockItemAdd : MonoBehaviour
//Activated when the confirm button is pressed
public void OnConfirmButtonPress()
{
// Validate that none of the inputs are left blank
if(idInput.text == "" || nameInput.text == "" || priceInput.text == "" || typeInput.text == "")
{
Debug.LogWarning("Missing data, cannot send request");
return;
}

// Format a query for the server and add it to the send queue
string q_toSend = "&STOCKWR|" + idInput.text + "|" + nameInput.text + "|" + priceInput.text + "|" + typeInput.text;
FindObjectOfType<Client>().toSend.AddLast(q_toSend);

//Reset the input fields
idInput.text = "";
nameInput.text = "";
priceInput.text = "";
Expand Down
6 changes: 0 additions & 6 deletions Scripts/Admin/StockModifyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ void Start()
client = FindObjectOfType<Client>();
}

// Update is called once per frame
void Update()
{

}

//Run when a UI button is pressed
public void ConfirmButtonPress()
{
Expand Down
57 changes: 51 additions & 6 deletions Scripts/Databases/DatabaseManager.cs

Large diffs are not rendered by default.

43 changes: 32 additions & 11 deletions Scripts/Databases/ServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,88 +23,110 @@ void Start()
//Processes a stock lookup request
public void StockLookupRequest(ServerClient client, long id, string itemName)
{
//reads stock items from the database
//Reads stock items from the database
List<Item> data = dbManager.instance.ReadValuesInStockTable(id, itemName);
//Debug.Log("Length of data: " + data.Count);
//cycle through each item

//Cycle through each item
foreach (Item item in data)
{
//send each item to the client that requested the lookup
//Send each item to the client that requested the lookup
string toSend = "%STOCKLURT|" + item.id.ToString() + "|" + item.name + "|" + item.price.ToString() + "|" + item.type.ToString();
server.instance.ToSend.AddLast((toSend, client));
}
//send the closing statement for the request

//Send the closing statement for the request
server.instance.ToSend.AddLast(("%STOCKLURT|~END", client));
}

//Processes a category request
public void CategoryRequest(ServerClient client, int id)
{
//Reads the categories from the database
List<Category> data = dbManager.instance.ReadValuesInCategoryTable(id);

//cycle through each piece of data
foreach(Category cat in data)
{
//Send each piece of data to the client that requested the lookup
string catColour = UnityEngine.ColorUtility.ToHtmlStringRGBA(cat.categoryColour);
string toSend = "%CATEGORYRT|" + cat.categoryID + "|" + cat.categoryName + "|" + catColour;
server.instance.ToSend.AddLast((toSend, client));
}

//Send the closing statement for the request
server.instance.ToSend.AddLast(("%CATEGORYRT|~END", client));
}

//Processes a category item request
public void CategoryItemRequest(ServerClient client, int id)
{
//Reads the category items from the database
List<KeyValuePair<long, int>> data = dbManager.instance.ReadValuesInCategoryItemTable(id); //ID, Pos

//Cycle through each piece of data
foreach(KeyValuePair<long, int> kvp in data)
{
//Send each piece of data to the client that requested the lookup
string toSend = "%CATEGORYITEMRT|" + kvp.Key.ToString() + "|" + kvp.Value.ToString();
server.instance.ToSend.AddLast((toSend, client));
}

//Send the closing statement for the request
server.instance.ToSend.AddLast(("%CATEGORYITEMRT|~END", client));
}

//Processes a request for category item data
public void CategoryItemDataRequest(ServerClient client, long id)
{
//Reads the category items from the database
List<Item> data = dbManager.instance.ReadValuesInStockTable(id, "");

//Cycle through each piece of data
foreach(Item item in data)
{
//Send each piece of data to the client that requested the lookup
string toSend = "%CATEGORYITEMNAMERT|" + item.id + "|" + item.name + "|" + item.price + "|" + item.type;
server.instance.ToSend.AddLast((toSend, client));
}
//server.instance.toSend.AddLast(("%CATEGORYITEMNAMERT|~END", client));

}

//Processes a staff login request
public void StaffLoginRequest(ServerClient client, int staffID)
{
//Reads the category items from the database
List<StaffMember> data = dbManager.instance.ReadStaffMembersInTable(staffID, "", "");
foreach(StaffMember sm in data)

//Cycle through each piece of data
foreach (StaffMember sm in data)
{
//Send each piece of data to the client that requested the lookup
string toSend = "%STAFFLOGINRT|" + sm.staffID.ToString() + "|" + sm.lastName + "|" + sm.firstName + "|" + sm.dateOfBirth + "|" + sm.startDate + "|" + sm.endDate + "|" + sm.permissionLevel.ToString();
server.instance.ToSend.AddLast((toSend, client));
}

//Send the closing statement for the request
server.instance.ToSend.AddLast(("%STAFFLOGINRT|~END", client));
}

//Processes a transaction write request
public void WriteTransactionData(ServerClient client, Transaction transToAdd)
{
dbManager.instance.InsertValuesIntoTransTable(transToAdd.transactionID, transToAdd.transactionDateTime, transToAdd.transactionAmount, transToAdd.paymentType, transToAdd.staffID);
//server.instance.toSend.AddLast(("%TRANSACTIONWRITERT|~COMPLETE", client));
}

//Processes a transaction item write request
public void WriteTransactionItemData(ServerClient client, long transId, long itemID, int quantity, float itemPrice)
{
dbManager.instance.InsertValuesIntoTransItemTable(transId, itemID, quantity, itemPrice);
//server.instance.toSend.AddLast(("%TRANSACTIONWRITERT|~COMPLETE", client));
}

//Processes an authorising staff member request
public void AuthStaffMemberData(ServerClient client, int idToSearch)
{
//Reads the category items from the database
List<StaffMember> data = dbManager.instance.ReadStaffMembersInTable(idToSearch, "", "");

//Send the data to the client that requested the lookup
string toSend = "%AUTHSTAFFRT|" + data[0].staffID.ToString() + "|" + data[0].lastName + "|" + data[0].firstName + "|" + data[0].dateOfBirth + "|" + data[0].startDate + "|" + data[0].endDate + "|" + data[0].permissionLevel.ToString();
server.instance.ToSend.AddLast((toSend, client));
}
Expand All @@ -113,7 +135,6 @@ public void AuthStaffMemberData(ServerClient client, int idToSearch)
public void WriteStockItem(ServerClient client, long id, string name, float price, int type)
{
dbManager.instance.InsertValueIntoStockTable(id, name, price, type);

}

//Processes a write staff member request
Expand Down
1 change: 0 additions & 1 deletion Scripts/Till Functions/ClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void CalculateSubTotal()
{
orderSubTotal += kvp.Key.price * kvp.Value;
}
//orderSubTotal = (float)(System.Math.Round(orderSubTotal, 3));
subTotalText.text = "Sub-Total: £" + orderSubTotal.ToString("0.00");
}

Expand Down
1 change: 0 additions & 1 deletion Scripts/Till Functions/OrderButtonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void UpdateButton()
if(clientController.instance.selectedItem == item)
{
gameObject.GetComponent<Image>().color = new Color(210, 210, 210);
//gameObject.GetComponent<Button>().Select();
}
else
{
Expand Down
5 changes: 0 additions & 5 deletions Scripts/Till Functions/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void CompleteTransaction()
string toSend_transactionItem = "&TRANSACTIONITEMDBWR|" + transactionToSend.transactionID.ToString() + "|" + item.Item1.id.ToString() + "|" + item.Item2.ToString() + "|" + item.Item1.price.ToString();
client.instance.toSend.AddLast(toSend_transactionItem);
}
//Debug.Log("Transaction details sent to server");
ClosePaymentScreen();
ageVerificationPanel.SetActive(false);
clientController.itemsInOrder.Clear();
Expand All @@ -120,16 +119,12 @@ Transaction GetTransactionDetails()
{
Transaction transDetails;
string transID = "";
//transID = Encoding.Default.GetBytes(clientController.instance.tillName.ToCharArray())[0].ToString() + clientController.instance.transactionNumber;
//for(int i = 0; i < clientController.instance.tillName.Length; i++)
for(int i = 0; i < clientController.instance.tillName.Length && i < 11; i++)
{
transID += Encoding.Default.GetBytes(clientController.instance.tillName.ToCharArray())[i].ToString();
}
transID += DateTime.Now.DayOfYear.ToString() + DateTime.Now.Year.ToString();
transID += clientController.instance.transactionNumber;
//Debug.Log(transID);
//transID = transID.Substring(transID.Length - 9, 8);
if(transID.Length > 18)
{
transID = transID.Substring(transID.Length - 17, transID.Length - 1);
Expand Down
1 change: 0 additions & 1 deletion Scripts/Till Functions/SaveLoadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public SaveData GetDataToSave()
};
if (clientController != null)
{
//Debug.Log("Transaciton Number retrieved");
data.transactionNumber = clientController.transactionNumber;
}
else
Expand Down
1 change: 0 additions & 1 deletion Scripts/Till Functions/StockLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public void RemoveSLUButtons()
return;
}
while(activeSLUButtons.Count > 0)
//foreach(GameObject go in activeSLUButtons)
{
Destroy(activeSLUButtons[0].gameObject);
activeSLUButtons.Remove(activeSLUButtons[0]);
Expand Down

0 comments on commit 8131d38

Please sign in to comment.