Public Class Frm_5_New
    Dim Dt As DataTable
    Dim Init As Boolean = False
    Dim SrcDrv As DataRowView

    Public Sub New()

        ' 디자이너에서 이 호출이 필요합니다.
        InitializeComponent()

        With fxLight
            .KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.None
            .KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.None
            .SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Cell
            .ShowButtons = C1.Win.C1FlexGrid.ShowButtonsEnum.Always
            .DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With

        With fxEnergy
            .KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.None
            .KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.None
            .SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Cell
            .ShowButtons = C1.Win.C1FlexGrid.ShowButtonsEnum.Always
            .DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With

        With fxGround
            .KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.None
            .KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.None
            .SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Cell
            .ShowButtons = C1.Win.C1FlexGrid.ShowButtonsEnum.Always
            .DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With

        With fxybh
            .KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.None
            .KeyActionTab = C1.Win.C1FlexGrid.KeyActionEnum.None
            .SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Cell
            .ShowButtons = C1.Win.C1FlexGrid.ShowButtonsEnum.Always
            .DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With


        AddHandler fxLight.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxLight.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxLight.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxLight.OwnerDrawCell, AddressOf flexOwnerDrawCell

        AddHandler fxEnergy.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxEnergy.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxEnergy.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxEnergy.OwnerDrawCell, AddressOf flexOwnerDrawCell

        AddHandler fxGround.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxGround.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxGround.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxGround.OwnerDrawCell, AddressOf flexOwnerDrawCell

        AddHandler fxybh.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxybh.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxybh.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxybh.OwnerDrawCell, AddressOf flexOwnerDrawCell

    End Sub

#Region "FlexGRid Events"

    Private Sub fgrid_BeginEditS(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
        Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = DirectCast(sender, C1.Win.C1FlexGrid.C1FlexGrid)

        '//데이터입력전에 IME를 맞춘다.
        Select Case grid.Cols(e.Col).Name.ToLower()
            Case "name", "position", "dept", "bigo", "memo", "jname", "설명", "비고", "메모"
                grid.ImeMode = Windows.Forms.ImeMode.Hangul
            Case Else
                grid.ImeMode = Windows.Forms.ImeMode.Alpha
        End Select
    End Sub

    Private Sub fgrid_AfterEdit(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
        Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = DirectCast(sender, C1.Win.C1FlexGrid.C1FlexGrid)
        'Dim IDX As Integer = CInt(grid.GetData(e.Row, grid.Cols("IDX").Index))
        Dim data As Object = grid.GetData(e.Row, e.Col)

        Select Case grid.Cols(e.Col).Name.ToLower()
            Case Else
                If Not MoveCellDown(grid, e.Col) Then MoveCellRight(grid)
                Exit Select
        End Select
        'grid.AutoSizeCols()
    End Sub

    Private Function FindRowIndex(grid As C1.Win.C1FlexGrid.C1FlexGrid, IDX As Integer, Optional IDXField As String = "IDX") As Integer
        For i As Integer = 1 To grid.Rows.Count
            Dim oIDX As Integer = CInt(grid.GetData(i, grid.Cols(IDXField).Index))
            If IDX = oIDX Then
                Return i
            End If
        Next
        Return -1
    End Function

    Private Sub fgrid_KeyPress(sender As Object, e As KeyPressEventArgs)

        '일반선택상태일때 엔터키를 누른다면
        If e.KeyChar = Chr(&HD) Then
            '엔터는 아래 혹은 우측으로
            Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = DirectCast(sender, C1.Win.C1FlexGrid.C1FlexGrid)
            e.Handled = True
            If Not MoveCellRight(grid) Then
                MoveCellDown(grid, grid.Cols("설명").Index)
            End If
        ElseIf e.KeyChar = Chr(&H8) Then
            '탭은 우측으로
            Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = DirectCast(sender, C1.Win.C1FlexGrid.C1FlexGrid)
            e.Handled = True
            MoveCellRight(grid)
        End If
    End Sub

    Private Function MoveCellDown(grid As C1.Win.C1FlexGrid.C1FlexGrid, Optional firstcol As Integer = -1) As [Boolean]
        Dim colidx As Integer = grid.CursorCell.c1
        '현재
        If firstcol > -1 Then
            colidx = firstcol
        End If
        Dim rowidx As Integer = grid.CursorCell.TopRow
        Dim newidx As Integer = rowidx + 1

        '다음셀을 찾는다.
        If newidx < grid.Rows.Count Then
            grid.[Select](newidx, colidx)
            Return True
        Else
            '마지막줄이므로 처리하지않ㄴ든다.
            Return False
        End If

    End Function

    Private Function MoveCellRight(grid As C1.Win.C1FlexGrid.C1FlexGrid) As [Boolean]

        Dim colidx As Integer = grid.CursorCell.c1
        '현재
        Dim newidx As Integer = colidx + 1
        Dim find As [Boolean] = False

        '다음셀을 찾는다.
        While True
            If newidx + 1 <= grid.Cols.Count Then
                If Not grid.Cols(newidx).IsVisible OrElse Not grid.Cols(newidx).AllowEditing Then
                    newidx += 1
                    Continue While
                Else
                    grid.[Select](grid.CursorCell.TopRow, newidx)
                    find = True
                    Exit While
                End If
            Else
                Exit While
            End If
        End While
        Return find

    End Function

    Sub flexOwnerDrawCell(sender As Object, e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs)
        Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = sender
        If e.Row >= grid.Rows.Fixed AndAlso e.Col = grid.Cols.Fixed - 1 Then
            e.Text = (e.Row - grid.Rows.Fixed) + 1
        End If

        If e.Row > 0 Then
            Select Case grid.Cols(e.Col).Name
                Case "태양광모듈효율"

                    Dim valo As Object = grid.GetData(e.Row, grid.Cols("태양광모듈종류").Index)
                    If Not valo Is Nothing Then
                        Dim vals As String = valo.ToString()
                        If vals <> "성능치입력" Then
                            e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds)
                            e.Handled = True
                        End If

                    End If

                Case "집열효율"

                    Dim valo As Object = grid.GetData(e.Row, grid.Cols("집열기유형").Index)
                    If Not valo Is Nothing Then
                        Dim vals As String = valo.ToString()
                        If vals <> "성능치입력" Then
                            e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds)
                            e.Handled = True
                        End If

                    End If

            End Select
        End If


    End Sub

    Private Sub RefreshCellFormat()
        ''//관리자는 색상을 파란색으로한다.
        'If fxList.Styles("chi0") Is Nothing Then
        '    Dim newstyle As C1.Win.C1FlexGrid.CellStyle = fxList.Styles.Add("chi0")
        '    newstyle.ForeColor = Color.Blue
        'End If
        'If fxList.Styles("chi1") Is Nothing Then
        '    Dim newstyle As C1.Win.C1FlexGrid.CellStyle = fxList.Styles.Add("chi1")
        '    newstyle.ForeColor = Color.Black
        'End If

        'For i As Integer = 1 To Me.fxList.Rows.Count - 1
        '    Dim obj_admin As Object = Me.fxList.GetData(i, Me.fxList.Cols("admin").Index)
        '    Dim admin As Boolean = False
        '    If Not obj_admin Is Nothing Then admin = CBool(obj_admin)

        '    If admin Then
        '        fxList.Rows(i).Style = fxList.Styles("chi0")
        '    Else
        '        fxList.Rows(i).Style = fxList.Styles("chi1")
        '    End If
        'Next
    End Sub

#End Region



    Public Overrides Function AcceptChanged() As Boolean
        Me.fxLight.FinishEditing()
        Me.fxEnergy.FinishEditing()
        Me.fxGround.FinishEditing()
        Me.fxybh.FinishEditing()

        Me.bs_energy.EndEdit()
        Me.bs_ground.EndEdit()
        Me.bs_light.EndEdit()
        Me.bs_열병합.EndEdit()

        DSET1.tbl_new_energy.AcceptChanges()
        DSET1.tbl_new_ground.AcceptChanges()
        DSET1.tbl_new_light.AcceptChanges()
        DSET1.tbl_new_열병합.AcceptChanges()
        DSET1.tbl_new.Clear()

        '//기본 없음을 하나 추가해준다.
        DSET1.tbl_new.Rows.Add(New String() {"0", "(없음)"})
        DSET1.tbl_new.AcceptChanges()

        '//데이터를 모은다
        For Each dr As DS.tbl_new_energyRow In DSET1.tbl_new_energy.Rows
            Dim newdr As DS.tbl_newRow = DSET1.tbl_new.NewRow
            For Each c As DataColumn In DSET1.tbl_new_energy.Columns
                newdr(c.ColumnName) = dr(c.ColumnName)
            Next
            newdr.기기종류 = "태양열"
            newdr.신재생냉난방구분 = newdr.태양열종류
            DSET1.tbl_new.Rows.Add(newdr)
        Next

        For Each dr As DS.tbl_new_groundRow In DSET1.tbl_new_ground.Rows
            Dim newdr As DS.tbl_newRow = DSET1.tbl_new.NewRow
            For Each c As DataColumn In DSET1.tbl_new_ground.Columns
                newdr(c.ColumnName) = dr(c.ColumnName)
            Next
            newdr.기기종류 = "지열"
            newdr.신재생냉난방구분 = newdr.지열냉난방구분
            DSET1.tbl_new.Rows.Add(newdr)
        Next

        For Each dr As DS.tbl_new_lightRow In DSET1.tbl_new_light.Rows
            Dim newdr As DS.tbl_newRow = DSET1.tbl_new.NewRow
            For Each c As DataColumn In DSET1.tbl_new_light.Columns
                newdr(c.ColumnName) = dr(c.ColumnName)
            Next
            newdr.기기종류 = "태양광"
            newdr.신재생냉난방구분 = ""
            DSET1.tbl_new.Rows.Add(newdr)
        Next


        For Each dr As DS.tbl_new_열병합Row In DSET1.tbl_new_열병합.Rows
            Dim newdr As DS.tbl_newRow = DSET1.tbl_new.NewRow
            For Each c As DataColumn In DSET1.tbl_new_열병합.Columns
                newdr(c.ColumnName) = dr(c.ColumnName)
            Next
            newdr.기기종류 = "열병합"
            newdr.신재생냉난방구분 = newdr.열병합냉난방구분
            DSET1.tbl_new.Rows.Add(newdr)
        Next


        DSET1.tbl_new.AcceptChanges()


        Return MyBase.AcceptChanged()
    End Function

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


        '//공유데이터셋에 연결한다.    
        Me.bs_ground.DataSource = DSET1.tbl_new_ground
        Me.bs_light.DataSource = DSET1.tbl_new_light
        Me.bs_energy.DataSource = DSET1.tbl_new_energy
        Me.bs_열병합.DataSource = DSET1.tbl_new_열병합

        Dt = DSET1.tbl_new_energy

        '//신재생
        AddHandler DSET1.tbl_new_energy.TableNewRow, AddressOf AddNewDataRow_new_energy
        AddHandler DSET1.tbl_new_light.TableNewRow, AddressOf AddNewDataRow_new_light
        AddHandler DSET1.tbl_new_ground.TableNewRow, AddressOf AddNewDataRow_new_ground
        AddHandler DSET1.tbl_new_열병합.TableNewRow, AddressOf AddNewDataRow_new_ybh

        AddHandler DSET1.tbl_new_energy.ColumnChanged, AddressOf DataColumnChanged_energy
        AddHandler DSET1.tbl_new_light.ColumnChanged, AddressOf DataColumnChanged_light
        AddHandler DSET1.tbl_new_ground.ColumnChanged, AddressOf DataColumnChanged_ground
        AddHandler DSET1.tbl_new_열병합.ColumnChanged, AddressOf DataColumnChanged_ybh

        '//콤보컨트롤 바인딩
        Binding_Zone()

        '//모든컨트롤의 cTrl_enter 를 추가합니다
        'BindProperty(CType(Me.SplitContainer1.Panel2.Controls, Control.ControlCollection))
        Me.Init = True

        Try
            Me.bs_energy.Position = CEnergy.ARINCLASS.Read_LastPos_Frm(Me)
        Catch ex As Exception
            Me.bs_energy.MoveFirst()
        End Try

        '//제목줄 크기변경
        fxEnergy.Rows()(0).HeightDisplay *= 2
        fxEnergy.Rows()(0).StyleDisplay.WordWrap = True

        fxGround.Rows()(0).HeightDisplay *= 2
        fxGround.Rows()(0).StyleDisplay.WordWrap = True

        fxLight.Rows()(0).HeightDisplay *= 2
        fxLight.Rows()(0).StyleDisplay.WordWrap = True

        fxybh.Rows()(0).HeightDisplay *= 2
        fxybh.Rows()(0).StyleDisplay.WordWrap = True

        '//열너비
        ReadfGridColWidth(Me.Name, fxLight)
        ReadfGridColWidth(Me.Name, fxEnergy)
        ReadfGridColWidth(Me.Name, fxGround)
        ReadfGridColWidth(Me.Name, fxybh)

        Me.Show()
        Application.DoEvents()
    End Sub



#Region "Data Column Changed"
    Private Sub DataColumnChanged_energy(sender As Object, e As System.Data.DataColumnChangeEventArgs)

    End Sub

    Private Sub DataColumnChanged_light(sender As Object, e As System.Data.DataColumnChangeEventArgs)
        Try

            Select Case e.Column.ColumnName.ToLower
                Case "태양광모듈기울기"
                    Select Case e.ProposedValue
                        Case "수평", "(없음)"
                            e.Row("태양광모듈방위") = "(없음)"
                            fxLight.Cols("태양광모듈방위").AllowEditing = False
                        Case Else
                            fxLight.Cols("태양광모듈방위").AllowEditing = True
                    End Select
            End Select
        Catch ex As Exception

        End Try

    End Sub

    Private Sub DataColumnChanged_ground(sender As Object, e As System.Data.DataColumnChangeEventArgs)

    End Sub
    Private Sub DataColumnChanged_ybh(sender As Object, e As System.Data.DataColumnChangeEventArgs)

    End Sub
#End Region

#Region "신재생"

    Private Function GetMaxCode(ByVal dt As DataTable, minimum As Integer) As String
        Dim newcnt As Integer = 0
        Try
            Dim Dr As DataRow = dt.Select("", "code desc")(0)
            newcnt = CInt(Dr("code")) + 1
        Catch ex As Exception
            newcnt = 0
        End Try

        If newcnt = 0 Then newcnt = 1
        If newcnt < minimum Then newcnt = minimum

        Return newcnt.ToString("0000")
    End Function

    Sub SelectIndexChange_태양광기울기(sender As Object, e As EventArgs)
        'Console.Write("SelectIndexChange_태양광기울기")
        fxLight.FinishEditing()
    End Sub
    Private Sub Binding_Zone()

        '//지열 : 가동연료
        Dim Bs가동연료 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1066'", .Sort = "code"}
        Dim cmd가동연룍 As New ComboBox With {.DataSource = Bs가동연료, .DisplayMember = "name", .ValueMember = "name"}
        fxGround.Cols("가동연료").Editor = cmd가동연룍

        '//지열 : 냉난방구분
        Dim cmd냉난방구분 As New ComboBox()
        With cmd냉난방구분.Items
            .Add("(없음)")
            .Add("난방용")
            .Add("급탕용")
            .Add("난방급탕용")
            .Add("냉방용")
            .Add("냉난방용")
        End With
        fxGround.Cols("지열냉난방구분").Editor = cmd냉난방구분

        '//열병합: 냉난방구분
        Dim cmdYBH냉난방구분 As New ComboBox()
        With cmdYBH냉난방구분.Items
            .Add("(없음)")
            .Add("난방용")
            .Add("급탕용")
            .Add("난방급탕용")
        End With
        fxybh.Cols("열병합냉난방구분").Editor = cmdYBH냉난방구분

        '//태양열시스템(FlexGrid)
        Dim Bs태양열종류 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1057'", .Sort = "code"}
        Dim cmd태양열종류 As New ComboBox With {.DataSource = Bs태양열종류, .DisplayMember = "name", .ValueMember = "name"}
        cmd태양열종류.DropDownStyle = ComboBoxStyle.DropDownList
        fxEnergy.Cols("태양열종류").Editor = cmd태양열종류

        Dim Bs집열기유형 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1058'", .Sort = "code"}
        Dim cmd집열기유형 As New ComboBox With {.DataSource = Bs집열기유형, .DisplayMember = "name", .ValueMember = "name"}
        cmd집열기유형.DropDownStyle = ComboBoxStyle.DropDownList
        fxEnergy.Cols("집열기유형").Editor = cmd집열기유형

        Dim Bs집열판방위 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1059'", .Sort = "code"}
        Dim cmd집열판방위 As New ComboBox With {.DataSource = Bs집열판방위, .DisplayMember = "name", .ValueMember = "name"}
        cmd집열판방위.DropDownStyle = ComboBoxStyle.DropDownList
        fxEnergy.Cols("집열판방위").Editor = cmd집열판방위

        Dim Bs축열탱크설치장소 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1061'", .Sort = "code"}
        Dim cmd축열탱크설치장소 As New ComboBox With {.DataSource = Bs축열탱크설치장소, .DisplayMember = "name", .ValueMember = "name"}
        cmd축열탱크설치장소.DropDownStyle = ComboBoxStyle.DropDownList
        fxEnergy.Cols("축열탱크설치장소").Editor = cmd축열탱크설치장소

        '//태양광시스템

        Dim Bs태양광기울기 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1062'", .Sort = "code"}
        Dim cmd태양광기울기 As New ComboBox With {.DataSource = Bs태양광기울기, .DisplayMember = "name", .ValueMember = "name"}
        cmd태양광기울기.DropDownStyle = ComboBoxStyle.DropDownList
        AddHandler cmd태양광기울기.SelectedIndexChanged, AddressOf SelectIndexChange_태양광기울기
        fxLight.Cols("태양광모듈기울기").Editor = cmd태양광기울기

        Dim Bs태양광종류 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1064'", .Sort = "code"}
        Dim cmd태양광종류 As New ComboBox With {.DataSource = Bs태양광종류, .DisplayMember = "name", .ValueMember = "name"}
        cmd태양광종류.DropDownStyle = ComboBoxStyle.DropDownList
        fxLight.Cols("태양광모듈종류").Editor = cmd태양광종류

        Dim Bs태양광적용타입 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1065'", .Sort = "code"}
        Dim cmd태양광적용타입 As New ComboBox With {.DataSource = Bs태양광적용타입, .DisplayMember = "name", .ValueMember = "name"}
        cmd태양광적용타입.DropDownStyle = ComboBoxStyle.DropDownList
        fxLight.Cols("태양광모듈적용타입").Editor = cmd태양광적용타입

        Dim Bs태양광모듈방위 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = "gubun='1063'", .Sort = "code"}
        Dim cmd태양광모듈방위 As New ComboBox With {.DataSource = Bs태양광모듈방위, .DisplayMember = "name", .ValueMember = "name"}
        cmd태양광모듈방위.DropDownStyle = ComboBoxStyle.DropDownList
        fxLight.Cols("태양광모듈방위").Editor = cmd태양광모듈방위

    End Sub

    Private Sub MdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.bs_light.EndEdit()
        Me.bs_energy.EndEdit()
        Me.bs_ground.EndEdit()
        Me.bs_열병합.EndEdit()

        CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me, Me.bs_energy.Position, True)
    End Sub

    Private Sub MdiMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.F12
        End Select
    End Sub

    Private Sub AddNewDataRow_new_energy(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//태양열
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_new_energy, 1000)
    End Sub
    Private Sub AddNewDataRow_new_light(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//태양광
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_new_light, 3000)
    End Sub
    Private Sub AddNewDataRow_new_ground(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//지열
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_new_ground, 2000)
    End Sub
    Private Sub AddNewDataRow_new_ybh(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//열병합
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_new_열병합, 4000)
    End Sub
#End Region

    Private Sub bs_CurrentItemChanged_energy(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_energy.CurrentItemChanged
        Try
            Me.bs_energy.EndEdit()
        Catch ex As Exception

        End Try

    End Sub

    Private Sub bs_CurrentItemChanged_light(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_light.CurrentItemChanged
        Try
            Me.bs_light.EndEdit()
        Catch ex As Exception

        End Try

    End Sub

    Private Sub bs_CurrentItemChanged_ground(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_ground.CurrentItemChanged
        Try
            Me.bs_ground.EndEdit()
        Catch ex As Exception

        End Try

    End Sub


    Private Sub fxLight_MouseUp(sender As Object, e As MouseEventArgs) Handles fxLight.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            Frm_Filter.ColumTitle = getColCaption(Me.Dt)
            Frm_Filter.ColumList = getColName(Me.Dt)
            Frm_Filter.Colorlist = ""
            '//getfiled 며령으로 모든 필드명을 찾아서
            '//그것을 그 화면으로  보내는거에요
            '//그런데 여기서 어떤필드는 색을 달리하겟다라고할려면 해당   ::::   정보도 같이 넘겨줘야해요
            '//그부분 구현이 좀 매끄럽게 생각정리가안되네요

            Frm_Filter.Numfield = ""    '//20100618  Color 리스트처럼 , 구분해서 필드들을 모두 넣으세요.(=, >= 등을 사용하기 위해서는 해당 항목을 추가 요망)
            If Frm_Filter.ShowDialog <> Windows.Forms.DialogResult.OK Then Return '//창떳을떄 확인아ㅣ고 취소눌르면 다음을 수행하지않는다는거에요.
            Dim Filter As String = Frm_Filter.tb_filter.Text   '//값은 아까 그 텍박에 잇구요.
            Try
                Me.bs_light.Filter = Filter

                '//바꾸기값이 있으면 변경 20100618
                If Frm_Filter.cmb_fieldc.SelectedIndex >= 0 AndAlso Frm_Filter.cmb_fieldc.Text.ToLower <> "code" AndAlso
                Frm_Filter.tb_valuec.Text <> "" Then
                    Dim Drow() As DataRow = DSET1.tbl_new_light.Select(Filter)
                    For Each Dr As DataRow In Drow
                        Dr(Frm_Filter.cmb_fieldc.Text) = Frm_Filter.tb_valuec.Text
                    Next
                    MsgBox("바꾸기 완료", MsgBoxStyle.Information, "확인")
                End If

            Catch ex As Exception
                Me.bs_light.Filter = ""
            End Try
        End If
    End Sub

    Private Sub fxEnergy_MouseUp(sender As Object, e As MouseEventArgs) Handles fxEnergy.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            Frm_Filter.ColumTitle = getColCaption(Me.Dt)
            Frm_Filter.ColumList = getColName(Me.Dt)
            Frm_Filter.Colorlist = ""
            '//getfiled 며령으로 모든 필드명을 찾아서
            '//그것을 그 화면으로  보내는거에요
            '//그런데 여기서 어떤필드는 색을 달리하겟다라고할려면 해당   ::::   정보도 같이 넘겨줘야해요
            '//그부분 구현이 좀 매끄럽게 생각정리가안되네요

            Frm_Filter.Numfield = ""    '//20100618  Color 리스트처럼 , 구분해서 필드들을 모두 넣으세요.(=, >= 등을 사용하기 위해서는 해당 항목을 추가 요망)
            If Frm_Filter.ShowDialog <> Windows.Forms.DialogResult.OK Then Return '//창떳을떄 확인아ㅣ고 취소눌르면 다음을 수행하지않는다는거에요.
            Dim Filter As String = Frm_Filter.tb_filter.Text   '//값은 아까 그 텍박에 잇구요.
            Try
                Me.bs_energy.Filter = Filter

                '//바꾸기값이 있으면 변경 20100618
                If Frm_Filter.cmb_fieldc.SelectedIndex >= 0 AndAlso Frm_Filter.cmb_fieldc.Text.ToLower <> "code" AndAlso
                Frm_Filter.tb_valuec.Text <> "" Then
                    Dim Drow() As DataRow = DSET1.tbl_new_energy.Select(Filter)
                    For Each Dr As DataRow In Drow
                        Dr(Frm_Filter.cmb_fieldc.Text) = Frm_Filter.tb_valuec.Text
                    Next
                    MsgBox("바꾸기 완료", MsgBoxStyle.Information, "확인")
                End If

            Catch ex As Exception
                Me.bs_energy.Filter = ""
            End Try
        End If
    End Sub

    Private Sub fxGround_MouseUp(sender As Object, e As MouseEventArgs) Handles fxGround.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            Frm_Filter.ColumTitle = getColCaption(Me.Dt)
            Frm_Filter.ColumList = getColName(Me.Dt)
            Frm_Filter.Colorlist = ""
            '//getfiled 며령으로 모든 필드명을 찾아서
            '//그것을 그 화면으로  보내는거에요
            '//그런데 여기서 어떤필드는 색을 달리하겟다라고할려면 해당   ::::   정보도 같이 넘겨줘야해요
            '//그부분 구현이 좀 매끄럽게 생각정리가안되네요

            Frm_Filter.Numfield = ""    '//20100618  Color 리스트처럼 , 구분해서 필드들을 모두 넣으세요.(=, >= 등을 사용하기 위해서는 해당 항목을 추가 요망)
            If Frm_Filter.ShowDialog <> Windows.Forms.DialogResult.OK Then Return '//창떳을떄 확인아ㅣ고 취소눌르면 다음을 수행하지않는다는거에요.
            Dim Filter As String = Frm_Filter.tb_filter.Text   '//값은 아까 그 텍박에 잇구요.
            Try
                Me.bs_ground.Filter = Filter

                '//바꾸기값이 있으면 변경 20100618
                If Frm_Filter.cmb_fieldc.SelectedIndex >= 0 AndAlso Frm_Filter.cmb_fieldc.Text.ToLower <> "code" AndAlso
                Frm_Filter.tb_valuec.Text <> "" Then
                    Dim Drow() As DataRow = DSET1.tbl_new_ground.Select(Filter)
                    For Each Dr As DataRow In Drow
                        Dr(Frm_Filter.cmb_fieldc.Text) = Frm_Filter.tb_valuec.Text
                    Next
                    MsgBox("바꾸기 완료", MsgBoxStyle.Information, "확인")
                End If

            Catch ex As Exception
                Me.bs_ground.Filter = ""
            End Try
        End If
    End Sub

    Private Sub fxLight_KeyDown(sender As Object, e As KeyEventArgs) Handles fxLight.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.. 사실원래 밋alt +d 인데.. ㅎㅎ 잘못해서 ctrl 됫다는
        Select Case e.KeyCode
            Case Keys.D
                If e.Alt Then
                    Dbbase.DelCrow(Me.bs_light, False)
                End If
            Case Keys.C
                If e.Control Then
                    Me.SrcDrv = Me.bs_light.Current
                    If Me.SrcDrv Is Nothing Then
                        MsgBox("저장할 ROW가 없습니다", MsgBoxStyle.Information, "확인")
                        Return
                    End If
                    ' My.Computer.Clipboard.SetData("ZDATA", Drv)
                End If
            Case Keys.V
                If e.Control Then
                    If SrcDrv Is Nothing Then Return
                    EndEdit()
                    bs_light.AddNew()
                    Dim NewDrv As DataRowView = Me.bs_light.Current

                    For Each C As DataColumn In Me.Dt.Columns
                        If C.ColumnName.ToUpper = "CODE" Then
                        ElseIf C.ColumnName.ToUpper = "설명" Then
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName) & "#1"
                        Else
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName)
                        End If
                    Next
                    Me.bs_light.EndEdit()
                    bs_light.MoveLast()
                End If
        End Select
    End Sub

    Private Sub fxEnergy_KeyDown(sender As Object, e As KeyEventArgs) Handles fxEnergy.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.. 사실원래 밋alt +d 인데.. ㅎㅎ 잘못해서 ctrl 됫다는
        Select Case e.KeyCode
            Case Keys.D
                If e.Alt Then
                    Dbbase.DelCrow(Me.bs_energy, False)
                End If
            Case Keys.C
                If e.Control Then
                    Me.SrcDrv = Me.bs_energy.Current
                    If Me.SrcDrv Is Nothing Then
                        MsgBox("저장할 ROW가 없습니다", MsgBoxStyle.Information, "확인")
                        Return
                    End If
                    ' My.Computer.Clipboard.SetData("ZDATA", Drv)
                End If
            Case Keys.V
                If e.Control Then
                    If SrcDrv Is Nothing Then Return
                    EndEdit()
                    bs_energy.AddNew()
                    Dim NewDrv As DataRowView = Me.bs_energy.Current

                    For Each C As DataColumn In Me.Dt.Columns
                        If C.ColumnName.ToUpper = "CODE" Then
                        ElseIf C.ColumnName.ToUpper = "설명" Then
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName) & "#1"
                        Else
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName)
                        End If
                    Next
                    Me.bs_energy.EndEdit()
                    bs_energy.MoveLast()
                End If
        End Select
    End Sub

    Private Sub fxGround_KeyDown(sender As Object, e As KeyEventArgs) Handles fxGround.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.. 사실원래 밋alt +d 인데.. ㅎㅎ 잘못해서 ctrl 됫다는
        Select Case e.KeyCode
            Case Keys.D
                If e.Alt Then
                    Dbbase.DelCrow(Me.bs_ground, False)
                End If
            Case Keys.C
                If e.Control Then
                    Me.SrcDrv = Me.bs_ground.Current
                    If Me.SrcDrv Is Nothing Then
                        MsgBox("저장할 ROW가 없습니다", MsgBoxStyle.Information, "확인")
                        Return
                    End If
                    ' My.Computer.Clipboard.SetData("ZDATA", Drv)
                End If
            Case Keys.V
                If e.Control Then
                    If SrcDrv Is Nothing Then Return
                    EndEdit()
                    bs_ground.AddNew()
                    Dim NewDrv As DataRowView = Me.bs_ground.Current

                    For Each C As DataColumn In Me.Dt.Columns
                        If C.ColumnName.ToUpper = "CODE" Then
                        ElseIf C.ColumnName.ToUpper = "설명" Then
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName) & "#1"
                        Else
                            NewDrv(C.ColumnName) = SrcDrv(C.ColumnName)
                        End If
                    Next
                    Me.bs_ground.EndEdit()
                    bs_ground.MoveLast()
                End If
        End Select
    End Sub

    
    Private Sub RibbonButton1_Click(sender As Object, e As EventArgs) Handles RibbonButton1.Click
        AcceptChanged()
    End Sub

    Sub EndEdit()
        Validate()
        fxEnergy.FinishEditing()
        fxGround.FinishEditing()
        fxLight.FinishEditing()
        fxybh.FinishEditing()

        bs_energy.EndEdit()
        bs_ground.EndEdit()
        bs_light.EndEdit()
        bs_열병합.EndEdit()
    End Sub
    Private Sub btAdd_Click(sender As Object, e As EventArgs) Handles btAdd.Click
        EndEdit()
        If C1DockingTab1.SelectedIndex = 0 Then
            Me.bs_light.AddNew()
        ElseIf C1DockingTab1.SelectedIndex = 1 Then
            Me.bs_energy.AddNew()
        ElseIf C1DockingTab1.SelectedIndex = 2 Then
            Me.bs_ground.AddNew()
        Else
            Me.bs_열병합.AddNew()
        End If
    End Sub

    Private Sub btDel_Click(sender As Object, e As EventArgs) Handles btDel.Click
        EndEdit()
        If C1DockingTab1.SelectedIndex = 0 Then
            Dbbase.DelCrow(Me.bs_light, True)
        ElseIf C1DockingTab1.SelectedIndex = 1 Then
            Dbbase.DelCrow(Me.bs_energy, True)
        ElseIf C1DockingTab1.SelectedIndex = 2 Then
            Dbbase.DelCrow(Me.bs_ground, True)
        Else
            Dbbase.DelCrow(Me.bs_열병합, True)
        End If
    End Sub

    Private Sub 열너비자동조정ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 열너비자동조정ToolStripMenuItem.Click

        Dim MenuItem As ToolStripMenuItem = sender
        If Not MenuItem Is Nothing Then
            Dim cMenu As ContextMenuStrip = MenuItem.Owner
            If Not cMenu Is Nothing Then
                Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = cMenu.SourceControl
                grid.AutoSizeCols()
            End If
        End If


    End Sub

    Private Sub 열너비저장ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 열너비저장ToolStripMenuItem.Click

        Dim MenuItem As ToolStripMenuItem = sender
        If Not MenuItem Is Nothing Then
            Dim cMenu As ContextMenuStrip = MenuItem.Owner
            If Not cMenu Is Nothing Then
                Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = cMenu.SourceControl
                SavefGridColWidth(Me.Name, grid)
            End If
        End If


    End Sub

    Private Sub 열너비초기화ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 열너비초기화ToolStripMenuItem.Click

        Dim MenuItem As ToolStripMenuItem = sender
        If Not MenuItem Is Nothing Then
            Dim cMenu As ContextMenuStrip = MenuItem.Owner
            If Not cMenu Is Nothing Then
                Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = cMenu.SourceControl
                '//모든데이터의 열너비를 초기화한다.
                ClearfGridColWidth(grid)
            End If
        End If

    End Sub

    Private Sub bs_열병합_CurrentChanged(sender As System.Object, e As System.EventArgs) Handles bs_열병합.CurrentChanged
        Try
            Me.bs_열병합.EndEdit()
        Catch ex As Exception

        End Try

    End Sub
End Class