Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Text
Imports DevExpress.ExpressApp
Imports DevExpress.Data.Filtering
Imports System.Collections.Generic
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Utils
Imports DevExpress.ExpressApp.Layout
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.Templates
Imports DevExpress.Persistent.Validation
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.ExpressApp.Model.NodeGenerators

' For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
Partial Public Class BusinessDirectory_VC
    Inherits ViewController
    Public Sub New()
        InitializeComponent()
        RegisterActions(components)
        ' Target required Views (via the TargetXXX properties) and create their Actions.
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub

    Private Sub aOpenDashboardforView_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aOpenDashboardforView.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _BusinessDirectory As BusinessDirectory = TryCast(View.SelectedObjects(0), BusinessDirectory)

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

            If IO.File.Exists(_FileName) Then
                GLOBAL_DASHBOARD_XML_DashboardXmlFile = _FileName
                GLOBAL_DASHBOARD_XML_UserName = _BusinessDirectory.DashBoard_UserName
                GLOBAL_DASHBOARD_XML_Password = _BusinessDirectory.DashBoard_Password
                GLOBAL_DASHBOARD_XML_ServerName = _BusinessDirectory.DashBoard_Server
                GLOBAL_DASHBOARD_XML_DatabaseName = _BusinessDirectory.DashBoard_Database
                Select Case _BusinessDirectory.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
