Public Class Report_설계개선

#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


    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.월별1차에너지사용량.Merge(DSETR.월별1차에너지사용량)
        'Me.DSR.Graph_ReqUse.Merge(DSETR.Graph_ReqUse)

        Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent
        Me.ReportViewer1.ZoomPercent = 100

        If MakeGraphTable() Then
            Dim 합율 As Decimal = Math.Round((1 - (변경후합 / 변경전합)) * 100, 2)
            Dim param As New Microsoft.Reporting.WinForms.ReportParameter("PSUM", 합율.ToString())
            Dim params As New Microsoft.Reporting.WinForms.ReportParameterCollection()
            params.Add(param)
            Me.ReportViewer1.LocalReport.SetParameters(params)

            Me.ReportViewer1.RefreshReport()

        Else
            Me.Close()
        End If


        


    End Sub
    Private Function MakeGraphTable() As Boolean
        '//월별 계산별,추측별 데이터를 기록한다.
        Me.DSR.Graph_ReqUse.Clear()
        Me.DSR.Graph_ReqUse.AcceptChanges()

        If DSETR1.월별1차에너지사용량.Rows.Count = 0 Then
            MsgBox("월별1차에너지사용량이 계산되어있지 않습니다." + vbCrLf + "계산을 먼저하세요", MsgBoxStyle.Information, "확인")
            Return False
        End If

        '//년면적값확인
        Dim 년면적 As Decimal = TOSG(DSET1.tbl_Desc.Rows(0)("buildm23"))
        If 년면적 = 0 Then
            MsgBox("년면적값이 없습니다" + vbCrLf + "건물개요를 확인하세요", MsgBoxStyle.Information, "확인")
            Return False
        End If

        If DSETR1.설계계산결과.Rows.Count < 1 Then
            MsgBox("설계개선결과가 없습니다" + vbCrLf + "계산을 먼저하세요", MsgBoxStyle.Information, "확인")
            Return False
        End If

        '//설계게산파라미터확인
        Dim 기저비율 As Decimal = 0
        If DSETR1.설계계산파라미터.Rows.Count > 0 Then
            Dim dr3 As DSR.설계계산파라미터Row = DSETR1.설계계산파라미터.Rows(0)
            기저비율 = CDec(dr3.기저비율)
        End If

        '//
        Dim 사용자입력값에너지사용량(12) As Decimal

        '//현재 1차에너지사용량
        Dim 년면적당1(12) As Decimal
        Dim 년면적당2(12) As Decimal


        For i As Integer = 1 To 12

            사용자입력값에너지사용량(i) = 0
            For Each dr1 As DSR.월별1차에너지사용량Row In DSETR1.월별1차에너지사용량.Select("월='" + i.ToString("00") + "'")
                사용자입력값에너지사용량(i) += TOSG(dr1.도시가스) + TOSG(dr1.전력) + TOSG(dr1.지역난방)
            Next

            '//변경전의데이터
            Dim 보정결과 As DSR.설계계산결과Row = DSETR1.설계계산결과.Rows(i - 1)
            년면적당1(i) = TOSG(보정결과.난방전) + TOSG(보정결과.냉방전) + TOSG(보정결과.급탕전) + TOSG(보정결과.조명전) + TOSG(보정결과.환기전)

            '//변경후(보정)데이터 (설계계산결과 테이블에 데이터가 있다)

            년면적당2(i) = TOSG(보정결과.난방) + TOSG(보정결과.냉방) + TOSG(보정결과.급탕) + TOSG(보정결과.조명) + TOSG(보정결과.환기)

            년면적당1(i) += 기저비율
            년면적당2(i) += 기저비율

            변경전합 += 년면적당1(i)
            변경후합 += 년면적당2(i)

            Dim dr2 As DSR.Graph_ReqUseRow

            dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
            dr2.Gubun = i.ToString("00")
            dr2.type = "에너지사용량"
            dr2.Req = Math.Round(사용자입력값에너지사용량(i), 2)
            Me.DSR.Graph_ReqUse.Rows.Add(dr2)

            dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
            dr2.Gubun = i.ToString("00")
            dr2.type = "1차소요량(전)"
            dr2.Req = Math.Round(년면적당1(i), 2)
            Me.DSR.Graph_ReqUse.Rows.Add(dr2)

            dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
            dr2.Gubun = i.ToString("00")
            dr2.type = "1차소요량(후)"
            dr2.Req = Math.Round(년면적당2(i), 2)
            Me.DSR.Graph_ReqUse.Rows.Add(dr2)

            '//결과% :   (1-(결과후/결과전))*100
            dr2 = Me.DSR.Graph_ReqUse.NewGraph_ReqUseRow
            dr2.Gubun = i.ToString("00")
            dr2.type = "개선결과(%)"
            dr2.Req = Math.Round((1 - (년면적당2(i) / 년면적당1(i))) * 100, 2)
            Me.DSR.Graph_ReqUse.Rows.Add(dr2)
        Next

        '//전체합
        DSR.Graph_ReqUse.AcceptChanges()
        Return True
    End Function

    Private Sub Report_그래프_SizeChanged(sender As Object, e As System.EventArgs) Handles Me.SizeChanged
        Me.Text = Me.Size.ToString
    End Sub

End Class