分页代码 —1

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 BLL;
using Model;

public partial class ProdList : System.Web.UI.Page
{
    ShopItemsBLL shopitemsbll 
= new ShopItemsBLL();
    MaxTypeBLL maxtypebll 
= new MaxTypeBLL();
    ProdTypeBLL prodtypebll 
= new ProdTypeBLL();
    MinTypeBLL mintypebll 
= new MinTypeBLL();

    ArrayList tmparry;

    
private int _Page; //当前页数
    private int PageCount; //总页数
    private int PageSize = 12//一页多少条数据
    private int DataCount;  //数据总条数

    
protected void Page_Load(object sender, EventArgs e)
    {
        
if(!this.IsPostBack)
        {
            _Page 
= 1;
            ViewState[
"page"= 1;

            BindList();

            
this.DropDownList1.DataSource = maxtypebll.GetMaxType();
            
this.DropDownList1.DataTextField = "Tname";
            
this.DropDownList1.DataValueField = "Tid";
            
this.DropDownList1.DataBind();
            
this.DropDownList1.Items.Insert(0"请选择商品类型");

            
if (Request.QueryString["maxtype"!= null)  //如果有大类型参数
            {
                MaxType maxtype 
= maxtypebll.GetMaxTypeByTid(Convert.ToInt32(Request.QueryString["maxtype"].ToString()));
                
this.DropDownList1.SelectedValue = maxtype.Tid.ToString();

                
this.DropDownList2.DataSource = prodtypebll.GetProdType(Convert.ToInt32(this.DropDownList1.SelectedValue));
                
this.DropDownList2.DataTextField = "Ptype";
                
this.DropDownList2.DataValueField = "Pid";
                
this.DropDownList2.DataBind();
                
this.DropDownList2.Items.Insert(0,"请选择商品分类");
            }
            
else
            {
                
this.DropDownList2.Items.Add("请选择商品分类");
            }

            
if (Request.QueryString["mintype"!= null)  //如果有小类型参数
            {
                ProdType prodtype 
= prodtypebll.GetProdTypeByPid(Convert.ToInt32(Request.QueryString["mintype"].ToString()));
                
this.DropDownList2.SelectedValue = prodtype.Pid.ToString();

                
this.DropDownList3.DataSource = mintypebll.GetMinTypeByPId(Convert.ToInt32(this.DropDownList2.SelectedValue));
                
this.DropDownList3.DataTextField = "Mname";
                
this.DropDownList3.DataValueField = "Mid";
                
this.DropDownList3.DataBind();
                
this.DropDownList3.Items.Insert(0"请选择商品分类");
            }
            
else
            {
                
this.DropDownList3.Items.Add("请选择商品分类");
            }

            
if (Request.QueryString["xitype"!= null)  //如果有细类型参数
            {
                MinType mintype 
= mintypebll.GetMinTypeByMid(Convert.ToInt32(Request.QueryString["xitype"].ToString()));
                
this.DropDownList3.SelectedValue = mintype.Mid.ToString();
            }

            
for (int i = 1; i <= (int)ViewState["pagecount"]; i++)
            {
                
this.DropDownList4.Items.Add(i.ToString());
            }
        }
    }

    
public void BindList()
    {
        
if (Request.QueryString["typeindex"== null)
        {
            tmparry 
= shopitemsbll.GetAllShopItems();
        }
        
else
        {
            
if (Request.QueryString["typeindex"].ToString().Equals("4"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"mintype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"xitype"].ToString()),
                    Request.QueryString[
"prodtxt"].ToString(),
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("3"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"mintype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"xitype"].ToString()),
                    
"null",
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("2"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"mintype"].ToString()),
                    
0,
                    
"null",
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("1"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    
0,
                    
0,
                    
"null",
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("5"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    Convert.ToInt32(Request.QueryString[
"mintype"].ToString()),
                    
0,
                    Request.QueryString[
"prodtxt"].ToString(),
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("6"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    Convert.ToInt32(Request.QueryString[
"maxtype"].ToString()),
                    
0,
                    
0,
                    Request.QueryString[
"prodtxt"].ToString(),
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
            
if (Request.QueryString["typeindex"].ToString().Equals("7"))
            {
                tmparry 
= shopitemsbll.GetAllShopItemByType(
                    
0,
                    
0,
                    
0,
                    Request.QueryString[
"prodtxt"].ToString(),
                    Convert.ToInt32(Request.QueryString[
"typeindex"].ToString()));
            }
        }
        
        DataCount 
= tmparry.Count; //得到数据条数
        PageCount = DataCount % PageSize == 0 ? DataCount / PageSize : DataCount / PageSize + 1//计算总页数
        ViewState["pagecount"= PageCount;

        ArrayList arry 
= new ArrayList();

        _Page 
= (int)ViewState["page"];

        
for (int i = (_Page - 1* PageSize; i < (_Page - 1* PageSize + PageSize; i++)
        {
            
if (i < DataCount)
            {
                arry.Add(tmparry[i]);
            }
            
else
            {
                
break;
            }
        }
        
this.ProdLists.DataSource = arry;
        
this.ProdLists.DataBind();

        
this.Label1.Text = ViewState["page"].ToString();
        
this.Label2.Text = PageCount.ToString();

        
if (_Page == PageCount)
        {
            
this.Finally.Enabled = false;
            
this.Next.Enabled = false;
        }
        
else
        {
            
this.Finally.Enabled = true;
            
this.Next.Enabled = true;
        }
        
if (_Page == 1)
        {
            
this.First.Enabled = false;
            
this.Previous.Enabled = false;
        }
        
else
        {
            
this.First.Enabled = true;
            
this.Previous.Enabled = true;
        }

    }

    
protected void First_Click(object sender, EventArgs e)
    {
        ViewState[
"page"= 1;
        BindList();
        
this.DropDownList4.SelectedValue = ViewState["page"].ToString();
    }
    
protected void Previous_Click(object sender, EventArgs e)
    {
        ViewState[
"page"= (int)ViewState["page"- 1;
        BindList();
        
this.DropDownList4.SelectedValue = ViewState["page"].ToString();
    }
    
protected void Next_Click(object sender, EventArgs e)
    {
        ViewState[
"page"= (int)ViewState["page"+ 1;
        BindList();
        
this.DropDownList4.SelectedValue = ViewState["page"].ToString();
    }
    
protected void Finally_Click(object sender, EventArgs e)
    {
        ViewState[
"page"= ViewState["pagecount"];
        BindList();
        
this.DropDownList4.SelectedValue = ViewState["page"].ToString();
    }
    
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        
int siid = Convert.ToInt32(((LinkButton)sender).CommandArgument);
        Response.Redirect(
"ProdInfo.aspx?siid="+siid);
    }
    
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
if (this.DropDownList1.SelectedValue != "请选择商品类型")
        {
            
this.DropDownList2.DataSource = prodtypebll.GetProdType(Convert.ToInt32(this.DropDownList1.SelectedValue));
            
this.DropDownList2.DataTextField = "Ptype";
            
this.DropDownList2.DataValueField = "Pid";
            
this.DropDownList2.DataBind();
            
this.DropDownList2.Items.Insert(0"请选择商品分类");
            
this.DropDownList3.Items.Clear();
            
this.DropDownList3.Items.Insert(0"请选择商品分类");
        }
        
else
        {
            
this.DropDownList2.Items.Clear();
            
this.DropDownList2.Items.Insert(0"请选择商品分类");
        }
    }
    
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        
if (this.DropDownList2.SelectedValue != "请选择商品分类")
        {
            
this.DropDownList3.DataSource = mintypebll.GetMinTypeByPId(Convert.ToInt32(this.DropDownList2.SelectedValue));
            
this.DropDownList3.DataTextField = "Mname";
            
this.DropDownList3.DataValueField = "Mid";
            
this.DropDownList3.DataBind();
            
this.DropDownList3.Items.Insert(0"请选择商品分类");
        }
        
else
        {
            
this.DropDownList3.Items.Clear();
            
this.DropDownList3.Items.Insert(0"请选择商品分类");
        }
    }


    
protected void Button1_Click(object sender, EventArgs e)
    {
        
int typeindex = 0;

        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex != 0 && this.DropDownList3.SelectedIndex != 0 && !this.txtprod.Text.Equals(""))
        {
            typeindex 
= 4;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue 
                
+ "&mintype=" + DropDownList2.SelectedValue 
                
+ "&xitype=" + DropDownList3.SelectedValue
                
+ "&prodtxt=" + txtprod.Text
                
+ "&typeindex=" + typeindex);
        }
        
        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex != 0 && this.DropDownList3.SelectedIndex != 0 && this.txtprod.Text.Equals(""))
        {
            typeindex 
= 3;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue
                
+ "&mintype=" + DropDownList2.SelectedValue
                
+ "&xitype=" + DropDownList3.SelectedValue
                
+ "&typeindex=" + typeindex);
        }

        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex != 0 && this.DropDownList3.SelectedIndex == 0 && this.txtprod.Text.Equals(""))
        {
            typeindex 
= 2;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue
                
+ "&mintype=" + DropDownList2.SelectedValue
                
+ "&typeindex=" + typeindex);
        }

        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex == 0 && this.DropDownList3.SelectedIndex == 0 && this.txtprod.Text.Equals(""))
        {
            typeindex 
= 1;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue
                
+ "&typeindex=" + typeindex);
        }

        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex != 0 && this.DropDownList3.SelectedIndex == 0 && !this.txtprod.Text.Equals(""))
        {
            typeindex 
= 5;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue
                
+ "&mintype=" + DropDownList2.SelectedValue
                
+ "&prodtxt=" + txtprod.Text
                
+ "&typeindex=" + typeindex);
        }

        
if (this.DropDownList1.SelectedIndex != 0 && this.DropDownList2.SelectedIndex == 0 && this.DropDownList3.SelectedIndex == 0 && !this.txtprod.Text.Equals(""))
        {
            typeindex 
= 6;
            Response.Redirect(
"ProdList.aspx?maxtype=" + DropDownList1.SelectedValue
                
+ "&prodtxt=" + txtprod.Text
                
+ "&typeindex=" + typeindex);
        }

        
if (this.DropDownList1.SelectedIndex == 0 && this.DropDownList2.SelectedIndex == 0 && this.DropDownList3.SelectedIndex == 0 && !this.txtprod.Text.Equals(""))
        {
            typeindex 
= 7;
            Response.Redirect(
"ProdList.aspx?prodtxt=" + txtprod.Text
                
+ "&typeindex=" + typeindex);
        }
    }


    
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
        ViewState[
"page"= Convert.ToInt32(this.DropDownList4.SelectedValue);
        BindList();
        
this.DropDownList4.SelectedValue =ViewState["page"].ToString();
    }

    
public bool Getreturn(string vipprice)
    {
        
bool falg=false;

        
if (!vipprice.Equals("0.0000"))
        {
            falg 
= true;
        }

        
return falg;
    }
}
posted @ 2008-07-11 18:27  supers  阅读(128)  评论(0)    收藏  举报