コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Initialize Tax table rates using ordered dictionaries
            OrderedDictionary payetable = new OrderedDictionary();
            OrderedDictionary nitable = new OrderedDictionary();
            OrderedDictionary sltable = new OrderedDictionary();
            OrderedDictionary empnitable = new OrderedDictionary();

            string YearSelected = Year.SelectedItem.ToString();

            //Checks to see if NI Category is not null otherwise select the default
            if (NICategory.SelectedItem == null){
                NICategory.SelectedItem = ReadXML("//YearEnd[@Year='" + YearSelected + "']/NIContributions/DefaultBand").First();
            }

            string BandLetter = NICategory.SelectedItem.ToString();
            decimal personalAllowance = 0m;
            string taxCodeLetter = "L";

            //Reads the tax rates from the XML file
            nitable = ReadRatesXML("//YearEnd[@Year='"+YearSelected+"']/NIContributions/Band[@letter='"+BandLetter+"']");
            sltable = ReadRatesXML("//YearEnd[@Year='" + YearSelected + "']/StudentLoan");
            empnitable = ReadRatesXML("//YearEnd[@Year='" + YearSelected + "']/EmployersNI/Band[@letter='" + BandLetter + "']");
            payetable = CreatePayeTable(YearSelected, out personalAllowance, out taxCodeLetter);

            //Initializes Tax objects
            Tax PAYE = new PAYETax("PAYE", taxCodeLetter, payetable);
            Tax NI = new Tax("National Insurance",nitable);
            Tax empNI = new Tax("Employer's National Insurance",empnitable);
            Tax SL = new Tax("Student Loan", sltable);

            List<Tax> taxes = new List<Tax> { PAYE, NI };
            List<Tax> taxesPayable = new List<Tax> { PAYE, NI ,empNI};

            //Checks if Student Loans is selected
            if (SLDeductions.IsChecked == true)
            {
                taxes.Add(SL);
                taxesPayable.Add(SL);
                StudentLoanRow.Height = new GridLength(0,GridUnitType.Auto);
            }
            else
            {
                StudentLoanRow.Height = new GridLength(0);
            }

            decimal Amount = 0m;
            decimal.TryParse(Salary.Text, out Amount);

            //Calculates which period we are using
            switch (Period.SelectionBoxItem.ToString())
            {
                case "Month":
                    Amount = Amount * 12;
                    break;
                case "Week":
                    Amount = Amount * 52;
                    break;
                default:
                    Period.Text = "Year";
                    break;
            }

            decimal GrossAmount = 0;

            //Checks to see whether we are calculating gross or net
            if (Net.IsChecked == true)
            {
                GrossAmount = CalculateGrossSalary(Amount, taxes);
            }
            else
            {
                GrossAmount = Amount;
            }

            //Displays the various calculations
            GrossYearlyAmount.Content = GrossAmount;
            GrossMonthlyAmount.Content = (GrossAmount / 12);
            GrossWeeklyAmount.Content = (GrossAmount / 52);

            decimal PAYEAmount = PAYE.CalculateTax(GrossAmount);
            PAYEYearlyAmount.Content = PAYEAmount;
            PAYEMonthlyAmount.Content = (PAYEAmount / 12);
            PAYEWeeklyAmount.Content = (PAYEAmount / 52);

            decimal NIAmount = NI.CalculateTax(GrossAmount);
            NIYearlyAmount.Content = NIAmount;
            NIMonthlyAmount.Content = (NIAmount / 12);
            NIWeeklyAmount.Content = (NIAmount / 52);

            decimal SLAmount = SL.CalculateTax(GrossAmount);
            SLYearlyAmount.Content = SLAmount;
            SLMonthlyAmount.Content = (SLAmount / 12);
            SLWeeklyAmount.Content = (SLAmount / 52);

            decimal NetAmount = CalculateNetSalary(GrossAmount,taxes);
            NetYearlyAmount.Content = NetAmount;
            NetMonthlyAmount.Content = (NetAmount / 12);
            NetWeeklyAmount.Content = (NetAmount / 52);

            decimal empNIAmount = empNI.CalculateTax(GrossAmount);
            empNIYearlyAmount.Content = empNIAmount;
            empNIMonthlyAmount.Content = (empNIAmount / 12);
            empNIWeeklyAmount.Content = (empNIAmount / 52);

            decimal TotalTaxAmount = CalculateTotalTax(GrossAmount, taxesPayable);
            TotalTaxYearlyAmount.Content = TotalTaxAmount;
            TotalTaxMonthlyAmount.Content = (TotalTaxAmount / 12);
            TotalTaxWeeklyAmount.Content = (TotalTaxAmount / 52);
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Initialize Tax table rates using ordered dictionaries
            OrderedDictionary payetable  = new OrderedDictionary();
            OrderedDictionary nitable    = new OrderedDictionary();
            OrderedDictionary sltable    = new OrderedDictionary();
            OrderedDictionary empnitable = new OrderedDictionary();

            string YearSelected = Year.SelectedItem.ToString();

            //Checks to see if NI Category is not null otherwise select the default
            if (NICategory.SelectedItem == null)
            {
                NICategory.SelectedItem = ReadXML("//YearEnd[@Year='" + YearSelected + "']/NIContributions/DefaultBand").First();
            }

            string  BandLetter        = NICategory.SelectedItem.ToString();
            decimal personalAllowance = 0m;
            string  taxCodeLetter     = "L";

            //Reads the tax rates from the XML file
            nitable    = ReadRatesXML("//YearEnd[@Year='" + YearSelected + "']/NIContributions/Band[@letter='" + BandLetter + "']");
            sltable    = ReadRatesXML("//YearEnd[@Year='" + YearSelected + "']/StudentLoan");
            empnitable = ReadRatesXML("//YearEnd[@Year='" + YearSelected + "']/EmployersNI/Band[@letter='" + BandLetter + "']");
            payetable  = CreatePayeTable(YearSelected, out personalAllowance, out taxCodeLetter);

            //Initializes Tax objects
            Tax PAYE  = new PAYETax("PAYE", taxCodeLetter, payetable);
            Tax NI    = new Tax("National Insurance", nitable);
            Tax empNI = new Tax("Employer's National Insurance", empnitable);
            Tax SL    = new Tax("Student Loan", sltable);

            List <Tax> taxes = new List <Tax> {
                PAYE, NI
            };
            List <Tax> taxesPayable = new List <Tax> {
                PAYE, NI, empNI
            };

            //Checks if Student Loans is selected
            if (SLDeductions.IsChecked == true)
            {
                taxes.Add(SL);
                taxesPayable.Add(SL);
                StudentLoanRow.Height = new GridLength(0, GridUnitType.Auto);
            }
            else
            {
                StudentLoanRow.Height = new GridLength(0);
            }

            decimal Amount = 0m;

            decimal.TryParse(Salary.Text, out Amount);

            //Calculates which period we are using
            switch (Period.SelectionBoxItem.ToString())
            {
            case "Month":
                Amount = Amount * 12;
                break;

            case "Week":
                Amount = Amount * 52;
                break;

            default:
                Period.Text = "Year";
                break;
            }

            decimal GrossAmount = 0;

            //Checks to see whether we are calculating gross or net
            if (Net.IsChecked == true)
            {
                GrossAmount = CalculateGrossSalary(Amount, taxes);
            }
            else
            {
                GrossAmount = Amount;
            }

            //Displays the various calculations
            GrossYearlyAmount.Content  = GrossAmount;
            GrossMonthlyAmount.Content = (GrossAmount / 12);
            GrossWeeklyAmount.Content  = (GrossAmount / 52);

            decimal PAYEAmount = PAYE.CalculateTax(GrossAmount);

            PAYEYearlyAmount.Content  = PAYEAmount;
            PAYEMonthlyAmount.Content = (PAYEAmount / 12);
            PAYEWeeklyAmount.Content  = (PAYEAmount / 52);

            decimal NIAmount = NI.CalculateTax(GrossAmount);

            NIYearlyAmount.Content  = NIAmount;
            NIMonthlyAmount.Content = (NIAmount / 12);
            NIWeeklyAmount.Content  = (NIAmount / 52);

            decimal SLAmount = SL.CalculateTax(GrossAmount);

            SLYearlyAmount.Content  = SLAmount;
            SLMonthlyAmount.Content = (SLAmount / 12);
            SLWeeklyAmount.Content  = (SLAmount / 52);

            decimal NetAmount = CalculateNetSalary(GrossAmount, taxes);

            NetYearlyAmount.Content  = NetAmount;
            NetMonthlyAmount.Content = (NetAmount / 12);
            NetWeeklyAmount.Content  = (NetAmount / 52);

            decimal empNIAmount = empNI.CalculateTax(GrossAmount);

            empNIYearlyAmount.Content  = empNIAmount;
            empNIMonthlyAmount.Content = (empNIAmount / 12);
            empNIWeeklyAmount.Content  = (empNIAmount / 52);

            decimal TotalTaxAmount = CalculateTotalTax(GrossAmount, taxesPayable);

            TotalTaxYearlyAmount.Content  = TotalTaxAmount;
            TotalTaxMonthlyAmount.Content = (TotalTaxAmount / 12);
            TotalTaxWeeklyAmount.Content  = (TotalTaxAmount / 52);
        }