Public Class Frm_YK

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

#Region "data Base 변경여부및 적용방법"

    '''변경된내용을적용한다.
    Public Overrides Function AcceptChanged() As Boolean
        bs.EndEdit()
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        BaseDT.AcceptChanges()
        Return True
    End Function

    '''변경된내용이있다면 취소한다.
    Public Overrides Function RejectChanged() As Boolean
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        BaseDT.RejectChanges()
        Return True
    End Function

    '''데이터에변형이있었는가?
    Public Overrides Function HasChanged() As Boolean
        bs.EndEdit()
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        Dim ChangeDT As DataTable = BaseDT.GetChanges
        If Not ChangeDT Is Nothing Then Return True
        Return False
    End Function

    '''기본데이터테이블을 반환합니다.
    Public Function DT() As DataTable
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Return BaseDS.Tables(bs.DataMember)
    End Function


#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 DSET.tbl_myoun
            Dim Dr As DS.tbl_ykRow = DSET.tbl_yk.Select("code='" & Drow.열관류율2.ToString & "'")(0)
            Drow.건축부위방식 = Dr.면형태    '// 링크된 열관류율에서 면형태를 가져옴..
            Select Case Dr.면형태
                Case "외벽(벽체)", "0"
                    Drow.건축부위방식 = "외벽"
                Case "외벽(지붕)", "0001"
                    Drow.건축부위방식 = "외벽"
                    'Drow.방위 = "수평"
                Case "외벽(바닥)", "0002"
                    Drow.건축부위방식 = "외벽"
                    'Drow.방위 = "일사없음"
                Case "내벽(벽체)", "0003"
                    Drow.건축부위방식 = "내벽"
                    Drow.방위 = "일사없음"
                Case "내벽(지붕)", "0004"
                    Drow.건축부위방식 = "내벽"
                    Drow.방위 = "일사없음"
                Case "내벽(바닥)", "0005"
                    Drow.건축부위방식 = "내벽"
                    Drow.방위 = "일사없음"
                Case "간벽", "0006"
                    Drow.건축부위방식 = "간벽"
                    Drow.방위 = "일사없음"
                Case "외부창", "0007"
                    Drow.건축부위방식 = "외부창"
                    Drow.투과율 = Dr.일사에너지투과율
                Case "내부창", "0008"
                    Drow.건축부위방식 = "내부창"
                    Drow.투과율 = Dr.일사에너지투과율
                Case Else
                    MsgBox("모르는값 " & Dr("면형태").ToString & "/" & Dr.면형태)
            End Select



            'Drow.열관류율2 = Dr.code

            'MsgBox(Drow.열관류율2)
            'MsgBox(Drow.열관류율)

            'End
        Next

        'MsgBox("close")
    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 = DSET
        Me.bs_detail.DataSource = DSET
        Me.bs_gubun.DataSource = DSET
        Me.bS_재료.DataSource = DSET

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

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

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

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


        Me.bs.Filter = "code <> '0' and 면형태 = '" + Me.Parameter + "'"
        Me.lb_grpname.Text = Get_CName("1088", Me.Parameter)

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

        refresh_Image()
        Me.init = True

        'Try '//열전도갱신

        Me.cmb_열전도율.Items.Clear()
        Dim 재료명 As String = ""
        If Me.bs_detail.Count > 0 Then  '//현재선택된 개체의 열전도율을 가져온다.
            Dim Drv As DataRowView = Me.bs_detail.Current
            재료명 = Drv("설명").ToString
        Else
            If Me.cmb_재료.Items.Count > 0 AndAlso Me.cmb_재료.SelectedIndex >= 0 Then 재료명 = CType(Me.cmb_재료.Items(Me.cmb_재료.SelectedIndex), DataRowView)("name").ToString
        End If
        Dim Filter = "gubun='1089' and name='" & 재료명 & "'"
        Dim Drow() As DS.tbl_commonRow = DSET.tbl_common.Select(Filter)
        Try
            If Drow.GetUpperBound(0) <> -1 Then Me.cmb_열전도율.Items.Add(Drow(0).valn1)
        Catch ex As Exception

        End Try



        'Me.cmb_열전도율.Items.Clear()
        'Dim Fil As String = "gubun='1089' and name='" & Me.cmb_재료.Text & "'"
        'Try
        '    If Me.cmb_재료.Text <> "" Then
        '        Dim Dr As DS.tbl_commonRow = DSET.tbl_common.Select(Fil)(0)
        '        'Dim Dr As DS.tbl_commonRow = DSET.tbl_common.Select("gubun='1089' and name='" & Me.cmb_재료.Text & "'")(0)
        '        If Me.cmb_재료.Text.IndexOf("공기층") = -1 Then
        '            Me.cmb_열전도율.Items.Add(Dr.valn1)
        '        End If
        '    End If
        'Catch ex As Exception
        '    'MsgBox("1. " & ex.Message.ToString)
        'End Try




    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.bs.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" '//데이터가 없을경위 최소 0001으로 반환 2011-05-06(a)

        '//데이터가있을경우 해당 데이터+1로 반환
        Return Format(CInt(Drow(0)("code")) + 1, "0000")

        'Try
        '    Dim Dr As DataRow = dt.Select("", "code desc")(0)
        '    Dim Dr_ykdetail As DataRow = dt_ykdetail.Select("", "code desc")(0)
        '    If Dr("code") >= Dr_ykdetail("code") Then

        '    Else
        '        Return Format(CInt(Dr_ykdetail("code")) + 1, "0000")
        '    End If

        'Catch ex As Exception
        '    MsgBox(ex.Message.ToString)
        '    Return "0001"
        'End Try
    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(DSET.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 = DSET.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 bt_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_add.Click
        If Not EndEdit(Me.bs) Then Return
        Me.bs.AddNew()
        Me.bs.EndEdit()
        INitRow(Me.Controls)
        'ToolStripButton1.PerformClick() '//2011.04.20 열관류율 생성시 세부 레이어를 기본적으로 추가
    End Sub


    Private Sub bt_Del_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Del.Click
        'Dbbase.DelCrow(Me.bs, True)
        Del_YKdetail(True)
    End Sub

    Private Sub ToolStripButton51_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_cancel.Click
        If Not EndEdit(Me.bs) Then Return
        Data_Cancel(DSET.tbl_profile, Nothing)
    End Sub

    Private Sub Binding_Zone()

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

        'Me.bS_재료.DataSource = DSET.tbl_common
        bS_재료.Filter = "gubun='1089'"
        bS_재료.Sort = "code"

        Me.cmb_재료.DataSource = bS_재료
        cmb_재료.DisplayMember = "name"
        cmb_재료.ValueMember = "name"
        Me.cmb_재료.DataBindings.Add("text", Me.bs_detail, "설명")
        AddHandler cmb_재료.KeyDown, AddressOf Cmb_DeleteVal
        'Me.cmb_재료.Text = ""

        'Me.bs_gubun.DataSource = DSET.tbl_common
        bs_gubun.Filter = "gubun='1090'"
        bs_gubun.Sort = "code"

    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) Handles bt_Del.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Right Then
            If MsgBox("전체삭제를 하시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                Dim dR() As DataRow = DSET.tbl_yk.Select(Me.bs.Filter, "")
                For i As Integer = dR.GetUpperBound(0) To 0 Step -1
                    dR(i).Delete()
                Next
                DSET.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 dv.MouseUp
        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH" OrElse Prj.UserAuthType = "BOTH2" OrElse Prj.UserAuthType = "BOTH1" Then  '//2011.03.08 추가
            If e.Button = Windows.Forms.MouseButtons.Right Then
                Dim Frm_FilterA As New Frm_Filter
                Frm_FilterA.ColumTitle = getColCaption(Me.DT)
                Frm_FilterA.ColumList = getColName(Me.DT)
                Frm_FilterA.Colorlist = ""

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

                    '//바꾸기값이 있으면 변경 20100618
                    If Frm_FilterA.cmb_fieldc.SelectedIndex >= 0 AndAlso Frm_FilterA.cmb_fieldc.Text.ToLower <> "code" AndAlso _
                    Frm_FilterA.tb_valuec.Text <> "" Then
                        Dim Drow() As DataRow = Me.DT.Select(Filter)
                        For Each Dr As DataRow In Drow
                            Dr(Frm_FilterA.cmb_fieldc.Text) = Frm_FilterA.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 If

    End Sub

    Private Sub dv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dv.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.
        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH" OrElse Prj.UserAuthType = "BOTH2" OrElse Prj.UserAuthType = "BOTH1" Then  '//2011.03.08 추가
            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
                        Me.bt_add.PerformClick()  '//신규추가
                        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 DSET.tbl_ykdetail.Select("pcode='" & src_pcode & "'")
                            Dim Newrow As DS.tbl_ykdetailRow = DSET.tbl_ykdetail.Newtbl_ykdetailRow
                            For Each C As DataColumn In DSET.tbl_ykdetail.Columns
                                Newrow(C.ColumnName) = Drow2(C.ColumnName)
                            Next
                            Newrow.pcode = new_pcode
                            DSET.tbl_ykdetail.Addtbl_ykdetailRow(Newrow)
                        Next

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

                        bs.MoveLast()
                    End If
            End Select
        End If
    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()
        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 DSET.tbl_ykdetail.Select(Me.bs_detail.Filter, "")    '//세부내역중 두께를 합치는 루틴입니다.
            'Try
            If Dr.설명 = "공기층" Then
                Dr.열전도율 = ""
                If TOSG(Dr.두께) > 10.0 Then
                    Dr.열저항 = TOST(0.086)
                    R_value += 0.086
                Else
                    Dr.열저항 = TOST(TOSG(Dr.두께) * 0.0086)
                    R_value = R_value + TOSG(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(Dr.열전도율) <> 0 Then
                        Dr.열저항 = TOSG(Math.Round(TOSG(Dr.두께) / 1000 / TOSG(Dr.열전도율), 4)).ToString
                        R_value += TOSG(Dr.열저항)  '//여부분에서는 나올수잇겟군요.?예
                    End If

                End If

            End If


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

        Try
            If cmb_형태.Text = "외부창" OrElse cmb_형태.Text = "내부창" Then
                Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text
            Else
                Me.열관류율NTb.Text = CSng(Math.Round(1 / R_value, 3)).ToString
            End If
        Catch ex As Exception
            Me.열관류율NTb.Text = ""
            'MsgBox("4. " & ex.Message.ToString)
        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.arindv1.RowCount - 1) As YkCtl.SM
        For i As Integer = 0 To Me.arindv1.RowCount - 1
            '//아까 열표시해서 검정색 선택해보니 검정은 값이 0 이 나오더라구요
            '//실재로 0값이 근데 표시가안됫어요 그러므로

            Try
                FT(i).BColor = Color.FromArgb(Me.arindv1.Rows(i).Cells("후경색").Value)

            Catch ex As Exception
                FT(i).BColor = Color.FromName("white")
                'MsgBox("5. " & ex.Message.ToString)
            End Try
            'Try
            '    If Me.arindv1.Rows(i).Cells("전경색").Value = "0" Then
            '        FT(i).FColor = Color.Black
            '    Else
            '        FT(i).FColor = Color.FromArgb(Me.arindv1.Rows(i).Cells("전경색").Value)
            '    End If

            'Catch ex As Exception
            '    FT(i).FColor = Color.FromName("black")
            '    'MsgBox("6. " & ex.Message.ToString)
            'End Try
            ' FT(i).Style=            
            Try
                FT(i).Style = Val(Me.arindv1.Rows(i).Cells("구분").Value)
            Catch ex As Exception
                FT(i).Style = Drawing2D.HatchStyle.Cross
                'MsgBox("7. " & ex.Message.ToString)
            End Try



            Try
                If Me.arindv1.Rows(i).Cells("두께").Value <> "" Then
                    FT(i).Width = Me.arindv1.Rows(i).Cells("두께").Value
                End If
            Catch ex As Exception
                'MsgBox("8. " & ex.Message.ToString)
            End Try


        Next
        Me.UserControl11.M1FillType = FT

    End Sub

    Private Sub arindv1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles arindv1.CellFormatting
        Try
            Me.arindv1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.FromArgb(Me.arindv1.Rows(e.RowIndex).Cells("후경색").Value)
            ' Me.arindv1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.FromName(Me.arindv1.Rows(e.RowIndex).Cells("전경색").Value)
        Catch ex As Exception
            Me.arindv1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
            'MsgBox("9. " & ex.Message.ToString)
        End Try

        Try
            If Me.arindv1.Rows(e.RowIndex).Cells("커스텀").Value = "Y" Then
                Me.arindv1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Magenta
            Else
                Me.arindv1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
            End If
        Catch ex As Exception
            Me.arindv1.Rows(e.RowIndex).Cells("커스텀").Value = "N"
        End Try

        Me.bs_detail.EndEdit()

    End Sub


    Private Sub Arindv1_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles arindv1.CellValidated
        refresh_Image()
    End Sub

    Private Sub Arindv1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs)

    End Sub

    Private Sub Arindv1_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
        refresh_Image()
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        'Try
        Me.bs_detail.AddNew()
        Me.bs_detail.EndEdit()
        refresh_Image()
        'Catch ex As Exception
        '    MsgBox(ex.Message.ToString)

        '    MsgBox("상위코드 선택하세요", MsgBoxStyle.Critical, "확인")
        'End Try

    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        If Me.bs_detail.Count > 0 Then
            Me.bs_detail.RemoveCurrent()
            Me.bs_detail.EndEdit()
        End If
    End Sub

    Private Sub arindv1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles arindv1.CellContentClick
        Select Case e.ColumnIndex
            Case 8  '//전경
                Dim Cd As New ColorDialog
                Cd.Color = Color.FromName(Me.arindv1.Rows(e.RowIndex).Cells("전경색").Value)
                If Cd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
                Me.arindv1.Rows(e.RowIndex).Cells("전경색").Value = Cd.Color.ToArgb
                Me.btn_전경색.BackColor = Cd.Color
                Me.bs_detail.EndEdit()
                refresh_Image()
            Case 9  '//배경
                Dim Cd As New ColorDialog
                Cd.Color = Color.FromName(Me.arindv1.Rows(e.RowIndex).Cells("후경색").Value)
                If Cd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
                Me.arindv1.Rows(e.RowIndex).Cells("후경색").Value = Cd.Color.ToArgb
                Me.btn_후경색.BackColor = Cd.Color
                Me.bs_detail.EndEdit()
                refresh_Image()
        End Select
    End Sub

    Private Sub arindv1_DataError1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles arindv1.DataError

    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
        Me.refresh_Image()
        If cmb_형태.Text = "외부창" OrElse cmb_형태.Text = "내부창" 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
        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

        End If

    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Dim Drv As DataRowView = Me.bs_detail.Current
        Dim 전경 As String
        Try
            전경 = Drv("전경색").ToString
        Catch ex As Exception
            'MsgBox("10. " & ex.Message.ToString)
        End Try
        Dim 후경 As String
        Try
            후경 = Drv("후경색").ToString
        Catch ex As Exception
            'MsgBox("11. " & ex.Message.ToString)
        End Try
        Dim A As New Frm_DisplayGubun(전경, 후경)
        A.Show()
    End Sub

    Private Sub SplitContainer1_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel2.Paint

    End Sub

    Private Sub btn_전경색_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_전경색.Click

        Try
            Dim Cd As New ColorDialog

            If Cd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
            Me.btn_전경색.BackColor = Cd.Color

            Dim Drv As DataRowView = Me.bs_detail.Current
            Drv("전경색") = Cd.Color.ToArgb

        Catch ex As Exception
            Me.btn_전경색.BackColor = Color.White
            'MsgBox("14. " & ex.Message.ToString)
        End Try
        Me.bs_detail.EndEdit()
        Me.refresh_Image()

    End Sub

    Private Sub cmb_재료_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_재료.SelectedIndexChanged

        cmb_재료_Changed()

    End Sub

    Private Sub btn_후경색_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_후경색.Click

        Try
            Dim Cd As New ColorDialog

            If Cd.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
            Me.btn_후경색.BackColor = Cd.Color

            Dim Drv As DataRowView = Me.bs_detail.Current
            Drv("후경색") = Cd.Color.ToArgb

        Catch ex As Exception
            Me.btn_후경색.BackColor = Color.White
            'MsgBox("18. " & ex.Message.ToString)
        End Try
        Me.bs_detail.EndEdit()
        Me.refresh_Image()

    End Sub

    Private Sub cmb_열전도율_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_열전도율.SelectedIndexChanged
        If Not init Then Return
        Dim Drv As DataRowView = Me.bs_detail.Current
        If Drv Is Nothing Then Return
        Drv("커스텀") = "N"
        Drv("열전도율") = Me.cmb_열전도율.Items(Me.cmb_열전도율.SelectedIndex)
        Me.bs_detail.EndEdit()
        Me.refresh_Image()
    End Sub

    'Private Sub cmb_열전도율_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb_열전도율.TextChanged
    '    Me.bs_detail.EndEdit()
    '    Me.refresh_Image()

    '    'Try
    '    '    If Me.cmb_열전도율.SelectedIndex = -1 Then
    '    '        Me.arindv1.CurrentRow.DefaultCellStyle.ForeColor = Color.FromArgb(Color.Red.ToArgb)
    '    '    Else
    '    '        Me.arindv1.CurrentRow.DefaultCellStyle.ForeColor = Color.FromArgb(Color.Black.ToArgb)
    '    '    End If
    '    'Catch ex As Exception
    '    '    MsgBox(ex.Message.ToString)
    '    'End Try

    'End Sub

    Private Sub cmb_재료_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb_재료.SelectionChangeCommitted
        If Not init Then Return
        Me.UserCommin = True
    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 = "외부창" OrElse cmb_형태.Text = "내부창" Then
            Me.열관류율NTb.Text = Me.NTb_창호열관류율.Text
        End If
    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 = DSET.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 cmb_열전도율_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmb_열전도율.KeyUp
        Me.keyUp1 = True
        If Not init Then Return
        'If e.KeyCode = Keys.Enter Then
        Me.bs_detail.EndEdit()
        Dim CUrvalue As String = Me.cmb_열전도율.Text
        Dim Find As Boolean = False
        For i As Integer = 0 To Me.cmb_열전도율.Items.Count - 1
            If Me.cmb_열전도율.Items(i).ToString = CUrvalue Then Find = True
        Next
        Dim Drv As DataRowView = Me.bs_detail.Current
        If Drv Is Nothing Then Return
        If Find = False Then  '//찾지못하였다면
            Drv("커스텀") = "Y"
        Else
            Drv("커스텀") = "N"
        End If
        Me.refresh_Image()
        Me.keyUp1 = False
        'End If
    End Sub

    Private Sub bs_detail_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs_detail.CurrentChanged
        If Not init Then Return
        Dim Drv As DataRowView = CType(Me.bs_detail.Current, DataRowView)
        If Drv Is Nothing Then Return '//선택된아이템이없으면 빠져나감
        Try
            Me.btn_전경색.BackColor = Color.FromArgb(Drv("전경색").ToString)
            Me.btn_후경색.BackColor = Color.FromArgb(Drv("후경색").ToString)
        Catch ex As Exception
            Me.btn_전경색.BackColor = Color.White
            Me.btn_후경색.BackColor = Color.White
            'MsgBox("12. " & ex.Message.ToString)
        End Try


        '//열전도율목록을 갱신
        Me.cmb_열전도율.Items.Clear()
        Dim Fil As String = "gubun='1089' and name='" & Me.cmb_재료.Text & "'"
        Dim Drow() As DS.tbl_commonRow = DSET.tbl_common.Select(Fil)
        Try
            If Drow.GetUpperBound(0) = 0 Then Me.cmb_열전도율.Items.Add(Drow(0).valn1)
        Catch ex As Exception

        End Try


        '//현재선택된 열전도율이 비정상(*?) 체크

        Dim CUrvalue As String = Drv("열전도율").ToString
        If CUrvalue <> "" Then
            Dim Dr() As DS.tbl_commonRow = DSET.tbl_common.Select("gubun='1089' and name='" & Me.cmb_재료.Text & "' and valn1='" & CUrvalue.Trim & "'")
            If Dr.GetUpperBound(0) = -1 Then    '//일치하는것이 없다면
                Drv("커스텀") = "Y"
            Else
                Drv("커스텀") = "N"
            End If
        End If

        'Drv("커스텀") = "N"
        'If CUrvalue <> "" Then
        '    Dim Find As Boolean = False
        '    For i As Integer = 0 To Me.cmb_열전도율.Items.Count - 1
        '        If Me.cmb_열전도율.Items(i).ToString = CUrvalue Then Find = True
        '    Next
        '    If Find = False Then  '//찾지못하였다면
        '        Drv("커스텀") = "Y"
        '        Me.arindv1.SelectedRows(0).DefaultCellStyle.ForeColor = Color.Red
        '    End If
        'End If
        Me.bs_detail.EndEdit()
        Me.arindv1.Refresh()
        Me.refresh_Image()
    End Sub


    Private Sub cmb_재료_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb_재료.TextChanged
        cmb_재료_Changed()
    End Sub

    Private Sub cmb_재료_Changed()
        If Not init Then Return
        If Me.bs_detail.Count < 1 Then Return '// ep데이터가없을경우 무시
        If Me.cmb_재료.SelectedIndex < 0 Then Return

        Dim 재료코드 As String = ""

        '//선택된재료명
        Dim 재료명 As String = CType(Me.cmb_재료.Items(Me.cmb_재료.SelectedIndex), DataRowView)("name")

        If UserCommin = False Then
            'UserCommin = True
            Return
        End If

        '//해당열전도율가져오기
        Try
            Dim Dr As DS.tbl_commonRow = DSET.tbl_common.Select(bS_재료.Filter & " and name='" & 재료명 & "'")(0)
            재료코드 = Dr.code
            Me.cmb_열전도율.Items.Clear()
            Try '// 20110210 Try문 추가 (열전달저항 관련 Null 값에 의한 재료코드에러수정)
                Me.cmb_열전도율.Items.Add(Dr.valn1)
                Me.cmb_열전도율.Text = Dr.valn1
            Catch ex As Exception
                Dim Drv As DataRowView = CType(Me.bs_detail.Current, DataRowView)
                Drv("커스텀") = "N"
            End Try

            'Me.tb_열전도.Text = Dr.valn1
            ' MsgBox(Dr.valn1)

        Catch ex As Exception
            'MsgBox(ex.Message.ToString)
            'MsgBox("15. " & ex.Message.ToString)
        End Try

        '//색및 패턴명 가져오기
        Dim DetailDrv As DataRowView = Me.bs_detail.Current
        DetailDrv("설명") = 재료명
        Dim Er As Boolean = False

        Dim Dr2() As DS.tbl_commonRow = DSET.tbl_common.Select("gubun='1090' and code='" & 재료코드 & "'")
        If Dr2.GetUpperBound(0) = -1 Then
            DetailDrv("전경색") = Color.Blue.ToArgb
            DetailDrv("후경색") = Color.White.ToArgb '//디비에 해당설ㅈㅇ이 없을경우 행하는 코드들
            DetailDrv("구분") = "5"
            Me.btn_전경색.BackColor = Color.FromArgb(DetailDrv("전경색"))
            Me.btn_후경색.BackColor = Color.FromArgb(DetailDrv("후경색"))
        Else  '//디비에 있을경우
            Try
                DetailDrv("전경색") = Dr2(0)("name").ToString.Split(",")(0)
            Catch ex As Exception
                DetailDrv("전경색") = Color.Black.ToArgb
                'MsgBox("16. " & ex.Message.ToString)
            End Try
            Try
                DetailDrv("후경색") = Dr2(0)("name").ToString.Split(",")(1)
            Catch ex As Exception
                DetailDrv("후경색") = Color.White.ToArgb
                ' MsgBox("17. " & ex.Message.ToString)
            End Try

            DetailDrv("구분") = CInt(Dr2(0)("valn1"))
            Me.btn_후경색.BackColor = Color.FromArgb(DetailDrv("후경색"))
            Me.btn_전경색.BackColor = Color.FromArgb(DetailDrv("전경색"))
        End If

        Me.bs_detail.EndEdit()
        Me.refresh_Image()
        UserCommin = False

    End Sub

    Private Sub bs_detail_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs_detail.CurrentItemChanged
        '//2011 06 18 : 아이템이동시 열전도율의 콤보박스가 생성되지않는현상 제거

        If Not Me.init OrElse Me.keyUp1 Then Return

        '//해당열전도율가져오기
        Dim Drow() As DS.tbl_commonRow = DSET.tbl_common.Select(bS_재료.Filter & " and name='" & Me.cmb_재료.Text & "'")

        Dim temp_item As String
        Try
            temp_item = Me.cmb_열전도율.Items(0)
        Catch ex As Exception
            temp_item = ""
        End Try

        If Drow.GetUpperBound(0) = 0 AndAlso Drow(0).valn1.ToString <> temp_item Then
            Me.cmb_열전도율.Items.Clear()
            Me.cmb_열전도율.Items.Add(Drow(0).valn1)
        End If

    End Sub


End Class
