Public Class Report_친환경

    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

    Dim 창면적비 As String = ""
    Dim 외벽평균열관류율 As String = ""

    Dim 신재생_1차소요량 As String = ""
    Dim 신재생_소요량 As String = ""
    Dim 신재생_요구량 As String = ""


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

        Me.DS.tbl_Desc.Merge(DSET1.tbl_Desc) '//건물정보
        Me.DS.tbl_ReqInfo.Merge(DSET1.tbl_ReqInfo) '//의무사항
        Me.DSR.ExtReport.Merge(DSETR1.ExtReport) '//결과

        Display_info()

        Dim 세대면적(4) As String
        Dim 세대수(4) As String
        For i As Integer = 0 To 4
            세대면적(i) = "0"
            세대수(i) = "0"
        Next

        '//세대면적, 세대수처리
        Dim idx As Integer = 0
        Dim 총세대수 As Integer = 0
        Dim 세대별면적합 As Single = 0
        For Each dr As DS.tbl_typeRow In DSET1.tbl_type.Select("code <> '0'", "세대수 desc")
            총세대수 += dr.세대수
            세대별면적합 += dr.세대수 * dr.세대면적
            If idx <= 4 Then

                세대면적(idx) = dr.세대면적
                세대수(idx) = dr.세대수

                idx += 1
            
            End If
        Next

        세대수(4) = 총세대수 - 세대수(0) - 세대수(1) - 세대수(2) - 세대수(3)   '//180122

        For i As Integer = 0 To 4
            If 세대면적(i) = "0" Then
                세대면적(i) = ""
            End If
            If 세대수(i) = "0" Then
                세대수(i) = ""
            End If
        Next


        Dim 단지평균전용면적 As Single = 0
        If 총세대수 <> 0 Then 단지평균전용면적 = 세대별면적합 / 총세대수

        Dim ReportData As DSR.ExtReportRow = DSETR1.ExtReport.Rows(0)
        Dim 소요량1차 As Single = 0 'Single.Parse(ReportData.c078)
        Dim 소요량1차Sum As Single = 0 'Single.Parse(ReportData.c082)
        If IsNumeric(ReportData.c078) Then
            소요량1차 = Single.Parse(ReportData.c078)
        End If
        If IsNumeric(ReportData.c082) Then
            소요량1차Sum = Single.Parse(ReportData.c082)
        End If
       
        

        Dim drDesc As DS.tbl_DescRow = DSET1.tbl_Desc.Rows(0)
        Dim areaCode As String = drDesc.buildarea
        Dim drWGs() As DS.weather_groupRow = DSET1.weather_group.Select("code = '" + areaCode + "'")
        Dim offset As Single = 0
        If drWGs.Length = 1 Then
            Dim drWG As DS.weather_groupRow = drWGs(0)
            Dim Area3 As String = drWG.area3
            If Area3 = "중부1" Then
                If 소요량1차 = 0 Then
                    offset = 1.1
                Else
                    offset = 1.2
                End If
            ElseIf Area3 = "중부2" Then
                If 소요량1차 = 0 Then
                    offset = 1.0
                Else
                    offset = 1.1
                End If
            ElseIf Area3 = "남부" Then
                If 소요량1차 = 0 Then
                    offset = 0.9
                Else
                    offset = 1.0
                End If

            ElseIf Area3 = "제주" Then
                If 소요량1차 = 0 Then
                    offset = 0.8
                Else
                    offset = 0.9
                End If
            End If
        Else
            '//지역코드가 연결되지 않은경우
            MsgBox("지역코드 에러", MsgBoxStyle.Critical, "확인")
        End If


        Dim 평가기준주택1차에너지소요량 As Single = 320 * offset
        Dim 평가대상주택1차에너지소요량 As Single = 소요량1차Sum
        Dim 총에너지절감률 As Single = 0

        If 평가기준주택1차에너지소요량 <> 0 Then
            총에너지절감률 = ((평가기준주택1차에너지소요량 - 평가대상주택1차에너지소요량) / 평가기준주택1차에너지소요량) * 100
        End If

        Dim params As New List(Of Microsoft.Reporting.WinForms.ReportParameter)
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("param1", drDesc.민간구분))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("창면적비", 창면적비))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("외벽평균열관류율", 외벽평균열관류율))

        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("평가기준주택1차에너지소요량", 평가기준주택1차에너지소요량))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("평가대상주택1차에너지소요량", 평가대상주택1차에너지소요량))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("총에너지절감률", 총에너지절감률.ToString("N2")))

        For i As Integer = 0 To 4
            params.Add(New Microsoft.Reporting.WinForms.ReportParameter("전용면적" + (i + 1).ToString(), 세대면적(i)))
            params.Add(New Microsoft.Reporting.WinForms.ReportParameter("세대수" + (i + 1).ToString(), 세대수(i)))
        Next
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("총세대수", 총세대수))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("단지평균전용면적", 단지평균전용면적))

        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("신재생_1차소요량", 신재생_1차소요량))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("신재생_소요량", 신재생_소요량))
        params.Add(New Microsoft.Reporting.WinForms.ReportParameter("신재생_요구량", 신재생_요구량))

        Me.ReportViewer1.LocalReport.SetParameters(params.ToArray)

        Me.ReportViewer1.LocalReport.SetParameters(params)
        Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
        Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
        Me.ReportViewer1.ZoomPercent = 100
        Me.ReportViewer1.PageCountMode = Microsoft.Reporting.WinForms.PageCountMode.Actual
        Me.ReportViewer1.RefreshReport()
    End Sub

   

    Private Sub Display_info()
        Dim T As String = "RPT:친환경"
        Dim WallArea As Decimal, WindowArea As Decimal, WallUvalue As Decimal, WindowUvalue As Decimal
        WallArea = 0
        WindowArea = 0
        WallUvalue = 0
        WindowUvalue = 0
        Try
            For Each Dr입력면 As DS.tbl_myounRow In DSET1.tbl_myoun.Select("건축부위방식='외벽' or 건축부위방식 ='외부창' or 건축부위방식 ='내벽' or 건축부위방식 ='내부창'")
                If Dr입력면.RowState = DataRowState.Deleted OrElse Dr입력면.RowState = DataRowState.Detached Then Continue For
                Dim Dr열관류율 As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2.ToString & "'")(0)

                Select Case Dr입력면.건축부위방식
                    Case "외벽"

                        If Dr열관류율.면형태 = "외벽(직접)" OrElse Dr열관류율.면형태 = "0" Then
                            WallArea = WallArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WallUvalue = WallUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적)
                        End If

                    Case "외부창"

                        If Dr열관류율.면형태 = "창(직접)" OrElse Dr열관류율.면형태 = "0007" OrElse _
                            Dr열관류율.면형태 = "문(직접)" OrElse Dr열관류율.면형태 = "0010" OrElse _
                            Dr열관류율.면형태 = "세대현관문(직접)" OrElse Dr열관류율.면형태 = "0012" Then
                            WindowArea = WindowArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WindowUvalue = WindowUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적)
                        End If
                    Case "내부창"

                        If Dr열관류율.면형태 = "창(간접)" OrElse Dr열관류율.면형태 = "0008" OrElse _
                             Dr열관류율.면형태 = "문(간접)" OrElse Dr열관류율.면형태 = "0011" OrElse _
                             Dr열관류율.면형태 = "세대현관문(간접)" OrElse Dr열관류율.면형태 = "0013" Then
                            WindowArea = WindowArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WindowUvalue = WindowUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적) * 0.8
                        End If
                    Case "내벽"
                        If Dr열관류율.면형태 = "외벽(간접)" OrElse Dr열관류율.면형태 = "0003" Then
                            WallArea = WallArea + TOSG(T, Dr입력면.건축부위면적)
                            Dim dr() As DS.tbl_ykRow = DSET1.tbl_yk.Select("code='" & Dr입력면.열관류율2 & "'")
                            WallUvalue = WallUvalue + TOSG(T, dr(0).열관류율) * TOSG(T, Dr입력면.건축부위면적) * 0.7
                        End If

                    
                End Select
            Next
        Catch ex As Exception

        End Try

        Try
            창면적비 = Math.Round(WindowArea / (WallArea + WindowArea) * 100, 2).ToString
        Catch ex As Exception
            창면적비 = ""
        End Try

        Try
            외벽평균열관류율 = Math.Round((WallUvalue + WindowUvalue) / (WallArea + WindowArea), 3).ToString
        Catch ex As Exception
            외벽평균열관류율 = ""
        End Try

    End Sub


End Class