示例#1
0
        /// <summary>
        /// Pump Timer Elapsed Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>y
        private void pumpTimer_Tick(object sender, EventArgs e)
        {
            // Create a timer variable and cast the object sender to a timer
            Timer activeTimer = ((Timer)sender);

            // Create a string that holds the tag of the btn that was clicked
            string activePump = (string)activeTimer.Tag;

            // Stop the timer for that event
            activeTimer.Stop();

            // Switch statement to decide what fuel to dispense
            switch ((string)activeTimer.Tag)
            {
            case "pumpOne":
                Pump.DispenseFuel(vehOnPumpOne[1], vehOnPumpOne[2]);

                // Re-enable pumpTwo and pumpThree
                btnPumpTwo.Enabled   = true;
                btnPumpThree.Enabled = true;

                // Reset text
                btnPumpTwo.Text   = "Available";
                btnPumpThree.Text = "Available";
                break;

            case "pumpTwo":
                Pump.DispenseFuel(vehOnPumpTwo[1], vehOnPumpTwo[2]);
                // Enable pumpThree
                btnPumpThree.Enabled = true;
                btnPumpThree.Text    = "Available";
                break;

            case "pumpThree":
                Pump.DispenseFuel(vehOnPumpThree[1], vehOnPumpThree[2]);
                break;

            case "pumpFour":
                Pump.DispenseFuel(vehOnPumpFour[1], vehOnPumpFour[2]);
                // Enable pumpFive and pumpSix
                btnPumpFive.Enabled = true;
                btnPumpSix.Enabled  = true;

                btnPumpFive.Text = "Available";
                btnPumpSix.Text  = "Available";
                break;

            case "pumpFive":
                Pump.DispenseFuel(vehOnPumpFive[1], vehOnPumpFive[2]);
                // Enable pumpSix
                btnPumpSix.Enabled = true;

                btnPumpSix.Text = "Available";
                break;

            case "pumpSix":
                Pump.DispenseFuel(vehOnPumpSix[1], vehOnPumpSix[2]);
                break;

            case "pumpSeven":
                Pump.DispenseFuel(vehOnPumpSeven[1], vehOnPumpSeven[2]);
                // Enable pumpEight and pumpNine
                btnPumpEight.Enabled = true;
                btnPumpNine.Enabled  = true;

                btnPumpEight.Text = "Available";
                btnPumpNine.Text  = "Available";
                break;

            case "pumpEight":
                Pump.DispenseFuel(vehOnPumpEight[1], vehOnPumpEight[2]);
                // Enable pumpNine
                btnPumpNine.Enabled = true;
                btnPumpNine.Text    = "Available";
                break;

            case "pumpNine":
                Pump.DispenseFuel(vehOnPumpNine[1], vehOnPumpNine[2]);
                break;
            }

            // Writes the type of vehicle, fuel and which pump it was fulled at
            log.CreateStatusLog(vehToBeServiced[0], vehToBeServiced[1], vehToBeServiced[2], (string)activeTimer.Tag, true);
            log.CreateFuellingLog(vehToBeServiced[1], Pump.litresDispensedThisTransaction, (string)activeTimer.Tag);

            // Switch of activePump
            switch (activePump)
            {
            case "pumpOne":
                btnPumpOne.Text = "Available";
                break;

            case "pumpTwo":
                btnPumpTwo.Text = "Available";
                break;

            case "pumpThree":
                btnPumpThree.Text = "Available";
                break;

            case "pumpFour":
                btnPumpFour.Text = "Available";
                break;

            case "pumpFive":
                btnPumpFive.Text = "Available";
                break;

            case "pumpSix":
                btnPumpSix.Text = "Available";
                break;

            case "pumpSeven":
                btnPumpSeven.Text = "Available";
                break;

            case "pumpEight":
                btnPumpEight.Text = "Available";
                break;

            case "pumpNine":
                btnPumpNine.Text = "Available";
                break;
            }

            // Increment the vehicleServiced variable
            vehServiced++;

            // Strings printed with $ according to Docs.microsoft.com (2017)

            lblPetrolDispensed.Text = $"Litres Dispensed: {Pump.petrolLitresDispensed}";
            lblDieselDispensed.Text = $"Litres Dispensed: {Pump.dieselLitresDispensed}";
            lblLpgDispensed.Text    = $"Litres Dispensed: {Pump.lpgLitresDispensed}";
            lblTakings.Text         = $"Total Takings: {Pump.totalTakings}";
            // Refresh the display
            DisplayRefresh();
        }
示例#2
0
        /// <summary>
        /// Starts the set timer, based on what button was clicked
        /// </summary>
        /// <param name="activeButton">From btnClick - the button that was clicked</param>
        private void startTimer(Button activeButton)
        {
            // Set the activeTimer variable to a string cast of the active button tag
            string activeTimer = (string)activeButton.Tag;

            // Switch to decide what timer to start
            switch (activeTimer)
            {
            // If the tag is pumpOne etc, then do the following code;
            case "pumpOne":
                // Start the timer
                pumpOneTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpOne[1]);
                pumpOneTimer.Start();
                // Print to console which timer has been started
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpTwo":
                pumpTwoTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpTwo[1]);
                pumpTwoTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpThree":
                pumpThreeTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpThree[1]);
                pumpThreeTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpFour":
                pumpFourTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpFour[1]);
                pumpFourTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpFive":
                pumpFiveTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpFive[1]);
                pumpFiveTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpSix":
                pumpSixTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpSix[1]);
                pumpSixTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpSeven":
                pumpSevenTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpSeven[1]);
                pumpSevenTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpEight":
                pumpEightTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpEight[1]);
                pumpEightTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;

            case "pumpNine":
                pumpNineTimer.Interval = (int)Pump.GenerateInterval(vehOnPumpNine[1]);
                pumpNineTimer.Start();
                Console.WriteLine($"{activeTimer} started");
                break;
            }
        }