Public Class Report_검토서

    Dim T As String = "검토서"


    Dim 신재생에너지 As Decimal = 0
    Dim 난방에너지 As Decimal = 0
    Dim 냉방에너지 As Decimal = 0
    Dim 급탕에너지 As Decimal = 0
    Dim 조명에너지 As Decimal = 0
    Dim 환기에너지 As Decimal = 0
    Dim 합계 As Decimal = 0


    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 param1 As New Microsoft.Reporting.WinForms.ReportParameter("p_heat", 난방에너지.ToString("N1"))
        Dim param2 As New Microsoft.Reporting.WinForms.ReportParameter("p_cool", 냉방에너지.ToString("N1"))
        Dim param3 As New Microsoft.Reporting.WinForms.ReportParameter("p_fan", 환기에너지.ToString("N1"))
        Dim param5 As New Microsoft.Reporting.WinForms.ReportParameter("p_light", 조명에너지.ToString("N1"))
        Dim param6 As New Microsoft.Reporting.WinForms.ReportParameter("p_kup", 급탕에너지.ToString("N1"))
        Dim param7 As New Microsoft.Reporting.WinForms.ReportParameter("p_sum", 합계.ToString("N1"))

        Dim 큰프로파일 As String = ""
        Dim 바닥면적 As Single = 0
        For Each dr As DS.tbl_myounRow In DSET1.tbl_myoun.Select("존분류 <> '0' and 존분류 <> ''")
            If dr.바닥면적 > 바닥면적 Then
                바닥면적 = dr.바닥면적
                큰프로파일 = dr.존분류
            End If
        Next
        Dim msg As String = ""
        If 큰프로파일 = "" Then
            msg = ""
        Else
            Dim 프로파일데이터 As DS.tbl_profile_odRow = DSET1.tbl_profile_od.Select("code ='" + 큰프로파일 + "'")(0)
            If CInt(큰프로파일) < 1 Then
                msg = "[ v ] 주거용 (" + 프로파일데이터.설명 + ")"
            Else
                msg = "[ v ] 주거용 외 ( " + 프로파일데이터.설명 + " )"
            End If
        End If

        Dim param8 As New Microsoft.Reporting.WinForms.ReportParameter("p_주용도", msg)

        Dim 건물용도 As Integer = CInt(DSET1.tbl_myoun.Select("존분류 <> '0'")(0)("존분류").ToString())
        If 건물용도 < 10 Then   '//주거
            If 합계 <= 190 Then
                msg = "[ v ] 적합    [ ] 부적합"
            Else
                msg = "[  ] 적합    [ v ] 부적합"
            End If
        Else '//비주고
            If 합계 <= 260 Then
                msg = "[ v ] 적합    [ ] 부적합"
            Else
                msg = "[  ] 적합    [ v ] 부적합"
            End If
        End If
        Dim param9 As New Microsoft.Reporting.WinForms.ReportParameter("p_1차적합여부", msg)

        '//r간접:내벽(3,4,5) , 직접:외벽(0,1,2,)
        '//벽체(0,3),지붕(1,4),바닥(2,5),창(7,8) 계산 (열관류율)

        '//벽체(0,3)
        Dim 직접_벽체 As Single = 0
        Dim 간접_벽체 As Single = 0
        Dim 직접_지붕 As Single = 0
        Dim 간접_지붕 As Single = 0
        Dim 직접_바닥 As Single = 0
        Dim 간접_바닥 As Single = 0
        Dim 직접_창 As Single = 0
        Dim 간접_창 As Single = 0
        Dim 평균열관류율 As Single = 0
        Dim 전체면적 As Single = 0
        msg = ""
        For Each dr면 As DS.tbl_myounRow In DSET1.tbl_myoun.Select("code <> '0'")
            Dim 열관류코드 As String = dr면.열관류율2
            If 열관류코드.Trim = "" Then Continue For

            Dim find As Boolean = False
            Dim multi As Single = 1
            For Each dr열 As DS.tbl_ykRow In DSET1.tbl_yk.Select("code='" + 열관류코드 + "'")
                Select Case CInt(dr열.면형태)
                    Case 0  '//외벽,벽체
                        If TOSG(T, dr열.열관류율) > 직접_벽체 Then 직접_벽체 = TOSG(T, dr열.열관류율)
                        find = True
                    Case 3  '//내벽,벽체
                        If TOSG(T, dr열.열관류율) > 간접_벽체 Then 간접_벽체 = TOSG(T, dr열.열관류율)
                        find = True
                        multi = 0.8
                    Case 1  '//외벽,지붕
                        If TOSG(T, dr열.열관류율) > 직접_지붕 Then 직접_지붕 = TOSG(T, dr열.열관류율)
                    Case 4 '//내벽,지붕
                        If TOSG(T, dr열.열관류율) > 간접_지붕 Then 간접_지붕 = TOSG(T, dr열.열관류율)
                    Case 2  '//외벽,바닥
                        If TOSG(T, dr열.열관류율) > 직접_바닥 Then 직접_바닥 = TOSG(T, dr열.열관류율)
                    Case 5  '//내벽,바닥
                        If TOSG(T, dr열.열관류율) > 간접_바닥 Then 간접_바닥 = TOSG(T, dr열.열관류율)
                    Case 7  '//외부창
                        If TOSG(T, dr열.열관류율) > 직접_창 Then 직접_창 = TOSG(T, dr열.열관류율)
                        find = True
                    Case 8  '//내부창
                        If TOSG(T, dr열.열관류율) > 간접_창 Then 간접_창 = TOSG(T, dr열.열관류율)
                        find = True
                        multi = 0.7
                End Select
            Next
            If find Then
                평균열관류율 += TOSG(T, dr면.열관류율 * multi) * TOSG(T, dr면.건축부위면적)
                전체면적 += TOSG(T, dr면.건축부위면적)
            End If
        Next
        평균열관류율 = 평균열관류율 / 전체면적


        msg = ""
        If 직접_벽체 <> 0 Then msg = "직접(" + 직접_벽체.ToString() + ")"
        If 간접_벽체 <> 0 Then msg += IIf(msg = "", "", " , ") + "간접(" + 간접_벽체.ToString() + ")"
        Dim param10 As New Microsoft.Reporting.WinForms.ReportParameter("p_yk1", msg)

        msg = ""
        If 직접_지붕 <> 0 Then msg = "직접(" + 직접_지붕.ToString() + ")"
        If 간접_지붕 <> 0 Then msg += IIf(msg = "", "", " , ") + "간접(" + 간접_지붕.ToString() + ")"
        Dim param11 As New Microsoft.Reporting.WinForms.ReportParameter("p_yk2", msg)

        msg = ""
        If 직접_바닥 <> 0 Then msg = "직접(" + 직접_바닥.ToString() + ")"
        If 간접_바닥 <> 0 Then msg += IIf(msg = "", "", " , ") + "간접(" + 간접_바닥.ToString() + ")"
        Dim param12 As New Microsoft.Reporting.WinForms.ReportParameter("p_yk3", msg)

        msg = ""
        If 직접_창 <> 0 Then msg = "직접(" + 직접_창.ToString() + ")"
        If 간접_창 <> 0 Then msg += IIf(msg = "", "", " , ") + "간접(" + 간접_창.ToString() + ")"
        Dim param13 As New Microsoft.Reporting.WinForms.ReportParameter("p_yk4", msg)

        Dim param14 As New Microsoft.Reporting.WinForms.ReportParameter("p_yksum", 평균열관류율.ToString("N3"))


        '//
        Dim 온열원설비종류 As String = ""
        Dim 보일러정격출력 As Single = 0
        Dim 보일러효율 As Single = 0
        Dim 보일러정격출력합 As Single = 0
        Dim 순환수용펌프동력 As Single = 0
        For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0'")
            If dr.난방급탕구분.IndexOf("난방") <> -1 Then
                If dr.보일러정격출력 > 보일러정격출력 Then
                    보일러정격출력 = dr.보일러정격출력
                    온열원설비종류 = dr.열생산기기방식
                    보일러효율 = dr.정격보일러효율
                    순환수용펌프동력 += TOSG(T, dr.펌프동력)
                End If
                보일러정격출력합 += TOSG(T, dr.보일러정격출력)
            End If
        Next
        Dim param15 As New Microsoft.Reporting.WinForms.ReportParameter("p_온열원설비종류", 온열원설비종류)
        Dim param16 As New Microsoft.Reporting.WinForms.ReportParameter("p_온열원설비합계", 보일러정격출력합)
        Dim param17 As New Microsoft.Reporting.WinForms.ReportParameter("p_온열원설비효율", 보일러효율)


        Dim 냉동기방식 As String = ""
        Dim 냉동기용량 As Single = 0
        Dim 냉동기효율 As Single = 0
        Dim 냉동기합 As Single = 0
        For Each dr As DS.tbl_nangbangkikiRow In DSET1.tbl_nangbangkiki.Select("code <> '0'")
            If dr.냉동기용량 > 냉동기용량 Then
                냉동기용량 = dr.냉동기용량
                냉동기방식 = dr.냉동기방식
                냉동기효율 = dr.열성능비
            End If
            냉동기합 += TOSG(T, dr.냉동기용량)
        Next
        Dim param18 As New Microsoft.Reporting.WinForms.ReportParameter("p_냉열원설비종류", 냉동기방식)
        Dim param19 As New Microsoft.Reporting.WinForms.ReportParameter("p_냉열원설비합계", 냉동기합)
        Dim param20 As New Microsoft.Reporting.WinForms.ReportParameter("p_냉열원설비효율", 냉동기효율)


        '//급탕
        Dim 급탕용펌프동력 As Single = 0
        Dim 급탕방식 As String = ""
        Dim 급탕용량 As Single = 0
        Dim 급탕효율 As Single = 0
        Dim 급탕용량합 As Single = 0
        For Each dr As DS.tbl_nanbangkikiRow In DSET1.tbl_nanbangkiki.Select("code <> '0'")
            If dr.난방급탕구분.IndexOf("난방") = -1 AndAlso dr.난방급탕구분.IndexOf("급탕") <> -1 Then
                If dr.보일러정격출력 > 급탕용량 Then
                    급탕용량 = dr.보일러정격출력
                    급탕방식 = dr.열생산기기방식
                    급탕효율 = dr.정격보일러효율
                    급탕용펌프동력 = TOSG(T, dr.펌프동력)
                End If
                급탕용량합 += TOSG(T, dr.보일러정격출력)
            End If
        Next
        Dim param21 As New Microsoft.Reporting.WinForms.ReportParameter("p_급탕설비종류", 급탕방식)
        Dim param22 As New Microsoft.Reporting.WinForms.ReportParameter("p_급탕설비합계", 급탕용량합)
        Dim param23 As New Microsoft.Reporting.WinForms.ReportParameter("p_급탕설비효율", 급탕효율)

        '//공조(반송설비)
        Dim 송풍기동력 As Single = 0
        For Each dr As DS.tbl_kongjoRow In DSET1.tbl_kongjo.Select("code <> '0'")
            송풍기동력 += dr.배기팬동력 + dr.급기팬동력
        Next

        Dim param24 As New Microsoft.Reporting.WinForms.ReportParameter("p_순환수용펌프동력", 순환수용펌프동력)
        Dim param25 As New Microsoft.Reporting.WinForms.ReportParameter("p_급탕용펌프동력", 급탕용펌프동력)
        Dim param26 As New Microsoft.Reporting.WinForms.ReportParameter("p_송풍기동력", 급탕효율)

        '//조명설비
        Dim 주거실조명전력 As Single = 0
        Dim 주조명광원옥내 As String = ""
        Dim dre As DS.tbl_electRow = DSET1.tbl_elect.Rows(0)
        Dim param27 As New Microsoft.Reporting.WinForms.ReportParameter("p_주거실조명전력", dre.조명밀도)
        Dim param28 As New Microsoft.Reporting.WinForms.ReportParameter("p_주조명광원옥내", dre.주조명광원옥내)

        '//지열시스템(2)
        Dim 지열_용량_난방 As Single = 0
        Dim 지열_용량_냉방 As Single = 0
        Dim 지열_효율_난방 As String = ""
        Dim 지열_효율_냉방 As String = ""
        For Each dr As DS.tbl_newRow In DSET1.tbl_new.Select("code like '2%'")
            If dr.지열냉난방구분.IndexOf("난방") <> -1 Then
                지열_용량_난방 += TOSG(T, dr.지열히트펌프용량)
                지열_효율_난방 = (dr.열성능비난방)
            ElseIf dr.지열냉난방구분.IndexOf("냉방") <> -1 Then
                지열_용량_냉방 += TOSG(T, dr.지열히트펌프용량)
                지열_효율_냉방 = (dr.열성능비냉방)
            End If
        Next
        Dim param29 As New Microsoft.Reporting.WinForms.ReportParameter("p_지열용량난방", 지열_용량_난방)
        Dim param30 As New Microsoft.Reporting.WinForms.ReportParameter("p_지열용량냉방", 지열_용량_냉방)
        Dim param31 As New Microsoft.Reporting.WinForms.ReportParameter("p_지열효율난방", 지열_효율_난방)
        Dim param32 As New Microsoft.Reporting.WinForms.ReportParameter("p_지열효율냉방", 지열_효율_냉방)


        '//태양열시스템(1)
        Dim 집열판면적 As Single = 0
        Dim 집열판면적합 As Single = 0
        Dim 집열판유형 As String = ""
        Dim 집열판방위 As String = ""
        Dim 태양열코드 As String = ""
        For Each dr As DS.tbl_newRow In DSET1.tbl_new.Select("code like '1%'")
            집열판면적합 += TOSG(T, dr.집열판면적)
            If TOSG(T, dr.집열판면적) > 집열판면적 Then
                태양열코드 = dr.code
                집열판면적 = dr.집열판면적
            End If
        Next
        If 태양열코드 <> "" Then
            Dim drn() As DS.tbl_newRow = DSET1.tbl_new.Select("code ='" + 태양열코드 + "'")
            If drn.GetUpperBound(0) <> -1 Then
                집열판유형 = drn(0).집열기유형
                집열판방위 = drn(0).집열판방위
            End If
        End If
        Dim param33 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양열집열판면적합", 집열판면적합)
        Dim param34 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양열집열판유형", 집열판유형)
        Dim param35 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양열집열판방위", 집열판방위)


        '//태양광시스템(3)
        Dim 모듈면적 As Single = 0
        Dim 모듈면적합 As Single = 0
        Dim 모듈방위 As String = ""
        Dim 모듈기울기 As String = ""
        Dim 모듈적용타입 As String = ""
        Dim 태양광코드 As String = ""
        For Each dr As DS.tbl_newRow In DSET1.tbl_new.Select("code like '3%'")
            모듈면적합 = TOSG(T, dr.태양광모듈면적)
            If TOSG(T, dr.태양광모듈면적) > 모듈면적 Then
                태양광코드 = dr.code
                모듈면적 = dr.태양광모듈면적
            End If
        Next
        If 태양광코드 <> "" Then
            Dim drn() As DS.tbl_newRow = DSET1.tbl_new.Select("code ='" + 태양광코드 + "'")
            If drn.GetUpperBound(0) <> -1 Then
                모듈방위 = drn(0).태양광모듈방위
                모듈기울기 = drn(0).태양광모듈기울기
                모듈적용타입 = drn(0).태양광모듈적용타입
            End If
        End If
        Dim param36 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양광모듈면적합", 모듈면적합)
        Dim param37 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양광모듈방위", 모듈방위)
        Dim param38 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양광모듈기울기", 모듈기울기)
        Dim param39 As New Microsoft.Reporting.WinForms.ReportParameter("p_태양광모듈적용타입", 모듈적용타입)


        Dim params As New Microsoft.Reporting.WinForms.ReportParameterCollection()
        params.Add(param1)
        params.Add(param2)
        params.Add(param3)
        params.Add(param5)
        params.Add(param6)
        params.Add(param7)
        params.Add(param8)
        params.Add(param9)
        params.Add(param10)
        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)
        params.Add(param21)
        params.Add(param22)
        params.Add(param23)
        params.Add(param24)
        params.Add(param25)
        params.Add(param26)
        params.Add(param27)
        params.Add(param28)
        params.Add(param29)
        params.Add(param30)
        params.Add(param31)
        params.Add(param32)
        params.Add(param33)
        params.Add(param34)
        params.Add(param35)
        params.Add(param36)
        params.Add(param37)
        params.Add(param38)
        params.Add(param39)

        Me.ReportViewer1.LocalReport.SetParameters(params)
        Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
        Me.ReportViewer1.ZoomPercent = 100
        Me.ReportViewer1.RefreshReport()
    End Sub
    Private Sub MakeGraphTable()
        'If DSR.TReqUse.Rows.Count < 1 Then Return

        'Dim Dr As DSR.Graph_ReqRow
        'For Gubun As Short = 0 To 1
        '    For mon As Short = 1 To 12
        '        If Gubun = 0 Then   '//6번
        '            Dr = Me.DSR.Graph_Req.NewGraph_ReqRow
        '            Dr.Gubun = "난방에너지요구량"
        '            Dr.Mon = Format(mon, "0") & "월"
        '            Dr.Req = Result1o.E요구량(mon).난방면적
        '            Me.DSR.Graph_Req.Rows.Add(Dr)
        '        Else    '//11번
        '            Dr = Me.DSR.Graph_Req.NewGraph_ReqRow
        '            Dr.Gubun = "냉방에너지요구량"
        '            Dr.Mon = Format(mon, "0") & "월"
        '            Dr.Req = Result1o.E요구량(mon).냉방면적
        '            Me.DSR.Graph_Req.Rows.Add(Dr)
        '        End If
        '    Next
        'Next

        '//연간에너지요구량및소요량
        '//Graph_requse gubun,type,
        '           1차에너지소요량	에너지소요량	에너지요구량	
        '신재생에너지(-57)
        '난방에너지	106	91.87445415	56.14013248	
        '냉방에너지	155.3678094	119.8832527	40.83005443	
        '급탕에너지	42.6421498	14.21404993	14.6	
        '조명에너지	144.2220948	48.07403159	73.08380082	
        '환기에너지	61.68818331	20.56272777		

        신재생에너지 = 0
        If (Result1o.사용면적.H_WF = 0) Then
            난방에너지 = 0
        Else
            난방에너지 = Result1o.일차E소요량(0).난방면적2 * Result1o.사용면적.H / Result1o.사용면적.H_WF
        End If

        If (Result1o.사용면적.C_WF = 0) Then
            냉방에너지 = 0
        Else
            냉방에너지 = TOSG(T, Result1o.일차E소요량(0).냉방면적 * Result1o.사용면적.C / Result1o.사용면적.C_WF)
        End If

        If (Result1o.사용면적.W_WF = 0) Then
            급탕에너지 = 0
        Else
            급탕에너지 = Result1o.일차E소요량(0).급탕면적2 * Result1o.사용면적.W / Result1o.사용면적.W_WF
        End If

        If (Result1o.사용면적.L_WF = 0) Then
            조명에너지 = 0
        Else
            조명에너지 = Result1o.일차E소요량(0).조명면적 * Result1o.사용면적.L / Result1o.사용면적.L_WF
        End If

        '계산결과!H92*3/계산결과!H27
        If (Result1o.사용면적.V_WF = 0) Then
            환기에너지 = 0
        Else
            환기에너지 = Result1o.일차E소요량(0).환기면적 * Result1o.사용면적.V / Result1o.사용면적.V_WF
        End If

        합계 = 난방에너지 + 냉방에너지 + 급탕에너지 + 조명에너지 + 환기에너지


    End Sub


End Class