//Below event of clicking Add Customer button adds customer in the list, calculates total bill amt of customer by their type, count total # of customer and calculate total bill of all customers in list
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            Customer c = null;

            if (Validator.IsProvided(txtCustName, "Customer Name") && Validator.IsProvided(txtCustName, "Account Number") && Validator.IsNonNegativeInt(txtAccountNo, "Account Number") && Validator.IsUnique(txtAccountNo, "Account#", lstCustomers))
            {
                if (rdResidential.Checked)
                {
                    c = new Residential(txtCustName.Text, Convert.ToInt32(txtAccountNo.Text), 'R'); //creating Residential customer object
                    c.CustomerCharge = c.calculateBill(int.Parse(txtKwh.Text));                     //Calculatinga a bill amt of  Residential customer
                    res += c.CustomerCharge;                                                        //Adding new bill charge of residential customer to the existing bill amount of Residential customers
                    txtResidentialType.Text = res.ToString("c");
                }
                if (rdCommercial.Checked)
                {
                    c = new Commercial(txtCustName.Text, Convert.ToInt32(txtAccountNo.Text), 'C'); // creating Commercial customer object
                    c.CustomerCharge = c.calculateBill(int.Parse(txtKwh.Text));                    //Calculatinga a bill amt of Commercial customer
                    com += c.CustomerCharge;                                                       //Adding new bill charge of Commercial customer to the existing bill amount of Commercial customers
                    txtCommercialType.Text = com.ToString("c");
                }
                if (rdIndustrial.Checked)
                {
                    c = new Industrial(txtCustName.Text, Convert.ToInt32(txtAccountNo.Text), 'I');               // creating Industrial customer object
                    c.CustomerCharge = c.calculateBill(int.Parse(txtOnPeak.Text), (int.Parse(txtOffPeak.Text))); //Calculating a bill amt of Industrial customer
                    ind += c.CustomerCharge;                                                                     //Adding new bill charge of industrial customer to the existing bill amount of industrial customers
                    txtIndutrialType.Text = ind.ToString("c");
                }
                customerList.Add(c);
                DisplayCustomers();
            }
        }
Exemple #2
0
        public void CommercialBill()    //Testing if usage is >1000 kwh for commercial customer
        {
            //arrange
            int        initial      = 2000;
            double     expectedbill = 105;
            double     actualBill;
            Commercial c; //ref of commercial class

            //act
            c          = new Commercial("Birju", 123, 'C');
            actualBill = c.calculateBill(initial, 0);  //calling the method to calculate bill for commercial customer to test actual bill against expected bill

            //assert
            Assert.AreEqual(actualBill, expectedbill);
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            //Residential Customer energy bill Calculation when residental customer radio button is selected
            if (rdResidential.Checked == true)
            {
                if (Validator.IsProvided(txtKwh, "Energy Usage") && Validator.IsNonNegativeInt(txtKwh, "Energy usage") && Validator.IsNonNegativeDbl(txtKwh, "usage"))
                {
                    Customer c            = new Residential(null, 0, '0'); //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      input        = Convert.ToInt32(txtKwh.Text);  //converting user input into integer
                    double   restotalBill = c.calculateBill(input);        //calling the function which calculates residential bill
                    txtChargeAmt.Text = restotalBill.ToString("c");        //displaying result with $ currancy
                }
            }
            //Commercial customer energy bill calculation when commercial customer radio button is selected
            if (rdCommercial.Checked == true)
            {
                if (Validator.IsProvided(txtKwh, "Energy Usage") && Validator.IsNonNegativeInt(txtKwh, "Energy usage") && Validator.IsNonNegativeDbl(txtKwh, "usage"))
                {
                    Customer c            = new Commercial(null, 0, '0'); //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      input        = Convert.ToInt32(txtKwh.Text); //converting user input into integer
                    double   comtotalBill = c.calculateBill(input);       //calling the function which calculates commercial bill
                    txtChargeAmt.Text = comtotalBill.ToString("c");       //displaying result with $ currancy
                }
            }


            //Industrial  customer energy bill calculation when indutrial customer radio button is selected
            if (rdIndustrial.Checked == true)
            {
                if (Validator.IsProvided(txtOnPeak, "Energy Usage") && Validator.IsNonNegativeInt(txtOnPeak, "Energy usage") && Validator.IsNonNegativeDbl(txtOnPeak, "Energy usage") &&
                    Validator.IsProvided(txtOffPeak, "Energy Usage") && Validator.IsNonNegativeInt(txtOffPeak, "Energy usage") && Validator.IsNonNegativeDbl(txtOffPeak, "Energy usage"))

                {
                    Customer c            = new Industrial(null, 0, '0');     //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      onpeak       = Convert.ToInt32(txtOnPeak.Text);  //converting user input into integer
                    int      offpeak      = Convert.ToInt32(txtOffPeak.Text); //converting user input into integer
                    double   indTotalBill = c.calculateBill(onpeak, offpeak); //calling the function which calculates industrial bill
                    txtChargeAmt.Text = indTotalBill.ToString("c");           //displaying result with $ currancy
                }
            }
        }