Module Pub

    Structure s_Project
        Dim FileName As String
        Dim MakeTime As String
        Dim Desc As String
        Dim Opened As Boolean
        Dim UIVersion As String
        Dim LGVersino As String
        Dim Name As String
        Dim MaxUI As String
        Dim MaxLG As String
        Dim SFType As String    '//저장파일 형태
        Dim EditTime As String
        Dim Admin As Boolean    '//현재프로그램이 관리자 모드인가?
        Dim Password As String  '//해당프로젝트가 엄호로 보호되어있는가?
        Dim IsError As Boolean  '//로드시 에러가 발생하였는가?
        Dim CUrIP As String
        Dim CUrMac As String
        Dim LoginTime As String '//로그인시간
        Dim UserId As String
        Dim UserName As String
        Dim UserPass As String
        Dim UserIp As String
        Dim UserMac As String
        Dim UserAuthType As String
        Dim UserAuthType_Real As String
    End Structure

    Public pLog As ArinLog.ArinLog

    Public Prj As New s_Project : Public StartVersion As String = "2010032000"
    Public Prj_test As New s_Project
    Public Myini As CEnergy.MyINI
    Public PrjChanged As Boolean = False

    ' Public Uselov As Lov.ModLov
    Public PreFile(4) As String
    Public msgf As Frm_Work = Nothing   '201130830

    Public DSET1_TEST As New DS   '//일반데이터

    Public DSET1 As New DS   '//일반데이터
    Public DSET2 As New DS   '//일반데이터(임시)
    Public DSETR1 As New DSR    '//결과데이터(결과)
    Public DSETR2 As New DSR    '//결과데이터(임시)
    Public DataDir As New System.IO.DirectoryInfo(My.Application.Info.DirectoryPath)
    Public TemplateDir As New System.IO.DirectoryInfo(DataDir.FullName & "\template")

    Public Calc As Calculator   '//계산로직이다.파일열릴떄 할당됨
    Public Result1 As New CResult(DSET1, DSETR1)    '//기본데이터결과
    Public Result2 As New CResult(DSET2, DSETR2)   '//설계개선용데이터결과
    Public LogSB As System.Text.StringBuilder

    Public EnDec As New ArinLogin.EnDec("tindevil.com")

    Public DSHistory As New DS2
    Public Importsameaddress As Boolean = False

    Public Sub Update_열관류율_140409()
        DSET1.tbl_yk.AcceptChanges()

        For Each DrowYK As DS.tbl_ykRow In DSET1.tbl_yk

            If DrowYK.RowState = DataRowState.Deleted OrElse DrowYK.RowState = DataRowState.Detached Then Continue For

            Dim R_value As Decimal = 0
            Dim width As Decimal = 0
            Dim filter As String = "pcode='" + DrowYK.code + "'"
            For Each Dr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select(filter, "")
                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 DrowYK.면형태 = "0" Then
                    DrowYK.열관류율 = CSng(Math.Round(1 / R_value, 3)).ToString
                    DrowYK.투과율 = ""
                Else
                    Dim 면형태 As DS.tbl_commonRow = DSET1.tbl_common.Select("gubun='1088' and code='" + DrowYK.면형태 + "'")(0)
                    If 면형태.name = "외부창" OrElse 면형태.name = "내부창" Then
                        If DrowYK.발코니창호여부 Then
                            DrowYK.열관류율 = Math.Round((1 / ((1 / TOSG(DrowYK.창호열관류율)) + (1 / TOSG(DrowYK.발코니창호열관류율)) * 0.5)), 3)
                            DrowYK.투과율 = Math.Round(TOSG(DrowYK.발코니투과율) * TOSG(DrowYK.일사에너지투과율), 3)
                        Else
                            DrowYK.열관류율 = DrowYK.창호열관류율
                            DrowYK.투과율 = DrowYK.일사에너지투과율
                        End If
                    Else
                        DrowYK.열관류율 = CSng(Math.Round(1 / R_value, 3)).ToString
                        DrowYK.투과율 = ""
                    End If
                End If

            Catch ex As Exception
                DrowYK.열관류율 = ""
                DrowYK.투과율 = ""
            End Try

        Next



        '//열관류율이 링크된 모든면의 건축부위 데이터를 열관류율 화면의 건축부위 데이터로 갱신
        For Each Drow As DS.tbl_myounRow In DSET1.tbl_myoun

            If Drow.RowState = DataRowState.Deleted OrElse Drow.RowState = DataRowState.Detached Then Continue For

#If DEBUG Then
            If Drow.code = "0009" Then
                MsgBox("test")
            End If
#End If

            If Drow.열관류율2 <> "0" Then
                Try   '==========================================2014.04.17 열관류율 삭제시 코드번호가 남아 오류 발생하는 현상을 try 안으로 넣음
                    Dim Dr As DS.tbl_ykRow = DSET1.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", "지중벽", "0009"
                            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

                Catch ex As Exception

                End Try
            End If

        Next
    End Sub

    Public Function 프로필급탕요구량(면적별범위 As Char) As Decimal
        'Drow프로필.일일급탕요구량()

        If 면적별범위 = "A"c Then
            Return 2333.2
        ElseIf 면적별범위 = "B"c Then
            Return 3051.2
        ElseIf 면적별범위 = "C"c Then
            Return 4307.5
        ElseIf 면적별범위 = "D"c Then
            Return 5025.4
        ElseIf 면적별범위 = "E"c Then
            Return 5743.4
        ElseIf 면적별범위 = "F"c Then
            Return 6281.8
        Else
            Return 8794.5
        End If

    End Function

    Public Function 면적별범위값(면적 As Decimal) As Char
        Select Case 면적
            Case Is > 165
                Return "G"c
            Case Is > 130
                Return "F"c
            Case Is > 100
                Return "E"c
            Case Is > 60
                Return "D"c
            Case Is > 40
                Return "C"c
            Case Is > 20
                Return "B"c
            Case Else
                Return "A"c
        End Select

    End Function

    Public Function CurrentUIVersion() As String
        Dim uiverstr As String = My.Application.Info.Version.Minor.ToString("0000") + _
            My.Application.Info.Version.Build.ToString("0000") + _
            My.Application.Info.Version.Revision.ToString("0000").Substring(0, 2)
        Return uiverstr
    End Function

    Public Sub NOTICE(ByVal MSG As String, ByVal Src As Windows.Forms.ToolStripStatusLabel, ByVal FCOLOR As Drawing.Color)
        If Not Src Is Nothing Then
            Src.Text = "▶ " & MSG & Space(1) & "[" & Format(Now, "HH시mm분ss초") & "]"
            Src.ForeColor = FCOLOR
        End If
        If FCOLOR = Drawing.Color.Red Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
    End Sub

    Public Sub MsgboxE(msg As String, Optional SaveLog As Boolean = False)
        MsgBox(msg, MsgBoxStyle.Critical, "확인")
        If SaveLog Then
            pLog.Add(msg, True)
        End If
    End Sub

    Public Sub MsgboxI(msg As String, Optional SaveLog As Boolean = False)
        MsgBox(msg, MsgBoxStyle.Information, "확인")
        If SaveLog Then
            pLog.Add(msg, True)
        End If
    End Sub

    Public Sub 항목별평가결과(ByRef DSR As Eco2Ar.DSR)
        Dim NDr As DSR.Pyonga_YKRow = DSR.Pyonga_YK.NewPyonga_YKRow

        '//기준(*)데이터가없는경우에는 1번째데이터를 쓰도록한다.
        Dim 외벽벽체찾음 As Boolean = False
        Dim 외벽지붕찾음 As Boolean = False
        Dim 외벽바닥찾음 As Boolean = False

        For Each dr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
            Dim gcode As String = dr.면형태.ToString()
            Dim gname As String = Get_CName("1088", gcode)

            If gname = "외벽(벽체)" OrElse gname = "내벽(벽체)" Then
                If dr.설명.Substring(0, 1) = "*" Then '//기준데이터가져오기
                    NDr.벽체값 = dr.열관류율

                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽벽체찾음 = True
                            NDr.벽체종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                End If
            ElseIf gname = "외벽(지붕)" OrElse gname = "내벽(지붕)" Then
                If dr.설명.Substring(0, 1) = "*" Then '//기준데이터가져오기
                    NDr.지붕값 = dr.열관류율

                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽지붕찾음 = True
                            NDr.지붕종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                End If
            ElseIf gname = "외벽(바닥)" OrElse gname = "내벽(바닥)" Then
                If dr.설명.Substring(0, 1) = "*" Then '//기준데이터가져오기
                    NDr.바닥값 = dr.열관류율

                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽바닥찾음 = True
                            NDr.바닥종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                End If
            End If
        Next

        If Not 외벽벽체찾음 Then
            For Each dr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
                Dim gcode As String = dr.면형태.ToString()
                Dim gname As String = Get_CName("1088", gcode)
                If gname = "외벽(벽체)" OrElse gname = "내벽(벽체)" Then
                    NDr.벽체값 = dr.열관류율
                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽벽체찾음 = True
                            NDr.벽체종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                    If 외벽벽체찾음 Then Exit For
                End If
            Next
            If Not 외벽벽체찾음 Then
                NDr.벽체종류 = ""
                NDr.벽체값 = 0
            End If
        End If

        If Not 외벽지붕찾음 Then
            For Each dr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
                Dim gcode As String = dr.면형태.ToString()
                Dim gname As String = Get_CName("1088", gcode)
                If gname = "외벽(지붕)" OrElse gname = "내벽(지붕)" Then
                    NDr.지붕값 = dr.열관류율
                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽지붕찾음 = True
                            NDr.지붕종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                    If 외벽지붕찾음 Then Exit For
                End If
            Next
            If Not 외벽지붕찾음 Then
                NDr.지붕종류 = ""
                NDr.지붕값 = 0
            End If
        End If


        If Not 외벽바닥찾음 Then
            For Each dr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
                Dim gcode As String = dr.면형태.ToString()
                Dim gname As String = Get_CName("1088", gcode)
                If gname = "외벽(바닥)" OrElse gname = "내벽(바닥)" Then
                    NDr.바닥값 = dr.열관류율
                    Dim 최대저항값 As Decimal = 0
                    '//세부데이터글가져온다 이중열저항이 가장큰것을 가져아야한다
                    For Each ddr As DS.tbl_ykdetailRow In DSET1.tbl_ykdetail.Select("code <> '0' and pcode = '" + dr.code + "'")
                        If CDec(ddr.열저항) > 최대저항값 Then   '//최대저항값의설명을 가져와야한다.
                            외벽바닥찾음 = True
                            NDr.바닥종류 = ddr.설명 + Space(1) + ddr.두께 + "mm"
                            최대저항값 = CDec(ddr.열저항)
                        End If
                    Next
                    If 외벽바닥찾음 Then Exit For
                End If
            Next
            If Not 외벽바닥찾음 Then
                NDr.바닥종류 = ""
                NDr.바닥값 = 0
            End If
        End If

        '//지열설비정보확인
        Dim Sum_지열히트펌프용량_난방 As Single = 0
        Dim Sum_지열히트펌프용량_냉방 As Single = 0
        Dim Max_난방 As Single = 0
        Dim Max_냉방 As Single = 0
        Dim JDROW() As DS.tbl_newRow = DSET1.tbl_new.Select("code <> '0' and 기기종류='지열'", "설명")
        If JDROW.GetUpperBound(0) = -1 Then '//지열데이터가없는경우엔 빈값처리
            NDr.지열히트펌프용량냉방 = ""
            NDr.지열히트펌프용량 = ""
            NDr.지열비고 = ""
            NDr.지열난방COP = ""
            NDr.지열냉방COP = ""
        Else '//데이터가있다면 1번째 데이터를 이용한다.


            Dim Max_Row_난방 As DS.tbl_newRow = Nothing
            Dim MAx_Row_냉방 As DS.tbl_newRow = Nothing

            NDr.지열비고 = JDROW(0).지열비고

            For Each jdrowrow As DS.tbl_newRow In JDROW

                Dim 난방연결수 As Integer = (DSET1.tbl_nanbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & jdrowrow.code.ToString & "'").GetUpperBound(0) + 1)
                Dim 냉방연결수 As Integer = (DSET1.tbl_nangbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & jdrowrow.code.ToString & "'").GetUpperBound(0) + 1)

                Dim 난방값 As String = jdrowrow.열성능비난방
                Dim 냉방값 As String = jdrowrow.열성능비냉방

                If 난방연결수 > 0 AndAlso 난방값 <> "" AndAlso IsNumeric(난방값) AndAlso 난방값 <> "0" Then
                    Sum_지열히트펌프용량_난방 += jdrowrow.지열히트펌프용량
                    If TOSG(jdrowrow.지열히트펌프용량) > Max_난방 Then
                        Max_난방 = TOSG(jdrowrow.지열히트펌프용량)
                        Max_Row_난방 = jdrowrow
                    End If
                End If

                If 냉방연결수 > 0 AndAlso 냉방값 <> "" AndAlso IsNumeric(냉방값) AndAlso 냉방값 <> "0" Then
                    Sum_지열히트펌프용량_냉방 += jdrowrow.지열히트펌프용량
                    If TOSG(jdrowrow.지열히트펌프용량) > Max_냉방 Then
                        Max_냉방 = TOSG(jdrowrow.지열히트펌프용량)
                        MAx_Row_냉방 = jdrowrow
                    End If
                End If
            Next


            NDr.지열히트펌프용량냉방 = Sum_지열히트펌프용량_냉방.ToString()
            NDr.지열히트펌프용량 = Sum_지열히트펌프용량_난방.ToString()

            'NDr.지열히트펌프용량냉방 = Sum_지열히트펌프용량_냉방.ToString() + "(" + Max_냉방.ToString() + ")"

            'If Sum_지열히트펌프용량_난방 > 0 Then
            '    NDr.지열히트펌프용량 = Sum_지열히트펌프용량_난방.ToString()
            '    'NDr.지열히트펌프용량 = "난방: " + Sum_지열히트펌프용량_난방.ToString() + "(" + Max_난방.ToString() + ")"
            'Else
            '    NDr.지열히트펌프용량 = ""
            'End If

            'If Sum_지열히트펌프용량_냉방 > 0 Then
            '    NDr.지열히트펌프용량 += " / 냉방: " + NDr.지열히트펌프용량냉방
            'End If

            If Max_난방 <> 0 Then
                NDr.지열난방COP = Max_Row_난방.열성능비난방
            Else
                NDr.지열난방COP = ""
            End If
            If Max_냉방 <> 0 Then
                NDr.지열냉방COP = MAx_Row_냉방.열성능비냉방
            Else
                NDr.지열냉방COP = ""
            End If
        End If

        '//######################
        '//13-12-08
        '//######################
        '//태양열시스템
        Dim JDROW2() As DS.tbl_newRow = DSET1.tbl_new.Select("code <> '0' and 기기종류='태양열'", "설명")
        Dim Max_태양열면적 As Single = -999
        Dim Max_집열기유형 As String = ""
        Dim Max_집열판방위 As String = ""
        Dim Sum_태양열면적 As Single = 0
        For Each rowsun As DS.tbl_newRow In JDROW2

            Dim 난방연결수 As Integer = (DSET1.tbl_nanbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & rowsun.code.ToString & "'").GetUpperBound(0) + 1)
            Dim 냉방연결수 As Integer = (DSET1.tbl_nangbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & rowsun.code.ToString & "'").GetUpperBound(0) + 1)

            If 난방연결수 > 0 OrElse 냉방연결수 > 0 Then

                Dim 태양면적 As String = rowsun.집열판면적
                If 태양면적 <> "" AndAlso IsNumeric(태양면적) AndAlso 태양면적 <> "0" Then
                    Sum_태양열면적 += TOSG(태양면적)
                    If TOSG(태양면적) > Max_태양열면적 Then
                        Max_태양열면적 = TOSG(태양면적)
                        Max_집열기유형 = rowsun.집열기유형
                        Max_집열판방위 = rowsun.집열판방위
                    End If
                End If

            End If

        Next
        If Sum_태양열면적 > 0 Then
            NDr.태양열집열판면적 = Sum_태양열면적.ToString() + "(" + Max_태양열면적.ToString + ")"
            NDr.태양열집열기유형 = Max_집열기유형
            NDr.태양열집열판방위 = Max_집열판방위
        Else
            NDr.태양열집열판면적 = ""
            NDr.태양열집열기유형 = ""
            NDr.태양열집열판방위 = ""
        End If



        '//태양광시스템
        Dim JDROW3() As DS.tbl_newRow = DSET1.tbl_new.Select("code <> '0' and 기기종류='태양광'", "설명")
        Dim Max_태양광면적 As Single = -999
        Dim Max_태양광종류 As String = ""
        Dim Max_태양광방위 As String = ""
        Dim Max_태양광기울기 As String = ""
        Dim Max_태양광적용타입 As String = ""
        Dim Sum_태양광면적 As Single = 0

        For Each rowsun As DS.tbl_newRow In JDROW3
            Dim 태양면적 As String = rowsun.태양광모듈면적
            If 태양면적 <> "" AndAlso IsNumeric(태양면적) AndAlso 태양면적 <> "0" Then
                Sum_태양광면적 += TOSG(태양면적)
                If TOSG(태양면적) > Max_태양광면적 Then
                    Max_태양광면적 = TOSG(태양면적)
                    Max_태양광종류 = rowsun.태양광모듈종류
                    Max_태양광방위 = rowsun.태양광모듈방위
                    Max_태양광기울기 = rowsun.태양광모듈기울기
                    Max_태양광적용타입 = rowsun.태양광모듈적용타입
                End If
            End If
        Next
        If Sum_태양광면적 > 0 Then
            NDr.태양광모듈면적 = Sum_태양광면적.ToString() '+ "(" + Max_태양광면적.ToString + ")"
            NDr.태양광모듈종류 = Max_태양광종류
            NDr.태양광모듈방위 = Max_태양광방위
            NDr.태양광모듈기울기 = Max_태양광기울기
            NDr.태양광모듈적용타입 = Max_태양광적용타입
            If NDr.태양광모듈방위 = "(없음)" Then
                NDr.태양광모듈방위 = ""
            End If
        Else
            NDr.태양광모듈면적 = ""
            NDr.태양광모듈종류 = ""
            NDr.태양광모듈방위 = ""
            NDr.태양광모듈기울기 = ""
            NDr.태양광모듈적용타입 = ""
        End If


        '//열병합시스템
        Dim JDROW4() As DS.tbl_newRow = DSET1.tbl_new.Select("code <> '0' and 기기종류='열병합'", "설명")
        Dim Max_열병합능력 As Single = -999
        Dim Max_열병합생산효율 As String = ""
        Dim Max_열병합발전효율 As String = ""
        Dim Max_열병합가동연료 As String = ""
        Dim Sum_열병합능력 As Single = 0

        For Each rowsun As DS.tbl_newRow In JDROW4


            Dim 난방연결수 As Integer = (DSET1.tbl_nanbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & rowsun.code.ToString & "'").GetUpperBound(0) + 1)
            Dim 냉방연결수 As Integer = (DSET1.tbl_nangbangkiki.Select("신재생연결여부='시스템연결' and 연결된시스템='" & rowsun.code.ToString & "'").GetUpperBound(0) + 1)

            If 난방연결수 > 0 OrElse 냉방연결수 > 0 Then
                Dim 값 As String = rowsun.열생산능력
                If 값 <> "" AndAlso IsNumeric(값) AndAlso 값 <> "0" Then
                    Sum_열병합능력 += TOSG(값)
                    If TOSG(값) > Max_열병합능력 Then
                        Max_열병합능력 = TOSG(값)
                        Max_열병합생산효율 = rowsun.열생산효율.ToString
                        Max_열병합발전효율 = rowsun.발전효율.ToString
                        Max_열병합가동연료 = rowsun.가동연료
                    End If
                End If
            End If
        Next

        If Sum_열병합능력 > 0 Then
            NDr.열병합열생산능력 = Sum_열병합능력.ToString() + "(" + Max_열병합능력.ToString + ")"
            NDr.열병합열생산효율 = Max_열병합생산효율
            NDr.열병합발전효율 = Max_열병합발전효율
            NDr.열병합가동연료 = Max_열병합가동연료
        Else
            NDr.열병합열생산능력 = ""
            NDr.열병합열생산효율 = ""
            NDr.열병합발전효율 = ""
            NDr.열병합가동연료 = ""
        End If

        '//창호종류 및 창호값확인
        Dim 창호종류찾음 As Boolean = False


        Dim 창호그룹 As New Dictionary(Of String, Double)

        For Each drmyoun As DS.tbl_myounRow In DSET1.tbl_myoun.Select("code <> '0'")
            If drmyoun.열관류율2 = "" OrElse drmyoun.열관류율2 = "0" Then Continue For

            For Each cdr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code= '" + drmyoun.열관류율2 + "'")


                Dim 면코드 As String = cdr.면형태
                If 면코드 = "" Then Continue For
                Dim 면이름 As String = Get_CName("1088", 면코드)
                If 면이름 = "" Then Continue For
                If 면이름.IndexOf("외부창") <> -1 Then    '//이름에 외부창이잇는것을 찾음

                    If Not 창호그룹.ContainsKey(cdr.code) Then
                        창호그룹.Add(cdr.code, TOSG(drmyoun.건축부위면적))
                    Else
                        창호그룹.Item(cdr.code) = 창호그룹.Item(cdr.code) + TOSG(drmyoun.건축부위면적)
                    End If

                End If
            Next

        Next

        Dim 최대면적 As Double = 0
        Dim 최대면적면코드 As String = ""
        For Each item As System.Collections.Generic.KeyValuePair(Of String, Double) In 창호그룹
            If item.Value > 최대면적 Then
                최대면적 = item.Value
                최대면적면코드 = item.Key
            End If
        Next

        For Each cdr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
            Dim 면코드 As String = cdr.code
            If 면코드 = 최대면적면코드 Then
                NDr.창호종류 = cdr.창호세부설명
                NDr.창호값 = TOSG(cdr.열관류율)
                Exit For
            End If
        Next







        '//조명설비값(모든존 ;  sum(면적*조명에너지부하율) / sum(면적)
        Dim 존면적합 As Decimal = 0
        Dim 존면적부하율 As Decimal = 0
        For Each drz As DS.tbl_zoneRow In DSET1.tbl_zone.Select("code <> '0'")

            If drz.조명부하산출방법 = "계산치" Then
                존면적합 += TOSG(drz.면적)
                존면적부하율 += TOSG(drz.면적) * TOSG(drz.조명에너지부하율계산치)
            ElseIf drz.조명부하산출방법 = "입력치" Then
                존면적합 += TOSG(drz.면적)
                존면적부하율 += TOSG(drz.면적) * TOSG(drz.조명에너지부하율입력치)
            End If
        Next
        If 존면적합 <> 0 Then
            NDr.주거실조명전력 = Math.Round(존면적부하율 / 존면적합, 2)
        End If

        '//주조명광원값()
        NDr.주조명광원 = DSET1.tbl_Desc.Rows(0)("주조명").ToString


        '///#################################################################################
        '///#################################################################################
        '//설비방식및사용연료 
        '//난방(입력존에서 가장많이 사용한놈)
        Dim fndr As DS.tbl_nanbangkikiRow = Nothing
        Dim fndrcnt As Integer = 0

        Dim sum_보일러 As Single = 0
        Dim sum_히트펌프 As Single = 0
        Dim sum_지역난방 As Single = 0
        Dim sum_전기보일러 As Single = 0

        For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0'")
            Dim cnt As Integer = 0
            Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code <> '0' and 열생산난방생산기기='" & dr.code & "' or 공조난방생산기기='" & dr.code & "'")

            '//131207
            If zDR.Length > 0 Then
                Select Case dr.열생산기기방식
                    Case "보일러"
                        sum_보일러 += TOSG(dr.보일러정격출력)
                    Case "히트펌프"
                        sum_히트펌프 += TOSG(dr.히트난방용량)
                    Case "지역난방"
                        sum_지역난방 += TOSG(dr.열교환기정격출력)
                    Case "전기보일러"
                        sum_전기보일러 += TOSG(dr.보일러정격출력)
                End Select
            End If
        Next


        '//합이 가장 큰 그룹을 검색
        Dim maxvalue As Single = 0
        ' Dim maxindex As Integer = 0
        maxvalue = Math.Max(sum_보일러, sum_히트펌프)
        maxvalue = Math.Max(maxvalue, sum_지역난방)
        maxvalue = Math.Max(maxvalue, sum_전기보일러)

        Dim searchfilter As String = ""

        If maxvalue = 0 Then
            searchfilter = ""
            ' maxindex = 0 '//없음
        ElseIf maxvalue = sum_보일러 Then
            ' maxindex = 1
            searchfilter = "열생산기기방식='보일러'"
        ElseIf maxvalue = sum_히트펌프 Then
            'maxindex = 2
            searchfilter = "열생산기기방식='히트펌프'"
        ElseIf maxvalue = sum_지역난방 Then
            '  maxindex = 3
            searchfilter = "열생산기기방식='지역난방'"
        ElseIf maxvalue = sum_전기보일러 Then
            ' maxindex = 4
            searchfilter = "열생산기기방식='전기보일러'"
        End If

        '//가장큰 그룹내의 개별 대표값 찾기
        If searchfilter <> "" Then
            For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0' and " + searchfilter)
                Dim cnt As Integer = 0
                Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code <> '0' and 열생산난방생산기기='" & dr.code & "' or 공조난방생산기기='" & dr.code & "'")

                '///
                For Each drow As DS.tbl_zoneRow In zDR
                    Dim 입력존수문자 As Integer = drow.입력존의수
                    If IsNumeric(입력존수문자) = False Then 입력존수문자 = "1"
                    cnt += CInt(입력존수문자)
                Next

                If cnt > fndrcnt Then   '//최대값찾기
                    fndr = dr
                    fndrcnt = cnt
                End If



                If Not fndr Is Nothing Then

                    '//20160327
                    If Not IsNumeric(fndr.보일러대수) Then fndr.보일러대수 = "0"
                    If CInt(fndr.보일러대수) = 0 AndAlso (fndr.운전방식 = "동시가동" OrElse fndr.운전방식 = "순차가동") Then
                        MsgBox("다음 난방기기의 보일러 대수 가 입력되지 않았습니다" + vbCrLf + vbCrLf + _
                            "난방기기 : " + fndr.설명 + vbCrLf + _
                            "운전방식 : " + fndr.운전방식 + vbCrLf + _
                            "보일러대수 : " + fndr.보일러대수 + vbCrLf + vbCrLf + _
                            "단독가동이 아닌 경우에는 보일러 대수가 입력되어야 합니다", MsgBoxStyle.Critical, "확인")
                    End If

                    NDr.온열원설비방식 = fndr.열생산기기방식
                    Select Case fndr.열생산기기방식
                        Case "보일러"
                            NDr.온열원설비연료 = fndr.사용연료
                            If fndr.운전방식 = "동시가동" OrElse fndr.운전방식 = "순차가동" Then
                                NDr.온열원용량 = maxvalue * CInt(fndr.보일러대수) '+ "(" + fndr.보일러정격출력 + ")"
                            Else
                                NDr.온열원용량 = maxvalue.ToString() '+ "(" + fndr.보일러정격출력 + ")"
                            End If

                            NDr.온열원효율 = fndr.정격보일러효율 + "%"
                        Case "히트펌프"
                            NDr.온열원설비연료 = fndr.히트연료
                            If fndr.운전방식 = "동시가동" OrElse fndr.운전방식 = "순차가동" Then
                                NDr.온열원용량 = maxvalue * CInt(fndr.보일러대수) '+ "(" + fndr.보일러정격출력 + ")"
                            Else
                                NDr.온열원용량 = maxvalue.ToString() '+ "(" + fndr.보일러정격출력 + ")"
                            End If
                            NDr.온열원효율 = fndr.히트난방정격7
                        Case "지역난방"
                            NDr.온열원설비연료 = "지역난방" 'fndr.사용연료
                            If fndr.운전방식 = "동시가동" OrElse fndr.운전방식 = "순차가동" Then
                                NDr.온열원용량 = maxvalue * CInt(fndr.보일러대수) '+ "(" + fndr.보일러정격출력 + ")"
                            Else
                                NDr.온열원용량 = maxvalue.ToString() '+ "(" + fndr.보일러정격출력 + ")"
                            End If
                            NDr.온열원효율 = fndr.정격보일러효율 + "%"
                        Case "전기보일러"
                            NDr.온열원설비연료 = "전기" ' fndr.사용연료
                            If fndr.운전방식 = "동시가동" OrElse fndr.운전방식 = "순차가동" Then
                                NDr.온열원용량 = maxvalue * CInt(fndr.보일러대수) '+ "(" + fndr.보일러정격출력 + ")"
                            Else
                                NDr.온열원용량 = maxvalue.ToString() '+ "(" + fndr.보일러정격출력 + ")"
                            End If
                            NDr.온열원효율 = fndr.정격보일러효율 + "%"
                    End Select
                End If
            Next
        Else
            NDr.온열원설비연료 = ""
            NDr.온열원용량 = ""
            NDr.온열원효율 = ""
        End If


        '///#################################################################################
        '///#################################################################################
        '//급탕(입력존에서 가장많이 사용한놈)
        fndr = Nothing
        fndrcnt = 0

        sum_보일러 = 0
        sum_히트펌프 = 0
        sum_지역난방 = 0
        sum_전기보일러 = 0

        For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0'")
            Dim cnt As Integer = 0
            Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code <> '0' and 열생산급탕생산기기='" & dr.code & "'")

            '//131207
            If zDR.Length > 0 Then
                Select Case dr.열생산기기방식
                    Case "보일러"
                        sum_보일러 += TOSG(dr.보일러정격출력)
                    Case "히트펌프"
                        sum_히트펌프 += TOSG(dr.히트난방용량)
                    Case "지역난방"
                        sum_지역난방 += TOSG(dr.열교환기정격출력)
                    Case "전기보일러"
                        sum_전기보일러 += TOSG(dr.보일러정격출력)
                End Select
            End If



        Next

        '//합이 가장 큰 그룹을 검색
        maxvalue = 0
        maxvalue = Math.Max(sum_보일러, sum_히트펌프)
        maxvalue = Math.Max(maxvalue, sum_지역난방)
        maxvalue = Math.Max(maxvalue, sum_전기보일러)

        searchfilter = ""

        If maxvalue = 0 Then
            searchfilter = ""
        ElseIf maxvalue = sum_보일러 Then
            searchfilter = "열생산기기방식='보일러'"
        ElseIf maxvalue = sum_히트펌프 Then
            searchfilter = "열생산기기방식='히트펌프'"
        ElseIf maxvalue = sum_지역난방 Then
            searchfilter = "열생산기기방식='지역난방'"
        ElseIf maxvalue = sum_전기보일러 Then
            searchfilter = "열생산기기방식='전기보일러'"
        End If

        '//가장큰 그룹내의 개별 대표값 찾기
        NDr.급탕설비방식 = ""
        NDr.급탕설비연료 = ""
        NDr.급탕용량 = ""
        NDr.급탕효율 = ""

        If searchfilter <> "" Then

            For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0' and " + searchfilter)
                Dim cnt As Integer = 0
                Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code <> '0' and 열생산급탕생산기기='" & dr.code + "'")

                For Each drow As DS.tbl_zoneRow In zDR
                    Dim 입력존수문자 As Integer = drow.입력존의수
                    If IsNumeric(입력존수문자) = False Then 입력존수문자 = "1"
                    cnt += CInt(입력존수문자)
                Next
                If cnt > fndrcnt Then   '//최대값찾기
                    fndr = dr
                    fndrcnt = cnt
                End If

                If Not fndr Is Nothing Then
                    NDr.급탕설비방식 = fndr.열생산기기방식


                    Select Case fndr.열생산기기방식
                        Case "보일러"
                            NDr.급탕설비연료 = fndr.사용연료
                            NDr.급탕용량 = maxvalue.ToString() '+ "(" + fndr.보일러정격출력 + ")"
                            NDr.급탕효율 = fndr.정격보일러효율 + "%"
                        Case "히트펌프"
                            NDr.급탕설비연료 = fndr.히트연료
                            NDr.급탕용량 = maxvalue.ToString() ' + "(" + fndr.히트난방용량 + ")"
                            NDr.급탕효율 = fndr.히트난방정격7
                        Case "지역난방"
                            NDr.급탕설비연료 = "지역난방" ' fndr.사용연료
                            NDr.급탕용량 = maxvalue.ToString() '+ "(" + fndr.열교환기정격출력 + ")"
                            NDr.급탕효율 = fndr.정격보일러효율 + "%"
                        Case "전기보일러"
                            NDr.급탕설비연료 = "전기" ' fndr.사용연료
                            NDr.급탕용량 = maxvalue.ToString() ' + "(" + fndr.보일러정격출력 + ")"
                            NDr.급탕효율 = fndr.정격보일러효율 + "%"
                    End Select

                End If

            Next
        End If









        '///#################################################################################
        '///#################################################################################
        '//냉방(입력존에서 가장많이 사용한놈)
        Dim fndr2 As DS.tbl_nangbangkikiRow = Nothing
        Dim fndr2cnt As Integer = 0

        Dim sum_압축식 As Single = 0
        Dim sum_압축식_LNG As Single = 0
        Dim sum_지역냉방 As Single = 0
        Dim sum_흡수식 As Single = 0

        For Each dr As DS.tbl_nangbangkikiRow In DSET1.tbl_nangbangkiki.Select("code <> '0'")
            Dim cnt2 As Integer = 0
            Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("열생산냉방생산기기='" & dr.code & "' or 공조냉방생산기기='" & dr.code & "'")

            '//131207
            If zDR.Length > 0 Then
                Select Case dr.냉동기방식
                    Case "압축식"
                        sum_압축식 += TOSG(dr.냉동기용량)
                    Case "압축식(LNG)"
                        sum_압축식_LNG += TOSG(dr.냉동기용량)
                    Case "지역냉방"
                        sum_지역냉방 += TOSG(dr.냉동기용량)
                    Case "흡수식"
                        sum_흡수식 += TOSG(dr.냉동기용량)
                End Select
            End If


        Next

        '//합이 가장 큰 그룹을 검색
        maxvalue = 0
        maxvalue = Math.Max(sum_압축식, sum_압축식_LNG)
        maxvalue = Math.Max(maxvalue, sum_지역냉방)
        maxvalue = Math.Max(maxvalue, sum_흡수식)

        searchfilter = ""

        If maxvalue = 0 Then
            searchfilter = ""
        ElseIf maxvalue = sum_압축식 Then
            searchfilter = "냉동기방식='압축식'"
        ElseIf maxvalue = sum_압축식_LNG Then
            searchfilter = "냉동기방식='압축식(LNG)'"
        ElseIf maxvalue = sum_지역냉방 Then
            searchfilter = "냉동기방식='지역냉방'"
        ElseIf maxvalue = sum_흡수식 Then
            searchfilter = "냉동기방식='흡수식'"
        End If




        '//가장큰 그룹내의 개별 대표값 찾기
        If searchfilter <> "" Then
            For Each dr As DS.tbl_nangbangkikiRow In DSET1.tbl_nangbangkiki.Select("code <> '0' and " + searchfilter)
                Dim cnt2 As Integer = 0
                Dim zDR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("열생산냉방생산기기='" & dr.code & "' or 공조냉방생산기기='" & dr.code & "'")

                For Each drow As DS.tbl_zoneRow In zDR
                    Dim 입력존수문자 As Integer = drow.입력존의수
                    If IsNumeric(입력존수문자) = False Then 입력존수문자 = "1"
                    cnt2 += CInt(입력존수문자)
                Next
                If cnt2 > fndr2cnt Then   '//최대값찾기
                    fndr2 = dr
                    fndr2cnt = cnt2
                End If

                If Not fndr2 Is Nothing Then
                    NDr.냉열원설비방식 = fndr2.냉동기방식
                    NDr.냉열원용량 = maxvalue.ToString() + "(" + fndr2.냉동기용량 + ")"
                    NDr.냉열원효율 = fndr2.열성능비
                    Select Case fndr2.냉동기방식
                        Case "압축식"
                            NDr.냉열원설비연료 = "전기"
                        Case "압축식(LNG)"
                            NDr.냉열원설비연료 = "천연가스"
                        Case "지역냉방"
                            NDr.냉열원설비연료 = "지역냉방"
                        Case "흡수식"
                            If fndr2.열생산연결방식 = "직화식" Then
                                NDr.냉열원설비연료 = fndr2.사용연료
                            ElseIf fndr2.열생산연결방식 = "외부연결" Then
                                Dim 온수열생산기기코드 As String = fndr2.온수열생산기기
                                If 온수열생산기기코드 <> "" Then
                                    Dim 난방기기() As DS.tbl_nanbangkikiRow = DSET1.tbl_nanbangkiki.Select("code='" + 온수열생산기기코드 + "'")
                                    If 난방기기.GetUpperBound(0) = 0 Then
                                        NDr.냉열원설비연료 = fndr2.사용연료
                                    End If
                                End If
                            End If
                    End Select

                End If

            Next
        Else
            NDr.냉열원설비방식 = ""
            NDr.냉열원용량 = ""
            NDr.냉열원효율 = ""
        End If


        DSR.Pyonga_YK.Rows.Add(NDr)
        DSR.Pyonga_YK.AcceptChanges()

    End Sub

    Public Function 면적존수합() As Tuple(Of Decimal, Int32)

        Dim 면적합 As Decimal = 0
        Dim 존수합 As Integer = 0
        Dim 면적 As Decimal = 0

        For Each dr존 As DS.tbl_zoneRow In DSET1.tbl_zone.Select("code <> '0'")
            Dim 존수 As Integer = 0
            If IsNumeric(dr존.입력존의수) Then
                존수 = CInt(dr존.입력존의수)
            Else
                존수 = 1
            End If

            존수합 += 존수
            If IsNumeric(dr존.면적) Then
                면적 = dr존.면적 * 존수
            Else
                면적 = 0
            End If

            면적합 = 면적합 + 면적

        Next

        Return New Tuple(Of Decimal, Int32)(면적합, 존수합)

    End Function


    ''' <summary>
    ''' 모든입력면의 창,문의 면적비를 계산하여 반환한다(frm_myoun의 Display_info 함수에서 가져옴)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function calc_창및문면적비(ByRef 면적비 As Decimal, ByRef 열관류율 As Decimal, ByRef 창열관류율 As Decimal, ByRef 일사에너지투과율 As Decimal, Optional 방위 As String = "") As Boolean
        면적비 = 0
        열관류율 = 0
        창열관류율 = 0
        일사에너지투과율 = 0
        Dim filter As String = "code <> '0' and (건축부위방식='외벽' or 건축부위방식 ='외부창' or 건축부위방식='내벽' or 건축부위방식 ='내부창')"
        If 방위 <> "" Then filter += " and 방위='" + 방위 + "'"

        Dim 면데이터() As DS.tbl_myounRow = DSET1.tbl_myoun.Select(filter)

        Dim WindowArea As Decimal = 0
        Dim WallArea As Decimal = 0
        Dim 열관류율합 As Double = 0
        Dim 창열관류율합 As Double = 0
        Dim 투과율합 As Decimal = 0


        For Each Dr입력면 As DS.tbl_myounRow In 면데이터
            Dim 존수 As Integer = 1
            Dim 열관 As Single = 0

            'If Dr입력면.열관류율2 = "0" Then Continue For '//열관류율이 연결되어 있어야한다



            Dim Dryk() As DS.tbl_ykRow = Nothing
            If Dr입력면.열관류율2 <> "0" Then
                Dryk = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                If Dryk.Length < 1 Then
                    MsgBox("입력면(" + Dr입력면.설명 + ")의 열관류율 연결값이 열관류율표에 존재하지 않습니다(Code=" + Dr입력면.열관류율2 + ")", MsgBoxStyle.Critical, "확인")
                    Continue For
                End If
                열관 = TOSG(Dryk(0).열관류율)
            Else
                열관 = TOSG(Dr입력면.열관류율)
            End If

            '//이 입력면을 사용하는 존의 정보를 가져온다(오류가 있다면 존의갯수를 1로한다)
            Dim dr존() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code='" + Dr입력면.존분류 + "'")
            If dr존.Length > 0 Then
                If IsNumeric(dr존(0).입력존의수) Then 존수 = CInt(dr존(0).입력존의수)
            End If


            Select Case Dr입력면.건축부위방식
                Case "외벽"
                    열관류율합 += 열관 * 1 * TOSG(Dr입력면.건축부위면적) * 존수
                Case "내벽"
                    열관류율합 += 열관 * 0.7 * TOSG(Dr입력면.건축부위면적) * 존수
                Case "외부창"
                    열관류율합 += 열관 * 1 * TOSG(Dr입력면.건축부위면적) * 존수
                    창열관류율합 += 열관 * 1 * TOSG(Dr입력면.건축부위면적) * 존수
                    '투과율합 += Dr입력면.투과율 * TOSG(Dr입력면.건축부위면적) * 존수
                    If Not Dryk Is Nothing Then
                        투과율합 += TOSG(Dryk(0).일사에너지투과율) * TOSG(Dr입력면.건축부위면적) * 존수
                    End If

                Case "내부창"
                    열관류율합 += 열관 * 0.8 * TOSG(Dr입력면.건축부위면적) * 존수
                    창열관류율합 += 열관 * 0.8 * TOSG(Dr입력면.건축부위면적) * 존수
                    '투과율합 += Dr입력면.투과율 * TOSG(Dr입력면.건축부위면적) * 존수
                    If Not Dryk Is Nothing Then
                        투과율합 += TOSG(Dryk(0).일사에너지투과율) * TOSG(Dr입력면.건축부위면적) * 존수
                    End If

            End Select

            If Dryk Is Nothing Then
                '//열관류 선택안된경우
                Select Case Dr입력면.건축부위방식
                    Case "외벽"
                        If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
                            WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
                        End If
                    Case "내벽" '
                        WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
                    Case "외부창"
                        If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
                            WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
                        End If
                    Case "내부창"
                        WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
                End Select
            Else

                Dim 면형태이름 As String = Get_CName("1088", Dryk(0).면형태)
                Select Case 면형태이름
                    Case "외벽(벽체)"
                        WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
                    Case "내벽(벽체)"
                        WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
                    Case "외부창"
                        If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
                            WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
                        End If
                    Case "내부창"
                        WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
                End Select
            End If

            'Debug.WriteLine(Dr입력면.code + ":wall=" + WallArea.ToString() + ",win=" + WindowArea.ToString())
        Next

        '//면적비계산
        Dim r As Decimal = 0
        If (WallArea + WindowArea) <> 0 Then
            r = WindowArea / (WallArea + WindowArea) * 100
        End If

        면적비 = r

        If WallArea + WindowArea = 0 Then
            열관류율 = (0.0F)
        Else
            열관류율 = 열관류율합 / (WallArea + WindowArea)
        End If

        If WindowArea = 0 Then
            창열관류율 = (0.0F)
            일사에너지투과율 = (0.0F)
        Else
            창열관류율 = 창열관류율합 / (WindowArea)
            일사에너지투과율 = 투과율합 / (WindowArea)
        End If

        Return True
    End Function

    ''' <summary>
    ''' 모든입력면의 창,문의 면적비를 계산하여 반환한다(frm_myoun의 Display_info 함수에서 가져옴)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function calc_평균열관류율(건축부위방식() As String) As Decimal
        Dim filter As String = "code <> '0' and 열관류율2 <> '' and 열관류율2 <> '0'"
        'If 방위 <> "" Then filter += " and 방위='" + 방위 + "'"

        '//해당방식을 사용한 열관류율을 모두 찾아서 

        Dim 면데이터() As DS.tbl_myounRow = DSET1.tbl_myoun.Select(filter)

        Dim WindowArea As Decimal = 0
        Dim WallArea As Decimal = 0
        Dim 열관류율합 As Double = 0

        For Each Dr입력면 As DS.tbl_myounRow In 면데이터

            '//이 입력면의 건축부위방식(열관류율테이블)이 일치한다면 그 값을 상요하도록 한다 
            Dim 열관데이터() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" + Dr입력면.열관류율2 + "' and 면형태 <> '' and 면형태 <> '0'")
            If 열관데이터.Length < 1 Then Continue For

            '//열관류율데이터의 형태가 건축부위방식과 맞는지 확인한다
            Dim 공용() As DS.tbl_commonRow = DSET1.tbl_common.Select("gubun = '1088' and code='" + 열관데이터(0).면형태 + "'")
            If 공용.Length < 1 Then Continue For

            Dim 부위찾음 As Boolean = False
            For Each 찾을부위 As String In 건축부위방식
                If 공용(0).name = 찾을부위 Then 부위찾음 = True
            Next

            If Not 부위찾음 Then Continue For

            Dim 존수 As Integer = 1
            Dim 열관 As Single = 0

            'If Dr입력면.열관류율2 = "0" Then Continue For '//열관류율이 연결되어 있어야한다

            Dim Dryk() As DS.tbl_ykRow = Nothing
            If Dr입력면.열관류율2 <> "0" Then
                Dryk = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                If Dryk.Length < 1 Then
                    MsgBox("입력면(" + Dr입력면.설명 + ")의 열관류율 연결값이 열관류율표에 존재하지 않습니다(Code=" + Dr입력면.열관류율2 + ")", MsgBoxStyle.Critical, "확인")
                    Continue For
                End If
                열관 = TOSG(Dryk(0).열관류율)
            Else
                열관 = TOSG(Dr입력면.열관류율)
            End If

            '//이 입력면을 사용하는 존의 정보를 가져온다(오류가 있다면 존의갯수를 1로한다)
            Dim dr존() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("code='" + Dr입력면.존분류 + "'")
            If dr존.Length > 0 Then
                If IsNumeric(dr존(0).입력존의수) Then 존수 = CInt(dr존(0).입력존의수)
            End If


            Select Case Dr입력면.건축부위방식
                Case "외벽"
                    열관류율합 += 열관 * 1 * TOSG(Dr입력면.건축부위면적) * 존수
                Case "내벽"
                    열관류율합 += 열관 * 0.7 * TOSG(Dr입력면.건축부위면적) * 존수
                Case "외부창"
                    열관류율합 += 열관 * 1 * TOSG(Dr입력면.건축부위면적) * 존수
                Case "내부창"
                    열관류율합 += 열관 * 0.8 * TOSG(Dr입력면.건축부위면적) * 존수
            End Select

            WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수

            'If Dryk Is Nothing OrElse Dryk.Length < 1 Then
            '    '//열관류 선택안된경우
            '    Select Case Dr입력면.건축부위방식
            '        Case "외벽"
            '            If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
            '                WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
            '            End If
            '        Case "내벽" '
            '            WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
            '        Case "외부창"
            '            If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
            '                WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
            '            End If
            '        Case "내부창"
            '            WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
            '    End Select
            'Else

            '    Dim 면형태이름 As String = Get_CName("1088", Dryk(0).면형태)
            '    Select Case 면형태이름
            '        Case "외벽(벽체)"
            '            WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
            '            'Case "내벽(벽체)"
            '            '    WallArea = WallArea + TOSG(Dr입력면.건축부위면적) * 존수
            '            'Case "외부창"
            '            '    If Dr입력면.방위 <> "수평" AndAlso Dr입력면.방위 <> "일사없음" AndAlso Dr입력면.방위 <> "(없음)" Then
            '            '        WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
            '            '    End If
            '            'Case "내부창"
            '            '    WindowArea = WindowArea + TOSG(Dr입력면.건축부위면적) * 존수
            '    End Select
            'End If

            'Debug.WriteLine(Dr입력면.code + ":wall=" + WallArea.ToString() + ",win=" + WindowArea.ToString())
        Next

        '//면적비계산
        'Dim r As Decimal = 0
        'If (WallArea + WindowArea) <> 0 Then
        '    r = WindowArea / (WallArea + WindowArea) * 100
        'End If

        '면적비 = r

        If WallArea + WindowArea = 0 Then
            Return (0.0F)
        Else
            Return 열관류율합 / (WallArea + WindowArea)
        End If



    End Function

    Public Function getColCaption(ByVal dt As DataTable) As String()
        Dim Clist(dt.Columns.Count - 1) As String
        For i As Integer = 1 To dt.Columns.Count
            If dt.Columns(i - 1).Caption.ToString <> "" Then Clist(i - 1) = dt.Columns(i - 1).Caption.ToString
        Next
        Return Clist
    End Function

    Public Function getColName(ByVal dt As DataTable) As String()
        Dim Clist(dt.Columns.Count - 1) As String
        For i As Integer = 1 To dt.Columns.Count
            If dt.Columns(i - 1).ColumnName.ToString <> "" Then Clist(i - 1) = dt.Columns(i - 1).ColumnName.ToString
        Next
        Return Clist
    End Function

    Public Function STB(ByVal src As String) As Byte()
        Return System.Text.Encoding.Default.GetBytes(src)
    End Function
    Public Function STB(ByVal src As Byte()) As String
        Return System.Text.Encoding.Default.GetString(src)
    End Function

    '''공용코드의코드반환
    Public Function Get_CCode(ByVal gubun As String, ByVal name As String) As String
        Dim DR() As DS.tbl_commonRow = CType(DSET1.tbl_common.Select("gubun='" & gubun & "' and name='" & name & "'"), DS.tbl_commonRow())
        If DR.GetUpperBound(0) = -1 Then Return ""
        Return DR(0).code
    End Function

    '''공용코드의이름반환
    Public Function Get_CName(ByVal gubun As String, ByVal code As String) As String
        Dim DR() As DS.tbl_commonRow = CType(DSET1.tbl_common.Select("gubun='" & gubun & "' and code='" & code & "'"), DS.tbl_commonRow())
        If DR.GetUpperBound(0) = -1 Then Return ""
        Return DR(0).name
    End Function

    Public Function NVL(ByVal src As Object, Optional ByVal DefVal As Object = "") As Object
        Try
            If src.ToString = "" Or src Is DBNull.Value Then
                Return DefVal
            Else
                Return src
            End If
        Catch ex As Exception
            Return DefVal
        End Try
    End Function

    '''평가결과등급을 반환 (1~10등급까지 있으며  1등급은 +++ ,2등급은 ++ 3등급은 + 4등급부터 1로 시작함)
    Public Function 평가결과등급(주거용 As Integer, 일차에너지소요량합계 As Decimal) As Integer

        If 주거용 <= 10 Then
            Select Case 일차에너지소요량합계
                Case Is < 60
                    Return 1
                Case Is < 90
                    Return 2
                Case Is < 120
                    Return 3
                Case Is < 150
                    Return 4
                Case Is < 190
                    Return 5
                Case Is < 230
                    Return 6
                Case Is < 270
                    Return 7
                Case Is < 320
                    Return 8
                Case Is < 370
                    Return 9
                Case Else
                    Return 10
            End Select
        Else
            Select Case 일차에너지소요량합계
                Case Is < 80
                    Return 1
                Case Is < 140
                    Return 2
                Case Is < 200
                    Return 3
                Case Is < 260
                    Return 4
                Case Is < 320
                    Return 5
                Case Is < 380
                    Return 6
                Case Is < 450
                    Return 7
                Case Is < 520
                    Return 8
                Case Is < 610
                    Return 9
                Case Else
                    Return 10
            End Select
        End If
    End Function


    Public Sub Read_CommonCode(Optional ByVal Version As String = "")
        Work_msg("공용코드 확인중")
        If Version = "" Then
            Dim L As New ArinLogin.ArinLOgin
            Dim VersionInfo As ArinLogin.ArinLOgin.sVersionInfo = Nothing
            VersionInfo = L.Get_LastVersion("C2")   '//버젼을 가져오는데  eco 버젼만 가져오게 바꺼야겟죵 ^^ 구분자를 넣도록 합시닷!
            Version = VersionInfo.Ver
        End If
        Try
            Dim TaC As New DSTableAdapters.tbl_commonTableAdapter
            TaC.Fill(DSET1.tbl_common)
            DSET1.tbl_Desc.Rows(0)("versionc") = Version
            DSET1.AcceptChanges()

            TaC.Fill(DSET2.tbl_common)
            'DSET2.tbl_Desc.Rows(0)("versionc") = Version
            DSET2.AcceptChanges()

        Catch ex As Exception
            MsgBox("공용코드 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
        End Try

        Work_msg("")
    End Sub

    Public Sub Read_ProfileData(Optional ByVal Version As String = "") '//2010.12.06 추가
        Work_msg("표준프로파일 확인중")
        If Version = "" Then
            Dim L As New ArinLogin.ArinLOgin
            Dim VersionInfo As ArinLogin.ArinLOgin.sVersionInfo = Nothing
            VersionInfo = L.Get_LastVersion("P2016")   '//버젼을 가져오는데  eco 버젼만 가져오게 바꺼야겟죵 ^^ 구분자를 넣도록 합시닷! 160327 p2 -> P2016
            Version = VersionInfo.Ver
        End If
        Try
            Dim TaC As New DSTableAdapters.tbl_profileTableAdapter
            TaC.Fill(DSET1.tbl_profile)
            DSET1.tbl_Desc.Rows(0)("versionp") = Version
            DSET1.AcceptChanges()

            TaC.Fill(DSET2.tbl_profile) '//160327 table  PROFILE2 -> PROFILE_2016
            'DSET2.tbl_Desc.Rows(0)("versionp") = Version
            DSET2.AcceptChanges()
        Catch ex As Exception
            MsgBox("표준프로파일 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
        End Try

        'MsgBox(Version)


        Work_msg("")
    End Sub

    Public Sub Read_WeatherData(Optional ByVal Version As String = "")
        Work_msg("기상데이터 확인중")
        Dim Iserror As Boolean = False
        If Version = "" Then
            Dim L As New ArinLogin.ArinLOgin
            Dim VersionInfo As ArinLogin.ArinLOgin.sVersionInfo = Nothing
            VersionInfo = L.Get_LastVersion("W2")   '//버젼을 가져오는데  eco 버젼만 가져오게 바꺼야겟죵 ^^ 구분자를 넣도록 합시닷!
            Version = VersionInfo.Ver
        End If

        DSET1.tbl_weather.Clear()
        DSET1.weather_cha.Clear()
        DSET1.weather_ilsa.Clear()
        DSET1.weather_temp.Clear()
        DSET1.weather_supdo.Clear()
        DSET1.weather_group.Clear()
        DSET1.weather_water.Clear()
        DSET1.weather_river.Clear()
        DSET1.weather_wind.Clear()
        DSET1.AcceptChanges()

        DSET2.tbl_weather.Clear()
        DSET2.weather_cha.Clear()
        DSET2.weather_ilsa.Clear()
        DSET2.weather_temp.Clear()
        DSET2.weather_supdo.Clear()
        DSET2.weather_group.Clear()
        DSET2.weather_water.Clear()
        DSET2.weather_river.Clear()
        DSET2.weather_wind.Clear()
        DSET2.AcceptChanges()

        Try
            Dim TaC As New DSTableAdapters.tbl_weatherTableAdapter
            TaC.Fill(DSET1.tbl_weather)
            TaC.Fill(DSET2.tbl_weather)
        Catch ex As Exception
            MsgBox("기상데이터0 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        Try
            Dim TaC As New DSTableAdapters.weather_chaTableAdapter
            TaC.Fill(DSET1.weather_cha)
            TaC.Fill(DSET2.weather_cha)
        Catch ex As Exception
            MsgBox("기상데이터1 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        Try
            Dim TaC As New DSTableAdapters.weather_ilsaTableAdapter
            TaC.Fill(DSET1.weather_ilsa)
            TaC.Fill(DSET2.weather_ilsa)
        Catch ex As Exception
            MsgBox("기상데이터2 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        Try
            Dim TaC As New DSTableAdapters.weather_supdoTableAdapter
            TaC.Fill(DSET1.weather_supdo)
            TaC.Fill(DSET2.weather_supdo)
        Catch ex As Exception
            MsgBox("기상데이터3 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        Try
            Dim TaC As New DSTableAdapters.weather_tempTableAdapter
            TaC.Fill(DSET1.weather_temp)
            TaC.Fill(DSET2.weather_temp)
        Catch ex As Exception
            MsgBox("기상데이터4 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        Try
            Dim TaC As New DSTableAdapters.weather_groupTableAdapter
            TaC.Fill(DSET1.weather_group)
            TaC.Fill(DSET2.weather_group)
        Catch ex As Exception
            MsgBox("기상데이터(GRP) 업데이트실패" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, "확인")
            Iserror = True
        End Try
        If Iserror = False Then
            DSET1.tbl_Desc.Rows(0)("versionw") = Version
            'DSET2.tbl_Desc.Rows(0)("versionw") = Version
            'MsgBox(Version)
            DSET1.AcceptChanges()
            DSET2.AcceptChanges()
        End If

        Work_msg("")
    End Sub

    Public Function TOIT(ByVal obj As Object) As Integer
        If obj Is DBNull.Value Then
            Return 0
        ElseIf obj.ToString = "" Then
            Return 0
        Else
            If IsNumeric(obj) Then
                Return CInt(obj)
            Else
                MsgBox("[TOIT]숫자형식이 요구되지만 문자가 들어있습니다" & vbCrLf & obj.ToString, MsgBoxStyle.Critical, "확인")
                Return 0
            End If

        End If
    End Function

    Public Function SolarAirHeatingSystem(DSET As DS, ByVal i_count_month As Integer, ByVal i_count_d_mth As Integer, ByVal Dr공조 As DS.tbl_kongjoRow, ByVal V_dot_A_AHU As Decimal, ByVal T_amb As Decimal, ByVal Delta_T_act As Decimal) ' ByVal d_mth As Integer,

        pLog.Add(String.Format(">>SolarAirHeatingSystem 진입 : i_count_month={0}, i_count_d_mth={1}, Dr공조={2}, 외기도입량={3}, theta_e={4}, Delta_T_act={5}", i_count_month, i_count_d_mth, Dr공조.code, V_dot_A_AHU, T_amb, Delta_T_act))

        Dim G_coll, G_tilt, A_coll As Decimal
        Dim e_HX, h_c, v_wind, t, alpha, h_dot_r, eta As Decimal
        Dim Q_dot_coll, Delta_T_avl, T_del_avl, T_del_act, T_del_max As Decimal
        Dim rho As Decimal = 1.225
        Dim C_p As Decimal = 1005 / 3600 '// [J/kg'C] 3600으로 나누어 Wh로 변환 [Wh/kg'C]
        Dim Delta_T_offset As Decimal = 3
        Dim h_sunlight As Decimal = 24
        Dim sigma_s As Decimal = 0.000000056703 '스테판볼츠만 상수
        T_del_max = 20


        '// 사용자 입력항목 : 집열기 면적(A_coll), 단면적, 집열기 표면방사율(e) 
        '// Q_dot_coll 은 외기도입풍량을 집열기 면적으로 나눈 값
        '// h_sunlight 는 주간 운전시간 적용 

        Dim Drow풍속 As DS.weather_windRow = CType(DSET.weather_wind.Select("pcode='" & Calc.Pub.기상데이터.code & "'")(0), DS.weather_windRow)
        v_wind = TOSG(Drow풍속("M" + i_count_month.ToString("00")))

        Dim Dr일사 As DS.weather_ilsaRow

        Select Case Dr공조.집열기방위.Trim
            Case "남" '"남"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 1, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "남동" '"남동"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 2, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "남서" '"남서"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 3, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "동" '"동"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 4, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "서" '"서"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 5, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "북동" '"북동"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 6, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "북서" '"북서"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 7, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24
            Case "북" '"북"
                Dr일사 = CType(DSET.weather_ilsa.Select("pcode='" & Calc.Pub.기상데이터.code & "' and code='" & Format(1 + 8, "0000") & "'")(0), DS.weather_ilsaRow)
                G_tilt = TOSG(Dr일사("M" & Format(i_count_month, "00"))) * 24

        End Select


        A_coll = TOSG(Dr공조.집열기면적)
        alpha = TOSG(Dr공조.집열기방사율)
        Q_dot_coll = V_dot_A_AHU / A_coll
        G_coll = G_tilt * A_coll '// * f_op 집열기 가동계수는 G_tilt 에 포함

        e_HX = 1 - 5 * Q_dot_coll
        h_c = 6.0 + 4.0 * v_wind - 76 * Q_dot_coll
        t = alpha * G_tilt / (rho * C_p * Q_dot_coll * e_HX + 4 * alpha * sigma_s * T_amb ^ 3 + h_c)  ' e는 alpha 로 공유
        h_dot_r = 4 * alpha * sigma_s * T_amb ^ 2 * (T_amb + 1.6 * t) ' e는 alpha 로 공유
        eta = alpha / (1 + (h_dot_r + h_c) / (rho * C_p * Q_dot_coll * e_HX))


        Delta_T_avl = (eta * G_tilt) / (Q_dot_coll * rho * C_p * h_sunlight)
        T_del_avl = (T_amb + Delta_T_offset) + Delta_T_avl
        T_del_act = Math.Min(T_del_max, T_del_avl)
        Delta_T_act = Math.Max(T_del_act - (T_amb + Delta_T_offset), 0)

        'f_util = Delta_T_act / Delta_T_avl

        'Q_sol = Sigma(eta * G_coll * f_util)

        Return Delta_T_act

    End Function



    Public Function Get_V_dot_A_AHU(tbl_profile As DS.tbl_profileDataTable, tbl_zone As DS.tbl_zoneDataTable, Dr공조Code As String) As Decimal


        Dim ZoneListKongjo() As DS.tbl_zoneRow = tbl_zone.Select("code<>'0' and 냉난방공조처리시스템 = '" + Dr공조Code + "'", "code")
        Dim V_dot_A_AHU As Decimal = 0
        For Each DrZonbyKongjo As DS.tbl_zoneRow In ZoneListKongjo

            Dim Dr프로필2 As DS.tbl_profileRow = CType(tbl_profile.Select("code='" & DrZonbyKongjo.프로필 & "'")(0), DS.tbl_profileRow)
            V_dot_A_AHU += TOSG(DrZonbyKongjo.면적) * TOSG(DrZonbyKongjo.입력존의수) * TOSG(Dr프로필2.최소도입외기량)
        Next
        Return V_dot_A_AHU
    End Function
    Public Function TOSG(ByVal obj As Object) As Decimal
        If obj Is DBNull.Value Then
            Return 0
        ElseIf obj.ToString = "" Then
            Return 0
        Else
            If IsNumeric(obj) Then
                Try
                    Return CDec(obj)
                Catch ex As Exception
                    MsgBox("[TOSG]에서 '" & obj & "'")
                    Return 0
                End Try

            Else
                MsgBox("[TOSG]숫자형식이 요구되지만 문자가 들어있습니다" & vbCrLf & obj.ToString, MsgBoxStyle.Critical, "확인")
                Return 0
            End If
        End If
    End Function
    Public Function TOST(ByVal obj As Object) As String
        If obj Is DBNull.Value Then
            Return ""
        Else
            Return CStr(obj)
        End If
    End Function


    ''' <summary>
    ''' 데이터를 모두 되돌립니다.
    ''' </summary>
    ''' <param name="SrcDs"></param>
    ''' <param name="DisplayLabel"></param>
    ''' <remarks></remarks>
    Public Sub Data_Cancel(ByRef SrcDs As DataTable, Optional ByVal DisplayLabel As ToolStripStatusLabel = Nothing)
        Dim Change As Integer
        Try
            Change = SrcDs.GetChanges.Rows.Count
        Catch ex As Exception
            Change = 0
        End Try

        If Change > 0 Then
            If MsgBox("변경된 내용을 취소하시겠습니까?", CType(MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, MsgBoxStyle), "확인") = MsgBoxResult.Ok Then
                SrcDs.RejectChanges()
                If Not DisplayLabel Is Nothing Then
                    NOTICE("변경된 내용이 취소되었습니다", DisplayLabel, Color.Red)
                Else
                    MsgBox("변경된 내용이 취소되었습니다", MsgBoxStyle.Information, "확인")
                End If
            Else
                If Not DisplayLabel Is Nothing Then NOTICE("취소되었습니다", DisplayLabel, Color.Blue)
            End If
        End If
        If Not DisplayLabel Is Nothing Then
            NOTICE("변경된 내용이 없습니다.", DisplayLabel, Color.Red)
        Else
            MsgBox("변경된 내용이 없습니다", MsgBoxStyle.Information, "확인")
        End If
    End Sub

    Public Function EndEdit(ByRef bs As BindingSource) As Boolean
        Try
            bs.EndEdit()
        Catch ex As System.Data.NoNullAllowedException
            MsgBox("반드시입력해야할 데이터가 없습니다" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "입력오류")
            Return False
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "처리되지않은 오류발생")
            Return False
        End Try
        Return True
    End Function

    Public Sub Check_Modify(ByRef DT As DataTable, Optional ByVal prompt As Boolean = True)
        Dim Cnt As Integer
        Try
            Cnt = DT.GetChanges.Rows.Count
        Catch ex As Exception
            Cnt = 0
        End Try

        If Cnt < 1 Then
            NOTICE("변경된 내용이 없습니다", Nothing, Color.Red)
            Return
        End If
        If prompt Then
            If MsgBox("변경된 데이터를 저장하시겠습니까?", CType(MsgBoxStyle.Information + MsgBoxStyle.OkCancel, MsgBoxStyle), "저장확인") <> MsgBoxResult.Ok Then Return
        End If
        Try
            DT.AcceptChanges()    '//Set All Green        
            NOTICE("저장완료", Nothing, Color.Blue)
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
        Catch ex As Exception
            MsgBox("데이터베이스 업데이트중 오류가 발생했습니다" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Critical, "ERROR-")
            NOTICE("저장 실패!", Nothing, Color.Red)
        Finally
            'view1.ActiveSheet.GetDataView(True) '//화면을 갱신한다.
        End Try
    End Sub


    '//지정된개체내의 컨트롤의 값을 초기화한다.
    Public Sub Clear_Control(ByVal Ctl As Control)
        Ctl.Focus()
        For Each C As Control In Ctl.Controls
            MsgBox(C.GetType.ToString)
            If C.Controls.Count > 1 Then
                Clear_Control(C)
            Else
                If C.GetType.ToString.ToUpper.IndexOf("TEXTBOX") <> -1 OrElse _
                 C.GetType.ToString.ToUpper.IndexOf("MYTB") <> -1 OrElse _
                  C.GetType.ToString.ToUpper.IndexOf("NTB") <> -1 Then
                    If CType(C, TextBox).ReadOnly = False Then CType(C, TextBox).Text = ""
                ElseIf C.GetType.ToString.ToUpper.IndexOf("COMBOBOX") <> -1 OrElse _
                C.GetType.ToString.ToUpper.IndexOf("MYCMB") <> -1 Then
                    'MsgBox("cb")
                    CType(C, ComboBox).SelectedIndex = -1
                End If

            End If
        Next
    End Sub

    Public Sub Work_msg(Optional ByVal P_m As String = "잠시만 기다려주세요", Optional ByVal pbar As Boolean = False)
        If P_m = "" Then
            Frm_Work.Dispose()
        Else
            If Frm_Work.Visible = False Then Frm_Work.Visible = True
            If Frm_Work.ProgressBar1.Visible <> pbar Then Frm_Work.ProgressBar1.Visible = pbar
            Frm_Work.Label1.Text = P_m
            My.Application.DoEvents()
        End If
    End Sub


    '''화면에메세지를 표시할때사용한다.    
    Public Sub Work_msg_timer(Optional ByVal P_m As String = "잠시만 기다려주세요", Optional ByVal time As Short = 5)
        Frm_Warning.Left = CInt(MdiMain.Left + ((MdiMain.Width - Frm_Warning.Width) / 2))
        Frm_Warning.Top = CInt(MdiMain.Top + ((MdiMain.Height - Frm_Warning.Height) / 2))
        Frm_Warning.Term = time
        Frm_Warning.Second = time
        Frm_Warning.Label1.Text = P_m
        Frm_Warning.Timer1.Enabled = True
        Frm_Warning.Show()
        My.Application.DoEvents()
    End Sub

    Public Sub Work_plus()
        If Frm_Work.ProgressBar1.Visible = False Then Frm_Work.ProgressBar1.Visible = True
        Frm_Work.ProgressBar1.Value += 1
        My.Application.DoEvents()
    End Sub

    Public Sub INitRow(ByVal Ctl As Control.ControlCollection)
        For Each C As Control In Ctl
            If C.Controls.Count > 1 Then
                INitRow(C.Controls)
            Else
                If C.GetType.ToString.ToUpper.IndexOf("MYTB") <> -1 Then
                    If CType(C, MyTb).Text = "" Then CType(C, MyTb).Text = "0"
                ElseIf C.GetType.ToString.ToUpper.IndexOf("MYCMB") <> -1 Then
                    If CType(C, MyCmb).Text = "" AndAlso CType(C, MyCmb).Items.Count > 0 Then CType(C, MyCmb).SelectedIndex = 0
                End If
            End If
        Next
    End Sub

    Public Function DeCryptArea(ByRef data As Byte(), Optional ByVal pxorkey() As Byte = Nothing) As Byte()
        Dim out(data.Length - 1) As Byte
        Dim pos As Integer = 0
        Dim i As Long = 0

        '//처음4바이트확인해서 보낸다.
        Dim XorKey() As Byte
        If pxorkey Is Nothing Then   '//없으면 자동검출
            XorKey = New Byte() {data(0), data(1), data(2), data(3)}
        Else  '//있으면 그걸 사용한다.
            XorKey = New Byte() {pxorkey(0), pxorkey(1), pxorkey(2), pxorkey(3)}
        End If

        For Each b As Byte In data
            out(i) = DeCryptByte(b, pos, XorKey)
            pos += 1
            i += 1
            If pos > 3 Then pos = 0
        Next
        Return out
    End Function
    Public Function DeCryptByte(ByVal num As Byte, ByVal column As Integer, Optional ByVal a() As Byte = Nothing) As Byte
        If a Is Nothing Then a = New Byte() {&HAC, &H29, &H55, &H42}
        Return (num Xor a(column))
    End Function

    Public Function EnCryptByte(ByVal num As Byte, ByVal column As Integer, Optional ByVal a() As Byte = Nothing) As Byte
        If a Is Nothing Then a = New Byte() {&HAC, &H29, &H55, &H42}
        Return (num Xor a(column))
    End Function
End Module
