Northwind Traders Sample Application Documentation Home | Online Sample | Documentation

ExportData.aspx.vb Language: Font Size:
Web Pages: ExportData.aspx.vb   ExportData.aspx   
Imports System
Imports System.Data
Imports Techmatica.Web.UI.WebControls
Imports TechmaticaNorthwindBusiness
Imports TechmaticaNorthwindHelper

Namespace TechmaticaNorthwindUserInterface
    Public Class ExportData
        Inherits System.Web.UI.Page
        Protected ExportCommandButton As System.Web.UI.WebControls.Button
        Protected ExportOptionsDropDownList As DotNetGenieDropDownList
        Protected GoBackLink As System.Web.UI.WebControls.HyperLink
        Protected MessageLabel As System.Web.UI.WebControls.Label
        Private designerPlaceholderDeclaration As Object
        Private Sub ExportCommandButtonClick(ByVal Sender As Object, ByVal E As System.EventArgs)
            Dim DataSet As System.Data.DataSet = Nothing
            Dim WhereStatement As String = String.Empty
            Dim ExportObjectName As String = System.Convert.ToString(Me.ViewState(Constants.QueryStringExport))
            If (System.Convert.ToString(Me.ViewState(Constants.QueryStringWhereStatement)).Length > 0) Then
                WhereStatement = System.Convert.ToString(Me.ViewState(Constants.QueryStringWhereStatement))
            End If
            Try 
                DataSet = BusinessFetchData.FetchDataSet(ExportObjectName, WhereStatement, false)
            Catch Exception As System.Exception
                Me.MessageLabel.Text = Exception.ToString
            End Try
            Try 
                System.Web.HttpContext.Current.Response.Buffer = true
                System.Web.HttpContext.Current.Response.ClearContent
                System.Web.HttpContext.Current.Response.ClearHeaders
                System.Web.HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", String.Concat(New String() {"attachment;filename=", ExportObjectName, ".xml"}))
                System.Web.HttpContext.Current.Response.ContentType = "Application/Oct-stream"
                Dim MemoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
                DataSet.WriteXml(MemoryStream, XmlWriteMode.WriteSchema)
                System.Web.HttpContext.Current.Response.BinaryWrite(MemoryStream.ToArray)
                System.Web.HttpContext.Current.Response.End
            Catch Exception As System.Exception
                Me.MessageLabel.Text = Exception.ToString
            End Try
        End Sub
        Protected Overridable Sub ExtractQueryString()
            Dim Position As Integer
            Dim URL As String = String.Empty
            If (Not (System.Web.HttpContext.Current.Request.UrlReferrer) Is Nothing) Then
                Position = System.Web.HttpContext.Current.Request.UrlReferrer.ToString.IndexOf("?")
                If (Position = -1) Then
                    URL = System.Web.HttpContext.Current.Request.UrlReferrer.ToString
                Else
                    URL = String.Concat(System.Web.HttpContext.Current.Request.UrlReferrer.ToString.Substring(0, Position), Constants.WebQueryStringDelimeter, System.Web.HttpContext.Current.Request.QueryString.ToString)
                End If
                Me.ViewState(Constants.WebURLReferer) = URL
                If (Not (System.Web.HttpContext.Current.Request.QueryString(Constants.QueryStringWhereStatement)) Is Nothing) Then
                    Me.ViewState(Constants.QueryStringWhereStatement) = System.Web.HttpContext.Current.Request.QueryString(Constants.QueryStringWhereStatement)
                End If
                Me.GoBackLink.NavigateUrl = System.Convert.ToString(Me.ViewState(Constants.WebURLReferer))
            Else
                Me.GoBackLink.Visible = false
            End If
            If (Not (System.Web.HttpContext.Current.Request.QueryString(Constants.QueryStringExport)) Is Nothing) Then
                Me.ViewState(Constants.QueryStringExport) = System.Web.HttpContext.Current.Request.QueryString(Constants.QueryStringExport)
            End If
        End Sub
        <System.Diagnostics.DebuggerStepThrough()>  _
        Private Sub InitializeComponent()
        End Sub
        Private Sub LoadClass(ByVal Sender As Object, ByVal E As System.EventArgs)
            If (Me.IsPostBack = false) Then
                Me.ExtractQueryString
            End If
        End Sub
        Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
            Me.InitializeComponent
            AddHandler MyBase.Load, AddressOf Me.LoadClass
            AddHandler MyBase.PreRender, AddressOf Me.PreRenderClass
            AddHandler ExportCommandButton.Click, AddressOf Me.ExportCommandButtonClick
            MyBase.OnInit(e)
        End Sub
        Private Sub PreRenderClass(ByVal Sender As Object, ByVal E As System.EventArgs)
            Try 
                If (Me.IsPostBack = false) Then
                    Me.ExportOptionsDropDownList.DataSource = BusinessFetchData.FetchDataView(Me.ExportOptionsDropDownList.TableToCombo)
                End If
            Catch Exception As System.Exception
                Me.MessageLabel.Text = Exception.ToString
            End Try
        End Sub
    End Class
End Namespace