Public Class StyleEdit
    Dim Path As System.IO.DirectoryInfo
    Dim FileName As String
    Dim Fullname As String
    Dim Target() As String = {"X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", "X11", "X12", "X13"}
    Dim AllFullLabel() As CEpole.C_Epole.S_FullLable

    Public Sub New(ByVal styleindex As Short, ByVal cPath As System.IO.DirectoryInfo, ByVal Fulllabel() As CEpole.C_Epole.S_FullLable)

        ' 이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()
        Me.Path = cPath
        Me.Fullname = Me.Path.FullName & "\" & StyleList(styleindex).File
        Me.FileName = StyleList(styleindex).File
        Me.AllFullLabel = Fulllabel
        ' InitializeComponent() 호출 뒤에 초기화 코드를 추가하십시오.

    End Sub
    Private Sub StyleEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Load_File()

    End Sub

    ''' <summary>
    ''' 지정된 파일의 내용을 화면에 표시합니다.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Load_File()
        Me.lb_filename.Text = Me.FileName
        Dim ini As New ACC.MyINI(Me.Fullname)
        If IO.File.Exists(Me.Fullname) = False Then
            MsgBox("편집할 파일명이 존재하지않습니다. 연락주세요", MsgBoxStyle.Information, "확인")
        Else
            Me.RichTextBox1.LoadFile(Me.Fullname, System.Windows.Forms.RichTextBoxStreamType.PlainText)
            Me.tb_desc.Text = ini.Read("style", "desc")
            Me.tb_filter.Text = ini.Read("style", "filter")
        End If

        Me.ComboBox1.Items.Clear()
        For Each A As CEpole.C_Epole.S_FullLable In Me.AllFullLabel
            Me.combobox1.Items.Add("[" & A.Tag.ToUpper & "]" & A.Desc)
        Next
    End Sub


    Private Sub bt_savenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_save.Click
        If MsgBox("저장을 하면 되돌릴수 없습니다" & vbCrLf & "저장하시겠습니까?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "저장확인") = MsgBoxResult.Ok Then
            IO.File.Copy(Me.Fullname, Path.FullName & "\bak_" & Format(Now, "MMddhhmmss") & Replace(Me.FileName.ToLower, "ini", "bak"), True)
            Me.RichTextBox1.SaveFile(Me.Fullname, System.Windows.Forms.RichTextBoxStreamType.PlainText)
            Dim ini As New ACC.MyINI(Me.Fullname)
            ini.Write("style", "desc", Me.tb_desc.Text)
            ini.Read("style", "filter", Me.tb_filter.Text)
            MsgBox("저장이완료되었습니다" & vbCrLf & "출력창을 다시 열었을 경우 반영됩니다", MsgBoxStyle.Information, "확인")
        End If
    End Sub

    Private Sub btloadStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_load.Click
        Me.RichTextBox1.LoadFile(Me.Fullname, System.Windows.Forms.RichTextBoxStreamType.PlainText)
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim src As String
        Dim pos() As String
        Dim Cnt As Integer = 0
        Dim NewStringArray() As String = Nothing
        Dim Si, Ei As Short
        Dim Tag As String
        Dim EffectRowcont As Integer = 0

        If Me.combobox1.SelectedIndex = -1 Then
            MsgBox("일괄변경할 개체를 선택하세요", MsgBoxStyle.Information, "확인")
            Return
        End If

        If IsNumeric(Me.tb_x.Text) = False Then Me.tb_x.Text = "0"
        If IsNumeric(Me.tb_y.Text) = False Then Me.tb_y.Text = "0"
        If IsNumeric(Me.tb_fontsize.Text) = False Then Me.tb_fontsize.Text = "0"
        If Me.tb_fontname.Text = "" Then Me.tb_fontname.Text = "HY견고딕"

        Si = 0 'Me.AllFullLabel(Me.combobox1.SelectedIndex).Si
        Ei = Me.AllFullLabel(Me.combobox1.SelectedIndex).Ei - Me.AllFullLabel(Me.combobox1.SelectedIndex).Si
        Tag = Me.AllFullLabel(Me.combobox1.SelectedIndex).Tag.ToUpper

        'For Each Z As String In Me.Target
        '    If A.ToUpper.IndexOf(Z & "POS") > -1 Then
        '        pos = A.Substring(A.IndexOf("=") + 1).Trim.Split(",")   '//위치값을 가졌으니 그 위치값으로 변경해서 다시 저장한다.
        '        pos(0) += Val(Me.tb_x.Text)
        '        pos(1) += Val(Me.tb_y.Text)
        '        Cnt += 1
        '        'Me.RichTextBox2.AppendText(Z & "POS = " & pos(0) & "," & pos(1) & "," & pos(2) & "," & pos(3) & vbCrLf)
        '        AddString(NewStringArray, Z & "POS = " & pos(0) & "," & pos(1) & "," & pos(2) & "," & pos(3) & vbCrLf)

        '    End If
        'Next

        For Each A As String In Me.RichTextBox1.Lines
            src = A
            Cnt = 0
            For i As Short = Si To Ei

                If A.ToUpper.IndexOf(Tag & CStr(i + 1) & "POS=") > -1 Then
                    pos = A.Substring(A.IndexOf("=") + 1).Trim.Split(",")   '//위치값을 가졌으니 그 위치값으로 변경해서 다시 저장한다.
                    pos(0) += Val(Me.tb_x.Text)
                    pos(1) += Val(Me.tb_y.Text)
                    Cnt += 1
                    AddString(NewStringArray, Tag & CStr(i + 1) & "POS=" & pos(0) & "," & pos(1) & "," & pos(2) & "," & pos(3)) '& vbCrLf)
                    EffectRowcont += 1
                End If
                If A.ToUpper.IndexOf(Tag & CStr(i + 1) & "FONT=") > -1 Then
                    pos = A.Substring(A.IndexOf("=") + 1).Trim.Split(",")   '//위치값을 가졌으니 그 위치값으로 변경해서 다시 저장한다.
                    pos(0) = Me.tb_fontname.Text
                    pos(1) += Val(Me.tb_fontsize.Text)
                    Cnt += 1
                    AddString(NewStringArray, Tag & CStr(i + 1) & "FONT=" & pos(0) & "," & pos(1) & "," & pos(2) & "," & pos(3) & "," & pos(4) & "," & pos(5) & "," & pos(6)) ' & vbCrLf)
                    EffectRowcont += 1
                End If
            Next
            If Cnt = 0 Then
                AddString(NewStringArray, A)
            End If
        Next
        Me.RichTextBox1.Clear()
        Me.RichTextBox1.Lines = NewStringArray
        MsgBox(EffectRowcont & "개의 줄이 변경되었습니다", MsgBoxStyle.Information, "확인")
    End Sub
    Private Sub AddString(ByRef Array() As String, ByVal str As String)
        If Array Is Nothing Then
            ReDim Array(0)
        Else
            ReDim Preserve Array(Array.GetUpperBound(0) + 1)
        End If

        Array(Array.GetUpperBound(0)) = str
    End Sub
End Class