📄 query_de.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.Data.SqlClient;
namespace BookManager
{
/// <summary>
/// Query_de 的摘要说明。
/// </summary>
public class Query_de : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlAdapter;
protected System.Data.SqlClient.SqlConnection sqlConn;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Web.UI.WebControls.DataGrid dgQuery;
protected System.Data.DataView dvQuery;
protected BookManager.dsQuery dsQueryInfo;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
this.DatasBind();
if(dgQuery.Items.Count==0)
{
Response.Redirect("NoInfo.aspx");
}
}
}
private void DatasBind()
{
sqlAdapter.Fill(dsQueryInfo);
dvQuery.RowFilter=this.GetAttribute()+" like '%"+TranVar.Var+"%'";
dgQuery.DataSource=dvQuery;
dgQuery.DataBind();
}
private string GetAttribute()
{
switch(TranVar.Type)
{
case "Name":{return "BookName";}
case "Author":{return "Author";}
case "Publish":{return "Publish";}
default: return "";
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlAdapter = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConn = new System.Data.SqlClient.SqlConnection();
this.dsQueryInfo = new BookManager.dsQuery();
this.dvQuery = new System.Data.DataView();
((System.ComponentModel.ISupportInitialize)(this.dsQueryInfo)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dvQuery)).BeginInit();
this.dgQuery.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgQuery_ItemDataBound);
//
// sqlAdapter
//
this.sqlAdapter.SelectCommand = this.sqlSelectCommand1;
this.sqlAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "tblBookInfo", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("BookName", "BookName"),
new System.Data.Common.DataColumnMapping("BookInfoId", "BookInfoId"),
new System.Data.Common.DataColumnMapping("Author", "Author"),
new System.Data.Common.DataColumnMapping("Publish", "Publish"),
new System.Data.Common.DataColumnMapping("BookAttribute", "BookAttribute"),
new System.Data.Common.DataColumnMapping("Storage", "Storage"),
new System.Data.Common.DataColumnMapping("BookAttributeID", "BookAttributeID"),
new System.Data.Common.DataColumnMapping("BookStorageID", "BookStorageID")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = @"SELECT tblBookInfo.BookName, tblBookInfo.ID AS BookInfoId, tblBookInfo.Author, tblBookInfo.Publish, tblBookAttribute.BookAttribute, tblBookStorage.Storage, tblBookAttribute.ID AS BookAttributeID, tblBookStorage.ID AS BookStorageID FROM tblBookInfo INNER JOIN tblBookStorage ON tblBookInfo.ID = tblBookStorage.BookId INNER JOIN tblBookAttribute ON tblBookInfo.Attribute = tblBookAttribute.ID";
this.sqlSelectCommand1.Connection = this.sqlConn;
//
// sqlConn
//
this.sqlConn.ConnectionString = "workstation id=QMX;packet size=4096;user id=sa;data source=\"QMX\\THUNDER\";persist " +
"security info=True;initial catalog=BookManager;password=gliu0307";
//
// dsQueryInfo
//
this.dsQueryInfo.DataSetName = "dsQuery";
this.dsQueryInfo.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// dvQuery
//
this.dvQuery.Table = this.dsQueryInfo.tblBookInfo;
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dsQueryInfo)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dvQuery)).EndInit();
}
#endregion
private void dgQuery_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType ==ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item )||(e.Item.ItemType==ListItemType.Separator))
{
e.Item.Attributes.Add("onclick","this.style.backgroundColor='#9671D8'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEDFDE'");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -