Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Diagnostics
Module Module1
Dim myConnection As MySqlConnection
Dim MySQLConnectionString As String
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
Dim FILE_NAME As String = Nothing
Dim dir As String = "C:\Mytest\"
Dim strDate As String = Nothing
Dim serv_type As String = Nothing
Dim strSubservice As String = Nothing
Dim member_no As String = Nothing
Dim strIndicator As String = Nothing
Dim strDirection As String = Nothing
Dim file_num As String = Nothing
Dim origin As String = Nothing
Dim transac_Type As String
Dim beginDayAck As String = "51"
Dim beginDayNack As String = "61"
Dim fileAck As String = "52"
Dim fileNack As String = "62"
Dim endDayAck As String = "59"
Dim endDayNack As String = "69"
Dim error_code As String
Dim recID As String = "00"
Dim num_records As String
Public watchfolder As FileSystemWatcher
Sub Main(ByVal args As String())
MySQLConnectionString = "Server=localhost;" & _
"Database=lebo_test;" & _
"Userid=root;" & _
"Password=12345;"
myConnection = New MySqlConnection(MySQLConnectionString)
For i As Integer = 0 To CommandLineArgs.Count - 1
If i = 0 Then
FILE_NAME = (CommandLineArgs(i))
End If
Next
Dim last_char As String = FILE_NAME.Substring(7, 1)
Dim last_three As String = FILE_NAME.Substring(5, 3)
Console.WriteLine("lastchar is: " + last_char)
If (last_char.Equals("D")) Then
Console.WriteLine("here")
Data_Validation()
Else
If (last_three.Equals("Z1C")) Then
Z1C()
ElseIf (last_three.Equals("Z9C")) Then
Z9C()
Else
' Call Z7C()
End If
End If
End Sub
Public Sub Nack(ByRef error_code As String)
Dim NACKFILE As String = FILE_NAME.Substring(0, 7) + "N"
Using writer As StreamWriter = New StreamWriter(dir + "\output\" + NACKFILE, False)
writer.Write(recID + transac_Type + strDate + serv_type + " " + strSubservice + " " + " " + member_no +
origin + strDirection + " " + strIndicator + (FILE_NAME.Substring(0, 7) + "N") + file_num + error_code)
End Using
'FileOpen(1, dir + NACKFILE, OpenMode.Output)
'PrintLine(1, "lebo testing")
'PrintLine(1, "LEBO AGAIN and AGAIN LEBO")
'FileClose(1)
End Sub
Public Sub Ack(ByRef error_code As String)
Dim ACKFILE As String = FILE_NAME.Substring(0, 7) + "A"
Using writer As StreamWriter = New StreamWriter(dir + "\output\" + ACKFILE, False)
writer.Write(recID + transac_Type + strDate + serv_type + " " + strSubservice + " " + member_no +
origin + strDirection + " " + strIndicator + (FILE_NAME.Substring(0, 7) + "A") + file_num + error_code)
End Using
End Sub
Public Sub Data_Validation()
'Dim FILE_NAME As String = Nothing
'"C:\Users\LebohangL\Desktop\Lebo\DEND001D"
'Dim dr As String = "C:\Users\LebohangL\Desktop\Lebo"
Dim TextLine As String = Nothing
Dim num As Integer = 0
'Dim strDate As String = Nothing
Dim processing_date As String = Nothing
'Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
Dim service_type As String = Nothing
'Dim serv_type As String = Nothing
'Dim strSubservice As String = Nothing
Dim subservice As String = Nothing
Dim indicator As String = Nothing
Dim direction As String = Nothing
'Dim strIndicator As String = Nothing
'Dim strDirection As String = Nothing
Dim user_no As String = Nothing
'Dim member_no As String = Nothing
Dim recordID As String = Nothing
Dim executeDA As MySqlDataAdapter
Dim datacombo As New DataTable
'Dim myConnection As MySqlConnection
'Dim MySQLConnectionString As String
'MySQLConnectionString = "Server=localhost;" & _
' "Database=lebo_test;" & _
' "Userid=root;" & _
' "Password=12345;"
'myConnection = New MySqlConnection(MySQLConnectionString)
'For i As Integer = 0 To CommandLineArgs.Count - 1
' If i = 0 Then
' FILE_NAME = (CommandLineArgs(i))
' End If
'Next
datacombo = New DataTable
If System.IO.File.Exists(dir + FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(dir + FILE_NAME)
'reading the txt file
Do While objReader.Peek() <> -1
num += 1
TextLine = objReader.ReadLine()
If num = 1 Then
serv_type = TextLine.Substring(10, 4).Trim
strSubservice = TextLine.Substring(14, 10).Trim
strDate = TextLine.Substring(2, 8)
member_no = TextLine.Substring(24, 4)
strIndicator = TextLine.Substring(59, 4)
strDirection = TextLine.Substring(48, 3).Trim
file_num = TextLine.Substring(40, 4)
origin = TextLine.Substring(28, 4)
recordID = TextLine.Substring(0, 2)
End If
'get number of records
If num > 1 Then
recordID = TextLine.Substring(0, 2)
End If
If recordID = "99" Then
num_records = TextLine.Substring(28, 6)
num_records = Val(num_records)
Exit Do
End If
Loop
Dim recNum As String = num
Console.WriteLine(recNum)
Console.WriteLine("Number of records are " + num_records)
If recNum.ToString <> num_records.ToString Then
transac_Type = fileNack
Nack("22")
Console.WriteLine("ERROR 22!!Invalid number of records")
Exit Sub
End If
'Verify Service and continue validation
Dim sqlcmd = "SELECT service_type from service where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("*Dataset Empty*")
Console.WriteLine("****************")
Else
Dim dtRow As DataRow
For Each dtRow In datacombo.Rows
'subservice = dtRow("subservice")
service_type = dtRow("service_type")
Next
End If
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
If (serv_type.Equals(service_type)) Then
transac_Type = fileAck
'Ack("00")
Console.WriteLine("Service Valid. Check Processing date to proceed")
Else
'Console.WriteLine("NACK NACK")
transac_Type = fileNack
Nack("03")
Console.WriteLine("ERROR 03!! Invalid service")
Exit Sub
End If
'Verify processing date
sqlcmd = "SELECT processing_date from cleanup where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("Dataset Empty")
Console.WriteLine("****************")
Else
For Each dtRow In datacombo.Rows
processing_date = dtRow("processing_date")
Next
End If
Console.WriteLine("File Processing Date is: " + strDate)
Console.WriteLine("Processing Date is : " + processing_date)
If strDate.ToString.Equals(processing_date) Then
transac_Type = fileAck
'Ack("00")
Console.WriteLine("Processing_date Valid.")
Else
transac_Type = fileNack
Nack("02")
Console.WriteLine("ERROR 02!! Invalid processing_date")
Exit Sub
End If
'Is member setup for service
sqlcmd = "SELECT user_no, service_type, subservice, direction, indicator FROM client where user_no = '" + member_no + "' AND service_type ='" + serv_type + "' AND subservice ='" + strSubservice + "' AND direction ='" + strDirection + "' AND indicator ='" + strIndicator + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("***********************************************")
Console.WriteLine("Dataset Empty.Member not setup on client table")
Console.WriteLine("***********************************************")
Else
For Each dtRow In datacombo.Rows
user_no = dtRow("user_no")
service_type = dtRow("service_type")
subservice = dtRow("subservice")
direction = dtRow("direction")
indicator = dtRow("indicator")
Next
End If
Console.WriteLine("File user number is: " + member_no)
Console.WriteLine("User number is : " + user_no)
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
Console.WriteLine("File subservice is:" + strSubservice)
Console.WriteLine("Subservice is:" + subservice)
Console.WriteLine("File direction is:" + strDirection)
Console.WriteLine("Direction is:" + direction)
Console.WriteLine("File indicator is:" + strIndicator)
Console.WriteLine("Indicator is:" + indicator)
If (member_no.ToString.Equals(user_no)) And (serv_type.Equals(service_type)) And (strDate.Equals(processing_date)) And (strSubservice.ToString.Equals(subservice)) And (strDirection.ToString.Equals(direction)) And (strIndicator.ToString.Equals(indicator)) Then
transac_Type = fileAck
Ack("00")
Console.WriteLine("Member configured.")
Else
transac_Type = fileNack
Nack("04")
Console.WriteLine("ERROR 04!! Member not configured")
End If
Exit Sub
Else
Nack("92")
End If
End Sub
Public Sub Z1C()
Dim TextLine As String
Dim num As Integer = 0
Dim processing_date As String = Nothing
Dim service_type As String = Nothing
Dim subservice As String = Nothing
Dim indicator As String = Nothing
Dim direction As String = Nothing
Dim user_no As String = Nothing
Dim executeDA As MySqlDataAdapter
Dim datacombo As New DataTable
datacombo = New DataTable
If System.IO.File.Exists(dir + FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(dir + FILE_NAME)
Do While objReader.Peek() <> -1
num += 1
TextLine = objReader.ReadLine()
If num = 1 Then
serv_type = TextLine.Substring(12, 4).Trim
strSubservice = TextLine.Substring(16, 10).Trim
strDate = TextLine.Substring(4, 8)
member_no = TextLine.Substring(26, 4)
strIndicator = TextLine.Substring(37, 4)
strDirection = TextLine.Substring(34, 3).Trim
origin = TextLine.Substring(30, 4)
transac_Type = TextLine.Substring(2, 4)
End If
Loop
'Verify Service and continue validation
Dim sqlcmd = "SELECT service_type from service where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("Dataset Empty")
Console.WriteLine("****************")
Else
Dim dtRow As DataRow
For Each dtRow In datacombo.Rows
'subservice = dtRow("subservice")
service_type = dtRow("service_type")
Next
End If
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
If (serv_type.Equals(service_type)) Then
transac_Type = beginDayAck
'Ack("00")
Console.WriteLine("Service Valid. Check Processing date to proceed")
Else
'Console.WriteLine("NACK NACK")
transac_Type = beginDayNack
Nack("03")
Console.WriteLine("ERROR 03!! Invalid service")
Exit Sub
End If
'Verify processing date
sqlcmd = "SELECT processing_date from cleanup where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("Dataset Empty")
Console.WriteLine("****************")
Else
For Each dtRow In datacombo.Rows
processing_date = dtRow("processing_date")
Next
End If
Console.WriteLine("File Processing Date is: " + strDate)
Console.WriteLine("Processing Date is : " + processing_date)
If strDate.ToString.Equals(processing_date) Then
transac_Type = beginDayAck
'Ack("00")
Console.WriteLine("Processing_date Valid.")
Else
transac_Type = beginDayNack
Nack("02")
Console.WriteLine("ERROR 02!! Invalid processing_date")
Exit Sub
End If
'Is member setup for service
sqlcmd = "SELECT user_no, service_type, subservice, direction, indicator FROM client where user_no = '" + member_no + "' AND service_type ='" + serv_type + "' AND subservice ='" + strSubservice + "' AND direction ='" + strDirection + "' AND indicator ='" + strIndicator + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("***********************************************")
Console.WriteLine("Dataset Empty.Member not setup on client table")
Console.WriteLine("***********************************************")
Else
For Each dtRow In datacombo.Rows
user_no = dtRow("user_no")
service_type = dtRow("service_type")
subservice = dtRow("subservice")
direction = dtRow("direction")
indicator = dtRow("indicator")
Next
End If
Console.WriteLine("File user number is: " + member_no)
Console.WriteLine("User number is : " + user_no)
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
Console.WriteLine("File subservice is:" + strSubservice)
Console.WriteLine("Subservice is:" + subservice)
Console.WriteLine("File direction is:" + strDirection)
Console.WriteLine("Direction is:" + direction)
Console.WriteLine("File indicator is:" + strIndicator)
Console.WriteLine("Indicator is:" + indicator)
If (member_no.ToString.Equals(user_no)) And (serv_type.Equals(service_type)) And (strDate.Equals(processing_date)) And (strSubservice.ToString.Equals(subservice)) And (strDirection.ToString.Equals(direction)) And (strIndicator.ToString.Equals(indicator)) Then
transac_Type = beginDayAck
Ack("00")
Console.WriteLine("Member configured.")
Else
transac_Type = beginDayNack
Nack("04")
Console.WriteLine("ERROR 04!! Member not configured")
Exit Sub
End If
Else
Nack("92")
End If
End Sub
Public Sub Z9C()
Dim TextLine As String
Dim num As Integer = 0
Dim processing_date As String = Nothing
Dim service_type As String = Nothing
Dim subservice As String = Nothing
Dim indicator As String = Nothing
Dim direction As String = Nothing
Dim user_no As String = Nothing
Dim executeDA As MySqlDataAdapter
Dim datacombo As New DataTable
datacombo = New DataTable
If System.IO.File.Exists(dir + FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(dir + FILE_NAME)
Do While objReader.Peek() <> -1
num += 1
TextLine = objReader.ReadLine()
If num = 1 Then
serv_type = TextLine.Substring(12, 4).Trim
strSubservice = TextLine.Substring(16, 10).Trim
strDate = TextLine.Substring(4, 8)
member_no = TextLine.Substring(26, 4)
strIndicator = TextLine.Substring(37, 4)
strDirection = TextLine.Substring(34, 3).Trim
origin = TextLine.Substring(30, 4)
End If
Loop
'Verify Service and continue validation
Dim sqlcmd = "SELECT service_type from service where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("Dataset Empty")
Console.WriteLine("****************")
Else
Dim dtRow As DataRow
For Each dtRow In datacombo.Rows
'subservice = dtRow("subservice")
service_type = dtRow("service_type")
Next
End If
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
If (serv_type.Equals(service_type)) Then
transac_Type = endDayAck
'Ack("00")
Console.WriteLine("Service Valid. Check Processing date to proceed")
Else
transac_Type = endDayNack
Nack("03")
Console.WriteLine("ERROR 03!! Invalid service")
Exit Sub
End If
'Verify processing date
sqlcmd = "SELECT processing_date from cleanup where service_type = '" + serv_type + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("****************")
Console.WriteLine("Dataset Empty")
Console.WriteLine("****************")
Else
For Each dtRow In datacombo.Rows
processing_date = dtRow("processing_date")
Next
End If
Console.WriteLine("File Processing Date is: " + strDate)
Console.WriteLine("Processing Date is : " + processing_date)
If strDate.ToString.Equals(processing_date) Then
transac_Type = endDayAck
Ack("00")
Console.WriteLine("Processing_date Valid.")
Else
transac_Type = endDayNack
Nack("02")
Console.WriteLine("ERROR 02!! Invalid processing_date")
Exit Sub
End If
'Is member setup for service
sqlcmd = "SELECT user_no, service_type, subservice, direction, indicator FROM client where user_no = '" + member_no + "' AND service_type ='" + serv_type + "' AND subservice ='" + strSubservice + "' AND direction ='" + strDirection + "' AND indicator ='" + strIndicator + "'"
executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
datacombo.Clear()
executeDA.Fill(datacombo)
If datacombo.Rows.Count = 0 Then
Console.WriteLine("***********************************************")
Console.WriteLine("Dataset Empty.Member not setup on client table")
Console.WriteLine("***********************************************")
Else
For Each dtRow In datacombo.Rows
user_no = dtRow("user_no")
service_type = dtRow("service_type")
subservice = dtRow("subservice")
direction = dtRow("direction")
indicator = dtRow("indicator")
Next
End If
Console.WriteLine("File user number is: " + member_no)
Console.WriteLine("User number is : " + user_no)
Console.WriteLine("FileService type is: " + serv_type)
Console.WriteLine("Service type is : " + service_type)
Console.WriteLine("File subservice is:" + strSubservice)
Console.WriteLine("Subservice is:" + subservice)
Console.WriteLine("File direction is:" + strDirection)
Console.WriteLine("Direction is:" + direction)
Console.WriteLine("File indicator is:" + strIndicator)
Console.WriteLine("Indicator is:" + indicator)
If (member_no.ToString.Equals(user_no)) And (serv_type.Equals(service_type)) And (strSubservice.ToString.Equals(subservice)) And (strDirection.ToString.Equals(direction)) And (strIndicator.ToString.Equals(indicator)) Then
transac_Type = endDayAck
Ack("00")
Console.WriteLine("Member configured.")
Else
transac_Type = endDayNack
Nack("04")
Console.WriteLine("ERROR 04!! Member not configured")
End If
Exit Sub
Else
Nack("92")
End If
End Sub