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.ExpressApp.Web.SystemModule

Public Class InstallationVC
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        If View.Id Like "Installation_InstallationDocumentations_ListView_Support" Then
            Frame.GetController(Of ListViewController).EditAction.Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id Like "Installation_InstallationDocumentations_ListView_Support" Then
            Frame.GetController(Of ListViewController).EditAction.Active.SetItemValue("", True)
        End If
    End Sub

    Private Sub aInstallationDocumentations_OpenDashboardWithViewer_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aInstallationDocumentations_OpenDashboardWithViewer.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _InstallationDocumentations As InstallationDocumentations = TryCast(View.SelectedObjects(0), InstallationDocumentations)

        If _InstallationDocumentations IsNot Nothing Then
            Dim _FileName As String = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempPath, _InstallationDocumentations.File.FileName)
            Dim _StreamFile As System.IO.Stream = New System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)
            _InstallationDocumentations.File.SaveToStream(_StreamFile)
            _StreamFile.Close()

            If IO.File.Exists(_FileName) Then
                GLOBAL_DASHBOARD_XML_DashboardXmlFile = _FileName
                GLOBAL_DASHBOARD_XML_UserName = _InstallationDocumentations.XML_UserName
                GLOBAL_DASHBOARD_XML_Password = _InstallationDocumentations.XML_Password
                GLOBAL_DASHBOARD_XML_ServerName = _InstallationDocumentations.XML_ServerName
                GLOBAL_DASHBOARD_XML_DatabaseName = _InstallationDocumentations.XML_DatabaseName
                Select Case _InstallationDocumentations.XML_SqlType
                    Case eSQLType.MSSQL
                        GLOBAL_DASHBOARD_XML_SQLType = "MSSQL"
                    Case eSQLType.MySQL
                        GLOBAL_DASHBOARD_XML_SQLType = "MYSQL"
                    Case eSQLType.PostgreSQL
                        GLOBAL_DASHBOARD_XML_SQLType = "PSQL"
                End Select

                DevExpress.ExpressApp.Web.WebWindow.CurrentRequestWindow.RegisterStartupScript("ShowCustomFormScriptKey", String.Format("window.open('{0}');", "Controls/DashboardViewer.aspx"))
            End If

        End If

    End Sub
End Class
