private void DisplayAvgLoanBase()
        {
            var calcUtil = new LoanCalcUtil(
                    10000 * decimal.Parse(txtTotalLoanBase.Text.Trim()),
                    int.Parse(cbxYears.Text),
                    0.01M * decimal.Parse(txtYearInterestRate.Text.Trim()),
                    PayLoanType.AvgLoanBase,
                    rbtnQuarterly.Checked ? PayCycleType.PerQuarter : PayCycleType.PerMonth);

            Dictionary<int, decimal> interestsDic = new Dictionary<int, decimal>();
            List<string> cyclePayList = new List<string>();

            decimal cycleInterest = 0.0M;
            decimal cycleLoanBase = calcUtil.TotalLoanBase / calcUtil.Cycles;
            for (int cycle = 0; cycle < calcUtil.Cycles; cycle++)
            {
                cycleInterest = calcUtil.CalcInterestForAvgLoanBase(cycle);
                interestsDic.Add(cycle, cycleInterest);

                string cyclePay = string.Format("第 {0} {1}: 本金({2:F2}),利息({3:F2}),共({4:F2})元;{5}",
                                    cycle + 1,
                                    calcUtil.PayCycle == PayCycleType.PerMonth ? "月" : "季",
                                    cycleLoanBase,
                                    cycleInterest,
                                    cycleLoanBase + cycleInterest,
                                    Environment.NewLine);
                cyclePayList.Add(cyclePay);
            }

            var totalInterests = interestsDic.Aggregate(0.0M, (seed, kvp) => { return seed + kvp.Value; });
            txtInterestsForLoanBase.Text = totalInterests.ToString("F2");

            string showText = cyclePayList.Aggregate(string.Empty, (seed, cyclePay) => { return seed + cyclePay; });
            rtxtCyclePays.Text = showText;
        }
Example #2
0
        private void DisplayAvgLoanBaseAndInterests()
        {
            var calcUtil = new LoanCalcUtil(
                10000 * decimal.Parse(txtTotalLoanBase.Text.Trim()),
                int.Parse(cbxYears.Text),
                0.01M * decimal.Parse(txtYearInterestRate.Text.Trim()),
                PayLoanType.AvgLoanBaseAndInterests,
                rbtnQuarterly.Checked ? PayCycleType.PerQuarter : PayCycleType.PerMonth);

            var cyclePay = calcUtil.CalcCyclePayForAvgLoanBaseAndInterests();

            txtCyclePayForInterests.Text             = cyclePay.ToString("F2");
            txtInterestsForLoanBaseAndInterests.Text = (cyclePay * calcUtil.Cycles - (double)calcUtil.TotalLoanBase).ToString("F2");
        }
        public LoanCalcUtilTest()
        {
            Decimal loanBase = 200000M;
            int years = 10;
            Decimal interestRate = 0.0558M;

            avgLoanBaseInMthUtil = new LoanCalcUtil(loanBase, years, interestRate,
                PayLoanType.AvgLoanBaseAndInterests, PayCycleType.PerMonth);
            avgLoanBaseInQtrUtil = new LoanCalcUtil(loanBase, years, interestRate,
                PayLoanType.AvgLoanBaseAndInterests, PayCycleType.PerQuarter);
            avgLoanBaseMthUtil = new LoanCalcUtil(loanBase, years, interestRate,
                PayLoanType.AvgLoanBase, PayCycleType.PerMonth);
            avgLoanBaseQtrUtil = new LoanCalcUtil(loanBase, years, interestRate,
                PayLoanType.AvgLoanBase, PayCycleType.PerQuarter);
        }
Example #4
0
        private void DisplayAvgLoanBase()
        {
            var calcUtil = new LoanCalcUtil(
                10000 * decimal.Parse(txtTotalLoanBase.Text.Trim()),
                int.Parse(cbxYears.Text),
                0.01M * decimal.Parse(txtYearInterestRate.Text.Trim()),
                PayLoanType.AvgLoanBase,
                rbtnQuarterly.Checked ? PayCycleType.PerQuarter : PayCycleType.PerMonth);

            Dictionary <int, decimal> interestsDic = new Dictionary <int, decimal>();
            List <string>             cyclePayList = new List <string>();


            decimal cycleInterest = 0.0M;
            decimal cycleLoanBase = calcUtil.TotalLoanBase / calcUtil.Cycles;

            for (int cycle = 0; cycle < calcUtil.Cycles; cycle++)
            {
                cycleInterest = calcUtil.CalcInterestForAvgLoanBase(cycle);
                interestsDic.Add(cycle, cycleInterest);

                string cyclePay = string.Format("第 {0} {1}: 本金({2:F2}),利息({3:F2}),共({4:F2})元;{5}",
                                                cycle + 1,
                                                calcUtil.PayCycle == PayCycleType.PerMonth ? "月" : "季",
                                                cycleLoanBase,
                                                cycleInterest,
                                                cycleLoanBase + cycleInterest,
                                                Environment.NewLine);
                cyclePayList.Add(cyclePay);
            }

            var totalInterests = interestsDic.Aggregate(0.0M, (seed, kvp) => { return(seed + kvp.Value); });

            txtInterestsForLoanBase.Text = totalInterests.ToString("F2");

            string showText = cyclePayList.Aggregate(string.Empty, (seed, cyclePay) => { return(seed + cyclePay); });

            rtxtCyclePays.Text = showText;
        }
        private void DisplayAvgLoanBaseAndInterests()
        {
            var calcUtil = new LoanCalcUtil(
                10000 * decimal.Parse(txtTotalLoanBase.Text.Trim()),
                int.Parse(cbxYears.Text),
                0.01M * decimal.Parse(txtYearInterestRate.Text.Trim()),
                PayLoanType.AvgLoanBaseAndInterests,
                rbtnQuarterly.Checked ? PayCycleType.PerQuarter : PayCycleType.PerMonth);

            var cyclePay = calcUtil.CalcCyclePayForAvgLoanBaseAndInterests();
            txtCyclePayForInterests.Text = cyclePay.ToString("F2");
            txtInterestsForLoanBaseAndInterests.Text = (cyclePay * calcUtil.Cycles - (double)calcUtil.TotalLoanBase).ToString("F2");
        }