//Method for calculating total bill on click of the "Calculate" button. private void BtnCalculateCost_Click(object sender, EventArgs e) { if (formValidator.IsNotEmpty(txtUsage, "Power usage") && formValidator.IsNumber(txtUsage, "Power usage") && formValidator.IsNotEmpty(txtCusName, "Customer Name") && formValidator.IsNotEmpty(txtAccNo, "Account No.")) { //Declares a variable to store user inputs. String cusName = txtCusName.Text; int accNo = Convert.ToInt32(txtAccNo.Text); int userUsage = Convert.ToInt32(txtUsage.Text); int offUsage; //Switch to handle form response depending on customer type. switch (comboCusType.SelectedItem) { case "Residential": ResCustomer testCusR = new ResCustomer(cusName, accNo, 'R', userUsage); //Declares a dummy customer to use for the form. ResResp(testCusR); break; case "Commercial": CommCustomer testCusC = new CommCustomer(cusName, accNo, 'C', userUsage); //Declares a dummy customer to use for the form. CommResp(testCusC, userUsage); break; case "Industrial": if (formValidator.IsNotEmpty(txtUsageOff, "Power usage") && formValidator.IsNumber(txtUsageOff, "Power usage")) { offUsage = Convert.ToInt32(txtUsageOff.Text); IndusCustomer testCusI = new IndusCustomer(cusName, accNo, 'I', userUsage, offUsage); IndusResp(testCusI, userUsage, offUsage); } break; } } //Updates the statistics regarding the customers. calcStats(currentCus); }
private void IndusResp(IndusCustomer args, int userUsage, int offUsage) { //Populates the form with extra details and the total bill. txtFlatRate.Text = FIXEDINDUSPEAK.ToString("c"); txtFlatRateLimit.Text = LIMITINDUSPEAK.ToString("n"); txtUsageRate.Text = RATEINDUSPEAK.ToString("c4"); //Checks to see if the customer has used more than their metered limit for peak hours. Same algorithm/logic as commerical case. if ((userUsage - LIMITINDUSPEAK) > 0) { txtOverLimit.Text = (userUsage - LIMITINDUSPEAK).ToString("n"); } else { txtOverLimit.Text = "N/A"; txtUsageCost.Text = "N/A"; } txtFlatRateOff.Text = FIXEDINDUSOFF.ToString("c"); txtFlatRateLimitOff.Text = LIMITINDUSOFF.ToString("n"); txtUsageRateOff.Text = RATEINDUSOFF.ToString("c4"); //Repeats the above method for the off-peak hours. if ((offUsage - LIMITINDUSOFF) > 0) { txtOverLimitOff.Text = (offUsage - LIMITINDUSOFF).ToString("n"); } else { txtOverLimitOff.Text = "N/A"; txtUsageCostOff.Text = "N/A"; } //Use the calculateCharge method and ToString method to return metered cost. args.CalculateCharge(); txtTotalCost.Text = args.ToString(); //Shows the user their total bill. //Write customer data to a local .txt file. String cusData = $"{args.CusName}|{args.AccNo}|{args.CusType}|{args.ToString()}"; ReadWrite.recordCustomer(cusData); /*Adds the new customer's data to the dataGridView. * Makes it so that the dataGridView does not need to be reinitialized every time.*/ addToDataGrid(args.CusName, args.AccNo, args.CusType, args.ToString()); //Adds the new customer to the list of Customer objects being accessed by the form. currentCus.Add(args); }
//Method to test if industiral customer class calculates properly on a peak usage of 2000 kWh and an off-peak usage of 2000 kWh. public void IndusCustomerWith2000And2000() { //Arrange //Set up all parameters to initalize a new industrial customer. String name = "Test"; int accNo = 0; char cusType = 'I'; int usage = 2000; int offUsage = 2000; IndusCustomer testCustomer = new IndusCustomer(name, accNo, cusType, usage, offUsage); string expectedCharge = "$209.00"; //Expected return value for CalculateCharge //Act testCustomer.CalculateCharge(); //Assert string actualCharge = testCustomer.ToString(); Assert.AreEqual(expectedCharge, actualCharge); }