using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Drawing;
namespace KuGo.Web.Admin
{
    public partial class OrdersList : Page
    {

        KuGo.BLL.OrdersBLL bll = new KuGo.BLL.OrdersBLL();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData("");
            }
        }

        //搜索
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            StringBuilder strWhere = new StringBuilder();//查询条件
            if (!string.IsNullOrEmpty(KeywordTextBox.Text.Trim())){
     
           strWhere.AppendFormat(" CustomerID like '%{0}%'", KeywordTextBox.Text.Trim());//Name 是搜索字段，请修改为实际需要的字段名称
    
            }
            BindData(strWhere.ToString());
        }

        // 删除          
        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        //翻页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            StringBuilder strWhere = new StringBuilder();//查询条件
            if (!string.IsNullOrEmpty(KeywordTextBox.Text.Trim())){
     
               strWhere.AppendFormat(" OrderID like '%{0}%'", KeywordTextBox.Text.Trim());//Name 是搜索字段，请修改为实际需要的字段名称
    
            }
            //如果查询条件更改了就应该重设 rcount 变量为 0
            //rcount = 0; //保存总记录数量 

            //加载数据
            BindData(strWhere.ToString());
        }
       
        /// <summary>
        /// 保存总记录数量 
        /// </summary>
        int rcount = 0; 
   
        /// <summary>
        /// Repeater数据绑定
        /// </summary>
        public void BindData(string strWhere)
        {
      

          string strOrder = "OrderID desc";                 //排序条件
      
          if (rcount == 0){
              rcount = bll.GetRecordCount(strWhere);
          }
          if (rcount > 0){
              DataSet ds = bll.GetPage("*", strWhere.ToString(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, strOrder);
              AspNetPager1.RecordCount = rcount;//设置总记录数
              //绑定数据源
              Repeater1.DataSource = (ds != null && ds.Tables.Count > 0) ? ds.Tables[0] : null;
              Repeater1.DataBind();

          } else{
            //显示错误信息
            Repeater1.DataSource = null;
            errLabel.Text = bll.GetLastError();
          }
         }
      
    }
}
  