stockpile_search.aspx.cs

来自「网上销售订单管理系统借助现代信息技术和管理理论」· CS 代码 · 共 84 行

CS
84
字号
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 Stockpile_Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HeardConfig();
        if (!IsPostBack)
        {
            PersonInfo.Return_SessionPerson();//检测是否登陆
            Session["sql"] = "";//初始化SQL语句的保存
            this.bind();//执行初始化绑定方法
        }
    }
    #region 页面初始化必需的内容
    public void HeardConfig()
    {
        Header.Title = "销售订单管理系统-库存查询";
        HeaderTextInfo.GetHeader(this, null);
    }
    #endregion
    //单击翻页
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.bind();
    }
    //表格文字的格式化
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        stockClass sc = new stockClass();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[3].Text = Convert.ToString(sc.stock(Convert.ToInt32(e.Row.Cells[3].Text)));
            e.Row.Cells[4].Text = Convert.ToString(sc.sell(Convert.ToInt32(e.Row.Cells[4].Text)));
            e.Row.Cells[5].Text = Convert.ToString(sc.stock(Convert.ToInt32(e.Row.Cells[5].Text)) - sc.sell(Convert.ToInt32(e.Row.Cells[5].Text)));
        }
    }
    //页面初始化绑定
    public void bind()
    {
        SqlConnection strcon = new SqlConnection(ConfigurationManager.ConnectionStrings["SellOrder_ConnectionString"].ConnectionString);
        strcon.Open();
        string sqlstr = "select * from Stockpile where id is not null " + Session["sqls"] + " order by id desc";
        SqlDataAdapter sda = new SqlDataAdapter(sqlstr, strcon);
        DataSet ds = new DataSet();
        sda.Fill(ds, "Stockpile");
        GridView1.DataSource = ds.Tables["Stockpile"];
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
    }
    //根据选择更新SQL语句
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sqls = "";
        if (this.CheckBox1.Checked)
        {
            sqls = sqls + "and CommodityName like '%" + this.TN.Text.Trim() + "%' ";
        }
        if (this.CheckBox2.Checked)
        {
            sqls = sqls + "and CompanyName like '%" + this.PN.Text.Trim() + "%'";
        }
        Session["sqls"] = sqls;
        this.bind();
    }
    //清空SQL语句缓存 执行页面绑定   等同重新加载页面
    protected void Button2_Click(object sender, EventArgs e)
    {
        Session["sqls"] = "";//此处不可使用Session["sql"]=null,  null是直接清空这个Session,而=""则是清空Session的值
        this.bind();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?