Public Class Frm_2_Build
    Dim T As String = "건축입력"
    Dim Dt As DataTable
    Dim isCopy As Boolean = False
    Dim Init As Boolean = False
    Dim SrcDrv As DataRowView
    Public Sub New()
        ' 디자이너에서 이 호출이 필요합니다.
        InitializeComponent()
        'AddHandler dvProfile1.DataError, Sub(sender, e)
        '                                     Console.WriteLine("dv error")
        '                                 End Sub
        With fxList
            .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
            .ExtendLastCol = False
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With
        With fxType
            .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
            .ExtendLastCol = False
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
        End With
        AddHandler fxList.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxList.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxList.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxList.OwnerDrawCell, AddressOf flexOwnerDrawCell
        AddHandler fxType.KeyPress, AddressOf fgrid_KeyPress
        AddHandler fxType.AfterEdit, AddressOf fgrid_AfterEdit
        AddHandler fxType.BeforeEdit, AddressOf fgrid_BeginEditS
        AddHandler fxType.OwnerDrawCell, AddressOf flexOwnerDrawCell
    End Sub
    Sub Make_형별성능내역_List(colindex As Integer)
        ' Console.WriteLine("yk2")
        Dim sl As New System.Collections.SortedList()
        For i As Integer = 1 To DSET1.tbl_yk.Rows.Count
            Dim dr As DS.tbl_ykRow = DSET1.tbl_yk.Rows(i - 1)
            sl.Add(dr.code, dr.설명)
        Next
        fxList.Cols(colindex).DataType = GetType(String)
        fxList.Cols(colindex).DataMap = sl
    End Sub
    Sub Make_존분류_List(colindex As Integer)
        ' Console.WriteLine("zon")
        Dim sl As New System.Collections.SortedList()
        For i As Integer = 1 To DSET1.tbl_zone.Rows.Count
            Dim dr As DS.tbl_zoneRow = DSET1.tbl_zone.Rows(i - 1)
            sl.Add(dr.code, dr.설명)
        Next
        fxList.Cols(colindex).DataType = GetType(String)
        fxList.Cols(colindex).DataMap = sl
    End Sub
    Sub Make_방위_List(colindex As Integer)
        '  Console.WriteLine("zon")
        Dim sl As New System.Collections.SortedList()
        For Each dr As DS.tbl_common_odRow In DSET1.tbl_common_od.Select("gubun='1007'")
            sl.Add(dr.name, dr.name)
        Next
        fxList.Cols(colindex).DataType = GetType(String)
        fxList.Cols(colindex).DataMap = sl
    End Sub
    Sub Make_비주거용도_List(colindex As Integer)
        '  Console.WriteLine("zon")
        Dim sl As New Dictionary(Of String, String)
        For Each dr As DS.tbl_profile_odRow In DSET1.tbl_profile_od.Select("code < 5000")
            sl.Add(dr.code, dr.설명)
        Next
        fxType.Cols(colindex).DataType = GetType(String)
        fxType.Cols(colindex).DataMap = sl
    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 "면적", "세대수", "세대면적"
                bsType_CurrentChanged(Nothing, Nothing)
            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 MoveCellDown(grid) Then
                MoveCellRight(grid)
            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 grid.Cols(e.Col).Name = "수직차양각" OrElse grid.Cols(e.Col).Name = "수평차양각" Then
            '//건축부위방식 가 외부창,내부창 일경우에만 수평,수직차양각 칸을 활성화한다.  170517
            Dim oVal As Object = grid.GetData(e.Row, "건축부위방식")
            Dim sVal As String = ""
            If Not oVal Is Nothing Then sVal = oVal.ToString()
            If oVal <> "외부창" AndAlso oVal <> "내부창" Then
                e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds)
                '  e.Graphics.DrawRectangle(Pens.Gray, e.Bounds)
            End If
        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
    Private Sub Frm_2_Build_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.fxList.FinishEditing()
        Me.bs.EndEdit()
        Me.bsType.EndEdit()
        Me.bs_desc.EndEdit()
        '//가운데분할자정보를 저장한다.
        Pub.Setting.Data("Mach", "Div" + Pub.Program.ToString(), "") = Me.SplitContainer1.SplitterDistance.ToString()
    End Sub
    Private Sub Frm_2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.bs.DataSource = DSET1
        Me.bs_desc.DataSource = DSET1
        Me.bs_열관류.DataSource = DSET1
        Me.bsType.DataSource = DSET1
        Me.bs방위.DataSource = DSET1
        Dt = DSET1.tbl_myoun
        AddHandler DSET1.tbl_myoun.TableNewRow, AddressOf AddNewDataRow_new
        AddHandler DSET1.tbl_myoun.ColumnChanged, AddressOf AddNewDataRow_Zone_Changed
        AddHandler DSET1.tbl_type.TableNewRow, AddressOf AddNewDataRow_type
        Binding_Zone()
        '//모든컨트롤의 cTrl_enter 를 추가합니다
        'BindProperty(CType(Me.SplitContainer1.Panel2.Controls, Control.ControlCollection))
        Me.Init = True
        Me.Show()
        Application.DoEvents()
        
        'Try
        '    Me.bs_zone.Position = CEnergy.ARINCLASS.Read_LastPos_Frm(Me.Name & "1")
        'Catch ex As Exception
        '    Me.bs_zone.MoveFirst()
        'End Try
        Try
            Me.bs.Position = CEnergy.ARINCLASS.Read_LastPos_Frm(Me)
        Catch ex As Exception
            Me.bs.MoveFirst()
        End Try
        Bs_CurrentChanged(sender, e)
        Validate_Control()
        '//주거,비주거형태로 열 정렬
        If Program = EProgram.총량평가 Then
            fxType.Cols("세대타입").Visible = False
            fxType.Cols("세대면적").Visible = False
            fxType.Cols("세대수").Visible = False
            Label35.Text = "연면적"
            Label17.Text = "층 별 개 요"
        Else
            fxType.Cols("층").Visible = False
            fxType.Cols("면적").Visible = False
            fxType.Cols("시설용도").Visible = False
            Label35.Text = "총전용면적"
            Label17.Text = "면적및세대합"
        End If
        '//제목줄 크기변경
        fxList.Rows()(0).HeightDisplay *= 2
        fxList.Rows()(0).StyleDisplay.WordWrap = True
        fxType.Rows()(0).HeightDisplay *= 2
        fxType.Rows()(0).StyleDisplay.WordWrap = True
        '//열너비
        ReadfGridColWidth(Me.Name, fxList)
        ReadfGridColWidth(Me.Name, fxType)
    End Sub
    Private Sub AddNewDataRow_new(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//존분류값가져오기(신규추가시)
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_myoun)
        'e.Row.Item("열관류율2") = Me.cmb_gubun.Text  '//선택된 그것의 값이 들어가도록..필드명만찾아서 입력하세요.
        e.Row.Item("설명") = bs.Count + 1
        'Try
        '    If Me.cmb_gubun.SelectedIndex = -1 OrElse Me.cmb_gubun.Text = "(없음)" Then
        '        e.Row.Item("설명") = bs.Count + 1
        '    Else
        '        e.Row.Item("설명") = Me.cmb_gubun.Text
        '    End If
        'Catch ex As Exception
        '    e.Row.Item("설명") = "ㅣ"
        'End Try
    End Sub
    Private Sub AddNewDataRow_type(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        '//존분류값가져오기(신규추가시)
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_type)
    End Sub
    Private Sub Calc_전체면적()
        Dim total As Double = 0
        Dim total2 As Integer = 0 '//세대수합
        For Each dr As DS.tbl_typeRow In DSET1.tbl_type.Rows
            If dr.RowState = DataRowState.Deleted OrElse dr.RowState = DataRowState.Detached Then Continue For
            If Pub.Program = EProgram.총량평가 Then
                total += dr.면적
            Else
                total += dr.세대면적 * dr.세대수
                total2 += dr.세대수
            End If
        Next
        If Pub.Program = EProgram.총량평가 Then
            tb_전체바닥면적.Text = total.ToString()
        Else
            tb_바닥면적.Text = total.ToString()
            tb_전체바닥면적.Text = total2.ToString()
        End If
    End Sub
#Region "Control_Enter"
    Private Sub BindProperty(ByVal Ctl As Control.ControlCollection)
        For Each C As Control In Ctl
            If C.Controls.Count > 1 Then
                BindProperty(C.Controls)
            Else
                If C.GetType.ToString.ToUpper.IndexOf("MYTB") <> -1 Then
                    AddHandler CType(C, MyTb).KeyDown, AddressOf TextBOx_KeyDown
                ElseIf C.GetType.ToString.ToUpper.IndexOf("MYCMB") <> -1 Then
                    AddHandler CType(C, MyCmb).KeyDown, AddressOf Cmd_KeyDown
                    AddHandler CType(C, MyCmb).MouseHover, AddressOf ComboBox_MouseHover
                End If
            End If
        Next
    End Sub
    Private Sub TextBOx_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter AndAlso e.Control Then
            Try
                Dim Field As String = (CType(sender, MyTb).DataBindings.Item("text").BindingMemberInfo.BindingField)
                For Each Dr As DataRow In Dt.Select(Me.bs.Filter, "")
                    If Dr.RowState = DataRowState.Deleted OrElse Dr.RowState = DataRowState.Detached Then Continue For
                    Dr(Field) = CType(sender, MyTb).Text
                Next
                Work_msg_timer("모든값이 변경되었습니다", 25)
            Catch ex As Exception
            End Try
        End If
    End Sub
    Private Sub Cmd_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter AndAlso e.Control Then
            Try
                Dim Field As String = (CType(sender, MyCmb).DataBindings.Item("selectedvalue").BindingMemberInfo.BindingField)
                For Each Dr As DataRow In Dt.Select(Me.bs.Filter, "")
                    If Dr.RowState = DataRowState.Deleted OrElse Dr.RowState = DataRowState.Detached Then Continue For
                    Dr(Field) = CType(sender, MyCmb).SelectedValue
                Next
                Work_msg_timer("모든값이 변경되었습니다", 25)
            Catch ex As Exception
            End Try
        End If
    End Sub
    Private Sub ComboBox_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        If CType(sender, ComboBox).SelectedIndex = -1 Then Return
        Me.ToolTip1.SetToolTip(CType(sender, ComboBox), CType(sender, ComboBox).DataBindings("selectedvalue").BindingMemberInfo.BindingMember & vbCrLf & CType(sender, ComboBox).SelectedValue.ToString)
    End Sub
#End Region
#Region "ComboxBox Binding"
    Dim 변경안함_바닥면적 As Boolean = False
    Private Sub AddNewDataRow_Zone_Changed(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs)
        '//값이바뀐다면 조명의실지수값을 재계산한다.
        'MsgBox(e.Column.ToString)
        Select Case e.Column.Caption.Trim
            Case "바닥면적"
                If 변경안함_바닥면적 Then Return
                '//존분류값이 바뀌었을경우 해당 데이터가 기록된 다른줄을 찾아서 그 값을 설정해준다.
                Dim 존분류 As String = e.Row("존분류").ToString
                Dim 코드 As String = e.Row("code").ToString
                '//순환참조에러방지
                변경안함_바닥면적 = True
                For Each dr As DS.tbl_myounRow In DSET1.tbl_myoun.Select("code <> '" + 코드 + "' and 존분류='" + 존분류 + "'")
                    If dr.RowState = DataRowState.Deleted OrElse dr.RowState = DataRowState.Detached Then Continue For
                    dr.바닥면적 = e.ProposedValue.ToString
                Next
                For Each dr As DS.tbl_myounRow In DSET1.tbl_myoun.Select("code <> '0' and (존분류='0' or 존분류='')")
                    If dr.RowState = DataRowState.Deleted OrElse dr.RowState = DataRowState.Detached Then Continue For
                    dr.바닥면적 = "0"
                Next
                변경안함_바닥면적 = False
                Calc_전체면적()
            Case "건축부위방식"
                'If e.ProposedValue.ToString = "내벽" OrElse e.ProposedValue.ToString = "간벽" OrElse e.ProposedValue.ToString = "내부창" Then
                '    e.Row("방위") = "일사없음"
                'End If
                'Me.bs.EndEdit()
            Case "열관류율2"   '//변경시 작업
                Dim ykcode As String = e.ProposedValue.ToString
                '   MsgBox("ykcode=" + ykcode, MsgBoxStyle.Information, "형별")
                Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & ykcode & "'")
                If dr.GetUpperBound(0) <> -1 Then
                    e.Row("열관류율") = dr(0).열관류율
                    e.Row("투과율") = dr(0).일사에너지투과율
                    Select Case dr(0).면형태
                        Case "외벽(직접)", "0"
                            e.Row("면형태") = "외벽(직접)"
                            e.Row("건축부위방식") = "외벽"
                        Case "지붕(직접)", "0001"
                            e.Row("면형태") = "지붕(직접)"
                            e.Row("건축부위방식") = "외벽"
                            e.Row("방위") = "수평"
                        Case "바닥(직접)", "0002"
                            e.Row("면형태") = "바닥(직접)"
                            e.Row("건축부위방식") = "외벽"
                            e.Row("방위") = "일사없음"
                        Case "외벽(간접)", "0003"
                            e.Row("면형태") = "외벽(간접)"
                            e.Row("건축부위방식") = "내벽"
                            e.Row("방위") = "(없음)"
                        Case "지붕(간접)", "0004"
                            e.Row("면형태") = "지붕(간접)"
                            e.Row("건축부위방식") = "내벽"
                            e.Row("방위") = "일사없음"
                        Case "바닥(간접)", "0005"
                            e.Row("면형태") = "바닥(간접)"
                            e.Row("건축부위방식") = "내벽"
                            e.Row("방위") = "일사없음"
                        Case "간벽", "0006"
                            e.Row("면형태") = "간벽"
                            e.Row("건축부위방식") = "간벽"
                            e.Row("방위") = "(없음)"
                        Case "창(직접)", "창(간접)", "문(직접)", "문(간접)", "세대현관문(직접)", "세대현관문(간접)", "0007", "0008", "0010", "0011", "0012", "0013"
                            If dr(0).면형태 = "0007" Then
                                e.Row("면형태") = "창(직접)"
                                e.Row("건축부위방식") = "외부창"
                            ElseIf dr(0).면형태 = "0008" Then
                                e.Row("면형태") = "창(간접)"
                                e.Row("건축부위방식") = "내부창"
                                e.Row("방위") = "(없음)"
                            ElseIf dr(0).면형태 = "0010" Then
                                e.Row("면형태") = "문(직접)"
                                e.Row("건축부위방식") = "외부창"
                            ElseIf dr(0).면형태 = "0011" Then
                                e.Row("면형태") = "문(간접)"
                                e.Row("건축부위방식") = "내부창"
                                e.Row("방위") = "(없음)"
                            ElseIf dr(0).면형태 = "0012" Then
                                e.Row("면형태") = "세대현관문(직접)"
                                e.Row("건축부위방식") = "외부창"
                            ElseIf dr(0).면형태 = "0013" Then
                                e.Row("면형태") = "세대현관문(간접)"
                                e.Row("건축부위방식") = "내부창"
                                e.Row("방위") = "(없음)"
                            End If
                        Case "지중벽", "0009"
                            e.Row("면형태") = "지중벽"
                            e.Row("건축부위방식") = "내벽"
                            e.Row("방위") = "(없음)"
                        Case Else
                            e.Row("면형태") = "--"
                            MsgBox("모르는값 " & dr(0).면형태 & "/")
                    End Select
                End If
                Me.bs.EndEdit()
                'Case "열관류율"
                '    Dim ykcode As String = e.ProposedValue.ToString
                '    MsgBox("ykcode=" + ykcode, MsgBoxStyle.Information, "열관류율")
                '    Dim dr() As DS.tbl_ykRow = DSET.tbl_yk.Select("code='" & ykcode & "'")
                '    If dr.GetUpperBound(0) <> -1 Then
                '        e.Row("투과율") = dr(0).일사에너지투과율
                '    End If
                '    Me.bs.EndEdit()
            Case Else
                'MsgBox(e.Column.Caption.Trim)
        End Select
    End Sub
    Private Sub MdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me, Me.bs.Position, True)
        'CEnergy.ARINCLASS.Save_LastPos_Frm(Me.Name & "1", Me.bs_zone.Position)
    End Sub
    Private Function GetMaxCode(ByVal dt As DataTable) As String
        Try
            Dim Dr As DataRow = dt.Select("", "code desc")(0)
            Return Format(CInt(Dr("code")) + 1, "0000")
        Catch ex As Exception
            Return "0001"
        End Try
    End Function
    Private Sub Binding_Zone()
        ' Dim filter As String = "gubun ='1007'"
        'Dim bs방위 As New BindingSource(DSET1, "tbl_common_od") With {.Filter = filter, .Sort = "code"}
        'Dim cmd방위 As New ComboBox With {.DataSource = bs방위, .DisplayMember = "name", .ValueMember = "name"}
        'fxList.Cols("방위").Editor = cmd방위
        Make_형별성능내역_List(fxList.Cols("열관류율2").Index)
        Make_존분류_List(fxList.Cols("존분류").Index)
        Make_방위_List(fxList.Cols("방위").Index)
        Make_비주거용도_List(fxType.Cols("시설용도").Index)
        'Dim bs형별성능내역 As New BindingSource(DSET1, "tbl_yk") With {.Filter = filter, .Sort = ""}
        'Dim cmd형별성능내역 As New ComboBox With {.DataSource = bs형별성능내역, .DisplayMember = "설명", .ValueMember = "code"}
        'fxList.Cols("열관류율2").Editor = cmd형별성능내역
        'filter = ""
        'Dim bs존분류 As New BindingSource(DSET1, "tbl_zone") With {.Filter = filter, .Sort = ""}
        'Dim cmd존분류 As New ComboBox With {.DataSource = bs존분류, .DisplayMember = "설명", .ValueMember = "code"}
        'fxList.Cols("존분류").Editor = cmd존분류
    End Sub
#End Region
    ''' 
    ''' 콤보박스등에의한 개체의 활성화여부를 확인
    ''' 
    ''' 
    Private Sub Validate_Control()
        If Not Init Then Return
        If Me.isCopy Then Return
        Display_info()
    End Sub
    Private Sub Display_info()
        Dim WallArea As Decimal, WindowArea As Decimal, WallUvalue As Decimal, WindowUvalue As Decimal
        WallArea = 0
        WindowArea = 0
        WallUvalue = 0
        WindowUvalue = 0
        Try
            For Each Dr입력면 As DS.tbl_myounRow In DSET1.tbl_myoun.Select("건축부위방식='외벽' or 건축부위방식 ='외부창' or 건축부위방식 ='내벽' or 건축부위방식 ='내부창'")
                If Dr입력면.RowState = DataRowState.Deleted OrElse Dr입력면.RowState = DataRowState.Detached Then Continue For
                Dim Dr열관류율 As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2.ToString & "'")(0)
                Select Case Dr입력면.건축부위방식
                    Case "외벽"
                        If Dr열관류율.면형태 = "외벽(직접)" OrElse Dr열관류율.면형태 = "0" Then
                            'If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
                            WallArea = WallArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WallUvalue = WallUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적)
                            'End If
                        End If
                    Case "외부창"
                        If Dr열관류율.면형태 = "창(직접)" OrElse Dr열관류율.면형태 = "문(직접)" OrElse Dr열관류율.면형태 = "세대현관문(직접)" OrElse _
                            Dr열관류율.면형태 = "0007" OrElse Dr열관류율.면형태 = "0010" OrElse Dr열관류율.면형태 = "0012" Then
                            'If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
                            WindowArea = WindowArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WindowUvalue = WindowUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적)
                            'End If
                        End If
                    Case "내부창"
                        If Dr열관류율.면형태 = "창(간접)" OrElse Dr열관류율.면형태 = "문(간접)" OrElse Dr열관류율.면형태 = "세대현관문(간접)" OrElse _
                            Dr열관류율.면형태 = "0008" OrElse Dr열관류율.면형태 = "0011" OrElse Dr열관류율.면형태 = "0013" Then
                            WindowArea = WindowArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WindowUvalue = WindowUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적) * 0.8
                        End If
                    Case "내벽"
                        If Dr열관류율.면형태 = "외벽(간접)" OrElse Dr열관류율.면형태 = "0003" Then
                            'Dim Dr열관류율 As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2.ToString & "'")(0)
                            'If Dr열관류율.면형태 <> "지중벽" AndAlso Dr열관류율.면형태 <> "0009" Then
                            'If Dr입력면.방위 <> "일사없음" Then
                            WallArea = WallArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WallUvalue = WallUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적) * 0.7
                            'End If
                            'End If
                        End If
                   
                End Select
            Next
            'For Each Dr입력면 As DS.tbl_myounRow In DSET.tbl_myoun.Select("건축부위방식='외부창'")
            '    WindowArea = WindowArea + TOSG(T,Dr입력면.건축부위면적)
            'Next
        Catch ex As Exception
        End Try
        Try
            tb_창면적비.Text = Math.Round(WindowArea / (WallArea + WindowArea) * 100, 2).ToString
        Catch ex As Exception
            tb_창면적비.Text = ""
        End Try
        Try
            tb_평균열관류율.Text = Math.Round((WallUvalue + WindowUvalue) / (WallArea + WindowArea), 3).ToString
        Catch ex As Exception
            tb_평균열관류율.Text = ""
        End Try
    End Sub
    Private Sub Cmb_블라인드설치유무_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Validate_Control()
    End Sub
    Private Sub Cmb_건축부위방식_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.V And e.Control Then
            Me.isCopy = True
            Dim StartPos As Integer = Me.bs.Position  '//현재 바인딩셋의 위치정보를 확인
            Dim CurPos As Integer = StartPos
            e.Handled = True
            e.SuppressKeyPress = False
            '//클립보드붙여넣기
            Dim CB() As String = My.Computer.Clipboard.GetText.Split(CChar(vbCrLf))
            If CB.GetUpperBound(0) <> 18 Then
                MsgBox("붙여넣기가 호환되는 데이터가 아닙니다.", MsgBoxStyle.Information, "확인")
                Return
            End If
            '//면개의 입력면이 존재하는지확인한다.
            For ii As Integer = 0 To CType(CB(0).Split(CChar(vbTab)), String()).GetUpperBound(0)
                If Me.bs.Count = 0 OrElse ii > 0 Then
                    AddNew()
                End If
                Dim Cnt As Short = 0
                For i As Integer = 0 To CB.GetUpperBound(0)
                    Select Case i
                        Case 0 '//설명
                            CType(Me.bs.Current, DataRowView)("설명") = CB(i).Split(CChar(vbTab))(ii).Trim
                    End Select
                Next
            Next
            Me.bs.EndEdit()
            Me.isCopy = False
            Me.Validate_Control()
        End If
    End Sub
    Private Sub Bs_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.CurrentChanged
        If Not Init Then Return
        Me.bs.EndEdit()
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return
      
    End Sub
    Private Sub Bt_Del_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Right Then
            If MsgBox("전체삭제를 하시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                Dim dR() As DataRow = DSET1.tbl_myoun.Select(Me.bs.Filter, "")
                For i As Integer = dR.GetUpperBound(0) To 0 Step -1
                    dR(i).Delete()
                Next
                DSET1.tbl_myoun.AcceptChanges()
            End If
        End If
    End Sub
    Private Sub Dv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles fxList.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            Frm_Filter.ColumTitle = getColCaption(Me.Dt)
            Frm_Filter.ColumList = getColName(Me.Dt)
            Frm_Filter.Colorlist = "존분류,대차대조존"
            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.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 = Me.Dt.Select(Filter)
                    Dim i As Integer = 0
                    For Each Dr As DataRow In Drow
                        If Dr.RowState = DataRowState.Deleted OrElse Dr.RowState = DataRowState.Detached Then Continue For
                        Dr(Frm_Filter.cmb_fieldc.Text) = Frm_Filter.tb_valuec.Text
                        i += 1
                    Next
                    MsgBox("'" & i & "'개 바꾸기 완료", MsgBoxStyle.Information, "확인")
                End If
            Catch ex As Exception
                Me.bs.Filter = ""
            End Try
        End If
    End Sub
    Private Sub Dv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.. 사실원래 밋alt +d 인데.. ㅎㅎ 잘못해서 ctrl 됫다는
        Select Case e.KeyCode
            Case Keys.D
                If e.Alt Then
                    Dbbase.DelCrow(Me.bs, False)
                End If
            Case Keys.C
                If e.Control Then
                    Me.SrcDrv = Me.bs.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 Me.SrcDrv Is Nothing Then Return
                    AddNew()
                    Dim NewDrv As DataRowView = Me.bs.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.EndEdit()
                    bs.MoveLast()
                End If
        End Select
    End Sub
    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Dim f As New Frm_V20091231_YK
        f.ShowDialog()
        '//형별성능내역목록 업데이트 170517
        Make_형별성능내역_List(fxList.Cols("열관류율2").Index)
    End Sub
    Private Sub MyTb1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_층고.TextChanged
        'Me.bs.EndEdit()   '//이부분이 박에서 수행되면 사라짐
        'Me.bs_desc.EndEdit()
    End Sub
    Private Sub Frm_2_Build_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        Me.bs.EndEdit()   '//이부분이 박에서 수행되면 사라짐
        Me.bs_desc.EndEdit()
        'Me.bs_zone.EndEdit()
    End Sub
    Private Sub Bs_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs.CurrentItemChanged
        Try
            Display_info()
            Me.bs.EndEdit()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Bs_열관류_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_열관류.CurrentItemChanged
        Display_info()
        bs_열관류.EndEdit()
    End Sub
    Private Sub Bs_desc_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_desc.CurrentItemChanged
        Display_info()
        Me.bs_desc.EndEdit()
    End Sub
    Private Sub Tb_바닥면적_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tb_바닥면적.KeyUp
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return
        If Pub.Program = EProgram.총량평가 Then
            drv("바닥면적") = tb_바닥면적.Text
        Else
            drv("세대면적") = tb_바닥면적.Text
        End If
    End Sub
    Public Overrides Function AcceptChanged() As Boolean
        fxType.FinishEditing()
        bsType.EndEdit()
        bs.EndEdit()
        DSET1.tbl_myoun.AcceptChanges()
        Return MyBase.AcceptChanged()
    End Function
    Private Sub C1StatusBar2_Click(sender As Object, e As EventArgs) Handles C1StatusBar2.Click
        AcceptChanged()
    End Sub
    Private Sub C1StatusBar3_Click(sender As Object, e As EventArgs)
    End Sub
    Sub AddNew()
        If Not EndEdit(Me.bs) Then Return
        '//Me.cmb_gubun.SelectedIndex = 0
        Me.bs.AddNew()
        INitRow(Me.Controls)
        '//추가한후에
        'Me.cmb_열관류율.Text = Me.cmb_gubun.Text
        '//이게 콤보넣을떄인데요. 면의형태의 값을.. 어디다가 넣으시게요?
        Dim Dr1() As DS.tbl_ykRow = DSET1.tbl_yk.Select("설명=''")
        If Dr1.GetUpperBound(0) = 0 Then   '//해당데이터가 찾아졋을경우에
            Dim dr2() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select("gubun='1088' and code='" & Dr1(0).면형태 & "'")
            Dim 면형태 As String = dr2(0).name
            'Select Case 면형태
            '    Case "외벽(벽체)"
            '        Me.cmb_건축부위방식.Text = "외벽"
            '    Case "외벽(지붕)"
            '        Me.cmb_건축부위방식.Text = "외벽"
            '        Me.cmb_방위.Text = "수평"
            '    Case "외벽(바닥)"
            '        Me.cmb_건축부위방식.Text = "외벽"
            '        Me.cmb_방위.Text = "일사없음"
            '    Case "내벽(벽체)"
            '        Me.cmb_건축부위방식.Text = "내벽"
            '        Me.cmb_방위.Text = "일사없음"
            '    Case "내벽(지붕)"
            '        Me.cmb_건축부위방식.Text = "내벽"
            '        Me.cmb_방위.Text = "일사없음"
            '    Case "내벽(바닥)"
            '        Me.cmb_건축부위방식.Text = "내벽"
            '        Me.cmb_방위.Text = "일사없음"
            '    Case "간벽"
            '        Me.cmb_건축부위방식.Text = "간벽"
            '        Me.cmb_방위.Text = "일사없음"
            '    Case "외부창", "내부창"
            '        If 면형태 = "외부창" Then
            '            Me.cmb_건축부위방식.Text = "외부창"
            '        Else
            '            Me.cmb_건축부위방식.Text = "내부창"
            '            Me.cmb_방위.Text = "일사없음"
            '        End If
            '        Dim Dr As DS.tbl_ykRow = DSET.tbl_yk.Select("code='" & Me.cmb_열관류율.SelectedValue & "'")(0)
            '        'Me.tb_04.Text = Dr("일사에너지투과율").ToString
            '    Case Else
            '        MsgBox("모르는값 " & Dr1(0).면형태 & "/" & 면형태)
            'End Select
        Else
            ' MsgBox("못찻음")
        End If
    End Sub
    Private Sub RibbonButton2_Click(sender As Object, e As EventArgs)
    End Sub
    Private Sub RibbonButton3_Click(sender As Object, e As EventArgs)
    End Sub
    Private Sub RibbonButton4_Click(sender As Object, e As EventArgs)
    End Sub
    Private Sub RibbonButton5_Click(sender As Object, e As EventArgs)
    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 RibbonButton1_Click(sender As Object, e As EventArgs) Handles RibbonButton1.Click
        AcceptChanged()
    End Sub
    Private Sub RibbonButton7_Click(sender As System.Object, e As System.EventArgs) Handles RibbonButton7.Click
        AddNew()
    End Sub
    Private Sub RibbonButton8_Click(sender As System.Object, e As System.EventArgs) Handles RibbonButton8.Click
        Dbbase.DelCrow(Me.bs, True)
    End Sub
    Private Sub RibbonButton2_Click_1(sender As System.Object, e As System.EventArgs) Handles RibbonButton2.Click
        bsType.AddNew()
    End Sub
    Private Sub RibbonButton6_Click(sender As System.Object, e As System.EventArgs) Handles RibbonButton6.Click
        ' bsType.RemoveCurrent()
        Dbbase.DelCrow(Me.bsType, True)
    End Sub
    Private Sub Frm_2_Build_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        '//가운데분할자를 불러온다.
        Dim spliterdist As String = Pub.Setting.Data("Mach", "Div" + Pub.Program.ToString(), "")
        If IsNumeric(spliterdist) Then Me.SplitContainer1.SplitterDistance = Integer.Parse(spliterdist)
    End Sub
    Private Sub bsType_CurrentChanged(sender As Object, e As EventArgs) Handles bsType.CurrentChanged
        Dim drv As DataRowView = Me.bsType.Current
        If drv Is Nothing Then Return
        'Dim dr As DS.tbl_typeRow = drv.Row
     
        Dim yongdo As String = String.Empty
        Dim area As Double = 0
        If Not drv("시설용도") Is DBNull.Value Then
            yongdo = drv("시설용도").ToString
            For Each dr As DS.tbl_typeRow In DSET1.tbl_type.Rows
                If dr.RowState = DataRowState.Deleted OrElse dr.RowState = DataRowState.Detached Then Continue For
                If dr.시설용도 = yongdo Then
                    If Pub.Program = EProgram.총량평가 Then
                        area += dr.면적
                    Else
                        area += dr.세대면적
                    End If
                End If
            Next
        End If
        tb_바닥면적.Text = area.ToString()
      
        Calc_전체면적()
    End Sub
End Class