Imports System.IO
Public Class Form1
Private Enum me_Col
c0SCHEMA
c1TABLE
c2SIZE
c3UNIT
c4LINES
c5TYPE
c6BYTE
End Enum
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.Font = New Font("MS ゴシック", 9)
Me.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
Me.DataGridView1.AllowDrop = True
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Call ms_TableLine("C:\oraclexe\app\oracle\admin\XE\dpdump\20180127EXP_ALL.LOG")
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.DataGridView1.Sort(New clsComparer(SortOrder.Ascending))
End Sub
Private Sub DataGridView1_CellPainting(sender As Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If e.ColumnIndex < 0 AndAlso e.RowIndex >= 0 Then
e.Paint(e.ClipBounds, DataGridViewPaintParts.All)
Dim indexRect As Rectangle = e.CellBounds
indexRect.Inflate(-2, -2)
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.CellStyle.Font, indexRect, e.CellStyle.ForeColor, TextFormatFlags.Right Or TextFormatFlags.VerticalCenter)
e.Handled = True
End If
End Sub
Private Sub DataGridView1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
Dim w_Files As String() = CType(e.Data.GetData(DataFormats.FileDrop, False), String())
Dim w_File As String = w_Files(0)
Call ms_TableLine(w_File)
End Sub
Private Sub DataGridView1_SortCompare(sender As Object, e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles DataGridView1.SortCompare
Select Case e.Column.Index
Case me_Col.c2SIZE, me_Col.c4LINES, me_Col.c6BYTE
e.SortResult = CInt(e.CellValue1) - CInt(e.CellValue2)
e.Handled = True
Case Else
End Select
End Sub
Private Sub ms_TableLine(wp_File As String)
Me.Text = wp_File
Dim w_Lines As IEnumerable(Of String) = File.ReadLines(wp_File)
Dim w_TableLines As New List(Of clsTableLine)
For Each w_Line As String In w_Lines
Dim w As String = mf_Line(w_Line)
If w <> "" Then
w_TableLines.Add(mf_TableLine(w))
End If
Next
Me.DataGridView1.Rows.Clear()
If w_TableLines.Count > 0 Then
Me.DataGridView1.Rows.Add(w_TableLines.Count)
For i As Integer = 0 To w_TableLines.Count - 1
Me.DataGridView1.Rows(i).Cells(me_Col.c0SCHEMA).Value = w_TableLines(i).c0SCHEMA
Me.DataGridView1.Rows(i).Cells(me_Col.c1TABLE).Value = w_TableLines(i).c1TABLE
Me.DataGridView1.Rows(i).Cells(me_Col.c2SIZE).Value = w_TableLines(i).c2SIZE
Me.DataGridView1.Rows(i).Cells(me_Col.c3UNIT).Value = w_TableLines(i).c3UNIT
Me.DataGridView1.Rows(i).Cells(me_Col.c4LINES).Value = w_TableLines(i).c4LINES
Me.DataGridView1.Rows(i).Cells(me_Col.c5TYPE).Value = w_TableLines(i).c5TYPE
Me.DataGridView1.Rows(i).Cells(me_Col.c6BYTE).Value = w_TableLines(i).c6BYTE
Next
End If
Me.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
End Sub
Private Function mf_Line(wp_Line As String) As String
Dim ret As String = ""
If wp_Line Like ". . ""*"".""*"" * * *行がエクスポートされました" Then
'. . "APEX_040000"."WWV_FLOW_PAGE_PLUGS" 27.27 MB 38984行がエクスポートされました
Dim w As String = wp_Line
w = w.Replace(". . """, "")
w = w.Replace(""".""", " ")
w = w.Replace(""" ", " ")
w = w.Replace("行がエクスポートされました", " EXPORT")
Dim i As Integer = w.IndexOf(" ")
Do While i >= 0
w = w.Replace(" ", " ")
i = w.IndexOf(" ")
Loop
w = w.Replace(" ", vbTab)
Dim w_Array As String() = Split(w, vbTab, -1, CompareMethod.Text)
If w_Array.Count = 6 Then
ret = w
End If
End If
Return ret
End Function
Private Function mf_TableLine(wp_Line As String) As clsTableLine
Dim ret As New clsTableLine()
Dim w_Array As String() = Split(wp_Line, vbTab, -1, CompareMethod.Text)
ret.c0SCHEMA = w_Array(0)
ret.c1TABLE = w_Array(1)
ret.c2SIZE = mf_StringToInteger(w_Array(2))
ret.c3UNIT = w_Array(3)
ret.c4LINES = mf_StringToInteger(w_Array(4))
ret.c5TYPE = w_Array(5)
ret.c6BYTE = mf_SizeUnitDouble(ret.c2SIZE, ret.c3UNIT)
Return ret
End Function
Private Function mf_StringToInteger(wp_String As String) As Integer
Dim ret As Integer = 0
If IsNumeric(wp_String) Then
ret = CInt(wp_String)
End If
Return ret
End Function
Private Function mf_SizeUnitDouble(wp_Size As Integer, wp_Unit As String) As Double
Dim ret As Double = CDbl(wp_Size)
Select Case wp_Unit
Case "KB"
ret = ret * 1024
Case "MB"
ret = ret * (1024 ^ 2)
Case "GB"
ret = ret * (1024 ^ 3)
Case "TB"
ret = ret * (1024 ^ 4)
Case Else
End Select
Return ret
End Function
End Class
Public Class clsTableLine
Public Property c0SCHEMA As String = ""
Public Property c1TABLE As String = ""
Public Property c2SIZE As Integer = 0
Public Property c3UNIT As String = ""
Public Property c4LINES As Integer = 0
Public Property c5TYPE As String = ""
Public Property c6BYTE As Double = 0
End Class
Public Class clsComparer
Implements IComparer
Private sOrder As Integer
Private comparer As Comparer
Public Sub New(ByVal order As SortOrder)
Me.sOrder = IIf(order = SortOrder.Descending, -1, 1)
Me.comparer = New Comparer(System.Globalization.CultureInfo.CurrentCulture)
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
Dim result As Integer = 0
Dim rowx As DataGridViewRow = CType(x, DataGridViewRow)
Dim rowy As DataGridViewRow = CType(y, DataGridViewRow)
'はじめの列のセルの値を比較し、同じならば次の列を比較する
For i As Integer = 0 To 1 'rowx.Cells.Count - 1
result = Me.comparer.Compare(rowx.Cells(i).Value, rowy.Cells(i).Value)
If result <> 0 Then
Exit For
End If
Next i
Return result * Me.sOrder
End Function
End Class
最終更新:2018年01月27日 23:35