using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using Model;
using System.Text;
 namespace WEB.AdminManage
{
    public partial class shipment_order_matching : System.Web.UI.Page
    {
        protected string arriving_notice_number, bill_company, bill_contacter, bill_number, superlier_name, Warehouse_id, superlier_order, submit_datetime;
        protected string sql,oldtime,newtime;
        ReceivingRecordModel rrm = new ReceivingRecordModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddl_WarehouseBind();
                this.ddl_Warehouse.Items.Insert(0, new ListItem("-ALL-", "0"));
            }
            noticeBind();
            //PageBind(string.Empty);
        }
        //通过运单号获取,进货预报信息
        protected void noticeBind()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["bill_number"].ToString()))
            {
                DataTable dt = new ShipmentOrderBLL().ShipmentOrder_query_info(Request.QueryString["bill_number"].ToString());
                if (dt.Rows.Count > 0)
                {
                    arriving_notice_number = dt.Rows[0]["arriving_notice_number"].ToString();
                    bill_contacter = dt.Rows[0]["bill_contacter"].ToString();
                    bill_company = dt.Rows[0]["bill_company"].ToString();
                    //bill_contacter = dt.Rows[0][""].ToString();
                    bill_number = dt.Rows[0]["bill_number"].ToString();
                    superlier_name = dt.Rows[0]["supplier_name"].ToString();
                    Warehouse_id = dt.Rows[0]["warehouseName"].ToString();
                    superlier_order = dt.Rows[0]["supplier_order_id"].ToString();
                    submit_datetime = dt.Rows[0]["submit_datetime"].ToString();
                    //bill_contacter = dt.Rows[0][""].ToString();
                }
            }
        }
        //下拉列表的绑定
        protected void ddl_WarehouseBind()
        {
            this.ddl_Warehouse.DataSource = new WareHouseBLL().ddl_warehouse_query();
            this.ddl_Warehouse.DataTextField = "warehouseName";
            this.ddl_Warehouse.DataValueField = "id";
            this.ddl_Warehouse.DataBind();
        }
        //同步
        protected void btn_select_Click(object sender, EventArgs e)
        {        }
        //rp查询
        protected void PageBind( string s)
        {
            //admin_user_id管理员id
            sql = "select warehouse.name, warehouse.description, receiving_record.receiving_record_number, receiving_record.warehouse_worker_id, receiving_record.rece_datetime, receiving_record.bill_number, receiving_record.bill_company, receiving_record.bill_contacter, receiving_record.supplier_name, receiving_record.supplier_order_id, receiving_record.has_match, receiving_record.submit_datetime, receiving_record.weight from receiving_record inner join warehouse on receiving_record.warehouse_id = warehouse.id where admin_user_id=1"+s;
            DataTable dt=new WareHouseWorkerBLL().shipment_order_receiving_record_query(rrm,sql,oldtime ,newtime);
            if(dt.Rows.Count>0)
            {
                rp_receiving_record_query.DataSource = dt;
                rp_receiving_record_query.DataBind();
            }        }        protected void btn_query_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();//sql语句where条件部分
            ArrayList arry = new ArrayList();//用来装条件的泛型
            if (this.ddl_Warehouse.SelectedValue != "0")
            {
                sb.Append(" and warehouse_id = @warehouse_id");
                arry.Add(this.ddl_Warehouse.SelectedValue);
            }
            if (!string.IsNullOrEmpty(this.txt_bill_contacter.Text.Trim().ToString()))
            {
                sb.Append(" and bill_contacter like @bill_contacter");
                arry.Add(this.txt_bill_contacter.Text.Trim().ToString());
            }
            if (!string.IsNullOrEmpty(this.txt_oldtime.Text.Trim()) && !string.IsNullOrEmpty(this.txt_newtime.Text.Trim()))
            {
                sb.Append(" and rece_datetime  between @old");
                arry.Add(this.txt_oldtime.Text.Trim());
                sb.Append(" and @new");
                arry.Add(this.txt_newtime.Text.Trim());
            }
            if ((!string.IsNullOrEmpty(this.txt_oldtime.Text.Trim()) && string.IsNullOrEmpty(this.txt_newtime.Text.Trim())) || (string.IsNullOrEmpty(this.txt_oldtime.Text.Trim()) && !string.IsNullOrEmpty(this.txt_newtime.Text.Trim())))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "run", "alert('时间段已选择就不能为空!')", true);
                return;
            }
            //为0是入仓----未处理            if (this.ddl_IsDispose.SelectedValue != "-1")
            {
                sb.Append(" and has_match = @has_match");
                arry.Add(this.ddl_IsDispose.SelectedValue);
            }
            if (!string.IsNullOrEmpty(this.txt_supplier_name.Text.Trim().ToString()))
            {
                sb.Append(" and supplier_name like @supplier_name");
                arry.Add(this.txt_supplier_name.Text.Trim().ToString());
            }
            if (!string.IsNullOrEmpty(this.txt_receiving_record_number.Text.Trim().ToString()))
            {
                sb.Append(" and receiving_record_number like @receiving_record_number");
                arry.Add(this.txt_receiving_record_number.Text.Trim().ToString());
            }
            if (!string.IsNullOrEmpty(this.txt_bill_company.Text.Trim().ToString()))
            {
                sb.Append(" and bill_company like @bill_company");
                arry.Add(this.txt_bill_company.Text.Trim().ToString());
            }
            //重量未做
            if (!string.IsNullOrEmpty(this.txt_bill_number.Text.Trim().ToString()))
            {
                sb.Append(" and bill_number like @bill_number");
                arry.Add(this.txt_bill_number.Text.Trim().ToString());
            }
            //是否已经处理---has_match
            //sql = "select * from receiving_record where warehouse_id=1 and has_match=0";
            sql = string.Format(sb.ToString(), arry.ToArray());            rrm.Warehouseid = int.Parse(this.ddl_Warehouse.SelectedValue);
            rrm.Billcontacter = this.txt_bill_contacter.Text.Trim().ToString();
            rrm.Hasmatch = int.Parse(this.ddl_IsDispose.SelectedValue.ToString());
            rrm.Suppliername = this.txt_supplier_name.Text.Trim().ToString();
            rrm.Receivingrecordnumber = this.txt_receiving_record_number.Text.Trim().ToString();
            rrm.Billcompany = this.txt_bill_company.Text.Trim().ToString();
            //重量
            rrm.Billnumber = this.txt_bill_number.Text.Trim().ToString();
            oldtime = this.txt_oldtime.Text.Trim().ToString();
            newtime = this.txt_newtime.Text.Trim().ToString();
            // ViewState[vsKey] = sql;
            //Session["sql"] = sql;
            PageBind(sql);
        }
    }
}

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      ddl_WarehouseBind();
      this.ddl_Warehouse.Items.Insert(0, new ListItem("-ALL-", "0"));
       noticeBind();
      }
      }
    或者把你的Dt 设置为全局也可以
      

  2.   

    protected string arriving_notice_number, bill_company, bill_contacter, bill_number, superlier_name, Warehouse_id, superlier_order, submit_datetime;
       protected string sql,oldtime,newtime;
       ReceivingRecordModel rrm = new ReceivingRecordModel();
     把你的那个Protected string sql 定位为一个全局的静态变量看看。
    protected static string sql