Imports System
Imports System.IO
Imports System.Text
Imports ACC.ARINCLASS
Imports ACC

Public Class XLSImport

    Dim Impctls(22) As NewImpCnt2

    ' Dim FN As String = vbNullString
    Dim Arin As New ACC.ARINCLASS

    Dim TabName As String
    Dim ColName() As String
    Dim Value() As String
    Dim vtype() As String
    Dim ColDesc() As String '열제목'

    Dim SubSqlCnt As Integer
    Dim SubSql() As String

    Dim USERFC() As String

    Dim DivString As String '//구분자

    Dim Err As Boolean = False  '//에러발생상태
    Dim StartPos As Integer = 0   '//시작열순서
    Dim EndPos As Integer = 0   '//종료열순서

    Dim IniFile As String = My.Application.Info.DirectoryPath & "\import.ini"
    Dim SelControl As System.Windows.Forms.TextBox
    Dim sql As New StringBuilder
    Dim DelSql As New StringBuilder

    Dim MyTextBox() As System.Windows.Forms.TextBox
    Dim MyComBo() As System.Windows.Forms.ComboBox
    Dim MyLaBel() As Label


    '// 임시데이터테이블
    Dim DT_tongsin As New DataSet.Detail_tongsinDataTable
    Dim DT_LCable As New DataSet.Detail_LCableDataTable

    '// 로우
    Dim ROW_Tongsin As DataSet.Detail_tongsinRow
    Dim ROW_LCable As DataSet.Detail_LCableRow

    Dim SrcDataSet As DataSet
    Dim gubunId As Integer    '//추가될 관리id를 받는다.
    Dim Wt As Work_Type   '//관리구분을 받는다. 없을경우 기본 0(가공번호찰로 한다)
    'Dim MaxArray As String '"엑셀의 최대범위"
    Dim Sview As FarPoint.Win.Spread.SheetView

    Public Sub New()
        ' 이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()
    End Sub

    Public Sub New(ByVal DataSrc As DataSet, ByVal rowid As Short, ByVal vgubun As Short)   '//현재이걸로 데이터를 가져온다.
        InitializeComponent()
        gubunId = rowid
        Wt = vgubun
        SrcDataSet = DataSrc
    End Sub

    Private Sub Control_Setting()
        Select Case Wt
            Case Work_Type.tongsin
                Me.Text = "일반번호찰 엑셀데이터 가져오기"
                Me.Set_ImpCtl(New String() {"간선명1", "간선명2", "전주번호1", "전주번호2", "규격", "시공일", "시공자", "운용기관", "중계기명", "문의전화1", "문의전화2", "단자함1", "단자함2", _
                "단자함3", "광단자함1", "광단자함2", "광단자함3", "광단자함4", "점용허가번호", "점용허가기관", "점용허가기간", "QRCODE"})
            Case Work_Type.Lcable
                Me.Text = "광케이블주의표찰 엑셀데이터 가져오기"
                Me.Set_ImpCtl(New String() {"OLT번호", "국축선번", "구간명", "시설구분", "케이블유형", "케이블종별", _
                                            "케이블명", "모분기케이블명", "접속점명", "제조회사", "설치년월", _
                                            "시공회사", "감리원", "관리기관", "비고", "QRCODE"})
            Case Else
                Me.Text = "번호찰 가져오기"
                MsgBox("Err: ControlSEtting : 알수없는 번호찰형식")
        End Select
    End Sub
    Private Sub Set_ImpCtl(ByVal Name() As String)
        Dim Offset As Short = 0
        For i As Short = 0 To Name.Length - 1
            Me.Impctls(i).제목 = Name(i)
            Me.Impctls(i).enable = True
            Me.Impctls(i).Visible = True
            Me.Impctls(i).값형태 = NewImpCnt2.E_vartype.문자
        Next
    End Sub

    Private Sub Apply_Tongshin() '//가로등 미리보기
        Dim 번호 As Integer     '//번호는 notnull 이다
        Dim NullChk As Boolean = Me.NullCHeck
        Dim NullVal As String = ""
        Dim cnt As Integer = -1
        Dim StartCnt As Integer = CInt(Me.tb_scnt.Text)
        Dim EndCnt As Integer = IIf(CInt(Me.tb_ecnt.Text) = 0, Me.CustFP1.ActiveSheet.RowCount, CInt(Me.tb_ecnt.Text))
        Dim index As Integer = 0
        Dim VarStr(22) As String   '//문자를 저장하는 변수
        Dim Nullcnt As Short = 0
        NOTICE("(임시)데이터베이스에 기록합니다(취소불가능)", Me.lb_msg)

        'If (Me.tb_ecnt.Text = 0 AndAlso UserInfo.Type = E_AuthType.Demo) OrElse (UserInfo.Type = E_AuthType.Demo AndAlso (Me.tb_ecnt.Text - Me.tb_scnt.Text) > 100) Then
        '    MsgBox("임시사용자는 자동종료카운트(0)을 사용할 수 없으며" & vbCrLf & vbCrLf & _
        '    "시작카운터와 종료카운터의 범위는 100까지만 가능합니다", MsgBoxStyle.Information, "확인")
        '    Me.tb_ecnt.Text = Me.tb_scnt.Text + 100
        'End If
        Me.DT_tongsin.Rows.Clear() : Me.DT_tongsin.AcceptChanges()

        For Each Dr As FarPoint.Win.Spread.Row In Me.CustFP1.ActiveSheet.Rows   '//모든로우에해당하는데 시작줄부터한다
            If Dr.Index + 1 >= StartCnt AndAlso Dr.Index + 1 <= EndCnt Then   '//시작인덱스 이상일경우에만 한다.
                index += 1
                SHowCnt(index, EndCnt)

                NullVal = False
                Try
                    번호 = index

                    For i As Short = 0 To VarStr.GetUpperBound(0)
                        If i = 21 Then
                            VarStr(i) = Me.GetFPData(Me.Impctls(i), Dr)
                        Else
                            VarStr(i) = Me.GetFPData(Me.Impctls(i), Dr).ToUpper
                        End If

                    Next

                    If NullChk Then '//널값 체크시에 체크된것이 null이라면 nullval 을 true로 바꾼다.
                        NullVal = ""
                        For i As Short = 0 To VarStr.GetUpperBound(0)
                            If Me.Impctls(i).빈값체크 AndAlso Me.Impctls(i).enable Then
                                NullVal &= IIf(VarStr(i).Trim = "", "", "X")
                                If NullVal <> "" Then Exit For
                            End If
                        Next
                    Else
                        NullVal = "X" '//기본false로 해줘야한다.
                    End If

                    If NullVal.Trim <> "" Then 'false일때만 추가한다. true는 널값이잇으므로 넘어간다.
                        Me.ROW_Tongsin = Me.DT_tongsin.NewDetail_tongsinRow   '//임시테이블
                        Me.ROW_Tongsin.rowid = System.Guid.NewGuid
                        Me.ROW_Tongsin.관리ID = gubunId
                        Me.ROW_Tongsin.번호 = index
                        Me.ROW_Tongsin.정렬번호 = "1" & Format(index, "0000") & "1000"
                        Me.ROW_Tongsin.출력 = True
                        '------------------------------------------
                        Me.ROW_Tongsin.간선명 = VarStr(0)
                        Me.ROW_Tongsin.간선명2 = VarStr(1)
                        Me.ROW_Tongsin.전주번호 = VarStr(2)
                        Me.ROW_Tongsin.전주번호2 = VarStr(3)
                        Me.ROW_Tongsin.규격 = VarStr(4)
                        Me.ROW_Tongsin.시공일 = VarStr(5)
                        Me.ROW_Tongsin.시공자 = VarStr(6)
                        Me.ROW_Tongsin.운용기관 = VarStr(7)
                        Me.ROW_Tongsin.중계기명 = VarStr(8)
                        Me.ROW_Tongsin.연락처1 = VarStr(9)
                        Me.ROW_Tongsin.연락처2 = VarStr(10)
                        Me.ROW_Tongsin.단자함1 = VarStr(11)
                        Me.ROW_Tongsin.단자함2 = VarStr(12)
                        Me.ROW_Tongsin.단자함3 = VarStr(13)
                        Me.ROW_Tongsin.광단자함1 = VarStr(14)
                        Me.ROW_Tongsin.광단자함2 = VarStr(15)
                        Me.ROW_Tongsin.광단자함3 = VarStr(16)
                        Me.ROW_Tongsin.광단자함4 = VarStr(17)
                        Me.ROW_Tongsin.점용허가번호 = VarStr(18)
                        Me.ROW_Tongsin.점용허가기관 = VarStr(19)
                        Me.ROW_Tongsin.점용허가기간 = VarStr(20)
                        Me.ROW_Tongsin.QRCODE = VarStr(21)
                        Me.DT_tongsin.Rows.Add(Me.ROW_Tongsin)                        '
                    Else   '//빈줄이 나왔음을 의미하므로 빈줄 카운터 증가
                        Nullcnt += 1
                        If Nullcnt >= 5 Then
                            Exit For
                        End If
                    End If
                Catch ex As ConstraintException '//중복
                    ' AddLog("번호중복", "중복된 번호:" & 번호)
                Catch ex As Exception
                    ' AddLog(ex.InnerException.ToString, ex.Message.ToString)
                End Try
            End If
        Next
        NOTICE("가져오기완료(" & Me.CustFP2_Sheet1.RowCount & "개)", Me.lb_msg)
        Me.CustFP2.DataSource = Me.DT_tongsin
        '//보여서 필요없는 열값을 숨긴다.
        Me.CustFP2.ActiveSheet.Columns(0).Width = 0  '//rowid
        Me.CustFP2.ActiveSheet.Columns(1).Width = 0  '//관리Id
        Me.CustFP2.ActiveSheet.Columns(2).Width = 0 '//정렬번호
        Me.CustFP2.ActiveSheet.Columns(3).Width = 0 '//출력
        'Me.CustFP2.ActiveSheet.Columns(21).Width = 0 '//출력
    End Sub
    Private Sub Apply_Lcable() '//광케이블주의표찰 미리보기
        Dim 번호 As Integer     '//번호는 notnull 이다
        Dim NullChk As Boolean = Me.NullCHeck
        Dim NullVal As String = ""
        Dim cnt As Integer = -1
        Dim StartCnt As Integer = CInt(Me.tb_scnt.Text)
        Dim EndCnt As Integer = IIf(CInt(Me.tb_ecnt.Text) = 0, Me.CustFP1.ActiveSheet.RowCount, CInt(Me.tb_ecnt.Text))
        Dim index As Integer = 0
        Dim VarStr(19) As String   '//문자를 저장하는 변수
        Dim Nullcnt As Short = 0
        NOTICE("(임시)데이터베이스에 기록합니다(취소불가능)", Me.lb_msg)

        'If (Me.tb_ecnt.Text = 0 AndAlso UserInfo.Type = E_AuthType.Demo) OrElse (UserInfo.Type = E_AuthType.Demo AndAlso (Me.tb_ecnt.Text - Me.tb_scnt.Text) > 100) Then
        '    MsgBox("임시사용자는 자동종료카운트(0)을 사용할 수 없으며" & vbCrLf & vbCrLf & _
        '    "시작카운터와 종료카운터의 범위는 100까지만 가능합니다", MsgBoxStyle.Information, "확인")
        '    Me.tb_ecnt.Text = Me.tb_scnt.Text + 100
        'End If
        Me.DT_LCable.Rows.Clear() : Me.DT_LCable.AcceptChanges()

        For Each Dr As FarPoint.Win.Spread.Row In Me.CustFP1.ActiveSheet.Rows   '//모든로우에해당하는데 시작줄부터한다
            If Dr.Index + 1 >= StartCnt AndAlso Dr.Index + 1 <= EndCnt Then   '//시작인덱스 이상일경우에만 한다.
                index += 1
                SHowCnt(index, EndCnt)

                NullVal = False
                Try
                    번호 = index

                    For i As Short = 0 To VarStr.GetUpperBound(0)
                        If i = 15 Then
                            VarStr(i) = Me.GetFPData(Me.Impctls(i), Dr)
                        Else
                            VarStr(i) = Me.GetFPData(Me.Impctls(i), Dr).ToUpper
                        End If

                    Next

                    If NullChk Then '//널값 체크시에 체크된것이 null이라면 nullval 을 true로 바꾼다.
                        NullVal = ""
                        For i As Short = 0 To VarStr.GetUpperBound(0)
                            'MsgBox(Me.Impctls(i).제목)
                            'If Me.Impctls(i).빈값체크 Then MsgBox(Me.Impctls(i).제목)

                            If Me.Impctls(i).빈값체크 AndAlso Me.Impctls(i).enable Then

                                NullVal &= IIf(VarStr(i).Trim = "", "", "X")
                                If NullVal <> "" Then Exit For
                            End If
                        Next
                    Else
                        NullVal = "X" '//기본false로 해줘야한다.
                    End If

                    If NullVal.Trim <> "" Then 'false일때만 추가한다. true는 널값이잇으므로 넘어간다.
                        Me.ROW_LCable = Me.DT_LCable.NewDetail_LCableRow   '//임시테이블
                        Me.ROW_LCable.rowid = System.Guid.NewGuid
                        Me.ROW_LCable.관리ID = gubunId
                        Me.ROW_LCable.번호 = index
                        Me.ROW_LCable.정렬번호 = "1" & Format(index, "0000") & "1000"
                        Me.ROW_LCable.출력 = True
                        '------------------------------------------
                        Me.ROW_LCable.OLT번호 = VarStr(0)
                        Me.ROW_LCable.국축선번 = VarStr(1)
                        Me.ROW_LCable.구간명 = VarStr(2)
                        Me.ROW_LCable.시설구분 = VarStr(3)
                        Me.ROW_LCable.케이블유형 = VarStr(4)
                        Me.ROW_LCable.케이블종별 = VarStr(5)
                        Me.ROW_LCable.케이블명 = VarStr(6)
                        Me.ROW_LCable.모분기케이블명 = VarStr(7)
                        Me.ROW_LCable.접속점명 = VarStr(8)
                        Me.ROW_LCable.제조회사 = VarStr(9)
                        Me.ROW_LCable.설치년월 = VarStr(10)
                        Me.ROW_LCable.시공회사 = VarStr(11)
                        Me.ROW_LCable.감리원 = VarStr(12)
                        Me.ROW_LCable.관리기관 = VarStr(13)
                        Me.ROW_LCable.비고 = VarStr(14)
                        Me.ROW_LCable.QRCODE = VarStr(15)
                        Me.DT_LCable.Rows.Add(Me.ROW_LCable)                        '
                    Else   '//빈줄이 나왔음을 의미하므로 빈줄 카운터 증가
                        Nullcnt += 1
                        If Nullcnt >= 5 Then
                            Exit For
                        End If
                    End If
                Catch ex As ConstraintException '//중복
                    ' AddLog("번호중복", "중복된 번호:" & 번호)
                Catch ex As Exception
                    ' AddLog(ex.InnerException.ToString, ex.Message.ToString)
                End Try
            End If
        Next
        NOTICE("가져오기완료(" & Me.CustFP2_Sheet1.RowCount & "개)", Me.lb_msg)
        Me.CustFP2.DataSource = Me.DT_LCable
        '//보여서 필요없는 열값을 숨긴다.
        Me.CustFP2.ActiveSheet.Columns(0).Width = 0  '//rowid
        Me.CustFP2.ActiveSheet.Columns(1).Width = 0  '//관리Id
        Me.CustFP2.ActiveSheet.Columns(2).Width = 0 '//정렬번호
        Me.CustFP2.ActiveSheet.Columns(18).Width = 0 '//출력
        Me.CustFP2.ActiveSheet.Columns(19).Width = 0 '//출력
    End Sub

    Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
        '//기존에 존재하는 모든 데이터를 삭제하고 새로 추가합니다.
        '//Byref 로가져온 원래데이터셋을 이용해서 데이터를 삭제합니다.
        Select Case Wt

            Case Work_Type.tongsin
                If Me.SrcDataSet.Detail_tongsin.Rows.Count <> 0 Then
                    NOTICE("기존의 자료를 삭제합니다", Me.lb_msg)
                    ' Me.SuspendLayout()
                    For I As Integer = Me.SrcDataSet.Detail_tongsin.Rows.Count - 1 To 0 Step -1
                        Me.SHowCnt(I, Me.SrcDataSet.Detail_tongsin.Rows.Count - 1)
                        Me.SrcDataSet.Detail_tongsin.Rows(I).Delete()
                    Next
                    '  Me.ResumeLayout()
                End If
                Me.SrcDataSet.Detail_tongsin.Merge(Me.DT_tongsin)
            Case Work_Type.Lcable
                If Me.SrcDataSet.Detail_LCable.Rows.Count <> 0 Then
                    NOTICE("기존의 자료를 삭제합니다", Me.lb_msg)
                    '  Me.SuspendLayout()
                    For I As Integer = Me.SrcDataSet.Detail_LCable.Rows.Count - 1 To 0 Step -1
                        Me.SHowCnt(I, Me.SrcDataSet.Detail_LCable.Rows.Count - 1)
                        Me.SrcDataSet.Detail_LCable.Rows(I).Delete()
                    Next
                    'Me.ResumeLayout()
                End If
                Me.SrcDataSet.Detail_LCable.Merge(Me.DT_LCable)
        End Select

        Me.Close()

    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        '//기존에 존재하는 모든 데이터를 삭제하고 새로 추가합니다.
        Dim DT As New DataTable
        Dim CT As New DataTable
        Select Case Wt
            Case Work_Type.tongsin
                DT = Me.SrcDataSet.Detail_tongsin
                CT = Me.DT_tongsin
            Case Work_Type.Lcable
                DT = Me.SrcDataSet.Detail_LCable
                CT = Me.DT_LCable
        End Select

        '//최대값을 찾습니다.
        NOTICE("새로운 번호를 찾습니다", Me.lb_msg)
        Dim 최대값 As Integer
        Dim Dv As New DataView(DT, "", "번호 desc", DataViewRowState.CurrentRows)
        If Dv.Count = 0 Then
            최대값 = 0
        Else
            최대값 = Dv(0)("번호")
        End If

        NOTICE("번호를 새로 부여합니다", Me.lb_msg)
        For I As Integer = 0 To CT.Rows.Count - 1   '//추가는 번호를 새로 받는다.
            Me.SHowCnt(I, CT.Rows.Count - 1)
            CT.Rows(I)("번호") = 최대값 + I + 1
            CT.Rows(I)("정렬번호") = "1" & Format((최대값 + I + 1), "0000") & "1000"
        Next
        NOTICE("기존의 데이터와 병합합니다", Me.lb_msg)
        DT.Merge(CT)

        Me.Close()
    End Sub

#Region "자주바꾸지앟음"

    Private Sub ToolStripButton2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        If Me.CustFP1.ActiveSheet.RowCount <= 0 Then
            NOTICE("데이터가 없습니다", Me.lb_msg)
            Exit Sub
        End If
        Select Case Wt
            Case Work_Type.tongsin
                Me.Apply_Tongshin()
            Case Work_Type.Lcable
                Me.Apply_Lcable()
        End Select

    End Sub

    Private Sub CustFP1_CellDoubleClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles CustFP1.CellDoubleClick
        If SelControl Is Nothing Then Return
        SelControl.Text = Me.CustFP1.ActiveSheet.ActiveColumnIndex + 1
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim OD As New OpenFileDialog
        Dim Aranini As New MyINI(IniFile)
        OD.FileName = Me.lb_file.Text
        OD.Filter = "MS Office Excel WorkSheet(*.xls)|*.xls"
        OD.FilterIndex = 1
        ' OD.RestoreDirectory = True
        If OD.ShowDialog() = System.Windows.Forms.DialogResult.Cancel Then
            NOTICE("불러오기가 취소되었습니다", Me.lb_msg)
        Else
            Aranini.Write("normal", "file", OD.FileName)
            Me.lb_file.Text = OD.FileName
            ReadXls(OD.FileName)
        End If
    End Sub
    Private Sub XLSImport_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Save_Setting()   '//현재설정을 저장하고나간다.
    End Sub
    Private Sub Control_init()
        Me.Impctls(0) = Me.ImpCtl2
        Me.Impctls(1) = Me.ImpCtl3
        Me.Impctls(2) = Me.ImpCtl4
        Me.Impctls(3) = Me.ImpCtl5
        Me.Impctls(4) = Me.ImpCtl6
        Me.Impctls(5) = Me.ImpCtl7
        Me.Impctls(6) = Me.ImpCtl8
        Me.Impctls(7) = Me.ImpCtl9
        Me.Impctls(8) = Me.ImpCtl10
        Me.Impctls(9) = Me.ImpCtl11
        Me.Impctls(10) = Me.ImpCtl12
        Me.Impctls(11) = Me.ImpCtl13
        Me.Impctls(12) = Me.ImpCtl14
        Me.Impctls(13) = Me.ImpCtl15
        Me.Impctls(14) = Me.ImpCtl16
        Me.Impctls(15) = Me.ImpCtl17
        Me.Impctls(16) = Me.ImpCtl18
        Me.Impctls(17) = Me.ImpCtl19
        Me.Impctls(18) = Me.ImpCtl20
        Me.Impctls(19) = Me.ImpCtl21
        Me.Impctls(20) = Me.ImpCtl22
        Me.Impctls(21) = Me.ImpCtl23
        Me.Impctls(22) = Me.ImpCtl24
        For i As Short = 0 To Me.Impctls.GetUpperBound(0)
            Me.Impctls(i).enable = False
        Next
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Control_init()
        Control_Setting()

        If Not GetINI(IniFile) Then
            MsgBox("오류로인해 프로그램이 종료됩니다." & vbCrLf & vbCrLf & "환경설정 데이터가 반환되지 않았습니다", MsgBoxStyle.Critical, "Er")
            End
        End If
        LOadCurrentSet()
        'Me.CustFP1.Font = New Font(ViewFont.FontName, ViewFont.FontSize, Me.Font.Style)
        'Me.ToolStrip1.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        'Me.ToolStrip2.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        'Me.StatusStrip1.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
    End Sub
    '''
    ''' 현재 텍스트박스 셋팅을 저장합니다.
    '''
    Private Sub LOadCurrentSet()
        Dim ini As New MyINI(IniFile)
        For Each A As NewControlGroup.NewImpCnt2 In Me.TableLayoutPanel3.Controls
            A.열번호 = ini.Read("CURSETNUM" & Wt, A.Name)
            A.문자열자르기 = ini.Read("CURSETSPL" & Wt, A.Name)
            A.빈값체크 = ini.Read("CURSETNUL" & Wt, A.Name, False)
        Next
    End Sub

    Private Sub Save_Setting()  '//현재 셋팅을 저장합니다.
        '//저장목록은 시작/종료 열번호 아이템의 텍스트이다.
        Dim Aranini As New MyINI(IniFile)
        Aranini.Write("normal", "startpos", Me.tb_scnt.Text)    '//시작
        Aranini.Write("normal", "endpos", Me.tb_ecnt.Text)  '//종료
        For Each A As NewControlGroup.NewImpCnt2 In Me.TableLayoutPanel3.Controls  '//각 텍스트박스
            Aranini.Write("CURSETNUM" & Wt, A.Name, A.열번호)
            Aranini.Write("CURSETSPL" & Wt, A.Name, A.문자열자르기)
            Aranini.Write("CURSETNUL" & Wt, A.Name, A.빈값체크)
        Next
    End Sub

    Private Sub MyDoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not SelControl Is Nothing Then SelControl.BackColor = Color.White
        If Not SelControl Is Nothing AndAlso SelControl.Tag = CType(sender, TextBox).Tag Then '//같은거라면 선택하제한다.
            SelControl.BackColor = Color.White
            'Me.lb_selcontrol.Text = "선택없음"
            SelControl = Nothing
            Return
        End If
        SelControl = CType(sender, System.Windows.Forms.TextBox)
        SelControl.BackColor = Color.Green
        If SelControl.Tag Is Nothing Then
            MsgBox("TAG 속성이 비어있습니다", MsgBoxStyle.Information, "Error")
        Else
            'Me.lb_selcontrol.Text = "선택됨 : " & SelControl.Tag.ToString
        End If
    End Sub

    Private Function GetINI(ByVal filename As String) As Boolean    '//'REad INi file

        If filename Is vbNullString Then Return False
        Dim INiFn As String

        If filename.IndexOf(":") >= 0 Then
            INiFn = filename
        Else
            INiFn = My.Application.Info.DirectoryPath & "\" & filename
        End If
        Dim Aranini As New MyINI(INiFn)

        Try
            StartPos = Aranini.Read("NORMAL", "StartPos")
            EndPos = Aranini.Read("NORMAL", "endpos")
            Me.lb_file.Text = Aranini.Read("NORMAL", "file")
            Me.lb_file.Text = Me.lb_file.Text.Trim(Chr(0))
            Value = Aranini.Read("NORMAL", "value").Split(",")
            'MaxArray = Aranini.Read("NORMAL", "MaxArray")
        Catch ex As Exception
            MsgBox("Err-Read_INI" & vbCrLf & vbCrLf & "File=" & INiFn _
            & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "Error")
            Return False
        End Try

        'Me.lb_file.Text = FN
        Me.tb_scnt.Text = StartPos
        Me.tb_ecnt.Text = EndPos

        Return True
    End Function

    Private Sub ControlChanged(ByVal sender As Object, ByVal e As System.EventArgs) '//Not use
        Dim A As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
        If A.Text.Length <= 0 Then Exit Sub
        Select Case A.Text.Substring(0, 1)
            Case ":"
                If IsNumeric(A.Text.Substring(1)) Then
                    A.BackColor = Color.LawnGreen
                Else
                    A.BackColor = Color.Tomato
                End If
            Case "?"
                A.BackColor = Color.Gray
            Case "#"
                A.BackColor = Color.SteelBlue
            Case Else
                A.BackColor = Color.White
        End Select
    End Sub


    Private Sub ReadXls(ByVal Filename As String)   '//Read xls File

        Me.CustFP1.OpenExcel(Filename)
        For index As Integer = 0 To Me.CustFP1.Sheets.Count - 1
            For Each Cl As FarPoint.Win.Spread.Column In Me.CustFP1.Sheets(index).Columns '//Set columns label
                Cl.Label = Cl.Index + 1
            Next
        Next
        ''//연속 5개의 공백이 보이면 카운트를 종료한다.
        Dim 공백 As Int16 = 0
        For Each Row As FarPoint.Win.Spread.Row In Me.CustFP1.ActiveSheet.Rows
            If Me.CustFP1.ActiveSheet.Cells(Row.Index, 0).Text = "" AndAlso Me.CustFP1.ActiveSheet.Cells(Row.Index, 1).Text = "" AndAlso Me.CustFP1.ActiveSheet.Cells(Row.Index, 2).Text = "" Then
                ' MsgBox(Row.Index)
                공백 += 1
            Else
                공백 = 0
            End If
            If 공백 >= 10 Then
                '  MsgBox("종료시점검색완료" & Row.Index)
                Me.CustFP1.ActiveSheet.RowCount = Row.Index + 1 - 8
                Exit For
            End If
        Next
    End Sub

    Private Function GetItemFP(ByVal Src As FarPoint.Win.Spread.Row, ByVal idx As TextBox, ByVal SUbstr As TextBox, Optional ByVal NotNull As Boolean = False) As Object
        Dim SUbidx As Integer = IIf(idx.Text = "", 0, Val(idx.Text))   '//없으면 -1을

        If SUbidx = 0 Then '//즉 없다는뜻이다.
            If NotNull Then Return Src.Index '//널이안되면 리뷰의 인덱스를 넘기고
            Return "" '//널이되면 빈값을 리턴한다.
        Else    '//있다.
            If SUbstr.Text = "" OrElse SUbstr.Text = "0,0" Then '//문자열자르기확인 없다 그대로 리턴
                Return Me.CustFP1.ActiveSheet.Cells(Src.Index, CInt(SUbidx - 1)).Text
            Else    '//문자열자르기가 있으면 잘라서 보내준다.
                Dim DIV() As String = SUbstr.Text.Split(",")
                If DIV(1) = "0" Then    '//시작부터 끝까지
                    Return Me.CustFP1.ActiveSheet.Cells(Src.Index, CInt(SUbidx - 1)).Text.Substring(DIV(0) - 1)
                Else    '/지정범위
                    Return Me.CustFP1.ActiveSheet.Cells(Src.Index, CInt(SUbidx - 1)).Text.Substring(DIV(0) - 1, DIV(1))
                End If
            End If
        End If
    End Function

    Private Function GetFPData(ByVal sender As NewControlGroup.NewImpCnt2, ByVal Drow As FarPoint.Win.Spread.Row) As String
        '//만약 날짜포맷이면 FORMAT 을 지정해서 사용한다"

        Dim SUbidx As Integer
        Dim VALSTR As String

        If sender.열번호 = "" Then '//즉 없다는뜻이다.
            Return ""
        Else    '//있다.
            SUbidx = sender.열번호
            If Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text = "" Then
                ' MsgBox("값이없어서 바로보낸다")
                Return "" '//데이터없으면 리턴
            End If
            If sender.문자열자르기 = "" OrElse sender.문자열자르기 = "0,0" Then '//문자열자르기확인 없다 그대로 리턴
                VALSTR = Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text
                Return VALSTR

            Else    '//문자열자르기가 있으면 잘라서 보내준다.
                Dim DIV() As String = sender.문자열자르기.Split(",")
                If DIV(1) = "0" Then    '//시작부터 끝까지
                    Try
                        VALSTR = (Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text.Substring(DIV(0) - 1))
                    Catch ex As Exception
                        VALSTR = Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text
                    End Try
                    Return VALSTR

                Else    '/지정범위
                    Try
                        VALSTR = Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text.Substring(DIV(0) - 1, DIV(1))
                    Catch ex As Exception
                        VALSTR = Me.CustFP1.ActiveSheet.Cells(Drow.Index, CInt(SUbidx - 1)).Text
                    End Try
                    Return VALSTR
                End If
            End If
        End If
    End Function

    Private Function NullCHeck() As Boolean
        For i As Short = 0 To 18
            If Me.Impctls(i).열번호 <> "" AndAlso Me.Impctls(i).enable AndAlso Me.Impctls(i).빈값체크 Then
                Return True
            End If
        Next
        Return False
    End Function

    Private Sub SHowCnt(ByVal cnt As Integer, ByVal maxcnt As Integer)
        Me.lb_cnt.Text = cnt & "/" & maxcnt
        My.Application.DoEvents()
    End Sub


#End Region


    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Me.Close()
    End Sub
End Class
