private static void CreateSecondScreen() { foodObjects = InitFoodObject(); // Create an array of food objects and set it equal to the function initFood cashierScreen = BuildSelectionOptions(foodObjects); // Start to build the GUI using the foodObjects array cashierScreen.InitializeComponent(); cashierScreen.Show(); //Application.Run(cashierScreen); // Run the cashier screen }
static Cashier BuildSelectionOptions(FoodObject[] foodObjects) { Cashier cashierScreen = new Cashier(); const int Y_ITEM_SEPARATION = 120; const int X_ITEM_SEPARATION = 300; const int BUTTON_PICTURE_SEPARATION = 110; const int GROUP_BOX_X_INITIAL = 40; const int GROUP_BOX_Y_INITIAL = 80; const int X_INITIAL_POSITION = 10; const int Y_INITIAL_POSITION = 20; const int Y_LABEL_SEPARATION = 40; int saladStartingX = 0; int saladStartingY = 0; int drinkStartingX = 0; int drinkStartingY = 0; int dessertStartingX = 0; int dessertStartingY = 0; int numOfSalads = 0; int numOfDrinks = 0; int numOfDesserts = 0; for (int i = 0; i < 3; i++) { const int GROUP_BOX_X_SIZE = 230; const int GROUP_BOX_Y_PER_ITEM = X_INITIAL_POSITION + 100 + 15; switch (i) { case 0: { int sizeY = (GROUP_BOX_Y_PER_ITEM * saladCount) + (Y_LABEL_SEPARATION * 3); int sizeX = GROUP_BOX_X_SIZE; int xPos = GROUP_BOX_X_INITIAL; int yPos = GROUP_BOX_Y_INITIAL; cashierScreen.addGroupBoxes(xPos, yPos, "Salads", i, sizeX, sizeY); break; } case 1: { int sizeY = (GROUP_BOX_Y_PER_ITEM * drinkCount) + (Y_LABEL_SEPARATION * 3); int sizeX = GROUP_BOX_X_SIZE; int xPos = GROUP_BOX_X_INITIAL + X_ITEM_SEPARATION; int yPos = GROUP_BOX_Y_INITIAL; cashierScreen.addGroupBoxes(xPos, yPos, "Drinks", i, sizeX, sizeY); break; } case 2: { int sizeY = (GROUP_BOX_Y_PER_ITEM * dessertCount) + (Y_LABEL_SEPARATION * 3); int sizeX = GROUP_BOX_X_SIZE; int xPos = GROUP_BOX_X_INITIAL + (X_ITEM_SEPARATION * 2); int yPos = GROUP_BOX_Y_INITIAL; cashierScreen.addGroupBoxes(xPos, yPos, "Desserts", i, sizeX, sizeY); break; } } } // Create the Dynamic GroupBoxes for (int i = 0; i < foodObjects.Length; i++) { //WriteLine("Object {0} with classification {1} and name {2} is being processed", i, foodObjects[i].Classification, foodObjects[i].Name); switch (foodObjects[i].Classification) { case 1: if (numOfSalads == 0) // If this is the first salad { saladStartingX = X_INITIAL_POSITION; saladStartingY = Y_INITIAL_POSITION; } else { saladStartingY += Y_ITEM_SEPARATION; } cashierScreen.addRadioButton(saladStartingX, saladStartingY, foodObjects[i].Name, 0); cashierScreen.addPictureBox(saladStartingX + BUTTON_PICTURE_SEPARATION, saladStartingY, foodObjects[i].Name, foodObjects[i].PhotoLocation, 0); numOfSalads++; cashierScreen.IncrementCurrentItemCount(); break; case 2: if (numOfDrinks == 0) { drinkStartingX = X_INITIAL_POSITION; drinkStartingY = Y_INITIAL_POSITION; } else { drinkStartingY += Y_ITEM_SEPARATION; } cashierScreen.addRadioButton(drinkStartingX, drinkStartingY, foodObjects[i].Name, 1); cashierScreen.addPictureBox(drinkStartingX + BUTTON_PICTURE_SEPARATION, drinkStartingY, foodObjects[i].Name, foodObjects[i].PhotoLocation, 1); numOfDrinks++; break; case 3: if (numOfDesserts == 0) { dessertStartingX = X_INITIAL_POSITION; dessertStartingY = Y_INITIAL_POSITION; } else { dessertStartingY += Y_ITEM_SEPARATION; } cashierScreen.addRadioButton(dessertStartingX, dessertStartingY, foodObjects[i].Name, 2); cashierScreen.addPictureBox(dessertStartingX + BUTTON_PICTURE_SEPARATION, dessertStartingY, foodObjects[i].Name, foodObjects[i].PhotoLocation, 2); numOfDesserts++; break; default: WriteLine("ERROR: Object {0} of name {1} does not have a classification", i, foodObjects[i].Name); break; } } // Create the Dynamic RadioButtons and PictureBoxes for (int i = 0; i < 3; i++) { switch (i) { case 0: saladStartingY += Y_ITEM_SEPARATION; cashierScreen.AddPriceLabel(saladStartingX, saladStartingY, "Salad Price", 0); saladStartingY += Y_LABEL_SEPARATION; cashierScreen.AddQuantityLabel(saladStartingX, saladStartingY, "Quantity", 0); saladStartingX += BUTTON_PICTURE_SEPARATION; cashierScreen.AddQuantityTextBox(saladStartingX, saladStartingY, 0); saladStartingY -= Y_LABEL_SEPARATION; cashierScreen.AddPriceTextBox(saladStartingX, saladStartingY, 0); saladStartingX -= BUTTON_PICTURE_SEPARATION; saladStartingY += (Y_LABEL_SEPARATION * 2); cashierScreen.AddSelectionLabel(saladStartingX, saladStartingY, 0); break; case 1: drinkStartingY += Y_ITEM_SEPARATION; cashierScreen.AddPriceLabel(drinkStartingX, drinkStartingY, "Drink Price", 1); drinkStartingY += Y_LABEL_SEPARATION; cashierScreen.AddQuantityLabel(drinkStartingX, drinkStartingY, "Quantity", 1); drinkStartingX += BUTTON_PICTURE_SEPARATION; cashierScreen.AddQuantityTextBox(drinkStartingX, drinkStartingY, 1); drinkStartingY -= Y_LABEL_SEPARATION; cashierScreen.AddPriceTextBox(drinkStartingX, drinkStartingY, 1); drinkStartingX -= BUTTON_PICTURE_SEPARATION; drinkStartingY += (Y_LABEL_SEPARATION * 2); cashierScreen.AddSelectionLabel(drinkStartingX, drinkStartingY, 1); break; case 2: dessertStartingY += Y_ITEM_SEPARATION; cashierScreen.AddPriceLabel(dessertStartingX, dessertStartingY, "Salad Price", 2); dessertStartingY += Y_LABEL_SEPARATION; cashierScreen.AddQuantityLabel(dessertStartingX, dessertStartingY, "Quantity", 2); dessertStartingX += BUTTON_PICTURE_SEPARATION; cashierScreen.AddQuantityTextBox(dessertStartingX, dessertStartingY, 2); dessertStartingY -= Y_LABEL_SEPARATION; cashierScreen.AddPriceTextBox(dessertStartingX, dessertStartingY, 2); dessertStartingX -= BUTTON_PICTURE_SEPARATION; dessertStartingY += (Y_LABEL_SEPARATION * 2); cashierScreen.AddSelectionLabel(dessertStartingX, dessertStartingY, 2); break; } } // Create the Dynamic Price and quanitity Labels and TextBoxes return(cashierScreen); }