Public Class Report_pyonga

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

    '''변경된내용을적용한다.
    Public Overrides Function AcceptChanged() As Boolean

        Return True
    End Function

    '''변경된내용이있다면 취소한다.
    Public Overrides Function RejectChanged() As Boolean

        Return True
    End Function

    '''데이터에변형이있었는가?
    Public Overrides Function HasChanged() As Boolean
        Return False
    End Function

#End Region


    Private Sub Frm_v20091231_Result_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.DSR.TReqUse.Merge(DSETR1.TReqUse)
        Me.DS.tbl_Desc.Merge(DSET1.tbl_Desc)

        MakeGraphTable()
        항목별평가결과()

        '//주거용건축물?
        Dim 건축물데이터 As DS.tbl_DescRow = DSET1.tbl_Desc.Rows(0)
        Dim 주거용 As Integer = CInt(건축물데이터.isjugo)

        Dim param As New Microsoft.Reporting.WinForms.ReportParameter("PTitle", Me.DS.tbl_Desc.Rows(0)("buildname").ToString())
        Dim param2 As New Microsoft.Reporting.WinForms.ReportParameter("PGrade", 평가결과등급(주거용, 일차에너지소요량합계))
        Dim param3 As New Microsoft.Reporting.WinForms.ReportParameter("PNewUse", Me.신재생에너지)
        Dim param4 As New Microsoft.Reporting.WinForms.ReportParameter("PP2CO2SUM", Me.단위면적당CO2배출량합계)
        Dim param5 As New Microsoft.Reporting.WinForms.ReportParameter("PCompany", DSET1.tbl_Desc.Rows(0)("인증기관").ToString())


        Dim param11 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param12 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param13 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param14 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param15 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param16 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param17 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param18 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param19 As Microsoft.Reporting.WinForms.ReportParameter
        Dim param20 As Microsoft.Reporting.WinForms.ReportParameter

        '//평가범위(주거용/비
        If 주거용 <= 10 Then
            param11 = New Microsoft.Reporting.WinForms.ReportParameter("PG1", "60미만")
            param12 = New Microsoft.Reporting.WinForms.ReportParameter("PG2", "60이상 90미만")
            param13 = New Microsoft.Reporting.WinForms.ReportParameter("PG3", "90이상 120미만")
            param14 = New Microsoft.Reporting.WinForms.ReportParameter("PG4", "120이상 150미만")
            param15 = New Microsoft.Reporting.WinForms.ReportParameter("PG5", "150이상 190미만")
            param16 = New Microsoft.Reporting.WinForms.ReportParameter("PG6", "190이상 230미만")
            param17 = New Microsoft.Reporting.WinForms.ReportParameter("PG7", "230이상 270미만")
            param18 = New Microsoft.Reporting.WinForms.ReportParameter("PG8", "270이상 320미만")
            param19 = New Microsoft.Reporting.WinForms.ReportParameter("PG9", "320이상 370미만")
            param20 = New Microsoft.Reporting.WinForms.ReportParameter("PG10", "370이상 420미만")
        Else
            param11 = New Microsoft.Reporting.WinForms.ReportParameter("PG1", "80미만")
            param12 = New Microsoft.Reporting.WinForms.ReportParameter("PG2", "80이상 140미만")
            param13 = New Microsoft.Reporting.WinForms.ReportParameter("PG3", "140이상 200미만")
            param14 = New Microsoft.Reporting.WinForms.ReportParameter("PG4", "200이상 260미만")
            param15 = New Microsoft.Reporting.WinForms.ReportParameter("PG5", "260이상 320미만")
            param16 = New Microsoft.Reporting.WinForms.ReportParameter("PG6", "320이상 380미만")
            param17 = New Microsoft.Reporting.WinForms.ReportParameter("PG7", "380이상 450미만")
            param18 = New Microsoft.Reporting.WinForms.ReportParameter("PG8", "450이상 520미만")
            param19 = New Microsoft.Reporting.WinForms.ReportParameter("PG9", "520이상 610미만")
            param20 = New Microsoft.Reporting.WinForms.ReportParameter("PG10", "610이상 700미만")
        End If


        Dim params As New Microsoft.Reporting.WinForms.ReportParameterCollection()
        params.Add(param)
        params.Add(param2)
        params.Add(param3)
        params.Add(param4)
        params.Add(param5)

        params.Add(param11)
        params.Add(param12)
        params.Add(param13)
        params.Add(param14)
        params.Add(param15)
        params.Add(param16)
        params.Add(param17)
        params.Add(param18)
        params.Add(param19)
        params.Add(param20)

        Me.ReportViewer1.LocalReport.SetParameters(params)
        Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent
        Me.ReportViewer1.ZoomPercent = 100
        Me.ReportViewer1.RefreshReport()
    End Sub

   

    '//항목별평가결과
    Private Sub 항목별평가결과()
        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 = "외벽(벽체)" 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 = "외벽(지붕)" 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 = "외벽(바닥)" 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 = "외벽(벽체)" 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 = "외벽(지붕)" 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 = "외벽(바닥)" 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() + "(" + Max_냉방.ToString() + ")"
            If Sum_지열히트펌프용량_난방 > 0 Then
                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
        For Each cdr As DS.tbl_ykRow In DSET1.tbl_yk.Select("code <> '0'")
            Dim 면코드 As String = cdr.면형태
            If 면코드 = "" Then Continue For
            Dim 면이름 As String = Get_CName("1088", 면코드)
            If 면이름 = "" Then Continue For
            If 면이름.IndexOf("외부창") <> -1 Then    '//이름에 외부창이잇는것을 찾음
                NDr.창호종류 = cdr.창호세부설명
                NDr.창호값 = 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
                    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


    Private 일차에너지소요량합계 As Decimal = 0
    Private Sub MakeGraphTable()
        If DSR.TReqUse.Rows.Count < 1 Then Return '//요구&사용량이 계산된경우에만 사용한다.


       



        '//1차에너지소요량값 구분별로기록한다.
        Dim DrE1 As DSR.Pyonga_1USERow
        DrE1 = Me.DSR.Pyonga_1USE.NewPyonga_1USERow
        DrE1.종류 = "난방" : DrE1.값 = Result1.일차E소요량(0).난방면적
        DSR.Pyonga_1USE.AddPyonga_1USERow(DrE1)

        DrE1 = Me.DSR.Pyonga_1USE.NewPyonga_1USERow
        DrE1.종류 = "냉방" : DrE1.값 = Result1.일차E소요량(0).냉방면적
        DSR.Pyonga_1USE.AddPyonga_1USERow(DrE1)

        DrE1 = Me.DSR.Pyonga_1USE.NewPyonga_1USERow
        DrE1.종류 = "급탕" : DrE1.값 = Result1.일차E소요량(0).급탕면적
        DSR.Pyonga_1USE.AddPyonga_1USERow(DrE1)

        DrE1 = Me.DSR.Pyonga_1USE.NewPyonga_1USERow
        DrE1.종류 = "조명" : DrE1.값 = Result1.일차E소요량(0).조명면적
        DSR.Pyonga_1USE.AddPyonga_1USERow(DrE1)

        DrE1 = Me.DSR.Pyonga_1USE.NewPyonga_1USERow
        DrE1.종류 = "환기" : DrE1.값 = Result1.일차E소요량(0).환기면적
        DSR.Pyonga_1USE.AddPyonga_1USERow(DrE1)




        '//등급용-131021
        Dim 난방에너지, 냉방에너지, 급탕에너지, 조명에너지, 환기에너지 As Single
        If (Result1.사용면적.H_WF = 0) Then
            난방에너지 = 0
        Else
            난방에너지 = Result1.일차E소요량(0).난방면적2 * Result1.사용면적.H / Result1.사용면적.H_WF
        End If
        If (Result1.사용면적.C_WF = 0) Then
            냉방에너지 = 0
        Else
            냉방에너지 = TOSG(Result1.일차E소요량(0).냉방면적 * Result1.사용면적.C / Result1.사용면적.C_WF)
        End If
        If (Result1.사용면적.W_WF = 0) Then
            급탕에너지 = 0
        Else
            급탕에너지 = Result1.일차E소요량(0).급탕면적2 * Result1.사용면적.W / Result1.사용면적.W_WF
        End If
        If (Result1.사용면적.L_WF = 0) Then
            조명에너지 = 0
        Else
            조명에너지 = Result1.일차E소요량(0).조명면적 * Result1.사용면적.L / Result1.사용면적.L_WF
        End If
        If (Result1.사용면적.V_WF = 0) Then
            환기에너지 = 0
        Else
            환기에너지 = Result1.일차E소요량(0).환기면적 * Result1.사용면적.V / Result1.사용면적.V_WF
        End If
        일차에너지소요량합계 = 냉방에너지 + 난방에너지 + 급탕에너지 + 조명에너지 + 환기에너지
        '일차에너지소요량합계 = Result1.일차E소요량(0).난방면적 + Result1.일차E소요량(0).냉방면적 _
        '                     + Result1.일차E소요량(0).급탕면적 + Result1.일차E소요량(0).조명면적 _
        '                     + Result1.일차E소요량(0).환기면적

      


        '//연간에너지소요량값 구분별로기록한다.
        Dim DrU1 As DSR.Pyonga_USERow
        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "난방" : DrU1.값 = Result1.E소요량(0).난방면적
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)

        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "냉방" : DrU1.값 = Result1.E소요량(0).냉방면적
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)

        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "급탕" : DrU1.값 = Result1.E소요량(0).급탕면적
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)

        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "조명" : DrU1.값 = Result1.E소요량(0).조명면적
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)

        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "환기" : DrU1.값 = Result1.E소요량(0).환기면적
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)

        DrU1 = Me.DSR.Pyonga_USE.NewPyonga_USERow
        DrU1.종류 = "신재생" : DrU1.값 = Me.신재생에너지
        DSR.Pyonga_USE.AddPyonga_USERow(DrU1)
        '//소요량 총합에는 신재생은 제거한다.


        '//연간에너지요구량값 구분별로기록한다.
        Dim DrR1 As DSR.Pyonga_REQRow
        DrR1 = Me.DSR.Pyonga_REQ.NewPyonga_REQRow
        DrR1.종류 = "난방" : DrR1.값 = Result1.E요구량(0).난방면적
        DSR.Pyonga_REQ.AddPyonga_REQRow(DrR1)

        DrR1 = Me.DSR.Pyonga_REQ.NewPyonga_REQRow
        DrR1.종류 = "냉방" : DrR1.값 = Result1.E요구량(0).냉방면적
        DSR.Pyonga_REQ.AddPyonga_REQRow(DrR1)

        DrR1 = Me.DSR.Pyonga_REQ.NewPyonga_REQRow
        DrR1.종류 = "급탕" : DrR1.값 = Result1.E요구량(0).급탕면적
        DSR.Pyonga_REQ.AddPyonga_REQRow(DrR1)

        DrR1 = Me.DSR.Pyonga_REQ.NewPyonga_REQRow
        DrR1.종류 = "조명" : DrR1.값 = Result1.E요구량(0).조명면적
        DSR.Pyonga_REQ.AddPyonga_REQRow(DrR1)

        '//변경사항을저장
        DSR.AcceptChanges()

    End Sub
    Function 단위면적당CO2배출량합계() As Decimal
        Dim DR() As DSR.TReqUseRow = DSR.TReqUse.Select("GRP='400' and DESC='단위면적당 CO2 배출량'")
        If DR.GetUpperBound(0) = -1 Then Return 0
        Return DR(0).M00
    End Function
    Function 신재생에너지() As Decimal



        Dim Sum As Decimal = (Result1.생산E(0).태양광전력생산량 + Result1.생산E(0).풍력전력생산량 + Result1.생산E(0).신재생열병합전력생산량) / (Result1.일차E소요량(0).난방전력 + Result1.일차E소요량(0).냉방전력 + Result1.일차E소요량(0).급탕전력 + Result1.일차E소요량(0).조명전력 + Result1.일차E소요량(0).환기전력)

        Dim 난방 As Decimal = Sum * Result1.일차E소요량(0).난방전력  '//아마게산이안도잇으니 여기값들이 0이잇을거에요.
        Dim 냉방 As Decimal = Sum * Result1.일차E소요량(0).냉방전력
        Dim 조명 As Decimal = Sum * Result1.일차E소요량(0).조명전력
        Dim 급탕 As Decimal = Sum * Result1.일차E소요량(0).급탕전력
        Dim 환기 As Decimal = Sum * Result1.일차E소요량(0).환기전력

        Dim 난방면적 As Decimal = 0
        Dim 냉방면적 As Decimal = 0
        Dim 조명면적 As Decimal = 0
        Dim 급탕면적 As Decimal = 0
        Dim 환기면적 As Decimal = 0

        If Result1.사용면적.H <> 0 Then 난방면적 = TOSG(IIf(난방 = 0, 0, 난방 / Result1.사용면적.H))
        If Result1.사용면적.C <> 0 Then 냉방면적 = TOSG(IIf(냉방 = 0, 0, 냉방 / Result1.사용면적.C))
        If Result1.사용면적.L <> 0 Then 조명면적 = TOSG(IIf(조명 = 0, 0, 조명 / Result1.사용면적.L))
        If Result1.사용면적.W <> 0 Then 급탕면적 = TOSG(IIf(급탕 = 0, 0, 급탕 / Result1.사용면적.W))
        If Result1.사용면적.V <> 0 Then 환기면적 = TOSG(IIf(환기 = 0, 0, 환기 / Result1.사용면적.V))


        Dim 면적 As Decimal = 난방면적 + 냉방면적 + 조명면적 + 급탕면적 + 환기면적

        '=-SUM(계산결과!G108:G109)-계산결과!F42-계산결과!F48-계산결과!F51-계산결과!F56-계산결과!F59

        'F42=IF($G$15=0,0,F38/$G$15)
        'f38=(G104)/(SUM(H76:S76)+SUM(H85:S85)+SUM(H93:S93)+SUM(H97:S97)+SUM(H101:S101))*SUM(H76:S76)
        'g15=난방면적

        'f48=IF($G$20=0,0,F44/$G$20)
        'f44=(G104)/(SUM(H76:S76)+SUM(H85:S85)+SUM(H93:S93)+SUM(H97:S97)+SUM(H101:S101))*SUM(H85:S85)
        'g20=냉방면적


        신재생에너지 = -1 * (Result1.생산E(0).면적당생산량태양열 + Result1.생산E(0).면적당생산량수열 + Result1.생산E(0).면적당생산량지열 + Result1.생산E(0).신재생면적당열생산량) - 면적
        Return 신재생에너지
    End Function


End Class