本文整理汇总了C#中DataGrid.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.RenderControl方法的具体用法?C# DataGrid.RenderControl怎么用?C# DataGrid.RenderControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataGrid
的用法示例。
在下文中一共展示了DataGrid.RenderControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportDataSetToExcel
public static void ExportDataSetToExcel(DataSet ds, string filename)
{
try
{
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
// set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
DataGrid dg = new DataGrid();
dg.Font.Size = 9;
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
}
}
catch (Exception)
{
throw;
}
}
示例2: Operation
Operation operation = new Operation(); //业务类对象
#endregion Fields
#region Methods
public void ExportResult(DataSet ds, string excelName)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
dg.RenderControl(htmlWrite);
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName));
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
示例3: ExportarDataTableToExcel3
public void ExportarDataTableToExcel3(DataTable dt)
{
if (dt.Rows.Count > 0)
{
string filename = "ReporteBasedatos.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
dgGrid.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
Response.Charset = "";
Response.Write(tw.ToString());
Response.End();
}
}
示例4: GetListadoUsuarios
public void GetListadoUsuarios()
{
UsuarioBLL usuariosbll = new UsuarioBLL();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + "ListadoUsuariosINCI_" + DateTime.Now.ToString() + "_.xls");
Response.ContentType = "application/vnd.ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
DataGrid dataExportExcel = new DataGrid();
dataExportExcel.ItemDataBound += new DataGridItemEventHandler(dataExportExcel_ItemDataBound);
dataExportExcel.DataSource = usuariosbll.SelectAllExcel();
dataExportExcel.DataBind();
dataExportExcel.RenderControl(htmlWrite);
StringBuilder sbResponseString = new StringBuilder();
sbResponseString.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"> <head><meta http-equiv=\"Content-Language\" content=\"es\"><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + "ListadoUsuariosINCI" + "</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
sbResponseString.Append(stringWriter + "</body></html>");
Response.Write(sbResponseString.ToString());
Response.End();
}
示例5: exportToExcel
public void exportToExcel(DataTable dt)
{
if(dt.Rows.Count>0)
{
string filename = "StudentRecord.xls";
StringWriter tw = new StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
dgGrid.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename = " + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
示例6: DataTable2Excel
/// <summary>
/// 导出Excel文件,转换为可读模式
/// </summary>
public static void DataTable2Excel(System.Data.DataTable dtData)
{
DataGrid dgExport = null;
HttpContext curContext = HttpContext.Current;
StringWriter strWriter = null;
HtmlTextWriter htmlWriter = null;
if (dtData != null)
{
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
curContext.Response.Charset = "";
strWriter = new StringWriter();
htmlWriter = new HtmlTextWriter(strWriter);
dgExport = new DataGrid();
dgExport.DataSource = dtData.DefaultView;
dgExport.AllowPaging = false;
dgExport.DataBind();
dgExport.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();
}
}
示例7: GerarExcel
private void GerarExcel(string pDataIni, string pDataFim)
{
//Conteúdo do Response
Response.ContentEncoding = System.Text.Encoding.GetEncoding("Windows-1252");
Response.AddHeader("content-disposition", "attachment; filename=DocumentoExcel.xls");
Response.Charset = "UTF-8";
Response.ContentType = "application/vnd.xls";
//Objetos
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//Inclui controles
DataGrid dgDados = new DataGrid();
this.form1.Controls.Add(dgDados);
//Definição de cores
//dgRecord.HeaderStyle.BackColor = System.Drawing.Color.Yellow;
dgDados.DataSource = AcompanharDo.GetConsultaResumidaNuplan(LocalInstance.ConnectionInfo, pDataIni, pDataFim, Session["_SessionPESF_ID"].ToString());
dgDados.DataBind();
//definição das cores das células
//foreach (DataGridItem dgi in dgRecord.Items)
// foreach (TableCell tcGridCells in dgi.Cells)
// tcGridCells.Attributes.Add("class", "sborder");
//Renderiza o DataGrid
dgDados.RenderControl(htmlWrite);
//Inluir a classe de estilo
//Response.Write(@"<style> .sborder { color : Red;border : 1px Solid Balck; } </style> ");
//Exporta
Response.Write(stringWrite.ToString());
//encerra
Response.End();
}
示例8: Page_Load
//.........这里部分代码省略.........
if (Request.QueryString["LangType"] != "")
{
ContentLanguage = Convert.ToInt32(Request.QueryString["LangType"]);
m_refContentApi.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString());
}
else
{
if (m_refContentApi.GetCookieValue("LastValidLanguageID") != "")
{
ContentLanguage = Convert.ToInt32(m_refContentApi.GetCookieValue("LastValidLanguageID"));
}
}
}
else
{
if (m_refContentApi.GetCookieValue("LastValidLanguageID") != "")
{
ContentLanguage = Convert.ToInt32(m_refContentApi.GetCookieValue("LastValidLanguageID"));
}
}
if (ContentLanguage == (int)Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED)
{
m_refContentApi.ContentLanguage = Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES;
}
else
{
m_refContentApi.ContentLanguage = ContentLanguage;
}
if (!(Request.QueryString["fieldname"] == null))
{
FieldName = Request.QueryString["fieldname"];
}
QueryLang = ContentLanguage.ToString();
if (!(Request.QueryString["qlang"] == null))
{
QueryLang = Request.QueryString["qlang"];
}
if (!String.IsNullOrEmpty(Request["form_id"]))
{
FormId = Convert.ToInt64(Request["form_id"]);
}
StartDate = Request["start_date"];
EndDate = Request["end_date"];
Flag = Request["flag"];
DataType = Request["data_type"];
ResultType = Request["result_type"];
CurrentUserId = m_refContentApi.UserId;
DisplayType = Request["display_type"];
FormTitle = Request["form_title"];
m_refMsg = m_refContentApi.EkMsgRef;
Security_info = m_refContentApi.LoadPermissions(FormId, "content", 0);
Response.AddHeader("content-disposition", "attachment; filename=Form_Data_Export.xls");
objForm = m_refContentApi.EkModuleRef;
gtForms = objForm.GetAllFormInfo();
Collection objFormData = new Collection();
Collection cDatas;
objFormData.Add(FormId, "FORM_ID", null, null);
objFormData.Add(CurrentUserId, "USER_ID", null, null);
objFormData.Add(StartDate, "START_DATE", null, null);
objFormData.Add(EndDate, "END_DATE", null, null);
objFormData.Add(QueryLang, "Query_Language", null, null);
objFormData.Add(FieldName, "Field_Name", null, null);
cDatas = objForm.GetAllFormData(objFormData);
if (cDatas.Count == 0)
{
FormResult.Text = "<table><tr><td>" + m_refMsg.GetMessage("msg no data report") + "</td></tr></table>";
return;
}
if (Information.IsNumeric(DisplayType))
{
//The following lines of code are extracted from dotnetjohn.com on "Export DataSets to Excel"
//http://www.dotnetjohn.com/articles.aspx?articleid=36
//first let's clean up the response.object
Response.Clear();
Response.Charset = "";
//set the response mime type for excel
Response.ContentType = "application/vnd.ms-excel";
//create a string writer
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
//instantiate a datagrid
DataGrid dg = new DataGrid();
//set the datagrid datasource to the dataset passed in
dg.DataSource = objForm.GetAllFormRawData(objFormData).Tables[0];
//bind the datagrid
dg.DataBind();
//tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite);
//all that's left is to output the html
Response.Write(stringWrite.ToString());
Response.End();
}
else
{
FormResult.Text = LoadResult(objFormData, cDatas);
}
}
示例9: Export
/// <summary>
/// GridView 控制項匯出。
/// </summary>
/// <param name="Encoding">編碼方式。</param>
/// <param name="FileName">檔案名稱。</param>
/// <param name="ContentType">內容類型標頭。</param>
public static void Export(System.Text.Encoding Encoding, string FileName, string ContentType, DataTable ExportData)
{
#region 更換匯出欄位名稱
//移除「零售價」(因在期別檔裏會造成多筆)、「供應商代號」(因已有「供應商」)
ExportData.Columns[0].ColumnName = "品號";
ExportData.Columns[1].ColumnName = "異動序號";
ExportData.Columns[2].ColumnName = "品名";
ExportData.Columns[3].ColumnName = "DC開始日";
ExportData.Columns[4].ColumnName = "DC結束日";
ExportData.Columns[5].ColumnName = "供應商";
ExportData.Columns[6].ColumnName = "大分類";
ExportData.Columns[7].ColumnName = "中分類";
ExportData.Columns[8].ColumnName = "小分類";
ExportData.Columns[9].ColumnName = "PatternNo";
ExportData.Columns[10].ColumnName = "是否定期";
ExportData.Columns[11].ColumnName = "首期期別";
ExportData.Columns[12].ColumnName = "期別累加值";
ExportData.Columns[13].ColumnName = "出刊間隔(天數)";
ExportData.Columns[14].ColumnName = "出刊種類";
ExportData.Columns[15].ColumnName = "銷售單位";
ExportData.Columns[16].ColumnName = "敘述";
ExportData.Columns[17].ColumnName = "配量方式";
ExportData.Columns[18].ColumnName = "定量出貨";
ExportData.Columns[19].ColumnName = "類似商品";
ExportData.Columns[20].ColumnName = "商品內容說明";
ExportData.Columns[21].ColumnName = "推薦理由";
ExportData.Columns[22].ColumnName = "暫時保留欄位";
ExportData.Columns[23].ColumnName = "作者";
ExportData.Columns[24].ColumnName = "系列性";
ExportData.Columns[25].ColumnName = "送貨數≦";
ExportData.Columns[26].ColumnName = "送貨數≧";
ExportData.Columns[27].ColumnName = "Pos使用";
ExportData.Columns[28].ColumnName = "Pos加權比率%";
ExportData.Columns[29].ColumnName = "新商品";
ExportData.Columns[30].ColumnName = "期間";
ExportData.Columns[31].ColumnName = "其他說明";
ExportData.Columns[32].ColumnName = "總進貨量";
ExportData.Columns[33].ColumnName = "VCMS出版社";
ExportData.Columns[34].ColumnName = "群分類";
ExportData.Columns[35].ColumnName = "出版社書系";
ExportData.Columns[36].ColumnName = "出版日期";
ExportData.Columns[37].ColumnName = "副主題";
ExportData.Columns[38].ColumnName = "絕版";
ExportData.Columns[39].ColumnName = "開數";
ExportData.Columns[40].ColumnName = "頁數";
ExportData.Columns[41].ColumnName = "中央圖書分類碼";
ExportData.Columns[42].ColumnName = "最新的主檔資料也要存異動序號與原因";
ExportData.Columns[43].ColumnName = "商品出版商代號";
ExportData.Columns[44].ColumnName = "商品出版商名稱";
ExportData.Columns[45].ColumnName = "深";
ExportData.Columns[46].ColumnName = "寬";
ExportData.Columns[47].ColumnName = "高";
ExportData.Columns[48].ColumnName = "建立日期";
ExportData.Columns[49].ColumnName = "建立人員";
ExportData.Columns[50].ColumnName = "維護日期";
ExportData.Columns[51].ColumnName = "維護人員";
#endregion
HttpResponse oResponse = default(HttpResponse);
System.IO.StringWriter oStringWriter = default(System.IO.StringWriter);
System.Web.UI.HtmlTextWriter oHtmlWriter = default(System.Web.UI.HtmlTextWriter);
bool bAllowPaging = false;
string sText = null;
string sFileName = null;
//檔案名稱需經 UrlEncode 編碼,解決中文檔名的問題
sFileName = HttpUtility.UrlEncode(FileName, Encoding);
oResponse = HttpContext.Current.Response;
oResponse.Clear();
sText = "<meta http-equiv='Content-Type'; content='text/html';charset='{0}'>";
sText = string.Format(sText, Encoding.WebName);
oResponse.Write(sText);
oResponse.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.HtmlEncode(sFileName));
oResponse.ContentEncoding = System.Text.Encoding.UTF8;
oResponse.Charset = Encoding.WebName;
oResponse.ContentType = "application/ms-excel";
// If you want the option to open the Excel file without saving than
// comment out the line below
// oResponse.Cache.SetCacheability(HttpCacheability.NoCache)
DataGrid dgExcel = new DataGrid();
dgExcel.DataSource = ExportData;
dgExcel.AutoGenerateColumns = true;
dgExcel.DataBind();
oStringWriter = new System.IO.StringWriter();
oHtmlWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dgExcel.AllowPaging = false;
dgExcel.RenderControl(oHtmlWriter);
oResponse.Write(oStringWriter.ToString());
//.........这里部分代码省略.........
示例10: Export
/// <summary>
/// GridView 控制項匯出。
/// </summary>
/// <param name="Encoding">編碼方式。</param>
/// <param name="FileName">檔案名稱。</param>
/// <param name="ContentType">內容類型標頭。</param>
public static void Export(System.Text.Encoding Encoding, string FileName, string ContentType, DataTable ExportData)
{
HttpResponse oResponse = default(HttpResponse);
System.IO.StringWriter oStringWriter = default(System.IO.StringWriter);
System.Web.UI.HtmlTextWriter oHtmlWriter = default(System.Web.UI.HtmlTextWriter);
bool bAllowPaging = false;
string sText = null;
string sFileName = null;
//檔案名稱需經 UrlEncode 編碼,解決中文檔名的問題
sFileName = HttpUtility.UrlEncode(FileName, Encoding);
oResponse = HttpContext.Current.Response;
oResponse.Clear();
sText = "<meta http-equiv='Content-Type'; content='text/html';charset='{0}'>";
sText = string.Format(sText, Encoding.WebName);
oResponse.Write(sText);
oResponse.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.HtmlEncode(sFileName));
oResponse.ContentEncoding = Encoding;
oResponse.Charset = Encoding.WebName;
oResponse.ContentType = "application/ms-excel";
// If you want the option to open the Excel file without saving than
// comment out the line below
// oResponse.Cache.SetCacheability(HttpCacheability.NoCache)
DataGrid dgExcel = new DataGrid();
dgExcel.DataSource = ExportData;
dgExcel.AutoGenerateColumns = true;
dgExcel.DataBind();
oStringWriter = new System.IO.StringWriter();
oHtmlWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dgExcel.AllowPaging = false;
dgExcel.RenderControl(oHtmlWriter);
oResponse.Write(oStringWriter.ToString());
oResponse.End();
}
示例11: ExportDialog
public static void ExportDialog(string One, string two, string three, DataSet ds, Page page)
{
string title = DateTime.Now.ToString("yyMMdd") + three + ".xls";
System.Web.UI.WebControls.DataGrid DataGrid1 = new DataGrid();
HttpResponse response = HttpContext.Current.Response;
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
StringWriter tw = new StringWriter();
HtmlTextWriter myWrite = new HtmlTextWriter(tw);
if (One != "")
myWrite.WriteLine(One);
if (two != "")
myWrite.WriteLine(two);
DataGrid1.RenderControl(myWrite);
response.Clear();
response.Buffer = true;
response.Charset = "GB2312";
response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
response.AppendHeader("Content-Disposition", "attachment;filename=" + title);
response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
response.ContentType = "application/vnd.xls";//Response.ContentType= "application/msword";
page.EnableViewState = false;
response.Write(tw.ToString());
response.End();
}
示例12: ExportToSpreadsheet
public static void ExportToSpreadsheet(DataTable table, string reportOIDStr, String reportType)
{
try
{
Reports report = null;
if (!string.IsNullOrEmpty(reportOIDStr))
{
report = new Reports().GetReportByOID(Int32.Parse(reportOIDStr));
}
if ((report == null) || (table == null))
{
return;
}
else
{
String gridColumnsStr = Convert.ToString(report.GridColumns);
String[] gridColumns = gridColumnsStr.Split('&');
foreach (String gridColumn in gridColumns)
{
String[] nameValue = gridColumn.Split('=');
if (nameValue[1] == "true")
{
try
{
table.Columns.Remove(nameValue[0]);
}
catch
{ }
}
}
}
if (reportType == "CSV")
{
//Remove Comma from Text
string tempStr = "";
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Columns.Count; j++)
{
tempStr = Convert.ToString(table.Rows[i][j]);
if (tempStr.Contains(','))
{
table.Rows[i][j] = tempStr.Replace(',', ' ');
}
}
}
HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + report.ReportName +"_"+DateTime .Now .ToShortDateString ()+ ".csv");
//Write a row for column names
foreach (DataColumn dataColumn in table.Columns)
context.Response.Write(dataColumn.ColumnName + ",");
context.Response.Write(Environment.NewLine);
//Write one row for each DataRow
foreach (DataRow dataRow in table.Rows)
{
for (int dataColumnCount = 0; dataColumnCount < table.Columns.Count; dataColumnCount++)
context.Response.Write(dataRow[dataColumnCount].ToString() + ",");
context.Response.Write(Environment.NewLine);
}
context.Response.End();
}
else if (reportType == "Excel")
{
DataGrid dtaFinal = new DataGrid();
dtaFinal.DataSource = table;
dtaFinal.DataBind();
dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White;
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White;
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
dtaFinal.RenderControl(hw);
HttpContext context = HttpContext.Current;
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ContentType = "application/ms-excel";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + report.ReportName + ".xls");
context.Response.Write(sw.ToString());
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
else if (reportType == "PDF")
{
HttpResponse Response = HttpContext.Current.Response;
Response.Clear();
Response.ContentType = "application/octet-stream";
//.........这里部分代码省略.........
示例13: Export_attachment
private void Export_attachment()
{
try
{
DataTable dt = null;
dt = (DataTable)ViewState["ExportReport"];
if (dt == null)
{
throw new Exception("No record found for export");
}
string Path = "D:\\ImportDailCallReport\\myexcelfile_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + ".xls";
FileInfo FI = new FileInfo(Path);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
DataGrid DataGrd = new DataGrid();
DataGrd.DataSource = dt;
DataGrd.DataBind();
DataGrd.RenderControl(htmlWrite);
string directory = Path.Substring(0, Path.LastIndexOf("\\"));
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true);
stringWriter.ToString().Normalize();
vw.Write(stringWriter.ToString());
vw.Flush();
vw.Close();
WriteAttachment(FI.Name, "application/vnd.ms-excel", stringWriter.ToString());
}
catch (Exception ex)
{
}
finally
{
}
}
示例14: sendEmail
public void sendEmail()
{
Whitfieldcore wCore = new Whitfieldcore();
whitfield_reports _wRep = new whitfield_reports();
MailMessage message = new MailMessage();
message.To.Add(System.Configuration.ConfigurationManager.AppSettings["devEmail"]);
//Here is where we add the receipients.
using (DataSet ds = wCore.GetRightDistributionList(Convert.ToInt32(ViewState["twc_project_number"].ToString())) ) //HHS Uncomment this portion when there is an email list.
{
DataTable dtUsr = ds.Tables[0];
if (dtUsr.Rows.Count > 0)
{
foreach (DataRow dRow in dtUsr.Rows)
{
string _email = dRow["Email"] == DBNull.Value ? "" : dRow["Email"].ToString();
message.To.Add(_email);
}
}
}
message.To.Add(System.Configuration.ConfigurationManager.AppSettings["AdminEmail"].ToString());
//This is commented by Harish on Friday, January 27th with the request of Jammie.
//message.To.Add(System.Configuration.ConfigurationManager.AppSettings["PMEmail"].ToString());
message.From = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["DFR_fromEmail"]);
message.Subject = txtReportDate.Text.Trim() + " Daily Field Report:" + lblPrjHeader.Text.Trim();
message.IsBodyHtml = true;
StringBuilder sb = new StringBuilder();
sb.Append("<html><head></head>");
sb.Append("<body>");
//Header
sb.Append("<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'><TR>");
sb.Append("<TD><IMG height='80' alt='' src='http://www.whitfield-co.com/whitfield-co/assets/img/TWC%20Primary%20Logo1.JPG' border='0'></TD>");
sb.Append("<TD class='form1' vAlign='bottom' align='right' width='100%'><b>The Whitfield Corporation, Inc.,<br>");
sb.Append("P.O. Box 0385<br>");
sb.Append("Fulton, MD 20759<br>");
sb.Append("(301)-483-0791<br>");
sb.Append("(301)-483-0792</b><br>");
sb.Append("<IMG height='9' alt='' src='http://www.whitfield-co.com/whitfield-co/assets/img/images.gif' width='1'>");
sb.Append("</TD>");
sb.Append("</TR></TABLE>");
//EmployeeHours
System.Drawing.ColorConverter colConvert = new ColorConverter();
DataGrid dgWorkOrders = new DataGrid();
dgWorkOrders.Font.Size = 9;
dgWorkOrders.CssClass = "data";
dgWorkOrders.HeaderStyle.BackColor = (System.Drawing.Color)colConvert.ConvertFromString("#60829F");
dgWorkOrders.HeaderStyle.CssClass = "subnav";
dgWorkOrders.HeaderStyle.Font.Bold = true;
dgWorkOrders.ItemStyle.BackColor = (System.Drawing.Color)colConvert.ConvertFromString("#EAEFF3");
dgWorkOrders.FooterStyle.BackColor = (System.Drawing.Color)colConvert.ConvertFromString("#D9D9D9");
dgWorkOrders.DataSource = _wRep.GetReportActivityForProjectMail(_wRep.GetReportNumber(Convert.ToInt32(ViewState["twc_project_number"].ToString()), txtReportDate.Text.Trim()), Convert.ToInt32(ViewState["twc_project_number"].ToString()));
dgWorkOrders.DataBind();
StringBuilder SBEmployeeHours = new StringBuilder();
StringWriter SWEmployeeHours = new StringWriter(SBEmployeeHours);
HtmlTextWriter htmlTWEmployeeHours = new HtmlTextWriter(SWEmployeeHours);
dgWorkOrders.RenderControl(htmlTWEmployeeHours);
string EmployeeHoursString = SBEmployeeHours.ToString();
sb.Append("<br><B>Work Executed for Today:</b><br>" + EmployeeHoursString);
//Daily Work Performed Notes/Comments
String StrRptNotes = "";
if (txtRptNotes.Text == "")
{
StrRptNotes = "None.";
}
else
{
StrRptNotes = txtRptNotes.Text.Trim();
}
sb.Append("<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'><TR>");
sb.Append("<TD>");
sb.Append("<br><b>Daily Work Performed Notes/Comments:</b>" + StrRptNotes + "<br>");
sb.Append("</TD>");
sb.Append("</TR></TABLE>");
//Significant Issues/Impediments Notes/Comments:
String StrRptIssues = "";
if (txtRptIssues.Text == "")
{
StrRptIssues = "None.";
}
else
{
StrRptIssues = txtRptIssues.Text.Trim();
}
sb.Append("<TABLE cellSpacing='0' cellPadding='0' width='100%' border='0'><TR>");
sb.Append("<TD>");
sb.Append("<br><b>Significant Issues/Impediments Notes/Comments:</b>" + StrRptIssues + "<br>");
sb.Append("</TD>");
//.........这里部分代码省略.........
示例15: Export
/// <summary>
/// GridView 控制項匯出。
/// </summary>
/// <param name="Encoding">編碼方式。</param>
/// <param name="FileName">檔案名稱。</param>
/// <param name="ContentType">內容類型標頭。</param>
public static void Export(System.Text.Encoding Encoding, string FileName, string ContentType, DataTable ExportData)
{
#region 更換匯出欄位名稱
//移除「零售價」(因在期別檔裏會造成多筆)、「供應商代號」(因已有「供應商」)
ExportData.Columns[0].ColumnName = "條碼";
ExportData.Columns[1].ColumnName = "品名";
ExportData.Columns[2].ColumnName = "DC開始日";
ExportData.Columns[3].ColumnName = "DC結束日";
ExportData.Columns[4].ColumnName = "零售價";
ExportData.Columns[5].ColumnName = "重量";
ExportData.Columns[6].ColumnName = "出版社代號";
ExportData.Columns[7].ColumnName = "出版社名稱";
ExportData.Columns[8].ColumnName = "進貨折扣";
ExportData.Columns[9].ColumnName = "商品狀態";
ExportData.Columns[10].ColumnName = "建立日期";
ExportData.Columns[11].ColumnName = "建立人員";
ExportData.Columns[12].ColumnName = "維護日期";
ExportData.Columns[13].ColumnName = "維護人員";
#endregion
HttpResponse oResponse = default(HttpResponse);
System.IO.StringWriter oStringWriter = default(System.IO.StringWriter);
System.Web.UI.HtmlTextWriter oHtmlWriter = default(System.Web.UI.HtmlTextWriter);
bool bAllowPaging = false;
string sText = null;
string sFileName = null;
//檔案名稱需經 UrlEncode 編碼,解決中文檔名的問題
sFileName = HttpUtility.UrlEncode(FileName, Encoding);
oResponse = HttpContext.Current.Response;
oResponse.Clear();
sText = "<meta http-equiv='Content-Type'; content='text/html';charset='{0}'>";
sText = string.Format(sText, Encoding.WebName);
oResponse.Write(sText);
oResponse.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.HtmlEncode(sFileName));
oResponse.ContentEncoding = System.Text.Encoding.UTF8;
oResponse.Charset = Encoding.WebName;
oResponse.ContentType = "application/ms-excel";
// If you want the option to open the Excel file without saving than
// comment out the line below
// oResponse.Cache.SetCacheability(HttpCacheability.NoCache)
DataGrid dgExcel = new DataGrid();
dgExcel.DataSource = ExportData;
dgExcel.AutoGenerateColumns = true;
dgExcel.DataBind();
oStringWriter = new System.IO.StringWriter();
oHtmlWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dgExcel.AllowPaging = false;
dgExcel.RenderControl(oHtmlWriter);
oResponse.Write(oStringWriter.ToString());
oResponse.End();
}