如何在生成大型csv文件时提供等待指示器

时间:2012-12-20 21:46:55

标签: asp.net csv webforms devexpress asynccallback

请交叉引用to devexpress forum

在ASP.NET WEBFORMS项目中,如何在用户点击一个devexpress按钮和回调控件后,在HAVING生成csv流后,通过Response对象将流推送到浏览器但是不能胜过devexpress提供的回调机制? ?? ...这是一些代码

Imports D5FPX
Imports System.Data.Linq
Imports System.Configuration.ConfigurationManager
Imports System.Data

Partial Class MyFolder_MyUserControl
    Inherits UserControlBase

 Const NINE_NUMERO As Integer = 1
 Const VBA As String = "xyz"
 Const CVS_FORMATTER As String = "{0:F2}"

 Dim realcode As String = "99999"
 Dim mycsv As String
 Dim pc As PersistenceClass

 Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init

      If Not Page.IsCallback Then
           h2.InnerText = UserControlName
      End If

 End Sub

 Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

 End Sub

 Protected Sub btnDownload_Click(sender As Object, e As System.EventArgs) Handles btnDownload.Click

     'blank

 End Sub

 Prviate Sub DoQuery()

      pc = New xxx.PersistenceClass(ConfigurationManager.ConnectionStrings("xxx").ConnectionString.ToString())

      Dim resultQuery = From vi In pc.dbo.xxx_VWs _
                          Join smv In pc.dbo.v_xxx _
                           On vi.givenKey Equals smv.givenKey _
                           Where (vi.Zone <> 0 And vi.user_fld_6 <> "H") _
                           Select New With {.Field1 = smv.Field1, _
                           .Field2 = smv.givenKey.Trim(), _
                           .AB = IIf(vi.Field3.Trim().Contains("old"), "O", "N"), _
                           .Zone = vi.Zone, _
                           .Zenith = vi.Zenith}

      Dim datatable As New DataTable()

      datatable.Columns.Add("Ninja")
      datatable.Columns.Add("Cowboy")
      datatable.Columns.Add("Soldier")
      datatable.Columns.Add("Worker")
      datatable.Columns.Add("Priest")
      datatable.Columns.Add("Zenith")

      For Each row In resultQuery               
           Dim specialZone As Nullable(Of Decimal) = pc.dbo.xxx_RealZone(NINE_NUMERO, realcode, row.Field2, VBA, Date.Now)

           'check for null return value from scalar db function call
           If specialZone Is Nothing Then
                specialZone = row.Zone
           End If

           Dim formattedZone = String.Format(CVS_FORMATTER, row.Zone)
           Dim formattedSpecZone = String.Format(CVS_FORMATTER, specialZone)
           Dim formattedZenithZone = String.Format(CVS_FORMATTER, row.Zenith)

           'datatable.Rows.Add(row.Field1, row.Field2, row.AB, row.Zone, specialZone, row.Core)
           datatable.Rows.Add(row.Field1, row.Field2, row.AB, formattedZone, formattedSpecZone, formattedZenithZone)
      Next

      mycsv = datatable.ConvertToCSV()

      OutputCsv(mycsv)
 End Sub

 Prviate Sub OutputCsv(csv As String)
      Dim finalByteArray As Byte() = Encoding.ASCII.GetBytes(csv)

      Response.ContentType = "text/csv"
      Response.AddHeader("content-disposition", "attachment;filename=abcdef.csv")
      Response.AddHeader("Content-lenght", finalByteArray.Length.ToString())
      Response.Clear()
      Response.Write(csv)          
      Response.Flush()


 End Sub   

 Protected Sub Callback1_Callback(source As Object, e As    DevExpress.Web.ASPxCallback.CallbackEventArgs) Handles Callback1.Callback

       DoQuery()

 End Sub
End Class

以下是devexpress按钮和回调控件的JavaScript函数......

function btnDownload_Click(s, e) {
 lp1.Show();
 cb1.PerformCallback();
}

function cb1_CallbackComplete(s, e) {
 var mydiv1 = document.getElementById('dv1');
 mydiv1.innerHTML = e.result;
 lp1.Hide();
}

0 个答案:

没有答案