Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text
Imports System.Drawing
Imports System.Object
Imports System.Windows.Forms

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.XtraPrinting
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.Win.SystemModule
Imports DevExpress.Data.Filtering

Public Class CustomPrintingController
    Inherits PrintingController

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
    End Sub
    'Protected Overrides Sub OnPrintingSettingsLoaded(ByVal args As PrintableComponentLinkEventArgs)
    '    MyBase.OnPrintingSettingsLoaded(args)
    '    CustomizePrintingSystem(args.PrintableComponentLink)
    'End Sub

    Private Sub CustomizePrintingSystem(ByVal link As PrintableComponentLink)
        Dim _IModelListViewExtender As IModelListViewExtender = TryCast(View.Model, IModelListViewExtender)

        Dim _CustomersFrom As CustomersFrom = View.ObjectSpace.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("IsDefault=True"))


        Dim _HeaderLeft As String = String.Format(_IModelListViewExtender.HeaderLeft, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)
        Dim _HeaderCenter As String = String.Format(_IModelListViewExtender.HeaderCenter, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)
        Dim _HeaderRight As String = String.Format(_IModelListViewExtender.HeaderRight, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)
        Dim _FooterLeft As String = String.Format(_IModelListViewExtender.FooterLeft, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)
        Dim _FooterCenter As String = String.Format(_IModelListViewExtender.FooterCenter, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)
        Dim _FooterRight As String = String.Format(_IModelListViewExtender.FooterRight, _CustomersFrom.FullName, View.Model.Caption, GLOBAL_MainModuleVersion)

        Dim _PageHeaderFooter As PageHeaderFooter = TryCast(link.PageHeaderFooter, PageHeaderFooter)

        _PageHeaderFooter.Header.Content.Clear()
        _PageHeaderFooter.Footer.Content.Clear()

        _PageHeaderFooter.Header.Content.AddRange(New String() {_HeaderLeft, _HeaderCenter, _HeaderRight})
        '_PageHeaderFooter.Header.LineAlignment = BrickAlignment.Far

        _PageHeaderFooter.Footer.Content.AddRange(New String() {_FooterLeft, _FooterCenter, _FooterRight})
        '_PageHeaderFooter.Footer.LineAlignment = BrickAlignment.Far

        '
    End Sub
    Private Sub CustomPrintingController_CustomPrint(sender As Object, e As HandledEventArgs) Handles Me.CustomPrint
        e.Handled = True
        Dim _PrintableComponentLink As PrintableComponentLink = New PrintableComponentLink(New PrintingSystem())
        _PrintableComponentLink.Component = GetPrintable()
        CustomizePrintingSystem(_PrintableComponentLink)
        _PrintableComponentLink.PrintDlg()
    End Sub
    Private Sub CustomPrintingController_CustomShowPrintPreview(sender As Object, e As CustomShowPrintPreviewEventArgs) Handles Me.CustomShowPrintPreview
        e.Handled = True
        Dim _PrintableComponentLink As PrintableComponentLink = New PrintableComponentLink(New PrintingSystem())
        _PrintableComponentLink.Component = GetPrintable()
        CustomizePrintingSystem(_PrintableComponentLink)
        _PrintableComponentLink.ShowPreviewDialog()
    End Sub
End Class
