Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.Xpo
Imports DevExpress.ExpressApp.Reports
Imports DevExpress.ExpressApp.Reports.Win
Imports DevExpress.Persistent.Validation
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Parameters
Imports DevExpress.XtraReports.Design
Imports DevExpress.XtraReports.UserDesigner
Imports DevExpress.Data.Filtering
Imports DevExpress.Persistent.AuditTrail
Imports DevExpress.Persistent.BaseImpl

Imports System.Data
Imports System.Drawing.Printing


Partial Public Class ReportWizardModifyController
    Inherits WindowController
    Private reportServiceController As WinReportServiceController
    Public Sub New()
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        reportServiceController = Frame.GetController(Of WinReportServiceController)()
        AddHandler reportServiceController.NewXafReportWizardShowing, AddressOf reportServiceController_NewXafReportWizardShowing
        'AddHandler reportServiceController.CustomShowPreview, AddressOf WinReportsController_CustomShowPreview
        AddHandler reportServiceController.CustomShowPreview, AddressOf reportServiceController_CustomShowPreview
    End Sub
    Protected Overrides Sub OnDeactivated()
        RemoveHandler reportServiceController.NewXafReportWizardShowing, AddressOf reportServiceController_NewXafReportWizardShowing
        'RemoveHandler reportServiceController.CustomShowPreview, AddressOf WinReportsController_CustomShowPreview
        reportServiceController = Nothing
        MyBase.OnDeactivated()
    End Sub
    Private Sub reportServiceController_CustomShowPreview(ByVal sender As Object, ByVal e As CustomShowPreviewEventArgs)
        AddHandler e.Report.PrintProgress, AddressOf report_PrintProgress

    End Sub
    Private Sub report_PrintProgress(sender As Object, e As DevExpress.XtraPrinting.PrintProgressEventArgs)

    End Sub
    Private Sub reportServiceController_NewXafReportWizardShowing(ByVal sender As Object, ByVal e As NewXafReportWizardShowingEventArgs)
        If (Not e.ReportDataType.Equals(GetType(CustomReportData))) Then
            Return
        End If
        Dim newReportParamsObject As New CustomReportWizardParameters(e.WizardParameters.Report)
        newReportParamsObject.ReportName = "Custom report name"
        newReportParamsObject.AdditionalInfo = "AdditionalInfo default value"
        e.WizardParameters = newReportParamsObject

    End Sub
    Private Sub WinReportsController_CustomShowPreview(ByVal sender As Object, ByVal e As CustomShowPreviewEventArgs)
        '    'Dim _NameOfCreator As XRLabel = TryCast(e.Report.FindControl("NameOfCreator", False), XRLabel)

        '    If e.Report.Name = "xafReport_OfferOut" Then
        '        Dim _ocur As Xpo.XPObjectSpace = TryCast(e.Report.ObjectSpace, Xpo.XPObjectSpace)
        '        Dim _AuditTrail As XPCollection(Of AuditDataItemPersistent) = AuditedObjectWeakReference.GetAuditTrail(_ocur.Session, e.Report.GetCurrentRow)

        '        'Dim _DocumentNumber As XRLabel = TryCast(e.Report.FindControl("DocumentNumber", False), XRLabel)

        '        'Dim _st As String = e.Report.GetCurrentColumnValue("DocumentNumber")
        '        'Dim _AuditedObjectWeakReference As XPCollection = AuditedObjectWeakReference.GetAuditTrail()

        '        'Dim _OfferOutHeader As OfferOutHeader = _ocur.FindObject(Of OfferOutHeader)(CriteriaOperator.Parse("DocumentNumber=?", _DocumentNumber.Text))
        '        'Dim _AuditDataItemPersistent As AuditDataItemPersistent = _ocur.FindObject(Of AuditDataItemPersistent)(CriteriaOperator.Parse("AuditedObject=?", _OfferOutHeader.Oid))

        '        '_NameOfCreator.Text = _AuditDataItemPersistent.UserName
        '    End If
        'Dim _ReportData As ReportData =
        'e.Report.ExportToPdf()

    End Sub
End Class
<NonPersistent()> _
Friend Class CustomReportWizardParameters
    Inherits NewXafReportWizardParameters
    Public Sub New(ByVal report As XafReport)
        MyBase.New(report)
    End Sub
    Public Property AdditionalInfo() As String
        Get
            Return (CType(Report, CustomXafReport)).AdditionalInfo
        End Get
        Set(ByVal value As String)
            CType(Report, CustomXafReport).AdditionalInfo = value
        End Set
    End Property
End Class

