Public Class AddEpoleETC
    Dim WithEvents DT As ireaDataSet.EtcTableDataTable
    Dim Sorted As ESorted = ESorted.NULL
    Dim IsNew As Boolean = False
    Private Sub NewRowAddToDataTable(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs) Handles DT.TableNewRow '//New Row Add & Setting Default Data
        Dim NEwrow As DataRow = e.Row
        NEwrow("rowid") = System.Guid.NewGuid
        NEwrow("관리ID") = CInt(Me.h_id.Text)
        NEwrow("번호") = CInt(Me.Get_NewNumber)
        NEwrow("출력") = True
        Dim newid As Integer = CInt(Me.Get_NewNumber)
        If Me.Sorted = ESorted.CANT Then
            NEwrow("정렬번호") = "히" & "1" & Format(newid, "00000") & "1000"
        Else
            NEwrow("정렬번호") = "1" & Format(newid, "00000") & "1000"
        End If
    End Sub

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

        Dim INI As New MyINI2(My.Application.Info.DirectoryPath & "\epole.ini")
        Me.h_date.Enabled = True
        Me.h_name.Enabled = True
        Me.h_bigo.Enabled = True
        Me.h_id.Enabled = False
        Me.h_dan.Enabled = True
        Me.Text = "중요수용 번호표찰 입력(신규작업)"
        Me.h_name.Text = INI.Read("main", "lastkname2") 'InputBox("거래처명을 입력하세요", "신규입력-거래처명", "해광기획")
        Me.h_dan.Text = "0" 'InputBox("수량별 단가를 입력하세요", "신규입력-단가", "0")
        Me.h_id.Text = maxid
        Me.h_bigo.Text = "중요수용 번호표찰(" & Format(Now, "MM") & "-" & Format(Now, "dd") & ")"
        Me.h_date.Text = Format(Now, "yyyy/MM/dd")
        Me.view1.EnterToNextItem()
        Me.IsNew = True
        '신규작업이므로 id를 재게산해서 지정해준다.
        'MsgBox(New_MID)
    End Sub

    Public Sub New(ByVal v_id As String, ByVal V_DATE As String, ByVal V_NAME As String, ByVal V_BIGO As String, ByVal V_DAN As String)

        ' 이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()
        Me.h_date.Text = V_DATE
        Me.h_name.Text = V_NAME
        Me.h_bigo.Text = V_BIGO
        Me.h_dan.Text = V_DAN
        Me.h_id.Text = v_id
        Me.h_date.Enabled = False
        Me.h_name.Enabled = False
        Me.h_bigo.Enabled = False
        Me.h_id.Enabled = False
        Me.h_id.Enabled = False
        Me.view1.EnterToNextItem()
        Me.Text = "중요수용 번호표찰 입력"
        ' MsgBox("new")
    End Sub

    Private Sub AddEpole_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        Me.bs.EndEdit()

        If bs.Count > 0 Then
            Dim Drv As DataRowView
            Drv = bs.Item(bs.Count - 1)
            If NVL(Drv("관리구"), "") = "" AndAlso NVL(Drv("전주번호"), "") = "" AndAlso NVL(Drv("선로명"), "") = "" AndAlso _
             NVL(Drv("번호1"), "") = "" AndAlso NVL(Drv("번호2"), "") = "" AndAlso NVL(Drv("번호3"), "") = "" AndAlso NVL(Drv("번호4"), "") = "" AndAlso _
            NVL(Drv("번호5"), "") = "" AndAlso NVL(Drv("비고1"), "") = "" AndAlso NVL(Drv("비고2"), "") = "" AndAlso NVL(Drv("비고3"), "") = "" Then
                Drv.Delete()
            End If
        End If

        Me.CHk_Modify()

        Frm_Main.bt_find.PerformClick()
    End Sub

    Private Sub AddEpole_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Me.view1.ColSize_Load()
        'Me.view1.ColName_Load()
        Me.view1.Setting_Load(False)
        'Ubound.Clear()

        'Me.etcdetailTableAdapter.Connection.ConnectionString = ConString

        Me.view1.Font = New Font(ViewFont.FontName, ViewFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        Me.bn.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        Me.ToolStrip1.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        Me.StatusStrip1.Font = New Font(MenuFont.FontName, MenuFont.FontSize, Me.Font.Style)   '//글자정보 불러오기
        Me.SETTOOLTIP()

        DT = Me.IreaDataSet1.EtcTable

        ''''''''데이터보여주기
        If Me.IsNew Then  '//현재id와같은 데이터는 모두삭제를 하게한다.
            Dim Cmd As New OleDbCommand("delete from  기타세부  where 관리id=" & Me.h_id.Text, Me.ta.Connection)
            If Cmd.Connection.State <> ConnectionState.Open Then Cmd.Connection.Open()
            Cmd.ExecuteNonQuery()
            Me.IsNew = False
        End If
        Display_Data()

        '''''데이터보여주기
        ' If Me.view1.ActiveSheet.RowCount <= 0 Then Me.bt_insertrow.PerformClick()

        Me.Show()
    End Sub
    Private Sub SETTOOLTIP()
        Dim TMSG As New System.Text.StringBuilder()
        TMSG.AppendLine()
        TMSG.AppendLine("오른쪽 클릭시 기타메뉴가 표시됩니다")
        TMSG.AppendLine()
        TMSG.AppendLine("<단축키 : ENTER:다음칸 , SHIFT+TAB:이전칸 , ALT+ENTER:윗칸복사>")
        TMSG.AppendLine("<단축키 : DELETE:현재칸 지우기 , SHIFT+DELETE 현재줄 삭제>")
        TMSG.AppendLine("<단축키 : F2:현재칸지우고 편집>")
        TMSG.AppendLine("<단축키 : SPACE-BAR/F3:현재칸 편집>")
        TMSG.AppendLine("<단축키 : CTRL + 마우스휠 : 화면크기를 조절합니다>")
        TMSG.AppendLine()
        Me.ToolTip1.SetToolTip(Me.view1, TMSG.ToString)

        'TMSG = New System.Text.StringBuilder()
        'TMSG.AppendLine()
        'TMSG.AppendLine("검색문자의 우선순위 : 숫자->영문자->한글")
        'TMSG.AppendLine("    ->0  은 000 보다 우선순위가 높습니다.")
        'Me.bt_findmenu.ToolTipText = "데이터베이스의 내용을 다시 불러옵니다" & vbCrLf & "번호정렬은 우측의 ▼ 를 클릭하세요"

    End Sub
    Private Sub SetFarPoint()
        Me.view1.EnterToNextItem()
        Me.view1.DataSource = Me.bs

        'Dim A As FarPoint.Win.Spread.CellType.TextCellType = Me.view1.ActiveSheet.Columns(2).CellType
        'A.CharacterSet = FarPoint.Win.Spread.CellType.CharacterSet.Ascii
        'A.CharacterCasing = CharacterCasing.Upper
        'Me.view1.ActiveSheet.Columns(2).CellType = A
        'Me.view1.ActiveSheet.Columns(3).CellType = A
        'Me.view1.ActiveSheet.Columns(4).CellType = A
        'Me.view1.ActiveSheet.Columns(5).CellType = A
        'Me.view1.ActiveSheet.Columns(6).CellType = A
        'Me.view1.ActiveSheet.Columns(7).CellType = A
        'Me.view1.ActiveSheet.Columns(8).CellType = A
        'Me.view1.ActiveSheet.Columns(9).CellType = A
        'Me.view1.ActiveSheet.Columns(10).CellType = A
        'Me.view1.ActiveSheet.Columns(11).CellType = A
        'Me.view1.ActiveSheet.Columns(12).CellType = A
        'Me.view1.ActiveSheet.Columns(13).CellType = A
        ''A.CharacterSet = FarPoint.Win.Spread.CellType.CharacterSet.Numeric
        ''  Me.view1.ActiveSheet.Columns(14).DataField = "선택"
        'Me.view1.ActiveSheet.Columns(15).DataField = "정렬번호"
    End Sub

    ''' <summary>
    ''' 신규추가시 번호를 생성해줍니다(현존최대넘버+1)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Get_NewNumber() As Integer
        Dim maxCnt As Integer = 0
        For i As Integer = 0 To Me.view1_Sheet1.RowCount - 1
            If Me.view1_Sheet1.Cells(i, 1).Value > maxCnt Then maxCnt = Me.view1_Sheet1.Cells(i, 1).Value
        Next
        Return maxCnt + 1
    End Function

    Private Sub CHk_Modify(Optional ByVal prompt As Boolean = True)
        Me.bs.EndEdit()

        If Not Me.IreaDataSet1.HasChanges Then
            NOTICE("변경된 내용이 없습니다", Me.lb_msg)
            Return
        End If

        If prompt Then
            If MsgBox("변경된 데이터를 저장하시겠습니까?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "저장확인") <> MsgBoxResult.Ok Then Return
        End If

        Try

            Me.etcdetailTableAdapter.Update(Me.IreaDataSet1.EtcTable)   '//Commit insert/update/delete
            Me.IreaDataSet1.EtcTable.AcceptChanges()    '//Set All Green

            Try
                Dim SQl As String = "insert into 전주관리(id,날짜,거래처명,비고,총수량,단가,금액,번호찰구분) values(:1,:2,:3,:4,:5,:6,:7,9)"
                If Me.etcdetailTableAdapter.Connection.State <> ConnectionState.Open Then Me.etcdetailTableAdapter.Connection.Open()
                Dim Cmd As New OleDbCommand(SQl, Me.etcdetailTableAdapter.Connection)
                Cmd.Parameters.Add(":1", OleDbType.Integer).Value = Val(Me.h_id.Text)
                Cmd.Parameters.Add(":2", OleDbType.Date).Value = IIf(Me.h_date.Text.Trim = "", DBNull.Value, Me.h_date.Text.Trim)
                Cmd.Parameters.Add(":3", OleDbType.VarChar).Value = Me.h_name.Text
                Cmd.Parameters.Add(":4", OleDbType.VarChar).Value = Me.h_bigo.Text
                Cmd.Parameters.Add(":5", OleDbType.Integer).Value = Me.IreaDataSet1.EtcTable.Rows.Count 'Me.view1_Sheet1.RowCount
                Cmd.Parameters.Add(":6", OleDbType.Integer).Value = Val(Me.h_dan.Text)
                Cmd.Parameters.Add(":7", OleDbType.Currency).Value = Val(Me.h_dan.Text) * Me.view1_Sheet1.RowCount
                Cmd.ExecuteNonQuery()
            Catch ex As Exception
                Dim SQl As String = "update 전주관리 set 날짜=:2,거래처명=:3,비고=:4,총수량=:5,단가=:6,금액=:7,번호찰구분=9 where id=:1"
                If Me.etcdetailTableAdapter.Connection.State <> ConnectionState.Open Then Me.etcdetailTableAdapter.Connection.Open()
                Dim Cmd As New OleDbCommand(SQl, Me.etcdetailTableAdapter.Connection)
                Cmd.Parameters.Add(":2", OleDbType.Date).Value = IIf(Me.h_date.Text.Trim = "", DBNull.Value, Me.h_date.Text.Trim)
                Cmd.Parameters.Add(":3", OleDbType.VarChar).Value = Me.h_name.Text
                Cmd.Parameters.Add(":4", OleDbType.VarChar).Value = Me.h_bigo.Text
                Cmd.Parameters.Add(":5", OleDbType.Integer).Value = Me.IreaDataSet1.EtcTable.Rows.Count 'Me.view1_Sheet1.RowCount
                Cmd.Parameters.Add(":6", OleDbType.Integer).Value = Val(Me.h_dan.Text)
                Cmd.Parameters.Add(":7", OleDbType.Currency).Value = Val(Me.h_dan.Text) * Me.view1_Sheet1.RowCount
                Cmd.Parameters.Add(":1", OleDbType.Integer).Value = Val(Me.h_id.Text)
                Cmd.ExecuteNonQuery()
            Finally
                'MakeList.bt_find.PerformClick()
                'Display_Data(True)
                Dim INI As New MyINI2(My.Application.Info.DirectoryPath & "\epole.ini")
                INI.Write("main", "lastkname2", Me.h_name.Text)
                NOTICE("저장되었습니다", Me.lb_msg)
                My.Computer.Audio.Play(My.Application.Info.DirectoryPath & "\sound\notify.wav", AudioPlayMode.Background)
                'MakeList.Display_Data() '//이건 bt_find 에서 재호출된다.
            End Try

        Catch ex As Exception
            MsgBox("데이터베이스 업데이트중 오류가 발생했습니다" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Critical, "ERROR-")
            Me.IreaDataSet1.EtcTable.RejectChanges()
            NOTICE("저장 실패!", Me.lb_msg)
        Finally
            view1.ActiveSheet.GetDataView(True) '//화면을 갱신한다.
        End Try
    End Sub


    Private Sub Display_Data()   '//뷰에데이터를 표시한다.
        Me.bs.Sort = "정렬번호,번호"   '//정렬된것들은 정렬된채로 보여준다.
        Me.etcdetailTableAdapter.Fill(Me.IreaDataSet1.EtcTable, Me.h_id.Text)   '//관리id를 통해서 데이터를 채운다.
        SetFarPoint()  '//여기서 파포인트를 바인딩 소스와 연결시킨다(바인딩 소스는 테이블에 연결되어있다)
        If Me.IreaDataSet1.EtcTable.Rows.Count <= 0 Then
            NOTICE("데이터가 존재하지 않습니다", Color.Red, Me.lb_msg)
            Me.bt_addrow.PerformClick()
            Return
        End If

        NOTICE(Me.view1.ActiveSheet.RowCount & "개의 데이터가 검색되었습니다", Me.lb_msg)
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Me.bt_commit.PerformClick() '//저장할게잇으면 다 저장한다.
        Me.view1.SuspendLayout()
        Dim A As New XLSImport(Me.IreaDataSet1, Me.h_id.Text, 9)
        A.ShowDialog()
        Me.CHk_Modify(False)
        Me.Display_Data()
        Me.view1.ResumeLayout()
    End Sub

    Private Sub ToolStripButton2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Me.bs.EndEdit()
        If Me.view1.Cells("출력").Value = False Then
            MsgBox("현재 선택된 줄은 출력이 되지않도록 설정되어있습니다", MsgBoxStyle.Critical, "확인")
            Return
        End If
        Dim A As New printformsy(Me.IreaDataSet1.EtcTable, CType(Me.bs.Current, DataRowView)) 'Me.view1.ActiveSheet.ActiveRowIndex)
        A.ShowDialog()
    End Sub

    Private Sub StripMenuItemolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StripMenuItem.Click
        '''''검색방법은 1번개체부터 마지막개체까지 풀루프를 돌면서 동일한 놈을 찾는다.
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim fcnt As Integer = 0

        Me.pbar.Value = 0
        Me.pbar.Minimum = 0
        Me.pbar.Maximum = Me.view1.ActiveSheet.RowCount

        NOTICE("중복되는 [관리구/전산번호]를 찾는중입니다...", Me.lb_msg)
        Me.Invalidate()
        For Each A As FarPoint.Win.Spread.Row In Me.view1.ActiveSheet.Rows
            원본 = Me.view1.ActiveSheet.Cells(A.Index, 2).Value & Me.view1.ActiveSheet.Cells(A.Index, 3).Value
            If 원본.ToString <> "" Then
                For Each B As FarPoint.Win.Spread.Row In Me.view1.ActiveSheet.Rows
                    If A.Index <> B.Index Then   '//같은라인은 피하고 그렇지 않은 라인의 번호를 확인한다.
                        대상 = Me.view1.ActiveSheet.Cells(B.Index, 2).Value & Me.view1.ActiveSheet.Cells(B.Index, 3).Value
                        If 원본.ToString = 대상.ToString Then
                            fcnt += 1
                            Me.view1.ActiveSheet.Cells(A.Index, 14).Value = True
                            Me.view1.ActiveSheet.Cells(B.Index, 14).Value = True
                        End If
                    End If
                Next
            End If
            If Me.pbar.Value < Me.pbar.Maximum Then Me.pbar.Value += 1
            Me.Invalidate()
        Next
        NOTICE("[관리구/전산번호] 중복검사 완료(" & fcnt & "개의 데이터를 찾았습니다)", Me.lb_msg)
    End Sub

    Private Sub dipdfsolStripMenuItemMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dipdfsolStripMenuItem.Click
        '''''검색방법은 1번개체부터 마지막개체까지 풀루프를 돌면서 동일한 놈을 찾는다.
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim fcnt As Integer = 0

        Me.pbar.Value = 0
        Me.pbar.Minimum = 0
        Me.pbar.Maximum = Me.view1.ActiveSheet.RowCount

        NOTICE("중복되는 [전주번호]를 찾는중입니다...", Me.lb_msg)
        Me.Invalidate()
        For Each A As FarPoint.Win.Spread.Row In Me.view1.ActiveSheet.Rows
            원본 = Me.view1.ActiveSheet.Cells(A.Index, 5).Value & Me.view1.ActiveSheet.Cells(A.Index, 6).Value & Me.view1.ActiveSheet.Cells(A.Index, 7).Value & _
                     Me.view1.ActiveSheet.Cells(A.Index, 8).Value & Me.view1.ActiveSheet.Cells(A.Index, 9).Value
            If 원본.ToString <> "" Then
                For Each B As FarPoint.Win.Spread.Row In Me.view1.ActiveSheet.Rows
                    If A.Index <> B.Index Then   '//같은라인은 피하고 그렇지 않은 라인의 번호를 확인한다.
                        대상 = Me.view1.ActiveSheet.Cells(B.Index, 5).Value & Me.view1.ActiveSheet.Cells(B.Index, 6).Value & Me.view1.ActiveSheet.Cells(B.Index, 7).Value & _
                     Me.view1.ActiveSheet.Cells(B.Index, 8).Value & Me.view1.ActiveSheet.Cells(B.Index, 9).Value
                        If 원본.ToString = 대상.ToString Then
                            fcnt += 1
                            Me.view1.ActiveSheet.Cells(A.Index, 14).Value = True
                            Me.view1.ActiveSheet.Cells(B.Index, 14).Value = True
                        End If
                    End If
                Next
            End If
            If Me.pbar.Value < Me.pbar.Maximum Then Me.pbar.Value += 1
            Me.Invalidate()
        Next
        NOTICE("[전주번호] 중복검사 완료(" & fcnt & "개의 데이터를 찾았습니다)", Me.lb_msg)

    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_addrow.Click
        If Me.Sorted = ESorted.NULL Then Check_Sorted()
        Me.view1.Arin_AddNewRow()
        'Dim NewRowIndex As Integer = Me.view1.NewRowsU()
        'With Me.view1.ActiveSheet
        '    .Cells(NewRowIndex, 0).Value = CInt(Me.h_id.Text)
        '    .Cells(NewRowIndex, 1).Value = CInt(Me.Get_NewNumber)
        '    .ActiveRowIndex = NewRowIndex
        '    .SetActiveCell(NewRowIndex, Me.view1.FIRST_FOCUSINDEX)
        '    SendKeys.Send("{ENTER}")
        'End With
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_commit.Click
        '//언바운드된 열을 여기서 바운드시켜분다.
        ' Me.view1.Attach_Ubound(3)
        Me.bs.EndEdit()

        If bs.Count > 0 Then
            Dim Drv As DataRowView
            Drv = bs.Item(bs.Count - 1)
            If NVL(Drv("관리구"), "") = "" AndAlso NVL(Drv("전주번호"), "") = "" AndAlso NVL(Drv("선로명"), "") = "" AndAlso _
             NVL(Drv("번호1"), "") = "" AndAlso NVL(Drv("번호2"), "") = "" AndAlso NVL(Drv("번호3"), "") = "" AndAlso NVL(Drv("번호4"), "") = "" Then
                Drv.Delete()
            End If
        End If

        If Not Me.IreaDataSet1.HasChanges Then
            NOTICE("변경된 데이터가 없습니다", Me.lb_msg)
            Return
        End If
        'Me.bt_find.PerformClick()
        Me.bt_find.PerformClick()
        'Return
        'CHk_Modify()
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_cancel.Click
        Me.view1.Attach_Ubound(3)
        Me.bs.EndEdit()

        If Me.IreaDataSet1.HasChanges Then
            Me.IreaDataSet1.RejectChanges()
            NOTICE("변경된 내용이 취소되었습니다.", Me.lb_msg)
        Else
            NOTICE("변경내역이 없습니다", Me.lb_msg)
        End If
    End Sub

    Private Sub allseloolStripMenuItem1nuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles allseloolStripMenuItem1.Click
        Me.view1.ItemCheck_Select(Me.view1.선택줄번호)
    End Sub

    Private Sub lStripMenuItem2enuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lStripMenuItem2.Click
        Me.view1.ItemCheck_Unselect(Me.view1.선택줄번호)
    End Sub

    Private Sub MenuItem2enuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Me.view1.ItemCheck_Reverse(Me.view1.선택줄번호)
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If Me.view1.ActiveSheet.Rows.Count > 0 Then
            Me.view1.ActiveSheet.ActiveRow.Remove()
            NOTICE("현재줄이 삭제되었습니다", Me.lb_msg)
        Else
            MsgBox("더이상 삭제할 줄이 없습니다")
        End If
    End Sub

    Private Sub view1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles view1.KeyDown
        Select Case e.KeyCode
            Case Keys.Insert '//삽입
                Me.bt_insertrow.PerformClick()
                'Me.bt_addrow.PerformClick()
            Case Keys.Enter '/마지막줄에 마지막 열이엿으면 bt_insertrow


                With Me.view1.ActiveSheet
                    '  Me.Text = .ActiveRowIndex & "/" & .ActiveColumnIndex
                    Select Case .ActiveColumnIndex
                        Case 2 '//구전산화번호 - 관리구 / 신전산화번호 - 관리구 / 시공년월 / 시공자
                            If .ActiveCell.Text = "" Then
                                .ActiveCell.Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text
                            End If
                        Case 3 '//구전산화번호 - 전산번호 / 시전산화번호 - 전산번호
                            If .ActiveCell.Text = "" AndAlso _
                            .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text <> "" AndAlso _
                            .Cells(.ActiveRowIndex, .ActiveColumnIndex - 1).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex - 1).Text Then
                                Dim Pnum As String = CInt(.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                Dim PnumI As Integer = IIf(Pnum = "", 0, CInt(Pnum))
                                .ActiveCell.Text = Format(Pnum, "000")
                            End If
                        Case 4  '//선로명 
                            If .ActiveCell.Text = "" AndAlso _
                                .Cells(.ActiveRowIndex, 2).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 2).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 5  '//전주번호1,장척
                            If .ActiveCell.Text = "" AndAlso _
                               .Cells(.ActiveRowIndex, 2).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 2).Text AndAlso _
                               .Cells(.ActiveRowIndex, 4).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 4).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 6  '//번호2
                            If .ActiveCell.Text = "" AndAlso _
                                .Cells(.ActiveRowIndex, 5).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 5).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 7  '//번호3
                            If .ActiveCell.Text = "" AndAlso _
                                .Cells(.ActiveRowIndex, 5).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 5).Text AndAlso _
                                .Cells(.ActiveRowIndex, 6).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 6).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 8  '//번호4
                            If .ActiveCell.Text = "" AndAlso _
                                .Cells(.ActiveRowIndex, 5).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 5).Text AndAlso _
                                .Cells(.ActiveRowIndex, 6).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 6).Text AndAlso _
                                .Cells(.ActiveRowIndex, 7).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 7).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 9  '//번호5
                            If .ActiveCell.Text = "" AndAlso _
                                .Cells(.ActiveRowIndex, 5).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 5).Text AndAlso _
                                .Cells(.ActiveRowIndex, 6).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 6).Text AndAlso _
                                .Cells(.ActiveRowIndex, 7).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 7).Text AndAlso _
                                .Cells(.ActiveRowIndex, 8).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 8).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                            '   Case 9
                            '      If .ActiveCell.Text = "" Then
                            'Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                            '.ActiveCell.Text = Pnum
                            '   End If
                        Case 11 '//비고1,비고2,비고3,비고4
                            If .ActiveCell.Text = "" AndAlso _
                               .Cells(.ActiveRowIndex, 9).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 9).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 12 '//비고1,비고2,비고3,비고4
                            If .ActiveCell.Text = "" AndAlso _
                               .Cells(.ActiveRowIndex, 9).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 9).Text AndAlso _
                              .Cells(.ActiveRowIndex, 10).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 10).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                        Case 13 '//비고1,비고2,비고3,비고4
                            If .ActiveCell.Text = "" AndAlso _
                               .Cells(.ActiveRowIndex, 9).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 9).Text AndAlso _
                              .Cells(.ActiveRowIndex, 10).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 10).Text AndAlso _
                                 .Cells(.ActiveRowIndex, 11).Text = .Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), 11).Text Then
                                Dim Pnum As String = (.Cells(IIf(.ActiveRowIndex > 0, .ActiveRowIndex - 1, 0), .ActiveColumnIndex).Text)
                                .ActiveCell.Text = Pnum
                            End If
                    End Select
                End With






                If Me.view1.ActiveSheet.ActiveRowIndex = Me.view1.ActiveSheet.RowCount - 1 Then '//마지막줄에
                    If Me.view1.NextRow_Index = Me.view1.ActiveSheet.ActiveColumnIndex Then '//다음줄로가아햘 경우라면
                        Me.bt_addrow.PerformClick()
                        Me.view1.ActiveSheet.SetActiveCell(Me.view1.ActiveSheet.RowCount - 1, Me.view1.FIRST_FOCUSINDEX)
                        e.Handled = True
                    ElseIf Me.view1.ActiveSheet.ActiveColumnIndex = Me.view1.ActiveSheet.ColumnCount - 1 Then   '//마지막열이라면
                        Me.bt_addrow.PerformClick()
                        Me.view1.ActiveSheet.SetActiveCell(Me.view1.ActiveSheet.RowCount - 1, Me.view1.FIRST_FOCUSINDEX)
                        e.Handled = True
                    End If
                End If



        End Select
    End Sub


    Private Sub view1_DragFillBlockCompleted(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.DragFillBlockCompletedEventArgs) Handles view1.DragFillBlockCompleted

        For i As Integer = e.RowBegin To e.RowBegin + e.NumberToCopy
            ' Dim ds As DataSet = FpSpread1.Sheets(0).DataSource
            Me.IreaDataSet1.EtcTable.Rows(view1.Sheets(0).GetModelRowFromViewRow(i)).EndEdit()
        Next

    End Sub

    Private Sub view1_Change(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChangeEventArgs) Handles view1.Change
        '//선택에 체크된것을 색상을 바꿔준다.

        If e.Column = Me.view1.선택줄번호 AndAlso Me.view1.ActiveSheet.Cells(e.Row, Me.view1.선택줄번호).Value = True Then   '//선택
            Me.view1.ActiveSheet.Rows(e.Row).BackColor = Color.LightGreen
        Else
            Me.view1.ActiveSheet.Rows(e.Row).BackColor = Color.White
        End If
    End Sub

    Private Sub Check_Sorted()
        If Me.Sorted = ESorted.NULL Then  '//아직 검색이된건지 확인안해봣다
            Me.Sorted = ESorted.No
            For i As Short = 0 To IIf(Me.DT.Rows.Count > 10, 10, Me.DT.Rows.Count - 1)
                If NVL(DT.Rows(i)("정렬번호")) <> "" AndAlso NVL(DT.Rows(i)("정렬번호")) <> "히히히000000000" AndAlso NVL(DT.Rows(i)("정렬번호")) <> "히" Then '//데이터가있다면
                    Me.Sorted = ESorted.YES
                    Exit For
                End If
            Next
        End If
    End Sub
    Private Sub Make_Index()
        Work_Form("인덱스를 생성하고 있습니다")
        Form_Work.ProgressBar1.Minimum = 0
        Form_Work.ProgressBar1.Maximum = Me.DT.Rows.Count
        Dim Num As Short
        For i As Integer = 0 To Me.DT.Rows.Count - 1
            Form_Work.pval = i
            Num = Me.DT.Rows(i)("번호")
            Me.DT.Rows(i)("정렬번호") = "1" & Format(Num, "00000") & "1000"
        Next
        Form_Work.Close()  '//작업창 닫기
        Me.Sorted = ESorted.YES
    End Sub
    Private Sub bt_insertrow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_insertrow.Click
        ' Me.view1.AInsertNewRow()    '//번호문제도있다.
        '//현재줄 바로위에 한줄을삽입한다.
        '//새로운ID는 전줄의ID+1 이며
        Me.bs.EndEdit()

        '//위에서부터 5개또는 마지막까지 이게 정렬된데이터인지 확인합니다.
        If Me.Sorted = ESorted.NULL Then Check_Sorted()
        If Me.Sorted = ESorted.No Then Make_Index() '//인덱스를 생성한다.

        Dim NR As ireaDataSet.EtcTableRow = Me.DT.NewEtcTableRow   '//삽입은 현재줄 위에 삽입하는것이다. 현재줄의 인덱스번호가 숫자형태라면 정렬이안된데이터다
        Dim 정렬번호 As String = bs.Current("정렬번호")
        Dim N정렬번호 As String
        If Not Me.Sorted = ESorted.CANT AndAlso IsNumeric(정렬번호) AndAlso 정렬번호.Length >= 8 Then  '//숫자라면 인덱스정렬법이다.
            Dim MN As String = 정렬번호.Substring(0, 6)
            Dim SN As Short = 정렬번호.Substring(6)
            'NR.번호 = bs.Current("번호") - 1 '//번호는 -1하고
            'If NR.번호 < 1 Then NR.번호 = 0
            N정렬번호 = MN & Format(SN - 1, "0000") '//현재 일련번호에 -을 해서 넣느다.  이부분 변경하자..변경한이름이 있을경우 해당위로의 숫자를 -1해야한다.

            '//새로우 정렬번호랑 같은것들은 -1해준다.
            For Each DR As DataRow In Me.DT.Select("정렬번호 like '" & MN & "%' and 정렬번호 <= '" & N정렬번호 & "'")
                MN = DR("정렬번호").Substring(0, 6)
                SN = DR("정렬번호").Substring(6)
                DR("정렬번호") = MN & Format(SN - 1, "0000")   '//원래번호-1해준다.
            Next
            '//
            NR.정렬번호 = N정렬번호

            Dim AR As Integer = Me.view1.ActiveSheet.ActiveRowIndex
            Me.DT.AddEtcTableRow(NR)
            Me.view1.ActiveSheet.ActiveRowIndex = AR


        Else   '//전주번호정렬법이다 이것은 정렬이 별도로 존재한다.
            MsgBox("번호형식으로 정렬되어있는 데이터입니다" & vbCrLf & "이데이터는 [한줄삽입]이 되지않습니다.", MsgBoxStyle.Information, "확인")
            Me.Sorted = ESorted.CANT
            'Me.bt_addrow.PerformClick()   '//한줄추가화럴ㅇ()
        End If
    End Sub

    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Text = Me.view1.ActiveSheet.ActiveRowIndex & "/" & Me.view1.ActiveSheet.ActiveColumnIndex
    End Sub


    Private Sub view1_EnterCell(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EnterCellEventArgs) Handles view1.EnterCell
        Select Case Me.view1.ActiveSheet.ActiveColumnIndex
            Case 4, 10, 11, 12, 13
                Me.view1.ImeMode = Windows.Forms.ImeMode.Hangul
                NOTICE("현재 셀 위치 (" & Me.view1.ActiveSheet.ActiveRowIndex + 1 & "," & Me.view1.ActiveSheet.ActiveColumnIndex + 1 & ") 입력형태(한글)", Me.lb_msg)

            Case Else
                Me.view1.ImeMode = Windows.Forms.ImeMode.NoControl
                NOTICE("현재 셀 위치 (" & Me.view1.ActiveSheet.ActiveRowIndex + 1 & "," & Me.view1.ActiveSheet.ActiveColumnIndex + 1 & ") 입력형태(일반)", Me.lb_msg)

        End Select
    End Sub


    Private Sub gdfolStripMenuItemtripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gdfolStripMenuItem.Click
        Me.ToolStripButton2.PerformClick()
    End Sub


    Private Sub ToolStripButton3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Process.Start(HomePage)
    End Sub

    Private Sub alldellStripMenuItemuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles alldellStripMenuItem.Click
        For i As Integer = Me.view1.ActiveSheet.RowCount - 1 To 0 Step -1
            If Me.view1.ActiveSheet.Cells(i, Me.view1.선택줄번호).Value = True Then Me.view1.ActiveSheet.Rows(i).Remove()
        Next
        '        For Each Dr As ireaDataSet.etctableRow In Me.IreaDataSet1.etctable.Rows
        ' If Dr.선택 Then Dr.Delete()
        ' Next

    End Sub

    Private Sub ToolStripButton4_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        Me.Close()
    End Sub

    Private Sub bt_save_all_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_save_all.Click
        Dim a As New SaveFileDialog
        a.Filter = "엑셀 워크시트파일(*.XLS)|*.XLS"
        a.FilterIndex = 0
        a.Title = "[모든데이터내보내기] 저장할 엑셀 파일을 지정하세요"
        If a.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            Dim msg As New System.Text.StringBuilder
            Me.view1.SaveExcel(a.FileName, FarPoint.Excel.ExcelSaveFlags.SaveAsViewed)
            msg.AppendLine("내보내진 파일은 기본값으로 [시트보호]가 되어있습니다")
            msg.AppendLine()
            msg.AppendLine()
            msg.AppendLine("[시트보호] 상태에서는 시트를 편집할 수 없습니다")
            msg.AppendLine()
            msg.AppendLine("[시트보호]를 해제하려면  해당파일을 엑셀에서 불러온후")
            msg.AppendLine("[도구]-[보호]-[시트보호해제]를 클릭하세요")
            MsgBox(msg.ToString, MsgBoxStyle.Information, "시트보호")
        End If
    End Sub

    Private Sub bt_save_current_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_save_current.Click
        Dim a As New SaveFileDialog
        a.Filter = "엑셀 워크시트파일(*.XLS)|*.XLS"
        a.FilterIndex = 0
        a.Title = "[현재데이터내보내기] 저장할 엑셀 파일을 지정하세요"
        If a.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            Dim msg As New System.Text.StringBuilder
            Me.view1.SaveExcel(a.FileName, FarPoint.Excel.ExcelSaveFlags.SaveAsFiltered)
            msg.AppendLine("내보내진 파일은 기본값으로 [시트보호]가 되어있습니다")
            msg.AppendLine()
            msg.AppendLine()
            msg.AppendLine("[시트보호] 상태에서는 시트를 편집할 수 없습니다")
            msg.AppendLine()
            msg.AppendLine("[시트보호]를 해제하려면  해당파일을 엑셀에서 불러온후")
            msg.AppendLine("[도구]-[보호]-[시트보호해제]를 클릭하세요")
            MsgBox(msg.ToString, MsgBoxStyle.Information, "시트보호")
        End If
    End Sub

    Private Sub fdsdfStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles outsalldatae.Click
        Me.bt_save_all.PerformClick()
    End Sub

    Private Sub savecurrentdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savecurrentdata.Click
        Me.bt_save_current.PerformClick()

    End Sub

    Private Sub AddEpoleETC_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Validated
        Me.view1.Focus()
        Me.view1.Focus()
    End Sub

    Private Sub bt_datasort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_datasort.Click
        Dim 번호 As String
        Dim 번호B, 번호b2 As System.Text.StringBuilder
        Me.pbar.Minimum = 0
        Me.pbar.Maximum = Me.IreaDataSet1.EtcTable.Rows.Count - 1
        Me.pbar.Value = 0
        Dim Cidx As Int16 = 0
        Dim Carray As ArrayList
        For Each dr As ireaDataSet.EtcTableRow In Me.IreaDataSet1.EtcTable.Rows
            번호 = (dr.번호1 & dr.번호2 & dr.번호3 & dr.번호4 & dr.번호5)
            If 번호 <> "" Then
                Cidx = 0
                번호B = New System.Text.StringBuilder
                번호b2 = New System.Text.StringBuilder
                Carray = New ArrayList
                For Each C As Char In 번호.ToCharArray
                    If Char.IsLetter(C) Then
                        Carray.Add(C) '//문자위치와 문자를 저장한다.
                        번호B.Append("@")   '//문자는 @로 변환한다.
                    Else
                        번호B.Append(C) '//숫자는 바로 저장해버린다.
                    End If
                    Cidx += 1
                Next
                For Each 번호s As String In 번호B.ToString.Split("@")
                    번호b2.Append(Format(Val(번호s), "000").ToString & "@")   '/3자리로바꾼후 문자열을 붙인다
                Next
                번호b2.Remove(번호b2.Length - 1, 1) '//쓰레기제거
                번호 = 번호b2.ToString
                For Each c As Char In Carray  '//문자와 위치가 있다
                    Cidx = 번호.IndexOf("@")
                    If Cidx <> -1 Then 번호 = 번호.Substring(0, Cidx) & c & 번호.Substring(Cidx + 1)
                Next
                dr.정렬번호 = dr.선로명 & CStr(번호.ToUpper.Replace("K", "0")).Replace("G", "0")
                If Me.pbar.Value < Me.pbar.Maximum Then Me.pbar.Value += 1
            Else   '//번호에 아무것도 없는경우
                dr.정렬번호 = dr.선로명 & "0"                    'If SORTNULL Then dr.정렬번호 = dr.선로명 & "0"
            End If
        Next
        NOTICE("정렬이 완료되었습니다", Me.lb_msg)
    End Sub

    Private Sub bt_find_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_find.Click
        CHk_Modify()
        Display_Data()
    End Sub

    Private Sub tripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tripMenuItem.Click
        Dim Frow, Fcol As Integer
        Me.view1.Search(Me.view1.ActiveSheetIndex, InputBox("선택된 열에서 검색할 문자를 입력하세요."), False, False, False, True, True, False, False, 0, 0, Frow, Fcol)
        If Frow >= 0 AndAlso Fcol >= 0 Then '//검색됫다면
            Me.view1.ActiveSheet.SetActiveCell(Frow, Fcol)
            SendKeys.Send("{ENTER}")
        End If
    End Sub

    Private Sub cm_RenewNum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cm_RenewNum.Click
        ReNum(Me.IreaDataSet1.EtcTable, "번호", Me.pbar)
    End Sub

    Private Sub vripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbt_vselall.Click
        For Each A As DataRow In Me.IreaDataSet1.EtcTable.Rows
            A("출력") = True
        Next
    End Sub

    Private Sub cbt_vusell_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbt_vusell.Click
        For Each A As DataRow In Me.IreaDataSet1.EtcTable.Rows
            A("출력") = False
        Next
    End Sub

    Private Sub cbt_vselrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbt_vselrev.Click
        For Each A As DataRow In Me.IreaDataSet1.EtcTable.Rows
            A("출력") = Not A("출력")
        Next
    End Sub

    Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click

    End Sub

    Private Sub bt_colsizesave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_colsizesave.Click
        Me.view1.Setting_Save(False) '//셋팅저장
    End Sub

    Private Sub 열너비초기화ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 열너비초기화ToolStripMenuItem.Click
        For c As Integer = 1 To view1_Sheet1.ColumnCount
            view1_Sheet1.Columns(c - 1).Width = 100
        Next
        Application.DoEvents()
    End Sub
End Class