#region 导出文件
private static void ImportPage(HttpContext Context, string app, string entity, string id)
{
#region 获取数据id
AppEntity.App AppObj = AppEntity.GetApp(app);
AppEntity.Entity En = AppObj.GetEntity(entity);
#endregion
string columns = Context.Request.Form["columns"];
string striphtml = Context.Request.Form["striphtml"];
XmlDocument ColDom = new XmlDocument();
Hashtable param = new Hashtable();
param.Add("appsetting", AppObj.AppDom);
param.Add("entitysetting", En.EntityDom);
param.Add("urn:functions-sbsinc-com:ext", new SBS.Common.XslExtensionObject());
param.Add("urn:functions-sbsinc-com:AppEntity", new SBS.AppEntity.AppEntityXslExtension());
param.Add("app", app);
param.Add("entity", entity);
param.Add("action", "export");
param.Add("columns", ColDom);
string Folder = AppEntity.GetAppFolder() + app + "http://www.cnblogs.com/jacd/admin/file://entity//" + entity + "http://www.cnblogs.com/jacd/admin/file://data//";
string html = SBS.Common.Convert.xml2html("<root/>", AppEntity.GetThemePath() + "common\\import.xsl", param);
Context.Response.Write(html);
}
private static void DownTemplate(HttpContext Context, string app, string entity, string id)
{
#region 获取数据id
AppEntity.App AppObj = AppEntity.GetApp(app);
AppEntity.Entity En = AppObj.GetEntity(entity);
var columns = En.columns.ToHashSet();
var sysColumnDict = AppEntity.GetAppBuilderSetting().Descendants("syscol").Elements("col").Select(
n => n.GetAttrValue("name")).ToHashSet();
#endregion
sysColumnDict.Remove("title");
sysColumnDict.Remove("description");
columns.ExceptWith(sysColumnDict);
string filename = AppObj.name + "-" + En.title + ".csv";
StreamWriter sw = new StreamWriter(Context.Response.OutputStream, Encoding.UTF8);
StringBuilder sb = new StringBuilder();
foreach (var c in columns)
{
sb.Append(c + ",");
}
sw.Write(sb.ToString().Substring(0, sb.Length - 1));
sw.Write("\r\n");
if (filename != "")
{
Context.Response.ContentEncoding = Encoding.UTF8;
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
// Context.Response.ContentType = "application/octet-stream";
// Context.Response.ContentType = "application/csv";
sw.Close();
Context.Response.End();
}
}
#region 下载 Xls 文件
private static void DownTemplateXls(HttpContext Context, string app, string entity, string id)
{
#region 获取数据id
AppEntity.App AppObj = AppEntity.GetApp(app);
AppEntity.Entity En = AppObj.GetEntity(entity);
string tableName = "ColumnExample";
var columns = En.columns.ToHashSet();
var sysColumnDict = AppEntity.GetAppBuilderSetting().Descendants("syscol").Elements("col").Select(
n => n.GetAttrValue("name")).ToHashSet();
sysColumnDict.Remove("title");
sysColumnDict.Remove("description");
columns.ExceptWith(sysColumnDict);
StringBuilder sb = new StringBuilder();
sb.Append(" CREATE TABLE " + tableName + " (");
foreach (var c in columns)
{
sb.Append(c + " VARCHAR(99),");
}
string CreateSql = sb.ToString();
CreateSql = CreateSql.Trim(',');
CreateSql = CreateSql + ")";
#endregion
string newFile = (Context.Server.MapPath(".") + "\\" + "TableColumn.xls");
File.Delete(newFile);
File.Copy(@"D:\tasktoday.353.us\fb.tasktoday.com\TableColumn.xls", newFile, true);
string cnStr = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" +
newFile + ";Extended Properties=Excel 8.0";
using (var cn = new OleDbConnection(cnStr))
{
cn.Open();
var cmd = new OleDbCommand(CreateSql, cn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
}
MemoryStream ms = new MemoryStream(File.ReadAllBytes(newFile));
ms.WriteTo(Context.Response.OutputStream);
ms.Close();
Context.Response.ContentEncoding = Encoding.UTF8;
string filename = AppObj.name + "-" + En.title + ".xls";
Context.Response.AddHeader("Content-Disposition", "attachment; filename= " + filename);
Context.Response.ContentType = "application/ms-excel";
Context.Response.End();
}
#endregion
#endregion