- 0
- 온텍
- 조회 수 4526
Imports System
Module Module1
Public Sub Main(ByVal ParamArray cmdArgs() As String)
Console.WriteLine("입력파라메터 체크.")
Dim arr_data(7000, 7000) As String
System.Console.WriteLine("입력 길이 : {0}", cmdArgs.Length)
'If called from C# using Process.Start(thisApp.exe,strArgs);
' For Each s As String In My.Application.CommandLineArgs
If cmdArgs.Length = 0 Then
System.Console.WriteLine("장안산단가압장 및 배수지용 일보 생성 프로그램 ... 이콘 박동연 차장 2011.10")
End
End If
If cmdArgs.Length < 1 Then
System.Console.WriteLine("csv 화일명을 경로포함해서 입력해주세요.")
End
End If
Console.WriteLine("화일 존재여부 체크.")
Dim I As Integer
I = 0
For Each s As String In cmdArgs
System.Console.WriteLine(cmdArgs(I))
' MsgBox("write out args " + cmdArgs(Val(s)))
I = I + 1
Next
Dim FavoritePictures As String = cmdArgs(0).ToString
Dim MyFilename As String = cmdArgs(0).ToString
If Right(MyFilename, 4) = ".csv" Then
Else
MyFilename = MyFilename & ".csv"
End If
If My.Computer.FileSystem.FileExists(MyFilename) Then
Else
Console.WriteLine(".csv 화일(" & MyFilename & ")이 없습니다.")
' MsgBox("지정한 경로에 csv 화일이 생성되어 있지 않습니다. " _
' & vbCrLf & "폴더 경로 및 화일생성여부를 확인해하세요.", MsgBoxStyle.OkOnly, "csv 화일 읽기 에러 경고")
End
End If
Dim WriteFilename As String ' = cmdArgs(1).ToString
WriteFilename = Left(Right(MyFilename, 10), 6) & ".xls"
If Right(WriteFilename, 4) = ".xls" Then
WriteFilename = "장안산단" & WriteFilename
Else
WriteFilename = "장안산단" & WriteFilename & ".xls"
End If
WriteFilename = "d:\report\일보\장안산단\" & WriteFilename
Dim PrintMode As String
If cmdArgs.Length = 2 Then
PrintMode = cmdArgs(1)
Else
PrintMode = 0
End If
' My.Computer.FileSystem.DeleteFile(FavoritePictures)
Console.WriteLine("메모리초기화.")
Console.WriteLine(MyFilename)
' Dim MyStream As System.IO.StreamReader = New System.IO.StreamReader(cmdArgs(0).ToString)
Dim sb As New System.Text.StringBuilder
Dim sr As New System.IO.StreamReader(MyFilename)
Dim Arr_txt() As String
Dim Line_int As Integer
Dim Col_int As Integer
Dim on_time(100, 2) As String
Dim off_time(100, 2) As String
Dim pump_on_count1 As Integer
Dim pump_on_count2 As Integer
Dim DATE_STRING As String
pump_on_count1 = 0
pump_on_count2 = 0
Line_int = 0
col_int = 0
Console.WriteLine(".csv 화일읽기.")
Do Until sr.EndOfStream
Arr_txt = sr.ReadLine.Split(",")
col_int = 0
For Each line As String In arr_txt
'System.Console.Write("{0} ", line)
System.Console.Write(".")
arr_data(Line_int, Col_int) = line.ToString
col_int = col_int + 1
Next
line_int = line_int + 1
' sb.AppendLine(sr.ReadLine) 'Note: You'll have to write your own FormatStr(Of String) As String
Console.WriteLine()
Loop
Dim Arr_cp_data(2000, 2000) As String
Dim arr_cpy_i, i_on_time_1, i_on_time_2 As Integer
arr_cpy_i = 0
i_on_time_1 = 0
i_on_time_2 = 0
Console.WriteLine("일보 요일 검출.")
DATE_STRING = arr_data(1, 0)
Dim DATE_CNV As String = Left(DATE_STRING, 6) & "20" & Right(DATE_STRING, 2)
Dim MyString As String = "10-12-2011"
Dim MyDateTime As DateTime = DateTime.Parse(DATE_CNV)
Dim MyDateWeek As String = MyDateTime.DayOfWeek
Select Case MyDateTime.DayOfWeek
Case 0
MyDateWeek = "일요일"
Exit Select
Case 1
MyDateWeek = "월요일"
Exit Select
Case 2
MyDateWeek = "화요일"
Exit Select
Case 3
MyDateWeek = "수요일"
Exit Select
Case 4
MyDateWeek = "목요일"
Exit Select
Case 5
MyDateWeek = "금요일"
Exit Select
Case 6
MyDateWeek = "토요일"
Exit Select
Case Else
Exit Select
End Select
Dim Pump_Total_Run_Count(2) As Integer
Dim MyDateString As String = MyDateTime.ToString("yyyy 년 MM 월 dd 일 ")
MyDateString = MyDateString & MyDateWeek
Pump_Total_Run_Count(0) = 0 ' 1호기
Pump_Total_Run_Count(1) = 1 ' 2호기
Console.WriteLine("펌프운전시간검출.")
For I = 1 To Line_int
If arr_data(I, 35) = "1" Then
Pump_Total_Run_Count(0) = Pump_Total_Run_Count(0) + 1
End If
If arr_data(I, 36) = "1" Then
Pump_Total_Run_Count(1) = Pump_Total_Run_Count(1) + 1
End If
If Right$(arr_data(I, 1), 5) = "00:00" Then
arr_cpy_i = arr_cpy_i + 1
For j = 0 To 40
Arr_cp_data(arr_cpy_i, j) = arr_data(arr_cpy_i, j)
' System.Console.WriteLine(arr_cpy_i)
Next j
End If
' System.Console.WriteLine(Arr_cp_data(arr_cpy_i, 1))
If arr_data(I, 35) = "1" And i_on_time_1 = 0 Then
on_time(pump_on_count1, 0) = arr_data(I, 1)
pump_on_count1 = pump_on_count1 + 1
i_on_time_1 = 1
End If
If arr_data(I, 35) = "0" And i_on_time_1 = 1 Then
off_time(pump_on_count1 - 1, 0) = arr_data(I, 1)
i_on_time_1 = 0
End If
If ((arr_data(I, 35) = "1") And (i_on_time_1 = 1)) And ((Right(arr_data(I, 1), 7) = "0:00:00")) Then
off_time(pump_on_count1 - 1, 0) = "23:59:59"
i_on_time_1 = 0
End If
If arr_data(I, 36) = "1" And i_on_time_2 = 0 Then
on_time(pump_on_count2, 1) = arr_data(I, 1)
pump_on_count2 = pump_on_count2 + 1
i_on_time_2 = 1
End If
If ((arr_data(I, 36) = "0") And (i_on_time_2 = 1)) Then
off_time(pump_on_count2 - 1, 1) = arr_data(I, 1)
i_on_time_2 = 0
End If
Console.WriteLine(Right(arr_data(I, 1), 8))
If ((arr_data(I, 36) = "1") And (i_on_time_2 = 1)) And ((Right(arr_data(I, 1), 7) = "0:00:00")) Then
off_time(pump_on_count2 - 1, 1) = "23:59:58"
i_on_time_2 = 0
End If
Next I
Console.WriteLine("엑셀 기동.")
' System.Console.WriteLine(sb.ToString)
' MsgBox("arr_data 배열크기 : " + Line_int.ToString)
' MsgBox("arr_data 배열크기 : " + arr_data.GetLength(0).ToString)
' MsgBox("arr_data rank크기 : " + arr_data.Rank.ToString)
' MsgBox("ARR_DATA SIZE : " + (arr_data.Length))
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Dim ExcelFilename As String = "d:\REPORT\원본\장안산단일보.xls"
If My.Computer.FileSystem.FileExists(ExcelFilename) Then
Else
Console.WriteLine("원본 엑셀화일(" & ExcelFilename & ")이 없습니다.")
End
End If
'Start a new workbook in Excel
oExcel = CreateObject("Excel.Application")
' oBook = oExcel.Workbooks.Add
oBook = oExcel.Workbooks.Open(ExcelFilename)
'Add data to cells of the first worksheet in the new workbook
oSheet = oBook.Worksheets("sheet1")
'oSheet.Range("A1").Value = "Last Name"
'oSheet.Range("B1").Value = "First Name"
'oSheet.Range("A1:B1").Font.Bold = True
'oSheet.Range("A2").Value = "Doe"
'oSheet.Range("B2").Value = "John"
Console.WriteLine("엑셀 값 쓰기.")
oSheet.Range("b3").Value = MyDateString
' oSheet.Range("A9").Value = arr_data(2, 3)
oSheet.Range("d33").Value = on_time(0, 0)
oSheet.Range("d34").Value = on_time(1, 0)
oSheet.Range("d35").Value = on_time(2, 0)
oSheet.Range("d36").Value = on_time(3, 0)
oSheet.Range("d37").Value = on_time(4, 0)
oSheet.Range("g33").Value = off_time(0, 0)
oSheet.Range("g34").Value = off_time(1, 0)
oSheet.Range("g35").Value = off_time(2, 0)
oSheet.Range("g36").Value = off_time(3, 0)
oSheet.Range("g37").Value = off_time(4, 0)
oSheet.Range("k33").Value = on_time(0, 1)
oSheet.Range("k34").Value = on_time(1, 1)
oSheet.Range("k35").Value = on_time(2, 1)
oSheet.Range("k36").Value = on_time(3, 1)
oSheet.Range("k37").Value = on_time(4, 1)
oSheet.Range("n33").Value = off_time(0, 1)
oSheet.Range("n34").Value = off_time(1, 1)
oSheet.Range("n35").Value = off_time(2, 1)
oSheet.Range("n36").Value = off_time(3, 1)
oSheet.Range("n37").Value = off_time(4, 1)
oSheet.Range("aj9").Value = Pump_Total_Run_Count(0) + Pump_Total_Run_Count(1)
Dim DataArray(0 To 100, 0 To 36) As Object
Dim r As Integer
Dim c As Integer
c = 0
For c = 0 To 35
For r = 1 To 24
DataArray(r - 1, c) = Arr_cp_data(r, c + 2)
Next r
Next c
'Transfer the array to the worksheet starting at cell A2
oSheet.Range("B9").Resize(24, 33).Value = DataArray
Console.WriteLine("엑셀(일보) 저장.")
If My.Computer.FileSystem.FileExists(WriteFilename) Then
My.Computer.FileSystem.DeleteFile(WriteFilename)
Else
End If
Console.WriteLine(WriteFilename)
'Save the Workbook and Quit Excel
oBook.SaveAs(WriteFilename)
Console.WriteLine("저장완료.")
If PrintMode = 1 Then
oBook.PrintOut()
Console.WriteLine("출력완료.")
End If
oExcel.Quit()
oExcel = Nothing
Console.WriteLine("프로그램 종료.")
Console.WriteLine("작업완료.")
End Sub
End Module