Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing
Public Class PaymentReceived
Private WithEvents cm As CurrencyManager
Dim dataset2 As New DataSet
Private Sub PaymentReceived_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataSet1.Tables(0).Rows.Add("100", "6/6/2009", "6")
DataSet1.Tables(0).Rows.Add("101", "7/6/2009", "6", "7")
Dim OdbcDA As New OleDbDataAdapter("SELECT Cancer FROM Cancer", MyConnectionString)
OdbcDA.Fill(DataSet2, "Table1")
Datagridview1_Setup()
'DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = DataSet1.Tables(0)
'calculate the running totals for the Clients Invoices & Payments
DataGridView1.Columns(2).HeaderText = "Invoice Amount (Total: " + FormatCurrency(totalsum(2)).ToString & ")"
DataGridView1.Columns(3).HeaderText = "Payment (Total: " + FormatCurrency(totalsum(3)).ToString & ")"
DataGridView1.Columns(4).HeaderText = "Amount Carried Over (Total: " + FormatCurrency(totalsum(4)).ToString & ")"
cm = Me.BindingContext(DataSet1.Tables(0))
End Sub
Private Sub cm_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles cm.ListChanged
'MessageBox.Show("List has changed. Add a call to your calculation routine here.")
Dim I As Double = 0
Dim P As Double = 0
Dim mytable As DataTable
Dim myrow As DataRow
If DataGridView1.CurrentCell.RowIndex - 1 Then
If DataGridView1.CurrentCell.ColumnIndex = 3 Then
With Me.DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex)
' Column 3 = Payment $$
Try
I = .Cells(0).Value
P = IIf(IsDBNull(.Cells(3).Value), "0", .Cells(3).Value)
Catch ex As Exception
End Try
End With
End If
End If
For Each mytable In DataSet1.Tables
For Each myrow In mytable.Rows
If myrow("Invoice") = I Then
myrow("Payment") = P
End If
Next
Next
DataGridView1.Columns(3).HeaderText = "Payment"
DataGridView1.Columns(3).HeaderText = "Payment (Total: " + FormatCurrency(totalsum(3)).ToString & ")"
DataGridView1.Columns(4).HeaderText = "Amount Carried Over"
DataGridView1.Columns(4).HeaderText = "Amount Carried Over (Total: " + FormatCurrency(totalsum(4)).ToString & ")"
End Sub
Function totalsum(ByVal colnum As Integer)
Dim currentRow As DataGridViewRow
Dim total As Double = 0
For Each currentRow In DataGridView1.Rows
total += IIf(IsDBNull(currentRow.Cells(colnum).Value), "0.0", currentRow.Cells(colnum).Value)
Next
Return total
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(0).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(1).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(2).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(3).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(4).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(5).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(6).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(7).Enabled = True
DirectCast(Me.ParentForm, MDIParent1).MenuStrip1.Items(8).Enabled = True
Close()
End Sub
#Region " Datagridview Setup "
Private Sub Datagridview1_Setup()
With DataGridView1
.BackColor = Color.GhostWhite
.BackgroundColor = Color.Lavender
.BorderStyle = BorderStyle.None
.Font = New Font("Tahoma", 12.0!)
End With
Dim grdTableStyle1 As New DataGridTableStyle
With grdTableStyle1
.AlternatingBackColor = Color.GhostWhite
.BackColor = Color.GhostWhite
.ForeColor = Color.MidnightBlue
.GridLineColor = Color.RoyalBlue
.HeaderBackColor = Color.MidnightBlue
.HeaderFont = New Font("Tahoma", 12.0!, FontStyle.Bold)
.HeaderForeColor = Color.Lavender
.SelectionBackColor = Color.Teal
.SelectionForeColor = Color.PaleGreen
' Do not forget to set the MappingName property.
' Without this, the DataGridTableStyle properties
' and any associated DataGridColumnStyle objects
' will have no effect.
.MappingName = "Table1"
.PreferredColumnWidth = 125
.PreferredRowHeight = 15
End With
Dim grdColStyle0 As New DataGridViewTextBoxColumn
With grdColStyle0
.HeaderText = "Invoice #"
.DataPropertyName = "Invoice"
.Width = 105
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ReadOnly = True
End With
Dim grdColStyle1 As New DataGridViewTextBoxColumn
With grdColStyle1
.HeaderText = "Invoice Date"
.DataPropertyName = "Date"
.Width = 148
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ReadOnly = True
End With
Dim grdColStyle2 As New DataGridViewTextBoxColumn
With grdColStyle2
.HeaderText = "Invoice Amount"
.DataPropertyName = "Amount"
.Width = 150
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ReadOnly = True
End With
Dim grdColStyle3 As New DataGridViewTextBoxColumn
With grdColStyle3
.HeaderText = "Payment"
.DataPropertyName = "Payment"
.Width = 120
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ReadOnly = False
End With
Dim grdColStyle4 As New DataGridViewTextBoxColumn
With grdColStyle4
.HeaderText = "Amount Carried Over"
.DataPropertyName = "Difference"
.Width = 190
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.ReadOnly = True
End With
' Add the style objects to the table style's collection of
' column styles. Without this the styles do not take effect.
Me.DataGridView1.Columns.Clear()
Me.DataGridView1.Columns.AddRange(grdColStyle0, grdColStyle1, grdColStyle2, grdColStyle3, grdColStyle4)
Me.DataGridView1.MultiSelect = False
Me.DataGridView1.RowHeadersVisible = False
Dim i As Integer = 0
Do While i < 5
Me.DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
Me.DataGridView1.Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.DataGridView1.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
i += 1
Loop
Me.DataGridView1.Columns(2).DefaultCellStyle.Format = "c"
Me.DataGridView1.Columns(3).DefaultCellStyle.Format = "c"
Me.DataGridView1.Columns(4).DefaultCellStyle.Format = "c"
End Sub
#End Region
End Class