Beispiel #1
0
        //If a customer is commercial, use the specified commercial rates.
        private void CommResp(CommCustomer args, int userUsage)
        {
            //Populates the form with extra details and the total bill.
            txtFlatRate.Text      = FIXEDCOMM.ToString("c");
            txtFlatRateLimit.Text = LIMITCOMM.ToString("n");

            txtUsageRate.Text = RATECOMM.ToString("c4");
            if ((userUsage - LIMITCOMM) > 0)
            {
                txtOverLimit.Text = (userUsage - LIMITCOMM).ToString("n");
            }
            else
            {
                txtOverLimit.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);
        }
Beispiel #2
0
        //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);
        }
        public void CommCustomerWith1000()
        {
            //Arrange
            //Set up all parameters to initalize a new commercial customer.
            String       name           = "Test";
            int          accNo          = 0;
            char         cusType        = 'C';
            int          usage          = 1000;
            CommCustomer testCustomer   = new CommCustomer(name, accNo, cusType, usage);
            string       expectedCharge = "$60.00"; //Expected return value for CalculateCharge

            //Act
            testCustomer.CalculateCharge();

            //Assert
            string actualCharge = testCustomer.ToString();

            Assert.AreEqual(expectedCharge, actualCharge);
        }