private void ResetButton_Click(object sender, EventArgs e) { //this event handler resets the windows app when clicked //and prompts the user before resetting DialogResult userAnswer; userAnswer = MessageBox.Show("Do you wish to Reset ?", "Bill Estimator", MessageBoxButtons.YesNo); switch (userAnswer) { case DialogResult.Yes: KwhTextBox1.Clear(); OffpeakKwhTextBox1.Clear(); CustomerTypecomboBox1.SelectedIndex = 0; break; case DialogResult.No: //do nothing break; default: KwhTextBox1.Clear(); CustomerTypecomboBox1.SelectedIndex = 0; break; } eraseTextField(); }
//this method clears all input into the form private void eraseTextField() { haveValidInput = true; EstimatedBillLabel.Text = "Estimated Bill: "; KwhLabel.Text = "How many Kwh?"; OffPeakKwhlabel.Visible = false; OffpeakKwhTextBox1.Visible = false; KwhTextBox1.Clear(); OffpeakKwhTextBox1.Clear(); accountNumberTextBox.Clear(); customerNameTextBox1.Clear(); }
//this event handler changes the form when the customer toggles between different customer types //industrial users have peakhours and offpeak hours //when an idustrial customer type is selected the forms toggles and dispays differently private void CustomerTypecomboBox1_SelectedIndexChanged(object sender, EventArgs e) { //when the user selects the Industrial customer type some labels and Text boxes become visible switch (CustomerTypecomboBox1.Text) { case "Industrial": KwhLabel.Text = "How many peak Kwh?"; OffPeakKwhlabel.Visible = true; OffpeakKwhTextBox1.Visible = true; break; default: KwhLabel.Text = "How many Kwh?"; OffPeakKwhlabel.Visible = false; OffpeakKwhTextBox1.Visible = false; break; } KwhTextBox1.Clear(); OffpeakKwhTextBox1.Clear(); }
private void PowerBillingSystem_Load(object sender, EventArgs e) { //open stream reader on "Customer txt" on load string pathLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string filePath = Path.Combine(pathLocation, "Customer.txt"); //this block of code checks if the "Customer.txt" exist //if the file does not exist a message box displays //the program does'nt crash if (File.Exists(filePath)) { try { StreamReader output = new StreamReader(filePath); while (!output.EndOfStream) { string lineFronline = output.ReadLine(); Customer c = new Customer(lineFronline); customerListListBox.Items.Add(c.ToFormattedString()); //add customer names to this list customerNames.Add(c.CustomerName); //the following of code calculates the summary statistics switch (c.CustomerType) { case "R": totalResidentialCustomerCharge += c.ChargeAmount; break; case "C": totalCommcercialCustomerCharge += c.ChargeAmount; break; case "I": totalIndustrialCustomerCharge += c.ChargeAmount; break; default: return; } calculateStatistics(); } output.Close(); //after loading the file , close it }catch (Exception excp) { MessageBox.Show($"File failed to load {excp.Message}"); return; } } else { MessageBox.Show("Customer.txt does not exist in the bin/Debug folder"); return; } //on loading the form application residential customer type is set as default //Focus is set to user input text box CustomerTypecomboBox1.SelectedIndex = 0; KwhTextBox1.Select(); }