Public Class Frm_V20091231_YK


    Dim T As String = "열관류율"


    Dim DT As DataTable
    Dim init As Boolean = False
    Dim pcode As String
    Dim UserCommin As Boolean = False
    Dim SrcDrv As DataRowView
    Dim keyUp1 As Boolean = False    '//열전도율 사용자가 수정하려할시를 나타냄(110618)

    Public Sub New()

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

        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 = True
            .AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
            .ShowSortPosition = C1.Win.C1FlexGrid.ShowSortPositionEnum.None
            .AutoGenerateColumns = False

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

        End With

        With fxData
            .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
            .AutoGenerateColumns = False

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

        End With

        Label3.Enabled = True
        Label4.Enabled = True
        Label5.Enabled = True
        열관류율NTb.ReadOnly = True


    End Sub

    Private Function Refresh_열전도율목록() As String
        If bs_detail.Count < 1 Then Return String.Empty
        Dim Drv As DataRowView = CType(Me.bs_detail.Current, DataRowView)
        If Drv Is Nothing Then Return String.Empty
        Dim dr As DS.tbl_ykdetailRow = Drv.Row

        '//해당열전도율가져오기
        Dim cmb As ComboBox = fxData.Cols("열전도율").Editor
        cmb.Items.Clear()

        Dim 재료코드 As String = String.Empty
        Dim Filter As String = String.Format("gubun='1089' and name='{0}'", dr.설명)
        Dim Drow() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select(bS_재료.Filter)
        If Drow.GetUpperBound(0) = 0 Then
            재료코드 = Drow(0).code
            cmb.Items.Add(Drow(0).valn1)
            cmb.Text = Drow(0).valn1
        Else
            dr.커스텀 = "N" '//해당값이 아에없는경우 변경된걸로 확인
        End If

        Return 재료코드
    End Function


#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)
        If Not grid Is fxData Then Return


        Dim data As Object = grid.GetData(e.Row, e.Col)

        Select Case grid.Cols(e.Col).Name.ToLower()


            Case "열전도율"
                '//열전도율이 바뀌었다면 목록내의 열전도율값과 비교하여 없다면 커스텀을 Y로 처리해준다.
                Dim o재료명 As Object = grid.GetData(e.Row, grid.Cols("설명").Index)
                Dim 재료명 As String = String.Empty
                If Not o재료명 Is Nothing Then 재료명 = o재료명.ToString()

                Dim o열전도율 As Object = grid.GetData(e.Row, e.Col)
                Dim 열전도율 As String = ""
                If Not o열전도율 Is Nothing Then 열전도율 = o열전도율.ToString()
                If String.IsNullOrEmpty(열전도율) OrElse String.IsNullOrEmpty(재료명) Then
                    grid.SetData(e.Row, grid.Cols("커스텀").Index, "N")
                Else

                    '//값이 들어있다면 목록내의 값인지 체크한다.
                    Dim Filter As String = String.Format("gubun='1089' and name='{0}'", 재료명)
                    Dim Drow() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select(Filter)
                    If Drow.GetUpperBound(0) = 0 Then
                        Dim 기준값 As String = Drow(0).valn1
                        If 열전도율 <> 기준값 Then
                            grid.SetData(e.Row, grid.Cols("커스텀").Index, "Y") '//해당값이 아에없는경우 변경된걸로 확인
                        Else
                            grid.SetData(e.Row, grid.Cols("커스텀").Index, "N") '//해당값이 아에없는경우 변경된걸로 확인
                        End If
                    Else
                        grid.SetData(e.Row, grid.Cols("커스텀").Index, "N") '//해당값이 아에없는경우 변경된걸로 확인
                    End If

                End If
            Case "설명"

                '//재료명이 바뀌었다면 열전도율 목록과 해당 재료의 색상코드로 그 값을 변경해준다.
                Dim o재료명 As Object = grid.GetData(e.Row, e.Col)
                Dim 재료명 As String = String.Empty
                If Not o재료명 Is Nothing Then 재료명 = o재료명.ToString()

                '//해당열전도율가져오기
                Dim cmb As ComboBox = fxData.Cols("열전도율").Editor
                cmb.Items.Clear()

                Dim 재료코드 As String = String.Empty
                Dim Filter As String = String.Format("gubun='1089' and name='{0}'", 재료명)
                Dim Drow() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select(Filter)
                If Drow.GetUpperBound(0) = 0 Then
                    재료코드 = Drow(0).code
                    cmb.Items.Add(Drow(0).valn1)
                    cmb.Text = Drow(0).valn1
                Else
                    grid.SetData(e.Row, grid.Cols("커스텀").Index, "Y") '//해당값이 아에없는경우 변경된걸로 확인
                End If


                '//색및 패턴명 가져오기
                Dim Er As Boolean = False

                Dim Dr2() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select("gubun='1090' and code='" & 재료코드 & "'")
                If Dr2.GetUpperBound(0) = -1 Then
                    grid.SetData(e.Row, grid.Cols("전경색").Index, Color.Blue.ToArgb.ToString())
                    grid.SetData(e.Row, grid.Cols("후경색").Index, Color.White.ToArgb.ToString()) '//디비에 해당설ㅈㅇ이 없을경우 행하는 코드들
                    grid.SetData(e.Row, grid.Cols("구분").Index, "5")
                Else  '//디비에 있을경우
                    Try
                        grid.SetData(e.Row, grid.Cols("전경색").Index, Dr2(0)("name").ToString.Split(",")(0))
                    Catch ex As Exception
                        grid.SetData(e.Row, grid.Cols("전경색").Index, Color.Black.ToArgb.ToString())
                    End Try
                    Try
                        grid.SetData(e.Row, grid.Cols("후경색").Index, Dr2(0)("name").ToString.Split(",")(1))
                    Catch ex As Exception
                        grid.SetData(e.Row, grid.Cols("후경색").Index, Color.White.ToArgb.ToString())
                    End Try
                    grid.SetData(e.Row, grid.Cols("구분").Index, CInt(Dr2(0)("valn1")))
                End If

                '//이자료에 맞는 열전도율 값을 가져와서 콤보박스에 넣는다
                If Not MoveCellDown(grid, e.Col) Then MoveCellRight(grid)
            Case Else
                If Not MoveCellDown(grid, e.Col) Then MoveCellRight(grid)
        End Select

        fxData.FinishEditing()
        bs_detail.EndEdit()


        ' grid.AutoSizeCols()
        RefreshCellFormat()
        refresh_Image()
    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
    End Sub

    Private Sub RefreshCellFormat()

        For i As Integer = 1 To Me.fxData.Rows.Count - 1
            Dim obj_admin As Object = Me.fxData.GetData(i, Me.fxData.Cols("후경색").Index)
            Dim str_admin As String = String.Empty
            If Not obj_admin Is Nothing Then str_admin = obj_admin.ToString()
            If String.IsNullOrEmpty(str_admin) Then str_admin = System.Drawing.Color.White.ToArgb().ToString()

            Dim newstyle As C1.Win.C1FlexGrid.CellStyle = fxData.Styles.Add(Nothing)
            newstyle.BackColor = Color.FromArgb(Int32.Parse(str_admin))

            Dim obj_custom As Object = Me.fxData.GetData(i, Me.fxData.Cols("커스텀").Index)
            Dim str_custom As String = String.Empty
            If Not obj_custom Is Nothing Then str_custom = obj_custom.ToString()
            If String.IsNullOrEmpty(str_custom) Then str_custom = System.Drawing.Color.Black.ToArgb().ToString()

            If str_custom = "Y" Then
                newstyle.ForeColor = Color.Red
            Else
                newstyle.ForeColor = Color.Black
            End If

            fxData.Rows()(i).Style = newstyle
        Next
    End Sub

#End Region


    Private Sub Frm_V20091231_YK_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.bs.EndEdit()
        Me.bs_detail.EndEdit()

        For Each Drow As DS.tbl_myounRow In DSET1.tbl_myoun.Select("isnull(열관류율2,'') <> ''")
            Dim Dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Drow.열관류율2.ToString & "'")
            If Dr.Length < 1 Then Continue For '//대상자료가없는 경우 skip

            If Drow.열관류율2 = "0" OrElse Drow.열관류율2 = "" Then

            Else
                Select Case Dr(0).면형태
                    Case "외벽(직접)", "0"
                        Drow.건축부위방식 = "외벽"
                        Drow.열관류율 = Dr(0).열관류율
                    Case "지붕(직접)", "0001"
                        Drow.건축부위방식 = "외벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "수평"
                    Case "바닥(직접)", "0002"
                        Drow.건축부위방식 = "외벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "외벽(간접)", "0003"
                        Drow.건축부위방식 = "내벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "지붕(간접)", "0004"
                        Drow.건축부위방식 = "내벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "바닥(간접)", "0005"
                        Drow.건축부위방식 = "내벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "간벽", "0006"
                        Drow.건축부위방식 = "간벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "창(직접)", "0007"
                        Drow.건축부위방식 = "외부창"
                        Drow.열관류율 = Dr(0).창호열관류율
                        Drow.투과율 = Dr(0).일사에너지투과율
                    Case "창(간접)", "0008"
                        Drow.건축부위방식 = "내부창"
                        Drow.열관류율 = Dr(0).창호열관류율
                        Drow.투과율 = Dr(0).일사에너지투과율
                    Case "문(직접)", "0010"
                        Drow.건축부위방식 = "외부창"
                        Drow.열관류율 = Dr(0).창호열관류율
                        Drow.투과율 = Dr(0).일사에너지투과율
                    Case "문(간접)", "0011"
                        Drow.건축부위방식 = "내부창"
                        Drow.열관류율 = Dr(0).창호열관류율
                        Drow.투과율 = Dr(0).일사에너지투과율
                    Case "지중벽", "0009"
                        Drow.건축부위방식 = "내벽"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case "세대현관문(직접)", "0012"
                        Drow.건축부위방식 = "외부창"
                        Drow.열관류율 = Dr(0).창호열관류율
                        Drow.투과율 = Dr(0).일사에너지투과율
                    Case "세대현관문(간접)", "0013"
                        Drow.건축부위방식 = "내부창"
                        Drow.열관류율 = Dr(0).열관류율
                        Drow.방위 = "일사없음"
                    Case Else
                        MsgBox("모르는값 " & Dr("면형태").ToString & "/" & Dr(0).면형태)
                End Select

            End If

        Next

    End Sub
    Private Sub MdiMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: 이 코드는 데이터를 'DS.tbl_common' 테이블에 로드합니다. 필요한 경우 이 코드를 이동하거나 제거할 수 있습니다.
        ' MdiMain.Toggle_Menu_Color(MdiMain.E_MenuIdx.열관류율)
        'CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me)
        '//프로필 관련

        '//공유데이터셋에 연결한다.
        Me.bs.DataSource = DSET1
        Me.bs_detail.DataSource = DSET1
        Me.bs_gubun.DataSource = DSET1
        Me.bS_재료.DataSource = DSET1

        bS_재료.Filter = "gubun='1089'"
        bS_재료.Sort = "code"

        DT = DSET1.tbl_yk

        '//냉방분배
        AddHandler DSET1.tbl_yk.TableNewRow, AddressOf AddNewDataRow_bunbae
        AddHandler DSET1.tbl_ykdetail.TableNewRow, AddressOf AddNewDataRow_Weatherilsa

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

        '//콤보컨트롤 바인딩
        Binding_Zone()
        Me.bsmain = Me.bs

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

        refresh_Image()

        Me.init = True
        bs_detail_CurrentChanged(Nothing, Nothing)

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

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

        '//열너비
        ReadfGridColWidth(Me.Name, fxData)

        RefreshCellFormat()


    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
                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, "")
                    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, "")
                    Dr(Field) = CType(sender, MyCmb).SelectedValue
                Next
                Work_msg_timer("모든값이 변경되었습니다", 25)
            Catch ex As Exception

            End Try
        End If
    End Sub
#End Region

#Region "기본"
    Private Sub MdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me, Me.bsmain.Position, True)
    End Sub
    Private Function GetMaxCode(ByVal dt As DataTable) As String
        Dim Drow() As DataRow = dt.Select("", "code desc")
        If Drow.GetUpperBound(0) = -1 Then Return "0001"
        Return Format(CInt(Drow(0)("code")) + 1, "0000")
    End Function
    Private Sub Cmb_DeleteVal(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Delete Then
            CType(sender, ComboBox).SelectedValue = ""
        End If
    End Sub
    Private Sub AddNewDataRow_bunbae(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_yk)
        '  MsgBox("22")
    End Sub
    Private Sub AddNewDataRow_Weatherilsa(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)

        Dim NewCode As String
        Try
            Dim Dr As DataRow = DSET1.tbl_ykdetail.Select("pcode = '" & Me.pcode & "'", "code desc")(0)
            NewCode = Format(CInt(Dr("code")) + 1, "0000")
        Catch ex As Exception
            NewCode = ("0001")
        End Try

        Try
            e.Row.Item("pcode") = Me.pcode ' CType(bs.Current, DataRowView)("code")
            e.Row.Item("code") = NewCode
            'MsgBox(e.Row.Item("code").ToString)

        Catch ex As Exception
            MsgBox("부모코드없음 선택다시")
        End Try

    End Sub


    Private Sub Binding_Zone()

        Dim bs_형태 As New BindingSource(DSET1, "tbl_common_od")
        bs_형태.Filter = "gubun='1088'"
        bs_형태.Sort = "code"
        Me.cmb_형태.DataSource = bs_형태
        cmb_형태.DisplayMember = "name"
        cmb_형태.ValueMember = "code"
        Me.cmb_형태.DataBindings.Clear()
        Me.cmb_형태.DataBindings.Add("selectedvalue", Me.bs, "면형태")
        AddHandler cmb_형태.KeyDown, AddressOf Cmb_DeleteVal

        'tbl_common_od
        bS_재료.Filter = "gubun='1089'"
        bS_재료.Sort = "code"

        '//이 값은 고정된 값이므로 그대로 적용한다.
        Dim cmd_재료List As New ComboBox
        For Each dr As DS.tbl_common_odRow In DSET1.tbl_common_od.Select("gubun='1089'", "code")
            cmd_재료List.Items.Add(dr.name)
        Next
        AddHandler cmd_재료List.SelectionChangeCommitted, AddressOf Selected_열전도율값
        fxData.Cols("설명").Editor = cmd_재료List


        Dim cmd_열전도율List As New ComboBox
        AddHandler cmd_열전도율List.SelectionChangeCommitted, AddressOf Selected_열전도율값
        fxData.Cols("열전도율").Editor = cmd_열전도율List


        bs_gubun.Filter = "gubun='1090'"
        bs_gubun.Sort = "code"

    End Sub

    Sub Selected_열전도율값(sender As Object, e As System.EventArgs)
        '//콤보박스를 선택했다면 입력을 완료한 것으로 간주한다.
        Me.Validate()
        bs_detail.EndEdit()

        'fxData.FinishEditing()
    End Sub
    Private Sub Frm_V20091231_Zone_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
        If e.Delta < 0 Then
            If Me.bs.Position < Me.bs.Count Then Me.bs.Position += 1
        Else
            If Me.bs.Position > 0 Then Me.bs.Position -= 1
        End If
        Me.Validate()
        My.Application.DoEvents()
    End Sub
#End Region

    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_yk.Select(Me.bs.Filter, "")
                For i As Integer = dR.GetUpperBound(0) To 0 Step -1
                    dR(i).Delete()
                Next
                DSET1.tbl_yk.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.Right 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)
                    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.Filter = ""
                'MsgBox("2. " & ex.Message.ToString)
            End Try
        End If


    End Sub

    Private Sub dv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles fxList.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.


        Select Case e.KeyCode
            Case Keys.D
                If e.Alt Then
                    'Dbbase.DelCrow(Me.bs, False)
                    Del_YKdetail(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
                    Func_Add()  '//신규추가
                    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

                    '//하위데이터복제
                    Dim src_pcode As String = SrcDrv("code").ToString
                    Dim new_pcode As String = NewDrv("code").ToString


                    For Each Drow2 As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("pcode='" & src_pcode & "'")
                        Dim Newrow As DS.tbl_ykdetailRow = DSET1.tbl_ykdetail.Newtbl_ykdetailRow
                        For Each C As DataColumn In DSET1.tbl_ykdetail.Columns
                            Newrow(C.ColumnName) = Drow2(C.ColumnName)
                        Next
                        Newrow.pcode = new_pcode
                        DSET1.tbl_ykdetail.Addtbl_ykdetailRow(Newrow)
                    Next

                    Me.bs.EndEdit()
                    Me.bs_detail.EndEdit()
                    Me.refresh_Image()

                    bs.MoveLast()
                End If
        End Select

    End Sub
    Private Sub Del_YKdetail(ByVal prompt As Boolean)
        If prompt Then
            If MsgBox("선택된 줄을 삭제하시겠습니까?", MsgBoxStyle.OkCancel Or MsgBoxStyle.Information, "삭제확인") <> MsgBoxResult.Ok Then Return
        End If
        Dim Drv As DataRowView = CType(bs.Current, DataRowView)
        If Drv Is Nothing Then Return
        Dim DR() As DataRow = DSET1.tbl_ykdetail.Select("code <> '0' and code='" & Drv("code").ToString & "'")
        If DR.GetUpperBound(0) <> -1 Then
            For i As Integer = DR.GetUpperBound(0) To 0 Step -1
                DR(i).Delete()
            Next
        End If
        Me.bs.RemoveCurrent()

    End Sub
    Private Sub bs_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.CurrentChanged
        Try
            pcode = CType(bs.Current, DataRowView)("code").ToString
            Me.bs_detail.Filter = "pcode='" & pcode & "'"

            Me.DS.tbl_ykdetail.AcceptChanges()
            Me.refresh_Image()

            RefreshCellFormat()
            fxData.AutoSizeCols()
        Catch ex As Exception
            'MsgBox("3. " & ex.Message.ToString)
        End Try
        Me.bs.EndEdit()
    End Sub

    Private Sub refresh_Image()
        ' MsgBox(Me.UserControl11.Vertical)

        Dim width As Decimal = 0   '//뭘고치던 여기 함수가 실행되므로 이곳에서 뭔가 작업하시는게 좋을것 같구요..어떤것을들 더하시려구요?
        Dim R_value As Decimal = 0

        For Each Dr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select(Me.bs_detail.Filter, "")    '//세부내역중 두께를 합치는 루틴입니다.
            'Try
            If Dr.설명 = "공기층" Then
                Dr.열전도율 = ""
                If TOSG(T, Dr.두께) > 10.0 Then
                    Dr.열저항 = TOST(0.086)
                    R_value += 0.086
                Else
                    Dr.열저항 = TOST(TOSG(T, Dr.두께) * 0.0086)
                    R_value = R_value + TOSG(T, Dr.두께) * 0.0086
                End If
            Else  '//여기아래 추가하신거에요?

                If Dr.설명.IndexOf("열전달저항") <> -1 Then
                    Dr.두께 = ""
                    Dr.열전도율 = ""
                    Select Case Dr.설명
                        Case "실내열전달저항(벽체)"
                            Dr.열저항 = TOST(0.11)
                            R_value += 0.11
                        Case "실외열전달저항(벽체,간접)"
                            Dr.열저항 = TOST(0.11)
                            R_value += 0.11
                        Case "실외열전달저항(벽체,직접)"
                            Dr.열저항 = TOST(0.043)
                            R_value += 0.043
                        Case "실내열전달저항(바닥)"
                            Dr.열저항 = TOST(0.086)
                            R_value += 0.086
                        Case "실외열전달저항(바닥,간접)"
                            Dr.열저항 = TOST(0.15)
                            R_value += 0.15
                        Case "실외열전달저항(바닥,직접)"
                            Dr.열저항 = TOST(0.043)
                            R_value += 0.043
                        Case "실내열전달저항(지붕)"
                            Dr.열저항 = TOST(0.086)
                            R_value += 0.086
                        Case "실외열전달저항(지붕,간접)"
                            Dr.열저항 = TOST(0.086)
                            R_value += 0.086
                        Case "실외열전달저항(지붕,직접)"
                            Dr.열저항 = TOST(0.043)
                            R_value += 0.043

                    End Select

                Else
                    If Dr.열전도율 <> "" AndAlso TOSG(T, Dr.열전도율) <> 0 Then
                        Dr.열저항 = TOSG(T, Math.Round(TOSG(T, Dr.두께) / 1000 / TOSG(T, Dr.열전도율), 4)).ToString
                        R_value += TOSG(T, Dr.열저항)  '//여부분에서는 나올수잇겟군요.?예
                    End If

                End If

            End If


            If Dr.설명.IndexOf("열전달저항") = -1 Then
                width += TOSG(T, Dr.두께)
            End If
        Next


        Try
            If cmb_형태.Text = "창(직접)" OrElse cmb_형태.Text = "창(간접)" OrElse cmb_형태.Text.StartsWith("문") OrElse cmb_형태.Text.StartsWith("세대현관문") Then
                'Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text

                If Me.chk_발코니여부.Checked Then
                    Me.tb_투과율.Text = Math.Round(TOSG(tb_발코니투과율.Text) * TOSG(NTb_일사에너지투과율.Text), 3)
                    Me.열관류율NTb.Text = Math.Round((1 / ((1 / TOSG(Me.NTb_창호열관류율.Text)) + (1 / TOSG(Me.tb_발코니열관류율.Text)) * 0.5)), 3)
                Else
                    Me.tb_투과율.Text = NTb_일사에너지투과율.Text
                    Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text
                End If

            Else
                Me.열관류율NTb.Text = CSng(Math.Round(1 / R_value, 3)).ToString
                Me.tb_투과율.Text = ""
            End If
            Check열관류율()
        Catch ex As Exception
            Me.열관류율NTb.Text = ""
            Me.tb_투과율.Text = ""
            'MsgBox("4. " & ex.Message.ToString)
        End Try

        'Try

        '    If cmb_형태.Text = "창(직접)" OrElse cmb_형태.Text = "창(간접)" Then
        '        If Me.chk_발코니여부.Checked Then
        '            Me.tb_투과율.Text = Math.Round(TOSG(tb_발코니투과율.Text) * TOSG(NTb_일사에너지투과율.Text), 3)
        '            Me.열관류율NTb.Text = Math.Round((1 / ((1 / TOSG(Me.NTb_창호열관류율.Text)) + (1 / TOSG(Me.tb_발코니열관류율.Text)) * 0.5)), 3)
        '        Else
        '            Me.tb_투과율.Text = NTb_일사에너지투과율.Text
        '            Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text
        '        End If
        '    Else
        '        Me.열관류율NTb.Text = CSng(Math.Round(1 / R_value, 3)).ToString
        '        Me.tb_투과율.Text = ""
        '    End If
        'Catch ex As Exception
        '    Me.열관류율NTb.Text = ""
        '    Me.tb_투과율.Text = ""
        'End Try



        '  Me.MyTb1.Text = width.ToString("N2")
        Me.UserControl11.MaxSize = width
        'MsgBox(width)

        ' Me.Label1.Text = Me.UserControl11.Width

        '//  0.51 : me.wid = x : ?

        '  Me.UserControl11.Vertical = True
        Dim FT(Me.fxData.Rows.Count - 1) As mn.UserControl1.SM
        For i As Integer = 1 To Me.fxData.Rows.Count - 1
            '//아까 열표시해서 검정색 선택해보니 검정은 값이 0 이 나오더라구요

            Dim o후경색 As Object = fxData.GetData(i, fxData.Cols("후경색").Index)
            Dim o구분 As Object = fxData.GetData(i, fxData.Cols("구분").Index)
            Dim o두께 As Object = fxData.GetData(i, fxData.Cols("두께").Index)

            Dim 후경색 As String = ""
            Dim 두께 As String = ""
            Dim 구분 As String = ""
            If Not o후경색 Is Nothing Then 후경색 = o후경색.ToString()
            If Not o구분 Is Nothing Then 구분 = o구분.ToString()
            If Not o두께 Is Nothing Then 두께 = o두께.ToString()

            Try
                FT(i).BColor = Color.FromArgb(후경색)
            Catch ex As Exception
                FT(i).BColor = Color.FromName("white")
            End Try

            Try
                FT(i).Style = Val(구분)
            Catch ex As Exception
                FT(i).Style = Drawing2D.HatchStyle.Cross
            End Try

            Try
                If 두께 <> "" Then
                    FT(i).Width = 두께
                End If
            Catch ex As Exception
                'MsgBox("8. " & ex.Message.ToString)
            End Try
        Next
        Me.UserControl11.M1FillType = FT
    End Sub

    Sub 법적기준확인()

        '//법적기준 확인  170601
        Dim drDesc As DS.tbl_DescRow = DSET1.tbl_Desc.Rows(0)
        Dim areaCode As String = drDesc.buildarea
        Dim drWGs() As DS.weather_groupRow = DSET1.weather_group.Select("code = '" + areaCode + "'")
        If drWGs.Length = 1 Then
            Dim drWG As DS.weather_groupRow = drWGs(0)
            Dim Area As String

            If Program = EProgram.총량평가 Then
                Area = drWG.area2
                Select Case Area
                    Case "중부1"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.170"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.150"
                            Case "바닥(직접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.150"
                                Else
                                    tb법적기준.Text = "0.170"
                                End If
                            Case "창(직접)"
                                tb법적기준.Text = "1.300"
                            Case "창(간접)"
                                tb법적기준.Text = "1.600"
                            Case "문(직접)"
                                tb법적기준.Text = "1.500"
                            Case "문(간접)"
                                tb법적기준.Text = "1.900"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.240"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.210"
                            Case "바닥(간접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.210"
                                Else
                                    tb법적기준.Text = "0.240"
                                End If

                            Case "지중벽"
                                tb법적기준.Text = "0.240"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.800"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "중부2"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.240"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.150"
                            Case "바닥(직접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.170"
                                Else
                                    tb법적기준.Text = "0.200"
                                End If
                            Case "창(직접)"
                                tb법적기준.Text = "1.500"
                            Case "창(간접)"
                                tb법적기준.Text = "1.900"
                            Case "문(직접)"
                                tb법적기준.Text = "1.500"
                            Case "문(간접)"
                                tb법적기준.Text = "1.900"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.340"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.210"
                            Case "바닥(간접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.240"
                                Else
                                    tb법적기준.Text = "0.290"
                                End If

                            Case "지중벽"
                                tb법적기준.Text = "0.340"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.800"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "남부"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.320"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.180"
                            Case "바닥(직접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.220"
                                Else
                                    tb법적기준.Text = "0.250"
                                End If
                            Case "창(직접)"
                                tb법적기준.Text = "1.800"
                            Case "창(간접)"
                                tb법적기준.Text = "2.200"
                            Case "문(직접)"
                                tb법적기준.Text = "1.800"
                            Case "문(간접)"
                                tb법적기준.Text = "2.200"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.450"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.260"
                            Case "바닥(간접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.310"
                                Else
                                    tb법적기준.Text = "0.350"
                                End If

                            Case "지중벽"
                                tb법적기준.Text = "0.450"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.800"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "제주"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.410"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.250"
                            Case "바닥(직접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.290"
                                Else
                                    tb법적기준.Text = "0.330"
                                End If
                            Case "창(직접)"
                                tb법적기준.Text = "2.200"
                            Case "창(간접)"
                                tb법적기준.Text = "2.800"
                            Case "문(직접)"
                                tb법적기준.Text = "2.200"
                            Case "문(간접)"
                                tb법적기준.Text = "2.800"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.560"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.350"
                            Case "바닥(간접)"
                                If 체크바닥난방여부.Checked Then
                                    tb법적기준.Text = "0.410"
                                Else
                                    tb법적기준.Text = "0.470"
                                End If

                            Case "지중벽"
                                tb법적기준.Text = "0.560"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.800"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case Else
                        '//지정안된경우
                        tb법적기준.Text = "--"
                End Select

            Else
                '//친환경
                Area = drWG.area3 'Area = drWG.area2  2018년 12월 친환경주택 지역 통일화 필요

                Select Case Area
                    Case "중부1"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.150"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.150"
                            Case "바닥(직접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.150"
                                'Else
                                'tb법적기준.Text = "0.170"
                                'End If
                            Case "창(직접)"
                                tb법적기준.Text = "0.900"
                            Case "창(간접)"
                                tb법적기준.Text = "1.200"
                            Case "문(직접)"
                                tb법적기준.Text = "0.900"
                            Case "문(간접)"
                                tb법적기준.Text = "1.200"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.210"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.210"
                            Case "바닥(간접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.210"
                                'Else
                                '    tb법적기준.Text = "0.240"
                                'End If

                            Case "지중벽"
                                tb법적기준.Text = "0.210"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.600"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "중부2"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.170"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.150"
                            Case "바닥(직접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.170"
                                'Else
                                '    tb법적기준.Text = "0.200"
                                'End If
                            Case "창(직접)"
                                tb법적기준.Text = "0.900"
                            Case "창(간접)"
                                tb법적기준.Text = "1.500"
                            Case "문(직접)"
                                tb법적기준.Text = "0.900"
                            Case "문(간접)"
                                tb법적기준.Text = "1.500"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.240"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.210"
                            Case "바닥(간접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.240"
                                'Else
                                '    tb법적기준.Text = "0.290"
                                'End If

                            Case "지중벽"
                                tb법적기준.Text = "0.240"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.600"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "남부"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.220"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.180"
                            Case "바닥(직접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.220"
                                'Else
                                '    tb법적기준.Text = "0.250"
                                'End If
                            Case "창(직접)"
                                tb법적기준.Text = "1.000"
                            Case "창(간접)"
                                tb법적기준.Text = "1.700"
                            Case "문(직접)"
                                tb법적기준.Text = "1.000"
                            Case "문(간접)"
                                tb법적기준.Text = "1.700"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.310"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.260"
                            Case "바닥(간접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.310"
                                'Else
                                '    tb법적기준.Text = "0.350"
                                'End If

                            Case "지중벽"
                                tb법적기준.Text = "0.310"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.600"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case "제주"
                        Select Case cmb_형태.Text
                            Case "외벽(직접)"
                                tb법적기준.Text = "0.290"
                            Case "지붕(직접)"
                                tb법적기준.Text = "0.250"
                            Case "바닥(직접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.290"
                                'Else
                                '    tb법적기준.Text = "0.330"
                                'End If
                            Case "창(직접)"
                                tb법적기준.Text = "1.500"
                            Case "창(간접)"
                                tb법적기준.Text = "1.700"
                            Case "문(직접)"
                                tb법적기준.Text = "1.500"
                            Case "문(간접)"
                                tb법적기준.Text = "1.700"
                            Case "외벽(간접)"
                                tb법적기준.Text = "0.410"
                            Case "지붕(간접)"
                                tb법적기준.Text = "0.350"
                            Case "바닥(간접)"
                                'If 체크바닥난방여부.Checked Then
                                tb법적기준.Text = "0.410"
                                'Else
                                '    tb법적기준.Text = "0.470"
                                'End If

                            Case "지중벽"
                                tb법적기준.Text = "0.410"
                            Case "세대현관문(직접)"
                                tb법적기준.Text = "1.400"
                            Case "세대현관문(간접)"
                                tb법적기준.Text = "1.600"
                            Case Else
                                tb법적기준.Text = "--"
                        End Select
                    Case Else
                        '//지정안된경우
                        tb법적기준.Text = "--"
                End Select





























                'Select Case Area
                '    Case "중부1"
                '        Select Case cmb_형태.Text
                '            Case "외벽(직접)"
                '                tb법적기준.Text = "0.15"
                '            Case "지붕(직접)"
                '                tb법적기준.Text = "0.15"
                '            Case "바닥(직접)"
                '                tb법적기준.Text = "0.15"
                '            Case "창(직접)"
                '                tb법적기준.Text = "0.90"
                '            Case "창(간접)"
                '                tb법적기준.Text = "1.30"
                '            Case "문(직접)"
                '                tb법적기준.Text = "1.40"
                '            Case "문(간접)"
                '                tb법적기준.Text = "1.80"
                '            Case "외벽(간접)"
                '                tb법적기준.Text = "0.21"
                '            Case "지붕(간접)"
                '                tb법적기준.Text = "0.21"
                '            Case "바닥(간접)"
                '                tb법적기준.Text = "0.21"
                '            Case "지중벽"
                '                tb법적기준.Text = "0.21"
                '        End Select
                '    Case "중부2"
                '        Select Case cmb_형태.Text
                '            Case "외벽(직접)"
                '                tb법적기준.Text = "0.17"
                '            Case "지붕(직접)"
                '                tb법적기준.Text = "0.15"
                '            Case "바닥(직접)"
                '                tb법적기준.Text = "0.17"
                '            Case "창(직접)"
                '                tb법적기준.Text = "1.00"
                '            Case "창(간접)"
                '                tb법적기준.Text = "1.50"
                '            Case "문(직접)"
                '                tb법적기준.Text = "1.40"
                '            Case "문(간접)"
                '                tb법적기준.Text = "1.80"
                '            Case "외벽(간접)"
                '                tb법적기준.Text = "0.24"
                '            Case "지붕(간접)"
                '                tb법적기준.Text = "0.21"
                '            Case "바닥(간접)"
                '                tb법적기준.Text = "0.24"
                '            Case "지중벽"
                '                tb법적기준.Text = "0.24"
                '        End Select
                '    Case "남부"
                '        Select Case cmb_형태.Text
                '            Case "외벽(직접)"
                '                tb법적기준.Text = "0.22"
                '            Case "지붕(직접)"
                '                tb법적기준.Text = "0.18"
                '            Case "바닥(직접)"
                '                tb법적기준.Text = "0.22"
                '            Case "창(직접)"
                '                tb법적기준.Text = "1.20"
                '            Case "창(간접)"
                '                tb법적기준.Text = "1.70"
                '            Case "문(직접)"
                '                tb법적기준.Text = "1.40"
                '            Case "문(간접)"
                '                tb법적기준.Text = "1.80"
                '            Case "외벽(간접)"
                '                tb법적기준.Text = "0.31"
                '            Case "지붕(간접)"
                '                tb법적기준.Text = "0.26"
                '            Case "바닥(간접)"
                '                tb법적기준.Text = "0.31"
                '            Case "지중벽"
                '                tb법적기준.Text = "0.31"
                '        End Select
                '    Case "제주"
                '        Select Case cmb_형태.Text
                '            Case "외벽(직접)"
                '                tb법적기준.Text = "0.29"
                '            Case "지붕(직접)"
                '                tb법적기준.Text = "0.25"
                '            Case "바닥(직접)"
                '                tb법적기준.Text = "0.29"
                '            Case "창(직접)"
                '                tb법적기준.Text = "1.60"
                '            Case "창(간접)"
                '                tb법적기준.Text = "2.00"
                '            Case "문(직접)"
                '                tb법적기준.Text = "1.40"
                '            Case "문(간접)"
                '                tb법적기준.Text = "1.80"
                '            Case "외벽(간접)"
                '                tb법적기준.Text = "0.41"
                '            Case "지붕(간접)"
                '                tb법적기준.Text = "0.35"
                '            Case "바닥(간접)"
                '                tb법적기준.Text = "0.41"
                '            Case "지중벽"
                '                tb법적기준.Text = "0.41"
                '        End Select
                '    Case Else
                '        '//지정안된경우
                '        tb법적기준.Text = "--"
                'End Select

            End If


        Else
            '//지역코드가 연결되지 않은경우
            tb법적기준.Text = "--"
        End If

        UpdateColor()


    End Sub

    Sub UpdateColor()
        '열관류율NTb,tb법적기준
        NTb_창호열관류율.BackColor = Color.WhiteSmoke
        열관류율NTb.BackColor = Color.WhiteSmoke

        If cmb_형태.Text = "창(간접)" Then
            If IsNumeric(tb법적기준.Text) AndAlso IsNumeric(NTb_창호열관류율.Text) Then
                Dim S1 As Single = TOSG(tb법적기준.Text)

                Dim S2 As Single = TOSG(NTb_창호열관류율.Text)
                If S2 > S1 Then
                    NTb_창호열관류율.BackColor = Color.HotPink
                    Label2.Text = "법적기준(부적합)"
                    Label2.ForeColor = Color.Red
                    Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Bold)
                Else
                    NTb_창호열관류율.BackColor = Color.WhiteSmoke
                    Label2.Text = "법적기준"
                    Label2.ForeColor = Color.Black
                    Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Regular)
                End If
            Else
                NTb_창호열관류율.BackColor = Color.WhiteSmoke
                Label2.Text = "법적기준"
                Label2.ForeColor = Color.Black
                Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Regular)
            End If
        Else
            If IsNumeric(tb법적기준.Text) AndAlso IsNumeric(열관류율NTb.Text) Then
                Dim S1 As Single = TOSG(tb법적기준.Text)

                Dim S2 As Single = TOSG(열관류율NTb.Text)
                If S2 > S1 Then
                    열관류율NTb.BackColor = Color.HotPink
                    Label2.Text = "법적기준(부적합)"
                    Label2.ForeColor = Color.Red
                    Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Bold)
                Else
                    열관류율NTb.BackColor = Color.WhiteSmoke
                    Label2.Text = "법적기준"
                    Label2.ForeColor = Color.Black
                    Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Regular)
                End If
            Else
                열관류율NTb.BackColor = Color.WhiteSmoke
                Label2.Text = "법적기준"
                Label2.ForeColor = Color.Black
                Label2.Font = New Font("맑은 고딕", 9.75, FontStyle.Regular)
            End If
        End If
   
    End Sub
    Private Sub cmb_형태_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_형태.SelectedIndexChanged
        If cmb_형태.Text = "지붕(직접)" OrElse cmb_형태.Text = "바닥(직접)" OrElse cmb_형태.Text = "지붕(간접)" OrElse cmb_형태.Text = "바닥(간접)" Then
            Me.UserControl11.Vertical = False
        Else
            Me.UserControl11.Vertical = True
        End If

        If cmb_형태.Text.IndexOf("직접") <> -1 Then
            체크열교방지구조.Enabled = True
        Else
            체크열교방지구조.Enabled = False
        End If

        If cmb_형태.Text.StartsWith("바닥") Then
            체크바닥난방여부.Enabled = True
            체크바닥난방여부.ForeColor = Color.Black
        Else
            체크바닥난방여부.Enabled = False
            체크바닥난방여부.ForeColor = Color.LightGray
        End If
        체크바닥난방여부.Refresh()
        '//형태가 바뀌었으므로 그림을 다시 그려준다.
        Me.refresh_Image()

        법적기준확인()

        '//컨트롤 Enable
        If cmb_형태.Text.StartsWith("창") OrElse cmb_형태.Text.StartsWith("문") OrElse cmb_형태.Text.StartsWith("세대현관문") Then
            Me.NTb_창호열관류율.Visible = True
            Me.NTb_일사에너지투과율.Visible = True
            Me.NTb_창호세부설명.Visible = True
            Me.lbl_창호열관류율.ForeColor = Color.Black
            Me.lbl_일사에너지투과율.ForeColor = Color.Black
            Me.lbl_창호세부설명.ForeColor = Color.Black

            Me.chk_발코니여부.ForeColor = Color.Black
            Application.DoEvents()
            Me.chk_발코니여부.Refresh()
            Application.DoEvents()
            Me.chk_발코니여부.Enabled = True
            Me.tb_투과율.Enabled = True
            Me.Label5.Enabled = True
            Me.tb_발코니투과율.Visible = True
            Me.tb_발코니열관류율.Visible = True
            Me.Label3.ForeColor = Color.Black
            Me.Label4.ForeColor = Color.Black
            Me.Label5.ForeColor = Color.Black
            ' 체크바닥난방여부.ForeColor = Color.Black
        Else
            Me.NTb_창호열관류율.Visible = False
            Me.NTb_일사에너지투과율.Visible = False
            Me.NTb_창호세부설명.Visible = False
            Me.lbl_창호열관류율.ForeColor = Color.LightGray
            Me.lbl_일사에너지투과율.ForeColor = Color.LightGray
            Me.lbl_창호세부설명.ForeColor = Color.LightGray
            Me.chk_발코니여부.Refresh()
            '체크바닥난방여부.ForeColor = Color.LightGray
            Application.DoEvents()
            Me.chk_발코니여부.Enabled = False
            Me.chk_발코니여부.Refresh()
            Me.Label3.ForeColor = Color.LightGray
            Me.Label4.ForeColor = Color.LightGray
            Me.Label5.ForeColor = Color.LightGray
            Me.tb_투과율.Enabled = False
            'Me.Label5.Enabled = False
            Me.tb_발코니투과율.Visible = False
            Me.tb_발코니열관류율.Visible = False

        End If


    End Sub

    Private Sub NTb_창호열관류율_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NTb_창호열관류율.TextChanged
        If Not init Then Return
        If cmb_형태.Text.StartsWith("창") OrElse cmb_형태.Text.StartsWith("문") OrElse cmb_형태.Text.StartsWith("세대현관문") Then
            Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text
            Check열관류율()
        End If
    End Sub

    Private Sub Check열관류율()
        '//MyTb1 에 지역그룹내의 area2 필드값을 참고하여 값을쓰고 그 값을 비교함

    End Sub


    Private Sub bs_detail_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs_detail.CurrentChanged
        If Not init OrElse Me.bs_detail.Position < 0 Then Return

        '//선
        Dim Drv As DataRowView = CType(Me.bs_detail.Current, DataRowView)
        If Drv Is Nothing Then Return '//선택된아이템이없으면 빠져나감
        Dim dr As DS.tbl_ykdetailRow = Drv.Row


        '//열전도율목록을 갱신
        Dim cmb열전도율 As ComboBox = fxData.Cols("열전도율").Editor
        cmb열전도율.Items.Clear()
        Dim Fil As String = "gubun='1089' and name='" & dr.설명 & "'"
        Dim Drow() As DS.tbl_common_odRow = DSET1.tbl_common_od.Select(Fil)
        If Drow.GetUpperBound(0) = 0 Then
            cmb열전도율.Items.Add(Drow(0).valn1)
        End If


    End Sub

    Public Overrides Function AcceptChanged() As Boolean
        fxList.FinishEditing()

        bs_detail.EndEdit()
        bs.EndEdit()

        DSET1.tbl_yk.AcceptChanges()
        DSET1.tbl_ykdetail.AcceptChanges()

        Return MyBase.AcceptChanged()
    End Function

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

    Sub Func_Add()
        If Not EndEdit(Me.bs) Then Return
        Me.bs.AddNew()
        Me.bs.EndEdit()
        INitRow(Me.Controls)
    End Sub
    Private Sub RibbonButton2_Click(sender As Object, e As EventArgs) Handles btAdd1.Click
        Func_Add()

        '  Dim cnt As Integer = DSET1.tbl_ykdetail.Rows.Count

    End Sub

    Private Sub RibbonButton3_Click(sender As Object, e As EventArgs) Handles btDel1.Click
        Dbbase.DelCrow(Me.bs, True)
        If bs.Count = 0 Then
            DSET1.tbl_ykdetail.Clear()
        End If
    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 RibbonButton6_Click(sender As Object, e As EventArgs) Handles RibbonButton6.Click
        Dim Drv As DataRowView = Me.bs_detail.Current
        Dim 전경 As String = String.Empty
        Try
            전경 = Drv("전경색").ToString
        Catch ex As Exception
        End Try
        Dim 후경 As String = String.Empty
        Try
            후경 = Drv("후경색").ToString
        Catch ex As Exception
        End Try
        Dim A As New Frm_DisplayGubun(전경, 후경)
        A.Show()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs)
        RefreshCellFormat()
    End Sub

    Private Sub RibbonButton1_Click_1(sender As Object, e As EventArgs) Handles RibbonButton1.Click
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return

        Me.bs_detail.AddNew()
        Me.bs_detail.EndEdit()
        refresh_Image()
    End Sub

    Private Sub RibbonButon2_Click_1(sender As Object, e As EventArgs) Handles RibbonButton2.Click

        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return

        If Me.bs_detail.Count > 0 Then
            Me.bs_detail.RemoveCurrent()
            Me.bs_detail.EndEdit()
        End If
    End Sub

    Private Sub 열너비저장ToolStripMenuItem_Click(sender As System.Object, e As System.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 System.Object, e As System.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 System.Object, e As System.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 체크바닥난방여부_Click(sender As System.Object, e As System.EventArgs) Handles 체크열교방지구조.Click, 체크바닥난방여부.Click
        법적기준확인()
    End Sub

    Private Sub 열관류율NTb_TextChanged(sender As System.Object, e As System.EventArgs) Handles 열관류율NTb.TextChanged
        UpdateColor()
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chk_발코니여부.CheckedChanged
        refresh_Image()

        Me.tb_발코니열관류율.Enabled = chk_발코니여부.Checked
        Me.tb_발코니투과율.Enabled = chk_발코니여부.Checked
        'Me.Label2.Enabled = chk_발코니여부.Checked
        'Me.Label3.Enabled = chk_발코니여부.Checked
    End Sub

    Private Sub tb_발코니열관류율_TextChanged(sender As System.Object, e As System.EventArgs) Handles tb_발코니열관류율.TextChanged, tb_발코니투과율.TextChanged
        refresh_Image()
    End Sub

    Private Sub chk_발코니여부_EnabledChanged(sender As System.Object, e As System.EventArgs) Handles chk_발코니여부.EnabledChanged
        refresh_Image()
        If chk_발코니여부.Enabled = False Then
            Me.tb_발코니열관류율.Enabled = chk_발코니여부.Enabled
            Me.tb_발코니투과율.Enabled = chk_발코니여부.Enabled
            'Me.Label2.Enabled = chk_발코니여부.Enabled
            'Me.Label3.Enabled = chk_발코니여부.Enabled
        Else
            CheckBox1_CheckedChanged(sender, e)
        End If
    End Sub
End Class
