📄 generalsearch.aspx.cs
字号:
/***********************
* 创建者:周建波
*
* 创建日期:2003-12-15
*
* 功能: 通用查询客户端
*
* ************************/
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 ZHENGYI;
namespace OI.GeneralSearch
{
/// <summary>
/// GeneralSearch 的摘要说明。
/// </summary>
public class GeneralSearch : OI.PageBase
{
protected System.Web.UI.WebControls.RadioButtonList RadioButtonListSort;
protected System.Web.UI.WebControls.DropDownList DropDownListTopN;
protected System.Web.UI.WebControls.DropDownList DropDownListTable;
protected System.Web.UI.WebControls.DropDownList DropDownListFieldName;
protected System.Web.UI.WebControls.DropDownList DropDownListOperation;
protected System.Web.UI.WebControls.TextBox TextBoxSearchValue;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected OI.DatabaseOper.DatabaseConnect dc;
protected System.Web.UI.WebControls.ImageButton ImageButtonSearch;
protected System.Web.UI.WebControls.Label LabelMsg;
protected OI.UserControls.GeneralSearch PFs;
private void Page_Load(object sender, System.EventArgs e)
{
dc=new OI.DatabaseOper.DatabaseConnect();
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack) {
loadData();//绑定数据。
}
}
private void loadData() {
loadDropDownListTable(DropDownListTable);//绑定表数据
//
}
/// <summary>
/// 绑定表数据
/// </summary>
/// <param name="DDL">要绑定的控件名称</param>
private void loadDropDownListTable(System.Web.UI.WebControls.DropDownList DDL) {
string sql="select Convert(char(20),querytableid)+'||||'+TableName as tt,viewName from QueryTables order by tt desc";
DataTable dt=dc.getBinding(sql,"QueryTables").Tables[0];
DDL.DataSource=dt;
DDL.DataTextField="ViewName";
DDL.DataValueField="tt";
DDL.DataBind();
}
/// <summary>
/// 绑定字段数据,根据不同的表取相应字段
/// </summary>
/// <param name="DDL">要绑定的控件名称</param>
/// <param name="QueryTableID">表的编号</param>
private void loadDropDownListFieldName(System.Web.UI.WebControls.DropDownList DDL,string QueryTableID) {
string sql="select QueryFiledValue, QueryFiledView from dbo.QueryFields where querytableid="+QueryTableID.Substring(0,19).Trim()+" and IsQuery=1";
DataTable dt=dc.getBinding(sql,"QueryFields").Tables[0];
DDL.DataSource=dt;
DDL.DataTextField="QueryFiledView";
DDL.DataValueField="QueryFiledValue";
DDL.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownListTable.SelectedIndexChanged += new System.EventHandler(this.DropDownListTable_SelectedIndexChanged);
this.ImageButtonSearch.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButtonSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ImageButtonSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
try
{
string sql=strsql(DropDownListTopN.SelectedValue,DropDownListTable.SelectedValue.Substring(24,DropDownListTable.SelectedValue.Length-24),DropDownListFieldName.SelectedValue,DropDownListOperation.SelectedValue,TextBoxSearchValue.Text.Trim(),RadioButtonListSort.SelectedValue);
PFs.SQL=sql;
PFs.DataBindToGrid();
}
catch{
LabelMsg.Text="查询时出错,请注意所选的字段类型要与输入值匹配";
}
}
private string strsql(string TopN,string TableName,string FieldName,string Operation,string SearchValue,string Sort) {
string topn="*";//命中率
if(TopN=="*") { //判断命中率。
topn="*";
}
else {
topn=" top "+TopN;
}
string sql="select "+topn+ " * from " +TableName+" where "+FieldName+""+Operation+"'"+SearchValue+"' order by "+FieldName+" "+Sort;
return sql;
}
private void DropDownListTable_SelectedIndexChanged(object sender, System.EventArgs e) {
loadDropDownListFieldName(DropDownListFieldName,DropDownListTable.SelectedValue);//根据表取该表字段
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -