Public Class Frm_v20091231_Report

    Dim T As String = "그래프"

    Private Sub Frm_v20091231_Result_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.DSR.TReqUse.Merge(DSETR1.TReqUse)
        MakeGraphTable()
        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		

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


        '//여기가 최종결과를 출력물에생성하는 구간입니다.
        '//각 항목별로, 냉/난... 그렇게 되어잇구요
        '//가중치가 결정되면 이곳에 곱하면 출력물에만 적용됩니다.
        '//곱해야할 가중치를 결정하는 방법좀 
        '// 예를들면 업무시설이 100m2 이고 교육연구시설(초중고)가 100m2이면 (100*1+100*1.2)/200 

        'Dim Total2 As Double = 0.0
        'Dim Total1 As Double = 0.0
        'For Each Dr0 As DS.tbl_typeRow In DSET1.tbl_type.Rows
        '    Dim multi As Double = 1.0
        '    Select Case Dr0.시설용도
        '        Case "0011" '교육연구시설(초중고)"
        '            multi = 1.12
        '        Case "0012" '교육연구시설(etc)
        '            multi = 0.98
        '    End Select
        '    Total1 += Dr0.면적 * multi
        '    Total2 += Dr0.면적
        'Next
        Dim addmulti As Double = 0
        'If Total2 <> 0 Then
        '    addmulti = Total1 / Total2
        'Else
        '    addmulti = 1.0
        'End If

        addmulti = 1.0

        Dim Multi(5) As Double
        Multi(0) = 0
        Multi(1) = 0
        Multi(2) = 0
        Multi(3) = 0
        Multi(4) = 0

        Dim Total1(5) As Double
        Dim Total2 As Double    '//total


        If Program = EProgram.총량평가 Then

            For Each Dr0 As DS.tbl_typeRow In DSET1.tbl_type.Rows
                'Dim multi As Double = 1.0
                Select Case Dr0.시설용도

                    Case "0013" '구내식당-0013
                        Multi(0) = 1.571
                        Multi(1) = 1.571
                        Multi(2) = 0.024
                        Multi(3) = 1.286
                        Multi(4) = 1.571
                    Case "0014" '전산실-0014
                        Multi(0) = 0.503
                        Multi(1) = 0.196
                        Multi(2) = 0.685
                        Multi(3) = 0.514
                        Multi(4) = 0.314
                    Case "0017" '병실-0017
                        Multi(0) = 0.314
                        Multi(1) = 0.314
                        Multi(2) = 0.251
                        Multi(3) = 0.514
                        Multi(4) = 0.314
                    Case "0016" '객실-0016
                        Multi(0) = 0.685
                        Multi(1) = 0.685
                        Multi(2) = 0.251
                        Multi(3) = 1.541
                        Multi(4) = 0.685
                    Case "0015" '초중고
                        Multi(0) = 1.964
                        Multi(1) = 1.964
                        Multi(2) = 1.25
                        Multi(3) = 1.875
                        Multi(4) = 1.964
                    Case "0018" '강의실
                        Multi(0) = 2.037
                        Multi(1) = 2.037
                        Multi(2) = 1.667
                        Multi(3) = 2.5
                        Multi(4) = 2.037
                    Case "0019" '체육시설
                        Multi(0) = 0.611
                        Multi(1) = 0.611
                        Multi(2) = 0.114
                        Multi(3) = 0.5
                        Multi(4) = 0.611
                    Case Else
                        Multi(0) = 1.0
                        Multi(1) = 1.0
                        Multi(2) = 1.0
                        Multi(3) = 1.0
                        Multi(4) = 1.0

                End Select

                Total1(0) += Dr0.면적 / Multi(0)
                Total1(1) += Dr0.면적 / Multi(1)
                Total1(2) += Dr0.면적 / Multi(2)
                Total1(3) += Dr0.면적 / Multi(3)
                Total1(4) += Dr0.면적 / Multi(4)

                Total2 += Dr0.면적

            Next


            For i As Integer = 0 To 4
                If Total2 = 0 Then
                    Multi(i) = 1
                Else
                    Multi(i) = Total2 / Total1(i) '//251002 수정
                End If
            Next


            'Multi(1) = 1.0 '//냉방
            'Multi(2) = 1.0 '//급탕
            'Multi(3) = 1.0 '//조명
            'Multi(4) = 1.0 '//환기
        Else
            Multi(0) = 1.0
            Multi(1) = 1.0
            Multi(2) = 1.0
            Multi(3) = 1.0
            Multi(4) = 1.0
        End If


        Dim Dr2 As DSR.Graph_ReqUseRow
        For Gubun As Short = 0 To 3
            Select Case Gubun
                Case 0  '//1차에너지소요량

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

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


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

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


                    '//열병합신재생에너지추가 130831 arin
                    신재생에너지 = -1 * (Result1o.생산E(0).면적당생산량태양열 + _
                                   Result1o.생산E(0).신재생면적당열생산량 + _
                                   Result1o.생산E(0).면적당생산량지열 + 전기 * 2.75)

                   

                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "신재생에너지"
                    Dr2.Req = 신재생에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    난방에너지 = Result1o.일차E소요량(0).난방면적 * Multi(0)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "난방에너지"
                    Dr2.Req = 난방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    냉방에너지 = Result1o.일차E소요량(0).냉방면적 * Multi(1) '//171021 
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "냉방에너지"
                    Dr2.Req = 냉방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    급탕에너지 = Result1o.일차E소요량(0).급탕면적 * Multi(2) '//171021 
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "급탕에너지"
                    Dr2.Req = 급탕에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    조명에너지 = Result1o.일차E소요량(0).조명면적 * Multi(3) '//171021 
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "조명에너지"
                    Dr2.Req = 조명에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    '계산결과!H92*3/계산결과!H27
                    환기에너지 = Result1o.일차E소요량(0).환기면적 * Multi(4) '//171021 
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "환기에너지"
                    Dr2.Req = 환기에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "1차소요량"
                    Dr2.type = "합계"
                    Dr2.Req = (난방에너지 + 냉방에너지 + 급탕에너지 + 조명에너지 + 환기에너지) * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)


                Case 1  '//에너지소요량

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


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

                    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 * (Result1o.생산E(0).면적당생산량태양열 + Result1o.생산E(0).면적당생산량지열) - 면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "신재생에너지"
                    Dr2.Req = 신재생에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    난방에너지 = Result1o.E소요량(0).난방면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "난방에너지"
                    Dr2.Req = 난방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)


                    냉방에너지 = Result1o.E소요량(0).냉방면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "냉방에너지"
                    Dr2.Req = 냉방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)


                    급탕에너지 = Result1o.E소요량(0).급탕면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "급탕에너지"
                    Dr2.Req = 급탕에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    조명에너지 = Result1o.E소요량(0).조명면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "조명에너지"
                    Dr2.Req = 조명에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    환기에너지 = Result1o.E소요량(0).환기면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "환기에너지"
                    Dr2.Req = 환기에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "소요량"
                    Dr2.type = "합계"
                    Dr2.Req = (난방에너지 + 냉방에너지 + 급탕에너지 + 조명에너지 + 환기에너지) * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)



                Case 2  '//에너지요구량


                    신재생에너지 = 0
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "신재생에너지"
                    Dr2.Req = 신재생에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    '계산결과!H14
                    난방에너지 = Result1o.E요구량(0).난방면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "난방에너지"
                    Dr2.Req = 난방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    냉방에너지 = Result1o.E요구량(0).냉방면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "냉방에너지"
                    Dr2.Req = 냉방에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    '계산결과!H25
                    급탕에너지 = Result1o.E요구량(0).급탕면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "급탕에너지"
                    Dr2.Req = 급탕에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    '계산결과!H22
                    조명에너지 = Result1o.E요구량(0).조명면적
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "조명에너지"
                    Dr2.Req = 조명에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    환기에너지 = 0
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "환기에너지"
                    Dr2.Req = 환기에너지 * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "요구량"
                    Dr2.type = "합계"
                    Dr2.Req = (난방에너지 + 냉방에너지 + 급탕에너지 + 조명에너지 + 환기에너지) * addmulti
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)
                Case 3  '//co2발생량

                    신재생에너지 = 0
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "신재생에너지"
                    Dr2.Req = 신재생에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    난방에너지 = Math.Round(Result1o.Co2발생량(0).난방면적, 1)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "난방에너지"
                    Dr2.Req = 난방에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    냉방에너지 = Math.Round(Result1o.Co2발생량(0).냉방면적, 1)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "냉방에너지"
                    Dr2.Req = 냉방에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    급탕에너지 = Math.Round(Result1o.Co2발생량(0).급탕면적, 1)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "급탕에너지"
                    Dr2.Req = 급탕에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    조명에너지 = Math.Round(Result1o.Co2발생량(0).조명면적, 1)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "조명에너지"
                    Dr2.Req = 조명에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    '계산결과!H92*3/계산결과!H27
                    환기에너지 = Math.Round(Result1o.Co2발생량(0).환기면적, 1)
                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "환기에너지"
                    Dr2.Req = 환기에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

                    Dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
                    Dr2.Gubun = "CO2발생량"
                    Dr2.type = "합계"
                    Dr2.Req = 난방에너지 + 냉방에너지 + 급탕에너지 + 조명에너지 + 환기에너지
                    Me.DSR.Graph_ReqUse.Rows.Add(Dr2)

            End Select
        Next

    End Sub

    
    Private Sub Frm_v20091231_Report_SizeChanged(sender As System.Object, e As System.EventArgs) Handles MyBase.SizeChanged
        'Me.Text = Me.Size.ToString()
    End Sub
End Class