📄 stockpile_search.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
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;
using LoginCheckClass;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) //验证该页面是否已经过登陆
{
LoginCheck a = new LoginCheck();
a.check();
}
//注册commodityname与companyid得checkbox得打勾验证事件,因为总共分为四种情况,所以利用if...else...语句分情况讨论
protected void commodityname_CheckedChanged(object sender, EventArgs e)
{
if (this.commodityname.Checked == true)
{
this.TextBox1.ReadOnly = false;
}
else
{
this.TextBox1.ReadOnly = true;
}
}
protected void companyid_CheckedChanged(object sender, EventArgs e)
{
if (this.companyid.Checked == true)
this.TextBox2.ReadOnly = false;
else
{
this.TextBox2.ReadOnly = true;
}
}
void select() //定义查寻函数
{
using (SqlCommand command = new SqlCommand())
{
if (this.commodityname.Checked == true) //利用if..else..进行分四种情况讨论
{
if (this.companyid.Checked == false)
{
this.SqlDataSource1.SelectCommand = "SELECT CommodityName,CompanyName,xiaoshou,unit,jinhuo,kucun from dbo.view_2 WHERE CommodityName like '%" + TextBox1.Text + "%'";
this.GridView1.DataBind();
}
else
{
this.SqlDataSource1.SelectCommand = "SELECT CommodityName,CompanyName,xiaoshou,unit,jinhuo,kucun from dbo.view_2 WHERE CommodityName like '%" + TextBox1.Text + "%' AND CompanyName like '%" + TextBox2.Text + "%'";
this.GridView1.DataBind();
}
}
else
{
if (this.companyid.Checked == true)
{
this.SqlDataSource1.SelectCommand = "SELECT CommodityName,CompanyName,xiaoshou,unit,jinhuo,kucun from dbo.view_2 WHERE CompanyName like '%" + TextBox2.Text + "%'";
this.GridView1.DataBind();
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
select();//调用查询函数赋给button1_1查询按钮
GridView1.DataBind();
if (GridView1.Rows.Count == 0)
{
Response.Write(@"<script>alert('没有您所要查询的内容');</script>"); //当数据库没有所查内容时,显示相应对话框信息
}
}
catch(Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
protected void Button2_Click(object sender, EventArgs e) //定义button2返回按钮得click事件
{
Response.Redirect("StockPile_search.aspx");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) //gridview1是连接数据库显示所要求信息得表
{
select(); //调用select函数
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -