using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace HCI_Coursework_EVCHARGE { public partial class ChargingDetails : Form { Pinpad pinpad; String vehicle; String duration; String bayNo; public ChargingDetails( int bayNo ) { this.bayNo = bayNo.ToString(); InitializeComponent(); bayLabel.Text = "Bay " + this.bayNo; } public String[] getCarInfo( String vehicleType ) { String[] max = {"",""}; switch (vehicleType) { case "car": max[0] = ("7"); max[1] = ("8"); break; case "e-bike": max[0] = ("0.9"); max[1] = ("2"); break; case "e-scooter": max[0] = ("0.25"); max[1] = ("1"); break; } return max; } private void vehicleButton_Click( object sender, EventArgs e) { if ( sender is Button button) { carButton.BackColor = SystemColors.ActiveBorder; bikeButton.BackColor = SystemColors.ActiveBorder; scooterButton.BackColor = SystemColors.ActiveBorder; vehicle = button.Text.ToLower(); String[] maxArr = getCarInfo(vehicle); Console.WriteLine(maxArr[0], maxArr[1]); if ( maxArr.Length > 0 ) { powerLabel.Text = $"{maxArr[0]} kW"; durationLabel.Text = $"{maxArr[1]} hours"; } button.BackColor = SystemColors.ControlDark; infoPanel.Visible = true; System.Threading.Thread.Sleep(100); } } private void backButton_Click(object sender, EventArgs e) { pinpad?.Close(); Close(); } private void confirmButton_Click(object sender, EventArgs e) { pinpad?.Close(); String maxDuration = getCarInfo(vehicle)[1]; if (Convert.ToInt16(textBox1.Text) > Convert.ToInt16(maxDuration)) { MessageBox.Show($"Duration must be less than {maxDuration} hours."); } else { duration = textBox1.Text; DialogResult confirm = MessageBox.Show($"Are you sure these details are correct?\nVehicle: {vehicle}\nDuration: {duration} hours?", "Confirm:", MessageBoxButtons.YesNo); if (confirm == DialogResult.Yes) { Payment payment = new Payment(bayNo, vehicle, duration); payment.Show(); payment.FormClosed += delegate { payment = null; }; } } } private void accountPin_Focus(object sender, EventArgs e) { TextBox textBox = (TextBox)sender; if (pinpad == null) { pinpad = new Pinpad(); pinpad.FormClosed += delegate { if( textBox.Text != null ) { confirmPanel.Visible = true; } pinpad = null; this.ActiveControl = label1; }; } pinpad.setTextBox(textBox); pinpad.Show(); pinpad.Top = this.Top + textBox.Top + textBox.Height - 250; } } }