My system is a Loan system with monthlypayment.
my problem here is the command button schedule.
after putting the details like first name id# , lastname etc. i will input the loan amount followed by interest and the date. and after entering those i will click the calculate button and it works. but the problem is the schedule
i created a datagridview . after calculating the amount i will click the schedule button but nothing works the datagridview wont loan anything like the date that the customer would pay. only blank
so here's my code :
Imports System.Data.OleDb
Public Class Form1
Public connstring As String = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = D:\Parang database\databasefinal.accdb;persist security info = false"
Public conn As New OleDbConnection
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = connstring
If conn.State = ConnectionState.Closed Then
conn.Open()
MsgBox("Open")
Else
MsgBox("Close")
End If
End Sub
Private Sub btncommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncommit.Click
Try
Dim SqlQuery As String = "INSERT INTO clientinfo (ID,Lastname,Firstname,Mi,Address) VALUES ('" & txtid.Text & "','" & txtlname.Text & "','" & txtfname.Text & "','" & txtmi.Text & "','" & txtaddress.Text & "')"
Dim SqlCommand As New OleDbCommand
With SqlCommand
.CommandText = SqlQuery
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("One record Successfully added.")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
btnaddnew.Enabled = True
End Sub
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Try
Dim SqlQuery As String = "UPDATE tblinfo SET ID = '" & txtid.Text & "', Lastname = '" & txtlname.Text & "', Firstname = '" & txtfname.Text & "', Mi = '" & txtmi.Text & "', Address = '" & txtaddress.Text & "' WHERE ID = " & txtid.Text & ";"
Dim SqlCommand As New OleDbCommand
With SqlCommand
.CommandText = SqlQuery
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("Update Success.")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub InterestPayment()
Dim intAmount As Double = 0
Dim principal As Double = Me.txtPrincipal.Text
Dim intInterestRate As Double = Me.txtInterest.Text
Dim principalPayment As Double = 0
intAmount = (principal * intInterestRate * 0.01) / 12
principalPayment = principal / CDbl(Me.txtPeriod.Text)
txtMonthlyInterestPayment.Text = FormatCurrency(intAmount, 2)
Me.txtMonthlyPrincipalPayment.Text = principalPayment
Dim intPay As Double = CDbl(Me.txtMonthlyInterestPayment.Text)
Dim principalpay As Double = Me.txtMonthlyPrincipalPayment.Text
Dim TotalPayment As Double = intPay + principalpay
Me.txtTotalPayment.Text = FormatCurrency(TotalPayment, 2)
End Sub
Private Sub btnCalculation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculation.Click
If Not IsNumeric(Me.txtPrincipal.Text) Then
MsgBox("Invalid principal value.", MsgBoxStyle.Exclamation, "Invalid Value.")
Return
End If
If Not IsNumeric(Me.txtPeriod.Text) Then
MsgBox("Invalid period value.", MsgBoxStyle.Exclamation, "Invalid Period.")
Return
End If
If Not IsNumeric(Me.txtInterest.Text) Then
MsgBox("Invalid interest rate value.", MsgBoxStyle.Exclamation, "Invalid Interest Rate.")
Return
End If
If Not IsNumeric(Me.txtid.Text) Then
MsgBox("Invalid id value.", MsgBoxStyle.Exclamation, "Please user numbers only.")
Return
End If
InterestPayment()
End Sub
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
G.GenerateScheule()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
conn.Close()
End Sub
Private Sub btnaddnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnew.Click
btncommit.Enabled = True
btnaddnew.Enabled = False
txtaddress.Clear()
txtfname.Clear()
txtid.Clear()
txtInterest.Clear()
txtlname.Clear()
txtmi.Clear()
txtPeriod.Clear()
txtPrincipal().Clear()
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
conn.Close()
Me.Close()
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
txtaddress.Clear()
txtfname.Clear()
txtid.Clear()
txtInterest.Clear()
txtlname.Clear()
txtmi.Clear()
txtPeriod.Clear()
txtPrincipal().Clear()
End Sub
Dim G As New Schedule
Public Class Schedule
Dim dPrincipal As Double = 0
Dim dIntInterestRate As Double = 0
Dim iPeriod As Integer
Dim dtValueDate As Date
Dim sType As String = ""
Public WriteOnly Property Principal() As Double
Set(ByVal value As Double)
dPrincipal = value
End Set
End Property
Public WriteOnly Property InterestRate() As Double
Set(ByVal value As Double)
dIntInterestRate = value
End Set
End Property
Public WriteOnly Property Period() As Double
Set(ByVal value As Double)
iPeriod = value
End Set
End Property
Public WriteOnly Property ValueDate() As Date
Set(ByVal value As Date)
dtValueDate = value
End Set
End Property
Public WriteOnly Property LoanType() As String
Set(ByVal value As String)
sType = value
End Set
End Property
Public Sub GenerateScheule()
Dim monthlyInt As Double = 0
Dim monthlyPrincipal As Double = 0
Dim dtDate As Date
Dim total As Double
monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12
monthlyPrincipal = dPrincipal / iPeriod
For i As Integer = 1 To iPeriod
dtDate = dtValueDate.AddMonths(i)
total = monthlyPrincipal + monthlyInt
Form1.dgvLoanSchedule.Rows.Add(i, Format(dtDate, "dd/MMM/yyyy"), FormatCurrency(monthlyInt, 2), FormatCurrency(monthlyPrincipal, 2), FormatCurrency(total, 2))
dPrincipal -= monthlyPrincipal
monthlyPrincipal = dPrincipal / iPeriod
monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12
Next
End Sub
End Class
End Class
heres the problem : is there something wrong with this?
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
G.GenerateScheule()
End Sub
but when i created a new form and clicking the schedule button my program works perfectly. but when i decided to transfer it to form1 inorder to have a single form the schedule button wont work anymore.

New Topic/Question
Reply



MultiQuote







|