📄 queryeatingprint.aspx.cs
字号:
//文件名:QueryEatingPrint.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class QueryManage_QueryEatingPrint : System.Web.UI.Page
{
private QueryManage_QueryEatingForm MyQueryForm;
protected void Page_Load(object sender, EventArgs e)
{//将查询结果输出到Excel文件中
MyQueryForm = (QueryManage_QueryEatingForm)Context.Handler;
this.Label1.Text = Session["MyCompanyName"].ToString() + "用餐信息表";
this.Label2.Text = "打印日期:" + DateTime.Now.ToShortDateString();
DataTable MyTable = new DataTable();
string MySQL = MyQueryForm.MyPrintSQL;
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MyEateryDBConnectionString"].ConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
SqlDataAdapter MyAdatper = new SqlDataAdapter(MySQL, MyConnection);
MyAdatper.Fill(MyTable);
this.GridView1.DataSource = MyTable;
this.GridView1.DataBind();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.Charset = "";
//关闭 ViewState
this.EnableViewState = false;
System.IO.StringWriter MyWriter;
System.Web.UI.HtmlTextWriter MyWeb;
//将信息写入字符串
MyWriter = new System.IO.StringWriter();
//在Web窗体页上写出一系列连续的HTML特定字符和文本
MyWeb = new System.Web.UI.HtmlTextWriter(MyWriter);
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{//在GridView控件单元格中设置短日期显示格式
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime MyDate = DateTime.Parse(e.Row.Cells[3].Text);
e.Row.Cells[3].Text = MyDate.ToShortDateString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -