|
楼主 |
发表于 2015-10-26 08:49
|
显示全部楼层
Ribbon1.vb:
- Imports Microsoft.Office.Tools.Ribbon
- Public Class Ribbon2
- Private Sub Ribbon2_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
- End Sub
- Private Sub Loan_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Loan.Click
- Loan.Checked = True
- Annuity.Checked = False
- EffectiveRate.Checked = False
- DataEntry.Label = "输入贷款信息"
- Term.Visible = True
- Payment.Visible = False
- Amount.Visible = True
- Amount.Label = "贷款金额"
- CalcType = "Loan"
- End Sub
- Private Sub Annuity_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Annuity.Click
- Loan.Checked = False
- Annuity.Checked = True
- EffectiveRate.Checked = False
- DataEntry.Label = "输入年金信息"
- Term.Visible = True
- Payment.Visible = True
- Amount.Visible = True
- Amount.Label = "每月年金付款"
- CalcType = "Annuity"
- End Sub
- Private Sub EffectiveRate_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles EffectiveRate.Click
- Loan.Checked = False
- Annuity.Checked = False
- EffectiveRate.Checked = True
- DataEntry.Label = "输入有效利率信息"
- Term.Visible = False
- Payment.Visible = False
- Amount.Visible = False
- CalcType = "EffectiveRate"
- End Sub
- Private Sub Button1_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
- ' 选择计算并调用
- Select Case CalcType
- Case "Loan"
- Globals.ThisAddIn.CalculatePMT(Rate.Text, Replace(Term.SelectedItem.Label, "年", ""), Amount.Text)
- Case "Annuity"
- Globals.ThisAddIn.CalculateFV(Rate.Text, Replace(Term.SelectedItem.Label, "年", ""), Payment.Text, Amount.Text)
- Case "Effective Rate"
- Globals.ThisAddIn.CalculateEFFECT(Rate.Text)
- End Select
- End Sub
- Private Sub RedundantCalcsLaunch_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles RedundantCalcsLaunch.Click
- ' 选择正确的过程.
- Select Case CalcType
- Case "Loan"
- PerformLoanRangeCalc()
- Case "Annuity"
- PerformAnnuityRangeCalc()
- Case "EffectiveRate"
- PerformEffectiveRateRangeCalc()
- End Select
- End Sub
- Private Sub PerformLoanRangeCalc()
- ' 创建对话框.
- Dim ThisSelection As LoanRangeSelection = New LoanRangeSelection()
- ' 在对话框中添加已存在的变量.
- ThisSelection.txtIntBeg.Text = Rate.Text
- ThisSelection.txtIntEnd.Text = Rate.Text
- ThisSelection.txtIntInc.Text = "1"
- ThisSelection.cbTermBeg.Text = Replace(Term.SelectedItem.Label, "年", "")
- ThisSelection.cbTermEnd.Text = Replace(Term.SelectedItem.Label, "年", "")
- ThisSelection.txtLoanAmt.Text = Amount.Text
- ' 显示对话框并且如果用户单击确定则处理数据.
- If ThisSelection.ShowDialog() = Windows.Forms.DialogResult.OK Then
- ' 转换数据值为Int32egers.
- R = Int32.Parse(ThisSelection.txtIntBeg.Text)
- T = Int32.Parse(ThisSelection.cbTermBeg.Text)
- A = Int32.Parse(ThisSelection.txtLoanAmt.Text)
- ' 创建本地变量,包括计算数据.
- Dim EndRate As Int32 = Int32.Parse(ThisSelection.txtIntEnd.Text)
- Dim IncRate As Int32 = Int32.Parse(ThisSelection.txtIntInc.Text)
- Dim EndTerm As Int32 = Int32.Parse(ThisSelection.cbTermEnd.Text)
- ' 更新功能区中的值.
- 'ribbon.InvalidateControl("Rate")
- 'ribbon.InvalidateControl("Term")
- 'ribbon.InvalidateControl("Amount")
- ' 添加初始标题.
- Globals.ThisAddIn.SetHeading("利息", 1, 1)
- ' 执行计算.
- Dim i As Int32
- For i = R To EndRate
- ' 计算X和Y的位置值.
- Dim X As Int32 = i + 2 - R
- Dim Y As Int32 = 2
- ' 打印Int32erest利率.
- Globals.ThisAddIn.SetHeading(i.ToString() + "%", X, 1)
- ' 使用一系列if语句确定年设置.
- If T = 10 And EndTerm >= 10 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculatePMTT(i, 10, A, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("10年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 15 And EndTerm >= 15 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculatePMTT(i, 15, A, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("15年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 20 And EndTerm >= 20 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculatePMTT(i, 20, A, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("20年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 30 And EndTerm >= 30 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculatePMTT(i, 30, A, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("30年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- Next
- End If
- End Sub
- Private Sub PerformAnnuityRangeCalc()
- ' 创建对话框.
- Dim ThisSelection As AnnuityRangeSelection = New AnnuityRangeSelection()
- ' 在对话框中添加已存在的变量.
- ThisSelection.txtIntBeg.Text = Rate.Text
- ThisSelection.txtIntEnd.Text = Rate.Text
- ThisSelection.txtIntInc.Text = "1"
- ThisSelection.cbTermBeg.Text = Replace(Term.SelectedItem.Label, "年", "")
- ThisSelection.cbTermEnd.Text = Replace(Term.SelectedItem.Label, "年", "")
- ThisSelection.txtLoanAmt.Text = Amount.Text
- ThisSelection.txtPayment.Text = Payment.Text
- ' 显示对话框并且如果用户单击确定则处理数据.
- If ThisSelection.ShowDialog() = Windows.Forms.DialogResult.OK Then
- ' 转换数据值为Int32egers.
- R = Int32.Parse(ThisSelection.txtIntBeg.Text)
- T = Int32.Parse(ThisSelection.cbTermBeg.Text)
- A = Int32.Parse(ThisSelection.txtLoanAmt.Text)
- P = Int32.Parse(ThisSelection.txtPayment.Text)
- ' 创建本地变量以包含计算数据.
- Dim EndRate As Int32 = Int32.Parse(ThisSelection.txtIntEnd.Text)
- Dim IncRate As Int32 = Int32.Parse(ThisSelection.txtIntInc.Text)
- Dim EndTerm As Int32 = Int32.Parse(ThisSelection.cbTermEnd.Text)
- ' 更新功能区中的值.
- 'ribbon.InvalidateControl("Rate")
- 'ribbon.InvalidateControl("Term")
- 'ribbon.InvalidateControl("Amount")
- 'ribbon.InvalidateControl("Payment")
- ' 添加初始标题.
- Globals.ThisAddIn.SetHeading("利息", 1, 1)
- ' 执行计算.
- Dim i As Int32
- For i = R To EndRate
- ' 计算X和Y的位置值.
- Dim X As Int32 = i + 2 - R
- Dim Y As Int32 = 2
- ' 打印Int32erest利率.
- Globals.ThisAddIn.SetHeading(i.ToString() + "%", X, 1)
- ' 使用一系列if语句决定年设置.
- If T = 5 And EndTerm >= 5 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculateFVV(i, 5, A, P, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("5年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 7 And EndTerm >= 7 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculateFVV(i, 7, A, P, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("7年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 10 And EndTerm >= 10 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculateFVV(i, 10, A, P, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("10年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 15 And EndTerm >= 15 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculateFVV(i, 15, A, P, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("15年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- If T <= 20 And EndTerm >= 20 Then
- ' 执行计算.
- Globals.ThisAddIn.CalculateFVV(i, 20, A, P, X, Y)
- ' 打印标题.
- Globals.ThisAddIn.SetHeading("20年", 1, Y)
- ' 如果已经使用则增加Y.
- Y = Y + 1
- End If
- Next
- End If
- End Sub
-
复制代码 |
|