Пример #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // various validation
            // if OK, pass info back to the parent and close
            // if not ok wait for them to fix the issues
            if (Validator.IsPresent(txtCustName, "Customer Name") &&
                Validator.CSVFriendly(txtCustName, "Customer Name") &&
                Validator.IsNonNegativeInt32(txtCustAcct, "Account Number") &&
                Validator.IsSelected(cmbCustType, "Customer Type"))
            {
                Object newCust;
                switch (cmbCustType.SelectedIndex)
                {
                case 0:
                    newCust = new ResidentialCustomer(txtCustName.Text, Convert.ToInt32(txtCustAcct.Text));
                    break;

                case 1:
                    newCust = new CommercialCustomer(txtCustName.Text, Convert.ToInt32(txtCustAcct.Text));
                    break;

                case 2:
                    newCust = new IndustrialCustomer(txtCustName.Text, Convert.ToInt32(txtCustAcct.Text));
                    break;

                default:
                    newCust = null;
                    break;
                }
                this.Tag = newCust;
                this.Close();
            }
        }
Пример #2
0
        public void CalculateCharge_Resprice_Not_Null()
        {
            //arrange
            ResidentialCustomer charge = new ResidentialCustomer();

            decimal res_price = 6.00m;

            //assert
            Assert.IsNotNull(res_price);
        }
        public void CalculateChargeTest()
        { // Test of normal input, kWh amount greater than the base charge
            ResidentialCustomer cust = new ResidentialCustomer("Test", 12345);
            int     kWh            = 2000;
            decimal expectedCharge = 110m;
            decimal actualCharge;

            actualCharge = cust.CalculateCharge(kWh);

            Assert.AreEqual(expectedCharge, actualCharge);
        }
Пример #4
0
        public void CalculateCharge_Respriceo_And_Resprice_NotEqual()
        {
            //arrange
            ResidentialCustomer charge = new ResidentialCustomer();

            decimal res_price  = 6.00m;
            decimal res_priceo = 0.052m;

            //assert
            Assert.AreNotEqual(res_price, res_priceo);
        }
Пример #5
0
        public void CalculateChargeWithZeroUsage()
        {
            // Arrange
            int    usage          = 0;
            double expectedCharge = 6;
            double actualCharge;

            // Act
            actualCharge = ResidentialCustomer.CalculateCharge(usage);
            // Assert
            Assert.AreEqual(expectedCharge, actualCharge);
        }
Пример #6
0
        public void CalculateChargeTest_PEAKRatioNotEqualToOffPEAKRatio()
        {
            //arrange
            ResidentialCustomer charge = new ResidentialCustomer();

            const decimal IND_PEAKPRICE     = 76.00m;
            const decimal IND_PEAKPRICEO    = 0.065m;
            const decimal IND_OFFPEAKPRICE  = 40.00m;
            const decimal IND_OFFPEAKPRICEO = 0.028m;

            //assert
            Assert.AreNotEqual(IND_PEAKPRICEO, IND_OFFPEAKPRICEO);
        }
Пример #7
0
        public void CalculateChargeTest_PEAKNotTheSameAsOffPEAK()
        {
            //arrange
            ResidentialCustomer charge = new ResidentialCustomer();

            const decimal IND_PEAKPRICE     = 76.00m;
            const decimal IND_PEAKPRICEO    = 0.065m;
            const decimal IND_OFFPEAKPRICE  = 40.00m;
            const decimal IND_OFFPEAKPRICEO = 0.028m;

            //assert
            Assert.AreNotSame(IND_OFFPEAKPRICE, IND_PEAKPRICE);
        }
        public void CalculateChargeTest1()
        {   // Test of abnormal input
            // validation should save the method from seeing a negative number, but if it does get there somehow,
            // it's expected to treat it as a zero and only charge the base amount
            ResidentialCustomer cust = new ResidentialCustomer("Test", 12345);
            int     kWh            = -2000;
            decimal expectedCharge = 6m;
            decimal actualCharge;

            actualCharge = cust.CalculateCharge(kWh);

            Assert.AreEqual(expectedCharge, actualCharge);
        }
Пример #9
0
        // testing that zero value is being added for KWH2 for residential calculations
        public void ResidentialKWH2ZeroValue()
        {
            int     acctnum           = 1111;
            string  custName          = "John Doe";
            char    custType          = 'R';
            decimal expectedkwh2value = 0;
            decimal kwhvalue          = 1500;
            decimal kwhvalue2         = 0;

            Customer calc = new ResidentialCustomer(acctnum, custName, custType, kwhvalue, kwhvalue2);

            Assert.AreEqual(expectedkwh2value, kwhvalue2);
        }
Пример #10
0
        public void ResidentialCustomerTestCheckForInvalidArguments2()
        {
            //Arrange
            int    number               = 1234;
            string name                 = "Kingsley";
            string type                 = "R";
            ResidentialCustomer c       = new ResidentialCustomer(number, name, type);
            decimal             khwused = -30M;
            decimal             expectedChargeAmount = 6M + (0.052M * khwused);
            //act
            decimal returnedChargeAmount = c.CalculateCharge(khwused);

            //Assert
            Assert.Fail();
        }
        public void CalculateChargeMoreThanZero()
        {
            //arrange
            decimal             resBase             = 6m;
            decimal             unitRate            = 0.052m;
            decimal             energyUsed          = 100;
            decimal             expectedCharge      = 11.2m;
            decimal             actualCharge        = 0;
            ResidentialCustomer residentialCustomer = new ResidentialCustomer(1, "john", "R", actualCharge);

            //act
            actualCharge = residentialCustomer.CalculateCharge(resBase, unitRate, energyUsed);

            //assert
            Assert.AreEqual(expectedCharge, actualCharge);
        }
Пример #12
0
        // Calculate Button Clicked: do validation, do calculation based on user type, show result(s)
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            // if not industrial user (residential or commercial), after validation, extract input, do calculation, show result
            if (!radIndustrial.Checked)
            {
                if (Validator.TBHasNonNegativeInt(txtUsage, "Usage"))
                {  // validation passed, extract input
                    int usage = Convert.ToInt32(txtUsage.Text);

                    // if residential user, use residential method
                    if (radResidential.Checked)
                    {
                        totalAmt = ResidentialCustomer.CalculateCharge(usage);
                    }
                    // if commercial user, use commercial method
                    else if (radCommercial.Checked)
                    {
                        totalAmt = CommercialCustomer.CalculateCharge(usage);
                    }

                    // do output
                    txtTotal.Text = totalAmt.ToString("c");
                    txtUsage.SelectAll();  // select all for easy next entry
                }
            }
            // if industrial user, after validation, extract inputs, do calculation, show results
            else
            {
                if (Validator.TBHasNonNegativeInt(txtPeakUsage, "Peak Hour Usage") && Validator.TBHasNonNegativeInt(txtOPUsage, "Off Peak Usage"))
                {  // validation passed, extract inputs
                    int peakUsage = Convert.ToInt32(txtPeakUsage.Text);
                    int opUsage   = Convert.ToInt32(txtOPUsage.Text);

                    totalAmt = IndustrialCustomer.CalculateCharge(peakUsage, opUsage);  // calculate use industrial method

                    // output peak & offpeak & total amount separately
                    grpForIndusAmt.Visible = true;
                    txtPeakCharge.Text     = IndustrialCustomer.peakAmt.ToString("c");
                    txtOPCharge.Text       = IndustrialCustomer.opAmt.ToString("c");
                    txtTotal.Text          = totalAmt.ToString("c");

                    // select all text for easy next entry
                    txtPeakUsage.Focus();
                    txtPeakUsage.SelectAll();
                }
            }
        }
        //Adds customer to the listBox
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            //local variables
            int      accountNo    = 0;
            string   customerName = "";
            string   customerType = "";
            decimal  chargeAmount;
            Customer customer;

            if (Validator.IsPresent(txtAccountNo, "Account No") && Validator.IsNonNegativeInt32(txtAccountNo, "Account No") &&
                Validator.IsPresent(txtCustomerName, "Customer Name") &&
                Validator.IsPresent(txtAmount, "Charge Amount"))
            {
                accountNo    = Convert.ToInt32(txtAccountNo.Text);
                customerName = txtCustomerName.Text;
                chargeAmount = Convert.ToDecimal(txtAmount.Text.Remove(0, 1));

                if (radResidential.Checked)
                {
                    customerType = "R";
                    customer     = new ResidentialCustomer(accountNo, customerName, customerType, chargeAmount);
                }
                else if (radCommercial.Checked)
                {
                    customerType = "C";
                    customer     = new CommercialCustomer(accountNo, customerName, customerType, chargeAmount);
                }
                else
                {
                    customerType = "I";
                    customer     = new IndustrialCustomer(accountNo, customerName, customerType, chargeAmount);
                }
                AddToList(customer);
                DisplayCustomers();
                Statistics();
            }
        }
        // When calculate button is clicked
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            // local variables
            decimal chargeAmount = 0;
            int     accountNo    = 0;
            string  customerName = "";

            //inistializes new customer;
            Customer customer;


            if (Validator.IsPresent(txtAccountNo, "Account No") && Validator.IsNonNegativeInt32(txtAccountNo, "Account No") &&
                Validator.IsPresent(txtCustomerName, "Customer Name"))
            {
                accountNo    = Convert.ToInt32(txtAccountNo.Text);
                customerName = txtCustomerName.Text;
            }

            /* if residential or commercial customer type radio buttons are checked this if statement runs.
             * Since residential and commercial both use the same energy used field, they are both wrapped in one if statement
             * */

            if (radResidential.Checked || radCommercial.Checked)
            {
                //validates if the field (Energy used) contains a value and then validates that the value is a positive whole number.
                //takes the input from energy used textBox and stores it in a decimal variable
                if (Validator.IsPresent(txtEnergy, "Energy Used") && Validator.IsNonNegativeInt32(txtEnergy, "Energy Used"))
                {
                    decimal energyUsed = Convert.ToDecimal(txtEnergy.Text);

                    // when the residential customer type is selected
                    // calculates the amount charged by calling a method and passing in base rate, the energy units to charge and the rate per unit
                    if (radResidential.Checked)
                    {
                        customer = new ResidentialCustomer(accountNo, customerName, "R", chargeAmount);

                        chargeAmount = customer.CalculateCharge(RESIDENTIAL_BASE, RESIDENTIAL_UNIT_RATE, energyUsed);
                    }

                    // when commercial cusotmer type is selected

                    else if (radCommercial.Checked)
                    {
                        customer = new CommercialCustomer(accountNo, customerName, "C", chargeAmount);

                        chargeAmount = customer.CalculateCharge(COMMERCIAL_FLAT_RATE, COMMERCIAL_UNIT_RATE, energyUsed);
                    }

                    // displays the amount charged by calling display amount and passing in the amount calculated in previous steps
                    // which is then shown in the amount charge field
                    //displayAmount(chargeAmount);
                }
            }

            /*
             * When the industrial customer type is checked, this statement runs
             * This is seperated from the top if condition because industrial used peak and off-peak hours energy used rather than total energy used.
             *
             */

            else if (radIndustrial.Checked)
            {
                // validates if peak hours and off peak hours fields have a value and that the value is a positive whole number.
                if (Validator.IsPresent(txtPeakHours, "Peak Hours") && Validator.IsNonNegativeInt32(txtPeakHours, "Peak Hours") &&
                    Validator.IsPresent(txtOffPeakHours, "Off-Peak Hours") && Validator.IsNonNegativeInt32(txtOffPeakHours, "Off-Peak Hours"))
                {
                    decimal peakHours    = Convert.ToDecimal(txtPeakHours.Text);    // stores peak hours input from txtpeakhours textbox in a decimal peakhours variable
                    decimal offPeakHours = Convert.ToDecimal(txtOffPeakHours.Text); // stores off-peak hours input from txtoffpeakhours textbox in a decimal offpeakhours variable

                    //initialize local peak and off-peak charge amount variables
                    decimal peakChargeAmount    = 0; // variable to keep track of the peak energy used charge amount.
                    decimal offPeakChargeAmount = 0; // variable to keep track of the off- peak energy used charge amount


                    customer            = new IndustrialCustomer(accountNo, customerName, "I", chargeAmount);
                    peakChargeAmount    = customer.CalculateCharge(INDUSTRIAL_PEAK_FLAT_RATE, PEAK_UNIT_RATE, peakHours);
                    offPeakChargeAmount = customer.CalculateCharge(INDUSTRIAL_OFF_PEAK_FLAT_RATE, OFF_PEAK_UNIT_RATE, offPeakHours);

                    // the total charge amount for industrial customer is the sum of the peak hours and off peak hours charge amount.
                    chargeAmount = peakChargeAmount + offPeakChargeAmount;
                }
            }
            // calls displayamount method and passess in the total charge amount to be displayed in the amount charge field.
            displayAmount(chargeAmount);
        }
Пример #15
0
        private void BtnCalculate_Click(object sender, EventArgs e)
        {   // create new customer type based on selection
            switch (cboxCustType.SelectedIndex)
            {
            case 0:     // residential

                // set customer type
                customerType       = 'R';
                this.ActiveControl = txtCustName;

                if (    // validating customer name
                    Validator.IsNotEmpty(txtCustName, "Customer name") &&
                    // validating account number
                    Validator.IsNotEmpty(txtAcctNum, "Account number") &&
                    Validator.IsInteger(txtAcctNum, "Account number") &&
                    Validator.IsNonNegativeInt(txtAcctNum, "Account number") &&
                    // validating KWH Total
                    Validator.IsNotEmpty(txtKwhUsed, "kWh") &&
                    Validator.IsInteger(txtKwhUsed, "kWh") &&
                    Validator.IsNonNegativeInt(txtKwhUsed, "kWh"))
                {
                    // set text values to customer variables
                    kwh1         = Convert.ToDecimal(txtKwhUsed.Text);
                    accountNo    = Convert.ToInt32(txtAcctNum.Text);
                    customerName = Convert.ToString(txtCustName.Text);
                    // create new customer object
                    ResidentialCustomer newResCust = new ResidentialCustomer(accountNo, customerName, customerType, kwh1, kwh2 = 0);
                    myCustomers.Add(newResCust);     // add to list
                    CustomerDB.SaveCustomers(myCustomers);
                    DisplayCustomers();
                    ClearFields();
                }
                break;

            case 1:     //commercial

                // set customer type
                customerType       = 'C';
                this.ActiveControl = txtCustName;

                if (    // validating customer name
                    Validator.IsNotEmpty(txtCustName, "Customer name") &&
                    // validating account number
                    Validator.IsNotEmpty(txtAcctNum, "Account number") &&
                    Validator.IsInteger(txtAcctNum, "Account number") &&
                    Validator.IsNonNegativeInt(txtAcctNum, "Account number") &&
                    // validating KWH Total
                    Validator.IsNotEmpty(txtKwhUsed, "kWh") &&
                    Validator.IsInteger(txtKwhUsed, "kWh") &&
                    Validator.IsNonNegativeInt(txtKwhUsed, "kWh"))
                {
                    // set text values to customer variables
                    kwh1         = Convert.ToDecimal(txtKwhUsed.Text);
                    accountNo    = Convert.ToInt32(txtAcctNum.Text);
                    customerName = Convert.ToString(txtCustName.Text);
                    // create new customer object
                    CommercialCustomer newComCust = new CommercialCustomer(accountNo, customerName, customerType, kwh1, kwh2 = 0);
                    myCustomers.Add(newComCust);     // add to list
                    CustomerDB.SaveCustomers(myCustomers);
                    DisplayCustomers();
                    ClearFields();
                }
                break;

            case 2:     // industrial

                // set customer type
                customerType       = 'I';
                this.ActiveControl = txtCustName;

                if (    // validating customer name
                    Validator.IsNotEmpty(txtCustName, "Customer name") &&
                    // validating account number
                    Validator.IsNotEmpty(txtAcctNum, "Account number") &&
                    Validator.IsInteger(txtAcctNum, "Account number") &&
                    Validator.IsNonNegativeInt(txtAcctNum, "Account number") &&
                    // validation Peak Hours
                    Validator.IsNotEmpty(txtPeakHours, "Peak Hours") &&
                    Validator.IsInteger(txtPeakHours, "Peak Hours") &&
                    Validator.IsNonNegativeInt(txtPeakHours, "Peak Hours") &&
                    // validation Off-Peak Hours
                    Validator.IsNotEmpty(txtOffPeakHours, "Off-Peak Hours") &&
                    Validator.IsInteger(txtOffPeakHours, "Off-Peak Hours") &&
                    Validator.IsNonNegativeInt(txtOffPeakHours, "Off-Peak Hours"))
                {
                    // set text values to customer variables
                    kwh1         = Convert.ToDecimal(txtPeakHours.Text);
                    kwh2         = Convert.ToDecimal(txtOffPeakHours.Text);
                    accountNo    = Convert.ToInt32(txtAcctNum.Text);
                    customerName = Convert.ToString(txtCustName.Text);
                    // create new customer object
                    IndustrialCustomer newIndusCust = new IndustrialCustomer(accountNo, customerName, customerType, kwh1, kwh2);
                    myCustomers.Add(newIndusCust);     // add to list
                    CustomerDB.SaveCustomers(myCustomers);
                    DisplayCustomers();
                    ClearFields();
                }
                break;
            }
        }