private void startPauseButton_Click(object sender, EventArgs e) { //currentOrdersTextBox.Text += "button\r\n"; //As this will be start and pause button the input may not necessarily change so no need to jump through hoops to process it again if (!openCloseParsed) { //currentOrdersTextBox.Text += "starting checks\r\n"; //Gather the inputs string openTime = OpeningTimeTextBox.Text; string closeTime = closingTimeTextBox.Text; //currentOrdersTextBox.Text += "gathered string inputs\r\n"; //Check inputs and see if they can be converted into our basic time class string[] opening = openTime.Split(':'); string[] closing = closeTime.Split(':'); //currentOrdersTextBox.Text += "split them\r\n"; //First check that the split has created two strings that we can then check further if (opening.Length == 2 && closing.Length == 2) { //currentOrdersTextBox.Text += "split successful\r\n"; //Now check that we can actually convert the two strings we have into integers int openHour, openMin, closeHour, closeMin; //Doing the checks now to save the results not only because it makes telling the user exactly what went wrong a lot easier but is also tidier Boolean openHCheck = int.TryParse(opening[0], out openHour); Boolean openMCheck = int.TryParse(opening[1], out openMin); Boolean closeHCheck = int.TryParse(closing[0], out closeHour); Boolean closeMCheck = int.TryParse(closing[1], out closeMin); //Check them all if (openHCheck && openMCheck && closeHCheck && closeMCheck) { //All of them succeeded now just need to be sure that they fit into the usual constraints of hours and minutes //*IF they don't we know they are still integers so we shall continue just shift them logically using mod to get them to a correct time //* and inform the user //currentOrdersTextBox.Text += "allParseFine\r\n"; Boolean inputChange = false; //Set up start of message to user if a value is changed String userMessage = "The following values were changed to there modular equivalents as they were outside the constraints of 24 Hour Time\r\n"; if (!(openHour >= 0 && openHour < 24) || !(openMin >= 0 && openMin < 60)) { //currentOrdersTextBox.Text += "openValueChange\r\n"; //So at least one of the opening time values need to change userMessage += "Opening time has been edited from " + openHour.ToString() + ":" + openMin.ToString() + " to "; //Change them to their modular equivalents openHour = openHour % 24; openMin = openMin % 60; userMessage += openHour + ":" + openMin + "\r\n"; inputChange = true; } if (!(closeHour >= 0 && closeHour < 24) || !(closeMin >= 0 && closeMin < 60)) { //currentOrdersTextBox.Text += "closeValueChange\r\n"; //At least one of the closing values need to change userMessage += "Closing time has been edited from " + closeHour.ToString() + ":" + closeMin.ToString() + " to "; //Change them to their modular equivalents closeHour = closeHour % 24; closeMin = closeMin % 60; userMessage += closeHour + ":" + closeMin + "\r\n"; inputChange = true; } //Send off the message if anything did change if (inputChange) { String messageTitle = "Input Change"; MessageBox.Show(userMessage, messageTitle); } //I know I am putting too much detail into this one aspect of the application at this point but last check I swear //If the open and closing time are the same then that means we never close and just keep going if (openHour == closeHour && openMin == closeMin) { neverClose = true; } //Set our global variable and time etc openingTime = new time(openHour, openMin); closingTime = new time(closeHour, closeMin); openCloseParsed = true; OpeningTimeTextBox.Text = openingTime.printTime(); closingTimeTextBox.Text = closingTime.printTime(); } else { //Something didn't parse successfully.... time for a slightly arrogant error message muhahaha! String errorMessage = "The "; if (!openHCheck || !openMCheck) { //At the very least the opening input failed errorMessage += "opening time "; //Now check the closing time input to see if it failed as well if (!closeHCheck || !closeMCheck) { //Now we know both time inputs failed to parse correctly errorMessage += " and closing time inputs could not be parsed.\r\nPlease ensure they are in the format: HOUR:MINUTE"; } } else { //This means only the closing time input failed so finish the error message and continue on errorMessage += "closing time input could not be parsed.\r\nPlease ensue it is in the format: HOUR:MINUTE"; } String errorTitle = "Input Format"; MessageBox.Show(errorMessage, errorTitle); } } else { //Can't explain it but am suddenly emjoying making informative error messages String errorMessage = "Please ensure your Opening Time and Closing Time inputs \r\nare seperated by a single ':'"; String errorTitle = "Input Format"; MessageBox.Show(errorMessage, errorTitle); } } //currentOrdersTextBox.Text += "Checked time inputs \r\n"; ////Get timing for sleep thing down to a nice thing and have it //for (int i = 0; i < 10; i++) //{ // currentOrdersTextBox.Text += "simSpeed = " + simSpeed.ToString(); // currentOrdersTextBox.Refresh(); // double sleepTime = 1000 / simSpeed; // int minuteTime = (int) Math.Round(sleepTime); // System.Threading.Thread.Sleep(minuteTime); //} //Set the current time **NEED to check if this restarting after a pause if (currentTime.getHour() == -1) { //This means that is a fresh start and so currentTime = new time(openingTime.getHour(), openingTime.getMinute()); } //Ok now to start randomly creating orders.... i've made this much more complex than it needed to be haha //if(neverClose) if (false) { //We never need to stop.... oh my //currentOrdersTextBox.Text += "I WILL NEVER SURRENDER"; } else { // currentOrdersTextBox.Text += "closing time equivalent: " + closingTime.getIntEquivalent().ToString() + "\r\n"; //The loop that makes every minute go by for (int i = currentTime.getIntEquivalent(); (i != closingTime.getIntEquivalent() && !notAcceptingOrders) || currentOrders.Count != 0; i++) { //Display the currentTime to the usr currentTimeTextBox.Text = currentTime.printTime(); currentTimeTextBox.Refresh(); //If we're no longer accepting orders we can skip all this stuff that creates orders if (!notAcceptingOrders) { //currentOrdersTextBox.Text += "-- Still Creating --"; //Decide how many orders are coming in at this minute NOTE- not really realistic..... SURPRISE! Random numberGenerator = new Random(); //I think zero to three orders could be fine for a reasonably busy place wouldn't be this consistent but oh well haha int numOrders = numberGenerator.Next(0, 4); //This is 0 to 3 because for some reason the first value is inclusive and the second is not... not sure why it's done that way haha int orderAmount = 0; int menuSelect; double totalCost = 0.0; //Just creating these variables here so I can print them without issue as the next two for loops are not code guaranteed to run //Now we have our number of orders we need to actually generate them and do necessary calculations to complete them for (int j = 0; j < numOrders; j++) { //the number of things for that order - 1 to 4 is just out of the air orderAmount = numberGenerator.Next(1, 5); //New order so reset things we calculated for the last one totalCost = 0.0; int longestItemTime = 0; List <string> orderContents = new List <string> { }; for (int k = 0; k < orderAmount; k++) { menuSelect = numberGenerator.Next(0, 10); totalCost += menu[menuSelect].getCost(); //Calculate the time will be longest item in order + 1 minute for everything else in the order //A vague attempt to show that things can be done at the same time but more items still adds more time if (menu[menuSelect].getTimeToMake() > longestItemTime) { longestItemTime = menu[menuSelect].getTimeToMake(); } //Collect the string of what the order will contain orderContents.Add(menu[menuSelect].getName()); } //Final bit of time calculation longestItemTime += orderAmount - 1; orderNumber++; time orderTime = new time(currentTime.getHour(), currentTime.getMinute()); time orderTimeComplete = currentTime.addMinutes(longestItemTime, currentTime); //Create the order with the info we've gathered order addition = new order(orderTime, orderTimeComplete, totalCost, longestItemTime, orderNumber, orderContents); //Print off because chances are something's gone wrong haha currentOrdersTextBox.Text += addition.print() + "\r\n"; //Add the order to the current list of orders and that's the end of the creation side of this stuff.... WOW this is now a mess haha currentOrders.Add(addition); } } //ACTUAL SIMULATION BIT //Ok check if any of the current orders are finished if they are move them to print in the completed text box for (int j = 0; j < currentOrders.Count; j++) { if ((currentOrders[j].getFinishTime().getIntEquivalent()) == currentTime.getIntEquivalent()) { //The order is finished so print, then remove from the list CompletedOrdersTextBox.Text += currentOrders[j].print() + "\r\n"; currentOrders.RemoveAt(j); //Current text box also needs updating ** BETTER WAY OF DOING THIS, will do for now but could be much better currentOrdersTextBox.Clear(); if (currentOrders.Count > 0) { for (int k = 0; k < currentOrders.Count; k++) { currentOrdersTextBox.Text += currentOrders[k].print() + "\r\n"; } } //Because we've just removed an entry we must now also reduce our index counter to make sure we don't skip an entry j--; //Must refresh the textbox aswell otherwise it doesn't update until the enitire loop is finished which may be a while CompletedOrdersTextBox.Refresh(); } } //Check this works as intended //currentOrdersTextBox.Text += "i= " + i.ToString() + "\tCT= " + currentTime.printTime() + "\tNO= " + numOrders.ToString() + " " //+ orderAmount.ToString() + " " + totalCost.ToString() + "\r\n"; //To create the cyclic nature for our little integer if (i % 100 == 60) { //This is to fix the 100 to 60 minute thing i += 40; //If because of this we're at 2400 then the day is done and we go back to zero if (i == 2400) { i = 0; } } //Same for the time variable currentTime.tick(); //Sleep for a bit so it doesn't just zoom past and the random generator seems to give repeats if the program runs too fast double sleepTime = 1000 / simSpeed; int minuteTime = (int)Math.Round(sleepTime); System.Threading.Thread.Sleep(minuteTime); currentOrdersTextBox.Refresh(); //CompletedOrdersTextBox.Text += "Checking " + i.ToString() + " and " + closingTime.getIntEquivalent().ToString() + "\r\n"; //Clock just ticked if we are now closed we need need to stop accepting orders if (i == closingTime.getIntEquivalent()) { notAcceptingOrders = true; //currentOrdersTextBox.Text += "\r\nNO MORE ORDERS\r\nNumber of Orders processed" + orderNumber.ToString(); } if (notAcceptingOrders && currentOrders.Count < 1) { break; } } //currentOrdersTextBox.Text += "\r\n Made OutSide Simulation Loop"; } }