📄 dataexport.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Configuration;
using Caisis.BusinessObject;
using Caisis.Controller;
using Caisis.Security;
using Caisis.UI;
using Caisis.UI.Core.Classes;
using Caisis.UI.Core.Utilities;
namespace Caisis.UI.Core.DataAnalysis.Export
{
/// <summary>
/// Summary description for DataExportForm.
/// </summary>
public class DataExport : BasePage
{
protected string disease;
protected HtmlSelect exportMethod;
protected CheckBoxList diseaseTables, baseTables;
protected string debugStr = "";
protected ErrorMsg errMsg;
protected System.Web.UI.HtmlControls.HtmlInputRadioButton diseaseProstate, diseaseBladder, diseaseAll,
privacyDeidentified, privacyIdentified, privacyLimited;
protected System.Web.UI.WebControls.Button submitBtn;
protected ImageButton submitImageBtn;
protected System.Web.UI.HtmlControls.HtmlForm ExportForm;
protected override void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.SetCheckBoxList();
}
//submitBtn.Attributes.Add("onClick", "if(confirm('You are exporting all patients to an XML file. This process may take up to ten minutes. Would you like to continue?')){this.form.submit(); swapVisibleTables();}else{return false)}");
//ExportForm.Attributes.Add("onSubmit", "confirmExport();");
if(IsPostBack)
{
if (Request.Form["submitBool"].Equals("true"))
{
CommandEventArgs ce = new CommandEventArgs("", e);
this.onSubmitBtnCommand(sender, ce);
}
else
{
this.SetParams();
}
}
}
protected void SetParams()
{
this.SetCheckBoxList();
switch (Request.Form["diseaseRadio"])
{
case "Prostate":
this.diseaseProstate.Checked = true;
break;
case "Bladder":
this.diseaseBladder.Checked = true;
break;
case "All":
this.diseaseAll.Checked = true;
break;
}
switch (Request.Form["privacyRadio"])
{
case "Identified":
this.privacyIdentified.Checked = true;
break;
case "Deidentified":
this.privacyDeidentified.Checked = true;
break;
case "Limited":
this.privacyLimited.Checked = true;
break;
}
}
protected void SetCheckBoxList()
{
DataExportController dc = new DataExportController();
// fill the disease specific table CheckBoxList
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("tableName", typeof(System.String)));
if (Request.Form["diseaseRadio"] != null)
{
disease = Request.Form["diseaseRadio"];
if (Request.Form["diseaseRadio"].Equals("All"))
{
this.AddToDataTable(dc.GetDiseaseTableList("Bladder"), dt);
this.AddToDataTable(dc.GetDiseaseTableList("Prostate"), dt);
}
else
{
this.AddToDataTable(dc.GetDiseaseTableList(Request.Form["diseaseRadio"]), dt);
}
}
else
{
disease = "Prostate";
this.AddToDataTable(dc.GetDiseaseTableList("Prostate"), dt);
}
diseaseTables.DataSource = dt;
diseaseTables.DataTextField = "tableName";
diseaseTables.DataBind();
//added 10/4 fs
for(int i=0; i<= (diseaseTables.Items.Count - 1); i++)
{
diseaseTables.Items[i].Selected = true;
}
// fill the base tables CheckBoxList
DataTable bt = new DataTable();
bt.Columns.Add(new DataColumn("tableName", typeof(System.String)));
this.AddToDataTable(dc.GetDiseaseTableList("base"), bt);
if (Request.Form["privacyRadio"] != null && ((string)Request.Form["privacyRadio"]).Equals("Identified"))
{
this.AddToDataTable(dc.GetDiseaseTableList("Identified"), bt);
}
baseTables.DataSource = bt;
baseTables.DataTextField = "tableName";
baseTables.DataBind();
//added 10/4 fs
for(int i=0; i<=(baseTables.Items.Count - 1); i++)
{
baseTables.Items[i].Selected = true;
}
}
protected void onSubmitBtnCommand (object s, CommandEventArgs e)
{
//Tell you to wait while the export runs!
/* CAN NOT USE THIS WITH EXPORT AS AN ATTACHMENT. Flush() can not occur before header is set.
Response.Write("<div id='mydiv' style='width:800;align:center;'>");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerHTML = '';</script>");
Response.Write("<script language=javascript>\n");
Response.Write("function ShowWait(){mydiv.innerHTML = '<table width=100%><tr><td align=center><br><br><img src=\"../images/Exporting.gif\"></td></tr></table>'}\n");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}\n");
Response.Write("ShowWait();</script>");
Response.Flush();
*/
//OLD WAY
//Response.Write("<script>mydiv.innerText = '';</script>");
//Response.Write("<script language=javascript>;");
//Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
//Response.Write("{var output; output = 'Exporting. Please Wait';dots++;if(dots>=dotmax)dots=1;");
//Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}");
//Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; window.setInterval('ShowWait()',1000);}");
//Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}");
//Response.Write("StartShowWait();</script>");
//Response.Flush();
//Thread.Sleep(10000) ; what is the purpose of this? all it seems to do is slow processing - 7/28/04 spy
try
{
Server.ScriptTimeout = 3600;//set request timeout to 1 hour for this page
DataExportController de;
if (exportMethod.Value.Equals("access"))
{
de = new AccessExporter();
}
else
{
de = new XmlExporter();
de.exportFormat = exportMethod.Value;
}
//de.method = exportMethod.Value.ToUpper();;
//**** Frank change the code here for webfarms servers!!
//de.FILE_LOCATION = Server.MapPath("/UserExports"); --> C:\Projects\CaisisSln\Caisis.UI\Export\UserExports
//de.FILE_LOCATION = "UserExports/"; --> C:\WINDOWS\system32\UserExports\
UserExport ue = (UserExport)this.GetParams();
string datasetSql = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]);
ArrayList selectedTables = this.GetSelectedTables();
object xml = de.GetDataExport(ue, datasetSql, selectedTables);
//Response.Write(exportXml);
//to debug, uncomment above line and comment below line. also see line 283 of DataExportController
this.WriteFileDownload(xml, ue);
}
catch (ClientException ex)
{
errMsg.Message = ex.Message;
}
}
/// <summary>
/// Retrieves the table names selected on a checkBoxList and stores them in an ArrayList
/// </summary>
/// <returns></returns>
protected ArrayList GetSelectedTables()
{
ArrayList selectedTables = new ArrayList();
foreach (ListItem item in diseaseTables.Items)
{
if (item.Selected == true)
{
selectedTables.Add(item.Text);
}
}
foreach (ListItem item in baseTables.Items)
{
if (item.Selected == true)
{
selectedTables.Add(item.Text);
}
}
return selectedTables;
}
// This should be moved to PageUtil when perfected - 8/10 spy
public void WriteFileDownload(object downloadContent, UserExport ue)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
SecurityController sc = new SecurityController();
string fileName = "Export_"+sc.GetUserName()+"_"+ue.Tables[0].Rows[0][UserExport.UserExportId].ToString();
if (downloadContent is byte[])
{
fileName += ".mdb";
}
else
{
Response.ContentType="text/xml";
Response.ContentType="application/unknown";
fileName += ".xml";
}
//Response.AppendHeader("content-length", lengthInBytes.ToString());
Response.AppendHeader("content-disposition","attachment; filename="+fileName);
debugStr += "\n done setting headers: " +DateTime.Now;
if (downloadContent is byte[])
{
byte[] content = (byte[])downloadContent;
Response.BinaryWrite(content);
}
else if (downloadContent is char[])
{
Response.Write((char[])downloadContent, 0, ((char[])downloadContent).Length);
}
else if (downloadContent is System.String)
{
this.WriteString(downloadContent);
}
debugStr += "\n finished writing response: "+DateTime.Now;
Response.Flush();
debugStr += "\n finished flushing response :"+DateTime.Now;
Response.End();
}
protected void WriteString(object content)
{
string downloadContent = (string)content;
Response.Write(downloadContent);
/*&int i = 0;
int chunk = 6000;
try
{
for (i=0; i < downloadContent.Length/chunk; i++)
{
Response.Write(downloadContent.Substring(i*chunk, chunk));
if ((downloadContent.Length - (i+1)*chunk ) < chunk)
{
Response.Write(downloadContent.Substring(i*chunk+chunk, downloadContent.Length % chunk));
}
}
debugStr += "\n done writing Response: "+DateTime.Now;
}
catch (Exception ex)
{
debugStr += "\n failed while writing response, total response written = "+i*chunk;
throw ex;
}*/
}
protected BizObject GetParams()
{
UserExport biz = new UserExport();
DataRow dr = biz.Tables[UserExport.Table_UserExport].NewRow();
dr[UserExport.DiseaseType] = Request.Form["diseaseRadio"];
dr[UserExport.PrivacyLevel] = Request.Form["privacyRadio"];
dr[UserExport.IRB_ApprovalDate] = PageUtil.ObjToDateTime(Request.Form["approvalDate"]);
dr[UserExport.IRB_ApprovalType] = Request.Form["approvalTypeRadio"];
dr[UserExport.Purpose] = Request.Form["purposeRadio"];
dr[UserExport.UserLoginId] = (int)Session[SessionKey.LoginId];
dr[UserExport.ExportedDate] = DateTime.Now;
biz.Tables[UserExport.Table_UserExport].Rows.Add(dr);
biz.AcceptChanges();
return biz;
}
/// <summary>
/// Used to convert an array of BizObjects into a DataTable of tablenames to be used as a DataSource for CheckBoxList
/// </summary>
/// <param name="tableArray">Array of BizObjects to be converted.</param>
protected void AddToDataTable(BizObject[] tableArray, DataTable dt)
{
for (int i = 0; i < tableArray.Length; i++)
{
if (tableArray[i] != null)
{
if (!tableArray[i].Tables[0].TableName.Equals(Patient.Table_Patients))
{
object[] values = {tableArray[i].Tables[0].TableName};
dt.Rows.Add(values);
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -