Imports System.IO
Imports MyControlOLEDBv2

Module Common


    Structure S_Arrow
        Dim Direction As Short
        Dim RectX As Short
        Dim RectY As Short
        Dim RectW As Short
        Dim RectH As Short
        Dim TriWidth As Short
        Dim TriHeight As Short
        Dim PenColor As Drawing.Color
        Dim PenWidth As Single
        'Dim FillColor As Drawing.Color
        Dim Field As String
    End Structure

    Structure S_Line
        Dim X As Short
        Dim Y As Short
        Dim X2 As Short
        Dim Y2 As Short
        Dim PenColor As Drawing.Color
        Dim PenWidth As Single
        Dim Field As String
    End Structure

    Structure S_Box
        Dim X As Short
        Dim Y As Short
        Dim Width As Short
        Dim Height As Short
        Dim PenColor As Drawing.Color
        Dim PenWidth As Single
        Dim Field As String
    End Structure

    Structure S_QRCode
        Dim X As Single
        Dim Y As Single
        Dim Width As Single
        Dim Height As Single
        Dim Field As String
    End Structure

    Structure S_QRCode1
        Dim X As Single
        Dim Y As Single
        Dim Width As Single
        Dim Height As Single
        Dim Field As String
    End Structure

    Structure S_Circle
        Dim X As Single
        Dim Y As Single
        Dim Width As Single
        Dim Height As Single
        Dim PenColor As Drawing.Color
        Dim PenWidth As Single
        'Dim Radius As Single    '//휘어짐수치
        Dim Field As String
    End Structure

    Structure S_Image
        Dim X As Single
        Dim Y As Single
        Dim Width As Single
        Dim Height As Single
        Dim FileName As String
        Dim Field As String
    End Structure

    Enum ESorted
        No = 1
        YES = 2
        NULL = 0
        CANT = 3
    End Enum
    Structure Cfont
        Dim FontName As String
        Dim FontSize As Int16
    End Structure

    Structure Str_Alllabels '레이블들을 저장한다.
        Dim ctl As MyControlOLEDBv2.MyLabel
        Dim desc As String
    End Structure

    Structure SStyle
        Dim Desc As String
        Dim File As String
        Dim LoadOK As Boolean
    End Structure

    Public StyleList() As SStyle
    Public PDS() As PatternDS

    Public Draw_Line As New List(Of S_Line)
    Public Draw_Box As New List(Of S_Box)
    Public Draw_Circle As New List(Of S_Circle)
    Public Draw_Image As New List(Of S_Image)
    Public Draw_QRcode As New List(Of S_QRCode)
    Public Draw_QRcode1 As New List(Of S_QRCode1)
    Public Draw_Arrow As New List(Of S_Arrow) '//방향화살표  170711


    Public DataBaseFile As String = My.Application.Info.DirectoryPath & "\database\database.mdb"
    'Public ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataBaseFile
    'Public Arin As New CommonClassv2.ARINCLASS
    'Public ArinPath As New CommonClassv2.MyPath
    Public Auto_Log As Boolean = False  '//디비나 각종 로그파일을 쌓을지 여부
    Public PICmanFile As String = vbNullString '//그림관리프로그램의 파일명을 적는다.
    Public MakeState As String = vbNullString
    Public PoleState As String = vbNullString
    Public PoleEtcState As String = vbNullString
    Public PicState As String = vbNullString   '/그림파일연결관리다.
    Public HelpWebSite As String = vbNullString  '//웹페이지주소 일단은 도움말을 얻기위해쓴다.
    Public HomePage As String = vbNullString
    Public SORTNULL As Boolean = True   '//전주세부-정렬이 번호가 비어잇을경우 가장위에표시할지 아닐지!
    Public NUMCOLOR As Boolean  '//가공번호찰에서 번호에 색상을 지정할지
    Public Admin As Boolean = False '//개발자모드로 접속햇을때
    Public IsPro As Boolean = False

    Public ViewFont As Cfont   '//뷰의 글자
    Public MenuFont As Cfont    '//메뉴의 글자
    Public FormFont As Cfont    '//폼의 글자

    'Public CEpole As CEpole.C_Epole  '//전신주용 DLL추가햇다.

    'Public Sub AddLog(ByVal msgtext As String, Optional ByVal ClearData As Boolean = False)   '//로그창에 기록을 남깁니다.
    '    If ClearData Then Frm_Log.RichTextBox1.Clear()
    '    Frm_Log.RichTextBox1.AppendText(msgtext & vbCrLf)
    'End Sub
    'Public Sub Showlog()
    '    Frm_Log.MdiParent = Main
    '    Frm_Log.Show()
    'End Sub

    Public Sub Work_Form(ByVal T As String)
        Form_Work.Show()
        Form_Work.Msg(T)
    End Sub
    Public Sub NWork_Form(ByVal T As String, ByVal maxcount As Integer)
        Form_Work.Show()
        Form_Work.Msg(T)
        Form_Work.ProgressBar1.Value = 0
        Form_Work.ProgressBar1.Minimum = 0
        Form_Work.ProgressBar1.Maximum = maxcount
    End Sub

    Public Sub NOTICE(ByVal MSG As String, ByVal Src As Object)
        On Error Resume Next
        If Src.GetType.Name.ToUpper = "TOOLSTRIPSTATUSLABEL" Then
            CType(Src, ToolStripStatusLabel).Text = "▶ " & MSG & Space(1)
            CType(Src, ToolStripStatusLabel).ForeColor = Color.Black
        ElseIf Src.GetType.Name.ToUpper = "LABEL" Then
            CType(Src, Label).Text = "▶ " & MSG & Space(1)
            CType(Src, Label).ForeColor = Color.Black
        End If
        ' My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
    End Sub
    Public Sub NOTICE(ByVal MSG As String, ByVal FCOLOR As Color, ByVal Src As Windows.Forms.ToolStripStatusLabel)
        Src.Text = "▶ " & MSG & Space(1)
        Src.ForeColor = FCOLOR
        '  My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
    End Sub

    Public Function NVL(ByVal Indata As Object, Optional ByVal nullVal As Object = "") As Object

        Try
            'If Indata = "" Then Return nullVal
            If Indata Is DBNull.Value Then Return nullVal
        Catch ex As Exception
            Return nullVal
        End Try
        If Indata Is vbNullString Then Return nullVal
        If Indata.ToString.Trim = "" Then Return nullVal
        Return Indata
    End Function

    Public Function PATTERN_ENC(ByVal SRCSTR As String, Optional IncludeH As Boolean = False) As String
        Dim MSG As New System.Text.StringBuilder
        For Each A As Char In SRCSTR.ToCharArray   '//모든문자의 숫자번호를 판별한다.

            If IncludeH Then
                If A = ";" Then '//구분자라면
                    MSG.Append(";")
                ElseIf A = "H" Then
                    MSG.Append("Z")
                ElseIf A = "-" Then
                    MSG.Append("-")
                ElseIf Char.IsNumber(A) Then
                    MSG.Append("1")
                ElseIf Asc(A) < 0 Then
                    MSG.Append("H")
                Else
                    MSG.Append("0")
                End If
            Else
                If A = ";" Then '//구분자라면
                    MSG.Append(";")
                ElseIf A = "-" Then
                    MSG.Append("-")
                ElseIf Char.IsNumber(A) Then
                    MSG.Append("1")
                ElseIf Asc(A) < 0 Then
                    MSG.Append("H")
                Else
                    MSG.Append("0")
                End If
            End If


        Next
        Return MSG.ToString
    End Function

    Public Sub ReNum(ByVal Srcspread As MyControlOLEDBv2.MyFpoint, ByVal NumColumnindex As Integer, Optional ByVal PBar As ProgressBar = Nothing)
        If Not PBar Is Nothing Then
            PBar.Minimum = 0
            PBar.Maximum = Srcspread.ActiveSheet.RowCount
            PBar.Value = 0
        End If

        For Each SR As FarPoint.Win.Spread.Row In Srcspread.ActiveSheet.Rows
            If Not PBar Is Nothing Then PBar.Value += 1
            Srcspread.ActiveSheet.Cells(SR.Index, NumColumnindex).Value = SR.Index + 1
        Next
    End Sub

    Public Sub AddLog(ByVal t1 As Boolean, ByVal txt As String, Optional ByVal t2fn As String = "")
        'If Admin Then Log.RichTextBox1.AppendText(txt & vbCrLf)
    End Sub
    Public Sub showlog()
        '  Log.Show()
    End Sub
    Public Sub hidelog()
        '  Log.Close()
    End Sub
    Public Sub resetLog()
        '  Log.RichTextBox1.Text = ""
    End Sub

    Public Function TextEnc(ByVal SrcText As String) As String
        If SrcText = "" Then Return ""

        Dim Ec As New System.Text.UnicodeEncoding
        Dim Msg1 As New System.Text.StringBuilder
        For Each bi As Byte In Ec.GetBytes(SrcText)
            Msg1.Append(bi.ToString & ",")
        Next
        Msg1.Remove(Msg1.Length - 1, 1)
        Return Msg1.ToString
    End Function
    Public Function TextDec(ByVal srctext As String) As String
        Dim Ec As New System.Text.UnicodeEncoding
        Dim Z(srctext.Split(",").GetUpperBound(0)) As Byte
        Dim i As Int16 = 0
        For Each aa As String In srctext.ToString.Split(",")
            Z(i) = CType(aa, Byte)
            i += 1
        Next
        Return Ec.GetString(Z)
    End Function



    Public Sub ReNum(ByRef SrcTable As DataTable, ByVal ColumnName As String, Optional ByVal PBar As ProgressBar = Nothing)


        If Not SrcTable.GetChanges Is Nothing Then
            MsgBox("변경된 내용이 있습니다" & vbCrLf & vbCrLf & "먼저 저장을 하세요", MsgBoxStyle.Information, "확인")
            Return
        End If

        If MsgBox("모든번호가 새로 갱신됩니다" & vbCrLf & vbCrLf & "계속하시겠습니까?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "확인") <> MsgBoxResult.Ok Then
            Return
        End If
        If Not PBar Is Nothing Then
            PBar.Minimum = 0
            PBar.Maximum = SrcTable.Rows.Count
            PBar.Value = 0
        End If

        Dim i As Integer = 0
        Dim DV As New DataView(SrcTable, "", "정렬번호,번호", DataViewRowState.CurrentRows)
        Dim DT As DataTable = DV.ToTable

        For Each dr As DataRow In DT.Rows
            i += 1
            dr(ColumnName) = i
            If Not PBar Is Nothing Then PBar.Value += 1
        Next
        SrcTable.Merge(DT)
        MsgBox("번호 정렬이 완료되었습니다", MsgBoxStyle.Information, "확인")
    End Sub

    Public Sub GetAllsection(ByVal FILENAME As String, ByVal CurIdx As Short)


        Dim f As New fProgress()
        f.ProgressBar1.Minimum = 0
        f.ProgressBar1.Maximum = 0
        f.ProgressBar1.Style = ProgressBarStyle.Marquee
        f.Label1.Text = "스타일(" + CurIdx.ToString() + ")을 불러오고 있습니다" + vbCrLf + FILENAME
        f.TopMost = True
        f.Show()
        Application.DoEvents()


        '//파일의내용을 데이터테이블에 바로 넣도록 변경작업

        'Dim wat As New System.Diagnostics.Stopwatch
        'Dim FS As New System.IO.FileStream(FILENAME, IO.FileMode.Open)
        'Dim SR As New IO.StreamReader(FS, System.Text.Encoding.Default)

        Dim buffers() As String = System.IO.File.ReadAllLines(FILENAME, System.Text.Encoding.Default)

        Dim Findkey As String = ""
        ' Dim Line As String
        Dim KeyPos As Integer = -1
        Dim Seppos As Integer = -1
        Dim dr As DataRow

        'WLog2(Auto_Log, "getallSection : 파일의 모든내용을 테이블로 옴긴다.()", "\지중(케이블라벨)순차로그.txt")

        'StyleList(CurIdx).PATTERNTABLE = New DataTable
        'StyleList(CurIdx).PATTERNTABLE.Columns.Add("설명")
        'StyleList(CurIdx).PATTERNTABLE.Columns.Add("값")

        '//초기값셋팅
        'StyleList(CurIdx).Backimg = ""
        'StyleList(CurIdx).CanvasX = 292
        'StyleList(CurIdx).CanvasY = 520
        'StyleList(CurIdx).Desc = "기본걸명"
        'StyleList(CurIdx).dummmyx = 0
        'StyleList(CurIdx).dummmyy = 50
        'StyleList(CurIdx).Dummy = False
        'StyleList(CurIdx).Dummytype = 1
        'StyleList(CurIdx).File = FILENAME
        'StyleList(CurIdx).IsXml = False
        ' MsgBox(FILENAME)

        'StyleList(CurIdx).Filter = ""
        'StyleList(CurIdx).LandScape = False
        'StyleList(CurIdx).MarginX = 50
        'StyleList(CurIdx).MarginY = 50
        'StyleList(CurIdx).picstyle = 1
        'StyleList(CurIdx).PrintFontOffset = 0
        'StyleList(CurIdx).ScaleX = 1.5
        'StyleList(CurIdx).ScaleY = 1.5
        'StyleList(CurIdx).Viewimage = False

        '//XMl테이블 동기화(기존데이터삭제)

        If Common.PDS(CurIdx) Is Nothing Then Common.PDS(CurIdx) = New PatternDS()

        Common.PDS(CurIdx).TStyle.Rows.Clear()
        Common.PDS(CurIdx).TPattern.Rows.Clear()

        '//set default value
        Dim Drow As PatternDS.TStyleRow = Common.PDS(CurIdx).TStyle.NewTStyleRow
        Drow.BACKIMG = String.Empty
        Drow.CANVASX = 292
        Drow.CANVASY = 520
        Drow.DESC = "기본설명"
        Drow.DUMMMYX = 0
        Drow.DUMMMYY = 50
        Drow.DUMMY = "false"
        Drow.DUMMYTYPE = "1"
        Drow.FILE = FILENAME
        Drow.ISXML = False
        Drow.DUMMYCNT = 0
        Drow.LANDSCAPE = "false"
        Drow.MARGINX = 50
        Drow.MARGINY = 50
        Drow.FILTER = String.Empty
        Drow.PICSTYLE = "1"
        Drow.PRINTFONTOFFSET = "0"
        Drow.SCALEX = "1.5"
        Drow.SCALEY = "1.5"
        Drow.VIEWIMAGE = "false"
        Drow.PRINTBG = "false"
        Drow.BAKX = "0"
        Drow.BAKY = "0"
        Drow.BAKW = "0"
        Drow.BAKH = "0"
        Drow.VIEWIMAGE = "false"

        'wat.Restart()
        'Console.WriteLine("File Read Ready")


        '//모든줄을 읽어서  섹션&키  = 설명  으로 한다.
        Try
            For Each Line As String In buffers
                If String.IsNullOrEmpty(Line) Then Continue For '//빈값제거
                If Line.StartsWith("#") Then Continue For '//주석제거


                If Findkey = "" Then '//아직 셋팅된 키가 없다면
                    If Line.ToUpper.IndexOf("[") > -1 Then Findkey = Line.Trim("[").ToString.Trim("]").ToString
                Else   '//셋팅된 키가 있다면 테이블에 추가해준다.
                    If Line.IndexOf("[") = -1 Then  '//그다음 키가 오기전까지 모두 추가한다.
                        Seppos = Line.IndexOf("=")

                        Select Case Line.Substring(0, Seppos).ToUpper
                            Case "DESC"
                                If Findkey.ToUpper = "STYLE" Then
                                    Drow.DESC = Line.Substring(Seppos + 1).ToUpper
                                Else
                                    'dr = StyleList(CurIdx).PATTERNTABLE.NewRow
                                    Dim stitle As String = CStr(Findkey & Line.Substring(0, Seppos)).ToUpper
                                    Dim svalue As String = Line.Substring(Seppos + 1).ToUpper
                                    '  StyleList(CurIdx).PATTERNTABLE.Rows.Add(dr)

                                    Dim Nrow As PatternDS.TPatternRow = Common.PDS(CurIdx).TPattern.NewTPatternRow
                                    Nrow.NAME = stitle ' PRow("설명")
                                    Nrow.Val = svalue ' PRow("값")
                                    Common.PDS(CurIdx).TPattern.AddTPatternRow(Nrow)

                                End If
                            Case "FILE" : Drow.FILE = FILENAME ''StyleList(CurIdx).File = Line.Substring(Seppos + 1).ToUpper
                            Case "BACKIMG" : Drow.BACKIMG = Line.Substring(Seppos + 1).ToUpper
                            Case "CANVASX" : Drow.CANVASX = Line.Substring(Seppos + 1).ToUpper
                            Case "CANVASY" : Drow.CANVASY = Line.Substring(Seppos + 1).ToUpper
                            Case "DUMMY" : Drow.DUMMY = Line.Substring(Seppos + 1).ToUpper
                            Case "DUMMYCNT" : Drow.DUMMYCNT = Line.Substring(Seppos + 1).ToUpper
                            Case "DUMMYTYPE" : Drow.DUMMYTYPE = Line.Substring(Seppos + 1).ToUpper
                            Case "DUMMMYX" : Drow.DUMMMYX = Line.Substring(Seppos + 1).ToUpper
                            Case "DUMMMYY" : Drow.DUMMMYY = Line.Substring(Seppos + 1).ToUpper
                            Case "LANDSCAPE" : Drow.LANDSCAPE = Line.Substring(Seppos + 1).ToUpper
                            Case "MARGINX" : Drow.MARGINX = Line.Substring(Seppos + 1).ToUpper
                            Case "MARGINY" : Drow.MARGINY = Line.Substring(Seppos + 1).ToUpper
                            Case "PICSTYLE" : Drow.PICSTYLE = Line.Substring(Seppos + 1).ToUpper
                            Case "PRINTFONTOFFSET" : Drow.PRINTFONTOFFSET = Line.Substring(Seppos + 1).ToUpper
                            Case "PRINTBG" : Drow.PRINTBG = Line.Substring(Seppos + 1).ToUpper
                            Case "SCALEX" : Drow.SCALEX = Line.Substring(Seppos + 1).ToUpper
                            Case "SCALEY" : Drow.SCALEY = Line.Substring(Seppos + 1).ToUpper
                            Case "BAKX" : Drow.BAKX = Line.Substring(Seppos + 1).ToUpper
                            Case "BAKY" : Drow.BAKY = Line.Substring(Seppos + 1).ToUpper
                            Case "BAKW" : Drow.BAKW = Line.Substring(Seppos + 1).ToUpper
                            Case "BAKH" : Drow.BAKH = Line.Substring(Seppos + 1).ToUpper
                            Case "VIEWIMAGE" : Drow.VIEWIMAGE = Line.Substring(Seppos + 1).ToUpper
                            Case "FILTER" : Drow.FILTER = Line.Substring(Seppos + 1).ToUpper
                            Case Else
                                'dr = StyleList(CurIdx).PATTERNTABLE.NewRow
                                Dim stitle As String = CStr(Findkey & Line.Substring(0, Seppos)).ToUpper
                                Dim svalue As String = Line.Substring(Seppos + 1).ToUpper
                                'StyleList(CurIdx).PATTERNTABLE.Rows.Add(dr)

                                Dim Nrow As PatternDS.TPatternRow = Common.PDS(CurIdx).TPattern.NewTPatternRow
                                Nrow.NAME = stitle ' PRow("설명")
                                Nrow.Val = svalue ' PRow("값")
                                Common.PDS(CurIdx).TPattern.AddTPatternRow(Nrow)


                        End Select
                    Else
                        Findkey = Line.Trim("[").ToString.Trim("]").ToString
                    End If
                End If

            Next

        Catch ex As Exception
            f.Close()
            MsgBox("Load Error " + vbCrLf + ex.Message, MsgBoxStyle.Critical, "Error")
        End Try

        ' MsgBox(tyleList(CurIdx).Filter)

        'Console.WriteLine("File Read : " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Restart()

        'SR.Close()
        'FS.Close()
        Dim CFile As New System.IO.FileInfo(FILENAME.ToLower.Replace("ini", "cfg"))
        If CFile.Exists = False Then  '//새로만들기
            AddLog(Admin, "로컬프린터정보 Config 파일이 존재하지않습니다. 새로 생성합니다.", "\Alllog.txt")
            Dim CfgIni As New MyINI2(CFile.FullName)
            CfgIni.Write("printer", "MARGINX", Drow.MARGINX)
            CfgIni.Write("printer", "MARGINY", Drow.MARGINY)
            CfgIni.Write("printer", "PRINTFONTOFFSET", Drow.PRINTFONTOFFSET)
            CfgIni.Write("printer", "SCALEX", Drow.SCALEX)
            CfgIni.Write("printer", "SCALEY", Drow.SCALEY)
            CfgIni.Write("printer", "PRINTBG", Drow.PRINTBG)
        Else   '//파일있으면 불러온다
            AddLog(Admin, "로컬프린터정보 Config 파일이 존재하므로 해당 파일을 이용합니다(" & CFile.FullName & ")", "\Alllog.txt")
            Dim CfgIni As New MyINI2(CFile.FullName)
            Drow.MARGINX = CfgIni.Read("printer", "MARGINX", 50)
            Drow.MARGINY = CfgIni.Read("printer", "MARGINY", 50)
            Drow.PRINTFONTOFFSET = CfgIni.Read("printer", "PRINTFONTOFFSET", 0)
            Drow.SCALEX = CfgIni.Read("printer", "SCALEX", 1.5)
            Drow.SCALEY = CfgIni.Read("printer", "SCALEY", 1.5)
            Drow.PRINTBG = CfgIni.Read("printer", "PRINTBG", True)
        End If

        ' Console.WriteLine("File Read  2: " + wat.ElapsedMilliseconds.ToString() + "ms")
        ' wat.Restart()

        '//필터파일추가한다.
        CFile = New System.IO.FileInfo(FILENAME.ToLower.Replace("ini", "filter"))
        If CFile.Exists = True Then  '//필터파일이있으며 불러오기한다.
            Dim CfgIni As New MyINI2(CFile.FullName)
            Drow.FILTER = CfgIni.Read("STYLE", "FILTER")
        End If

        ' Console.WriteLine("File Read  3: " + wat.ElapsedMilliseconds.ToString() + "ms")
        ' wat.Restart()

        '//XML테이블 데이터 동기화
        'Dim Drow As PatternDS.TStyleRow = Common.PDS(CurIdx).TStyle.NewTStyleRow
        'Drow.DESC = StyleList(CurIdx).Desc
        'Drow.BACKIMG = StyleList(CurIdx).Backimg
        'Drow.CANVASX = StyleList(CurIdx).CanvasX
        'Drow.CANVASY = StyleList(CurIdx).CanvasY
        'Drow.DUMMY = StyleList(CurIdx).Dummy
        'Drow.DUMMYCNT = StyleList(CurIdx).DummyCnt
        'Drow.DUMMYTYPE = StyleList(CurIdx).Dummytype
        'Drow.DUMMMYX = StyleList(CurIdx).dummmyx
        'Drow.DUMMMYY = StyleList(CurIdx).dummmyy
        'Drow.LANDSCAPE = StyleList(CurIdx).LandScape
        'Drow.MARGINX = StyleList(CurIdx).MarginX
        'Drow.MARGINY = StyleList(CurIdx).MarginY
        'Drow.PICSTYLE = StyleList(CurIdx).picstyle
        'Drow.PRINTFONTOFFSET = StyleList(CurIdx).PrintFontOffset
        'Drow.PRINTBG = StyleList(CurIdx).Printbg
        'Drow.SCALEX = StyleList(CurIdx).ScaleX
        'Drow.SCALEY = StyleList(CurIdx).ScaleY
        'Drow.BAKX = StyleList(CurIdx).bakx
        'Drow.BAKY = StyleList(CurIdx).baky
        'Drow.BAKW = StyleList(CurIdx).bakw
        'Drow.BAKH = StyleList(CurIdx).bakh
        'Drow.VIEWIMAGE = StyleList(CurIdx).Viewimage
        'Drow.FILE = StyleList(CurIdx).File
        'Drow.FILTER = StyleList(CurIdx).Filter
        Common.PDS(CurIdx).TStyle.AddTStyleRow(Drow)  '//기본스타일 데이터 추가


        '  Console.WriteLine("File Read  4: " + wat.ElapsedMilliseconds.ToString() + "ms")
        '  wat.Restart()

        '//패턴정보 추가하기
        'For i As Integer = 1 To StyleList(CurIdx).PATTERNTABLE.Rows.Count
        '    Dim PRow As DataRow = StyleList(CurIdx).PATTERNTABLE.Rows(i - 1)
        '    Dim Nrow As PatternDS.TPatternRow = Common.PDS(CurIdx).TPattern.NewTPatternRow
        '    Nrow.NAME = PRow("설명")
        '    Nrow.Val = PRow("값")
        '    Common.PDS(CurIdx).TPattern.AddTPatternRow(Nrow)
        'Next
        Common.PDS(CurIdx).TPattern.AcceptChanges()

        '  Console.WriteLine("File Read  5: " + wat.ElapsedMilliseconds.ToString() + "ms")
        '  wat.Stop()

        f.Close()
        f.Dispose()
        Application.DoEvents()

    End Sub


    Public Sub GetAllsection_INI_Backup(ByVal FILENAME As String, ByVal CurIdx As Short)

        'Dim wat As New System.Diagnostics.Stopwatch
        'Dim FS As New System.IO.FileStream(FILENAME, IO.FileMode.Open)
        'Dim SR As New IO.StreamReader(FS, System.Text.Encoding.Default)
        'Dim Findkey As String = ""
        'Dim Line As String
        'Dim KeyPos As Integer = -1
        'Dim Seppos As Integer = -1
        'Dim dr As DataRow

        ''WLog2(Auto_Log, "getallSection : 파일의 모든내용을 테이블로 옴긴다.()", "\지중(케이블라벨)순차로그.txt")

        'StyleList(CurIdx).PATTERNTABLE = New DataTable
        'StyleList(CurIdx).PATTERNTABLE.Columns.Add("설명")
        'StyleList(CurIdx).PATTERNTABLE.Columns.Add("값")

        ''//초기값셋팅
        'StyleList(CurIdx).Backimg = ""
        'StyleList(CurIdx).CanvasX = 292
        'StyleList(CurIdx).CanvasY = 520
        'StyleList(CurIdx).Desc = "기본걸명"
        'StyleList(CurIdx).dummmyx = 0
        'StyleList(CurIdx).dummmyy = 50
        'StyleList(CurIdx).Dummy = False
        'StyleList(CurIdx).Dummytype = 1
        'StyleList(CurIdx).File = FILENAME
        'StyleList(CurIdx).IsXml = False
        '' MsgBox(FILENAME)

        'StyleList(CurIdx).Filter = ""
        'StyleList(CurIdx).LandScape = False
        'StyleList(CurIdx).MarginX = 50
        'StyleList(CurIdx).MarginY = 50
        'StyleList(CurIdx).picstyle = 1
        'StyleList(CurIdx).PrintFontOffset = 0
        'StyleList(CurIdx).ScaleX = 1.5
        'StyleList(CurIdx).ScaleY = 1.5
        'StyleList(CurIdx).Viewimage = False

        ''//XMl테이블 동기화(기존데이터삭제)

        'Common.PDS(CurIdx).TStyle.Rows.Clear()
        'Common.PDS(CurIdx).TPattern.Rows.Clear()

        'wat.Restart()
        'Console.WriteLine("File Read Ready")


        ''//모든줄을 읽어서  섹션&키  = 설명  으로 한다.
        'While SR.Peek > -1
        '    Line = SR.ReadLine.ToUpper

        '    If Line <> "" Then

        '        If Findkey = "" Then '//아직 셋팅된 키가 없다면
        '            If Line.ToUpper.IndexOf("[") > -1 Then Findkey = Line.Trim("[").ToString.Trim("]").ToString
        '        Else   '//셋팅된 키가 있다면 테이블에 추가해준다.
        '            If Line.IndexOf("[") = -1 Then  '//그다음 키가 오기전까지 모두 추가한다.
        '                Seppos = Line.IndexOf("=")

        '                Select Case Line.Substring(0, Seppos).ToUpper
        '                    Case "DESC"
        '                        If Findkey.ToUpper = "STYLE" Then
        '                            StyleList(CurIdx).Desc = Line.Substring(Seppos + 1).ToUpper
        '                        Else
        '                            dr = StyleList(CurIdx).PATTERNTABLE.NewRow
        '                            dr(0) = CStr(Findkey & Line.Substring(0, Seppos)).ToUpper
        '                            dr(1) = Line.Substring(Seppos + 1).ToUpper
        '                            StyleList(CurIdx).PATTERNTABLE.Rows.Add(dr)
        '                        End If
        '                    Case "FILE" 'StyleList(CurIdx).File = Line.Substring(Seppos + 1).ToUpper
        '                    Case "BACKIMG" : StyleList(CurIdx).Backimg = Line.Substring(Seppos + 1).ToUpper
        '                    Case "CANVASX" : StyleList(CurIdx).CanvasX = Line.Substring(Seppos + 1).ToUpper
        '                    Case "CANVASY" : StyleList(CurIdx).CanvasY = Line.Substring(Seppos + 1).ToUpper
        '                    Case "DUMMY" : StyleList(CurIdx).Dummy = Line.Substring(Seppos + 1).ToUpper
        '                    Case "DUMMYCNT" : StyleList(CurIdx).DummyCnt = Line.Substring(Seppos + 1).ToUpper
        '                    Case "DUMMYTYPE" : StyleList(CurIdx).Dummytype = Line.Substring(Seppos + 1).ToUpper
        '                    Case "DUMMMYX" : StyleList(CurIdx).dummmyx = Line.Substring(Seppos + 1).ToUpper
        '                    Case "DUMMMYY" : StyleList(CurIdx).dummmyy = Line.Substring(Seppos + 1).ToUpper
        '                    Case "LANDSCAPE" : StyleList(CurIdx).LandScape = Line.Substring(Seppos + 1).ToUpper
        '                    Case "MARGINX" : StyleList(CurIdx).MarginX = Line.Substring(Seppos + 1).ToUpper
        '                    Case "MARGINY" : StyleList(CurIdx).MarginY = Line.Substring(Seppos + 1).ToUpper
        '                    Case "PICSTYLE" : StyleList(CurIdx).picstyle = Line.Substring(Seppos + 1).ToUpper
        '                    Case "PRINTFONTOFFSET" : StyleList(CurIdx).PrintFontOffset = Line.Substring(Seppos + 1).ToUpper
        '                    Case "PRINTBG" : StyleList(CurIdx).Printbg = Line.Substring(Seppos + 1).ToUpper
        '                    Case "SCALEX" : StyleList(CurIdx).ScaleX = Line.Substring(Seppos + 1).ToUpper
        '                    Case "SCALEY" : StyleList(CurIdx).ScaleY = Line.Substring(Seppos + 1).ToUpper
        '                    Case "BAKX" : StyleList(CurIdx).bakx = Line.Substring(Seppos + 1).ToUpper
        '                    Case "BAKY" : StyleList(CurIdx).baky = Line.Substring(Seppos + 1).ToUpper
        '                    Case "BAKW" : StyleList(CurIdx).bakw = Line.Substring(Seppos + 1).ToUpper
        '                    Case "BAKH" : StyleList(CurIdx).bakh = Line.Substring(Seppos + 1).ToUpper
        '                    Case "VIEWIMAGE" : StyleList(CurIdx).Viewimage = Line.Substring(Seppos + 1).ToUpper
        '                    Case "FILTER" : StyleList(CurIdx).Filter = Line.Substring(Seppos + 1).ToUpper
        '                    Case Else
        '                        dr = StyleList(CurIdx).PATTERNTABLE.NewRow
        '                        dr(0) = CStr(Findkey & Line.Substring(0, Seppos)).ToUpper
        '                        dr(1) = Line.Substring(Seppos + 1).ToUpper
        '                        StyleList(CurIdx).PATTERNTABLE.Rows.Add(dr)
        '                End Select



        '            Else
        '                Findkey = Line.Trim("[").ToString.Trim("]").ToString
        '            End If
        '        End If
        '    End If
        'End While
        '' MsgBox(tyleList(CurIdx).Filter)

        'Console.WriteLine("File Read : " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Restart()

        'SR.Close()
        'FS.Close()
        'Dim CFile As New System.IO.FileInfo(FILENAME.ToLower.Replace("ini", "cfg"))
        'If CFile.Exists = False Then  '//새로만들기
        '    AddLog(Admin, "로컬프린터정보 Config 파일이 존재하지않습니다. 새로 생성합니다.", "\Alllog.txt")
        '    Dim CfgIni As New MyINI2(CFile.FullName)
        '    CfgIni.Write("printer", "MARGINX", StyleList(CurIdx).MarginX)
        '    CfgIni.Write("printer", "MARGINY", StyleList(CurIdx).MarginY)
        '    CfgIni.Write("printer", "PRINTFONTOFFSET", StyleList(CurIdx).PrintFontOffset)
        '    CfgIni.Write("printer", "SCALEX", StyleList(CurIdx).ScaleX)
        '    CfgIni.Write("printer", "SCALEY", StyleList(CurIdx).ScaleY)
        '    CfgIni.Write("printer", "PRINTBG", StyleList(CurIdx).Printbg)
        'Else   '//파일있으면 불러온다
        '    AddLog(Admin, "로컬프린터정보 Config 파일이 존재하므로 해당 파일을 이용합니다(" & CFile.FullName & ")", "\Alllog.txt")
        '    Dim CfgIni As New MyINI2(CFile.FullName)
        '    StyleList(CurIdx).MarginX = CfgIni.Read("printer", "MARGINX", 50)
        '    StyleList(CurIdx).MarginY = CfgIni.Read("printer", "MARGINY", 50)
        '    StyleList(CurIdx).PrintFontOffset = CfgIni.Read("printer", "PRINTFONTOFFSET", 0)
        '    StyleList(CurIdx).ScaleX = CfgIni.Read("printer", "SCALEX", 1.5)
        '    StyleList(CurIdx).ScaleY = CfgIni.Read("printer", "SCALEY", 1.5)
        '    StyleList(CurIdx).Printbg = CfgIni.Read("printer", "PRINTBG", True)
        'End If

        'Console.WriteLine("File Read  2: " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Restart()

        ''//필터파일추가한다.
        'CFile = New System.IO.FileInfo(FILENAME.ToLower.Replace("ini", "filter"))
        'If CFile.Exists = True Then  '//필터파일이있으며 불러오기한다.
        '    Dim CfgIni As New MyINI2(CFile.FullName)
        '    StyleList(CurIdx).Filter = CfgIni.Read("STYLE", "FILTER")
        'End If

        'Console.WriteLine("File Read  3: " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Restart()

        ''//XML테이블 데이터 동기화
        'Dim Drow As PatternDS.TStyleRow = Common.PDS(CurIdx).TStyle.NewTStyleRow
        'Drow.DESC = StyleList(CurIdx).Desc
        'Drow.BACKIMG = StyleList(CurIdx).Backimg
        'Drow.CANVASX = StyleList(CurIdx).CanvasX
        'Drow.CANVASY = StyleList(CurIdx).CanvasY
        'Drow.DUMMY = StyleList(CurIdx).Dummy
        'Drow.DUMMYCNT = StyleList(CurIdx).DummyCnt
        'Drow.DUMMYTYPE = StyleList(CurIdx).Dummytype
        'Drow.DUMMMYX = StyleList(CurIdx).dummmyx
        'Drow.DUMMMYY = StyleList(CurIdx).dummmyy
        'Drow.LANDSCAPE = StyleList(CurIdx).LandScape
        'Drow.MARGINX = StyleList(CurIdx).MarginX
        'Drow.MARGINY = StyleList(CurIdx).MarginY
        'Drow.PICSTYLE = StyleList(CurIdx).picstyle
        'Drow.PRINTFONTOFFSET = StyleList(CurIdx).PrintFontOffset
        'Drow.PRINTBG = StyleList(CurIdx).Printbg
        'Drow.SCALEX = StyleList(CurIdx).ScaleX
        'Drow.SCALEY = StyleList(CurIdx).ScaleY
        'Drow.BAKX = StyleList(CurIdx).bakx
        'Drow.BAKY = StyleList(CurIdx).baky
        'Drow.BAKW = StyleList(CurIdx).bakw
        'Drow.BAKH = StyleList(CurIdx).bakh
        'Drow.VIEWIMAGE = StyleList(CurIdx).Viewimage
        'Drow.FILE = StyleList(CurIdx).File
        'Drow.FILTER = StyleList(CurIdx).Filter
        'Common.PDS(CurIdx).TStyle.AddTStyleRow(Drow)  '//기본스타일 데이터 추가

        'Console.WriteLine("File Read  4: " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Restart()

        ''//패턴정보 추가하기
        'For i As Integer = 1 To StyleList(CurIdx).PATTERNTABLE.Rows.Count
        '    Dim PRow As DataRow = StyleList(CurIdx).PATTERNTABLE.Rows(i - 1)
        '    Dim Nrow As PatternDS.TPatternRow = Common.PDS(CurIdx).TPattern.NewTPatternRow
        '    Nrow.NAME = PRow("설명")
        '    Nrow.Val = PRow("값")
        '    Common.PDS(CurIdx).TPattern.AddTPatternRow(Nrow)
        'Next
        'Common.PDS(CurIdx).TPattern.AcceptChanges()

        'Console.WriteLine("File Read  5: " + wat.ElapsedMilliseconds.ToString() + "ms")
        'wat.Stop()

    End Sub

    Public Function GetSpread(ByRef dv As DataView, ByVal row As Integer, ByVal col As Integer) As String
        Try
            If row >= dv.Count Then Return String.Empty
            Return dv(row)(col).ToString.Trim
            'Return Me.CustFP1_Sheet1.Cells(row, col).Value.ToString
        Catch ex As Exception
            Return ""
        End Try
    End Function
    Public Function GetSpread1(ByRef dv As DataView, ByVal col As Integer) As String   'QR QR
        Try
            Return dv(col).ToString.Trim
            'Return Me.CustFP1_Sheet1.Cells(row, col).Value.ToString
        Catch ex As Exception
            Return ""
        End Try
    End Function
    Public Function GetSpread(ByRef dv As DataView, ByVal row As Integer, ByVal colname As String) As String
        Try
            If row >= dv.Count Then Return String.Empty
            Return dv(row)(colname).ToString.Trim
            'Return Me.CustFP1_Sheet1.Cells(row, col).Value.ToString
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Public Sub WLog(ByVal msg As String, ByVal fname As String)
        '//로그를 기록합니다.
        Dim FD As String = My.Application.Info.DirectoryPath & "\LOG"
        If Not Directory.Exists(FD) Then Directory.CreateDirectory(FD)
        Dim FS As FileStream = New FileStream(FD & fname, FileMode.Append)
        Dim SW As StreamWriter = New StreamWriter(FS, System.Text.Encoding.Default)
        SW.WriteLine(Now.TimeOfDay.ToString & ":" & msg)
        SW.Flush()
        SW.Close()
        FS.Close()
    End Sub
    Public Sub WLog2(ByVal enable As Boolean, ByVal msg As String, ByVal fname As String)
        '//로그를 기록합니다.
        If Not enable Then Return
        Dim FD As String = My.Application.Info.DirectoryPath & "\LOG"
        If Not Directory.Exists(FD) Then Directory.CreateDirectory(FD)
        Dim FS As FileStream = New FileStream(FD & fname, FileMode.Append)
        Dim SW As StreamWriter = New StreamWriter(FS, System.Text.Encoding.Default)
        SW.WriteLine(Now.TimeOfDay.ToString & ":" & msg)
        SW.Flush()
        SW.Close()
        FS.Close()
    End Sub
    Public Sub Log(ByVal msg As String)
        '//로그를 기록합니다.
        Dim FD As String = My.Application.Info.DirectoryPath & "\LOG"
        If Not Directory.Exists(FD) Then Directory.CreateDirectory(FD)
        Dim FS As FileStream = New FileStream(FD & "\log.txt", FileMode.Append)
        Dim SW As StreamWriter = New StreamWriter(FS, System.Text.Encoding.Default)
        SW.WriteLine(Now.TimeOfDay.ToString & ":" & msg)
        SW.Flush()
        SW.Close()
        FS.Close()
    End Sub

End Module
Class XML
    Public Shared Sub SavePatterN(ByVal index As Short, ByVal name As String, ByVal val As String)
        '//변경을 시도하는데 데이터가 없다면 추가를 하게한다.
        Dim Dr() As DataRow = Common.PDS(index).TPattern.Select("설명='" & name & "'")
        If Dr.GetUpperBound(0) < 1 Then
            Dim NDR As PatternDS.TPatternRow = Common.PDS(index).TPattern.NewTPatternRow
            NDR.NAME = name
            NDR.Val = val
        Else
            Dr(0)("값") = val
        End If
    End Sub
    Public Shared Sub SaveChkBox(ByVal index As Short, ByVal name As String, ByVal val As Boolean)
        '//변경을 시도하는데 데이터가 없다면 추가를 하게한다.
        Dim Dr() As DataRow = Common.PDS(index).TCheckBox.Select("name='" & name & "'")
        If Dr.GetUpperBound(0) < 1 Then
            Dim NDR As PatternDS.TCheckBoxRow = Common.PDS(index).TCheckBox.NewTCheckBoxRow
            NDR.Name = name
            NDR.Val = val
        Else
            Dr(0)("val") = val
        End If
    End Sub

End Class