Imports System.Data
Imports System.Data.OleDb
Public Class frmMain
'Images that will be used for buttons
Dim btnBG As System.Drawing.Image = Image.FromFile("C:\Documents and Settings\Allan Hernandez\My Documents\Visual Studio 2005\Projects\E-Z Watt Electric Co\E-Z Watt Electric Co\btnbg.jpeg")
Dim btnBG2 As System.Drawing.Image = Image.FromFile("C:\Documents and Settings\Allan Hernandez\My Documents\Visual Studio 2005\Projects\E-Z Watt Electric Co\E-Z Watt Electric Co\btnbg2.jpeg")
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Change Button Backgrounds
btnUpload.BackgroundImage = btnBG2
btnReports.BackgroundImage = btnBG2
btnExit.BackgroundImage = btnBG2
End Sub
Private Sub btnUpload_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.MouseHover
'Change background when the mouse moves over the button.
btnUpload.BackgroundImage = btnBG
slMain.Text = "Upload a File for processing."
End Sub
Private Sub btnReports_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReports.MouseHover
'Change background when the mouse moves over the button.
btnReports.BackgroundImage = btnBG
slMain.Text = "Print/View Month's Reports"
End Sub
Private Sub btnExit_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.MouseHover
'Change background when the mouse moves over the button.
btnExit.BackgroundImage = btnBG
slMain.Text = "Exit the application"
End Sub
Private Sub btnUpload_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.MouseLeave
'Change background when the mouse leaves the button.
btnUpload.BackgroundImage = btnBG2
slMain.Text = ""
End Sub
Private Sub btnReports_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReports.MouseLeave
'Change background when the mouse leaves the button.
btnReports.BackgroundImage = btnBG2
slMain.Text = ""
End Sub
Private Sub btnExit_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.MouseLeave
'Change background when the mouse leaves the button.
btnExit.BackgroundImage = btnBG2
slMain.Text = ""
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub tmrTime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTime.Tick
'Aqcuires current date and time for label
Dim CurrentDate As DateTime = DateTime.Now
'Updates label with current Time, and Company Name
lblTime.Text = "E-Z Watt Electric Co-Op: " & CurrentDate
End Sub
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim FileName As String = "", LineOfText As String = ""
OpenFormDialog.Filter = "Text files (*.TXT)|*.TXT" 'Display only Text Files
OpenFormDialog.ShowDialog() 'Display Dialog Boz
If OpenFormDialog.FileName <> "" Then
FileName = OpenFormDialog.FileName
Try 'open file and catch any errors
FileOpen(1, OpenFormDialog.FileName, OpenMode.Input)
Dim conn As New RECORDSDataSet
Dim tablename = 1
Dim ct As DataTable = conn.Tables.Add(FileName)
ct.Columns.Add("CustomerNumber", GetType(Integer))
ct.Columns.Add("CustomerName", GetType(String))
ct.Columns.Add("MeterNumber", GetType(String))
ct.Columns.Add("PreviousMonth", GetType(Double))
ct.Columns.Add("Owed", GetType(Double))
ct.Columns.Add("Paid", GetType(Double))
ct.Columns.Add("CurrentMonth", GetType(Double))
Do Until EOF(1) 'Read lines from file, stop when it reaches the end
LineOfText = LineInput(1)
'add each line to the AllText variable
Call CreateDatabase(LineOfText, conn, ct, FileName)
Loop
Catch
MsgBox("Error Opening File") 'Display message box if file cannot be opened
Finally
FileClose(1) 'close file
End Try
End If
End Sub
Sub CreateDatabase(ByVal LineOfText As String, ByRef conn As RECORDSDataSet, ByVal ct As DataTable, ByVal FileName As String)
'Variables that will be required for input into the database
Dim arr() As String = Split(LineOfText, " ")
Dim CustomerNumber, LastMonth, CurrentHours As Integer
Dim Owed, Paid As Double
Dim CustomerName, MeterNumber As String
Dim NR As DataRow
CustomerNumber = arr(0)
CustomerName = arr(1) & arr(2) 'Combine first and last name
MeterNumber = arr(3)
LastMonth = arr(4)
Owed = arr(5)
Paid = arr(6)
CurrentHours = arr(7)
NR = conn.Tables(FileName).NewRow
NR.BeginEdit()
NR.Item(0) = CustomerNumber
NR.Item(1) = CustomerName
NR.Item(2) = MeterNumber
NR.Item(3) = LastMonth
NR.Item(4) = Owed
NR.Item(5) = Paid
NR.Item(6) = CurrentHours
NR.EndEdit()
conn.Tables(FileName).Rows.Add(NR)
End Sub
End Class