📄 albumindex.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Com.SMS.SMSUI
{
/// <summary>
/// AlbumIndex 的摘要说明。
/// </summary>
public class AlbumIndex : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtSearch;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DataList dtlPhotos;
protected System.Web.UI.WebControls.HyperLink HyperLink4;
protected System.Web.UI.WebControls.HyperLink HyperLink3;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList ddlPage;
const int PAGE_SIZE = 15;
int curpage = 1;
protected System.Web.UI.HtmlControls.HtmlSelect album;
protected System.Web.UI.HtmlControls.HtmlSelect ddlAlbumType;
string keyword="";
int typeId=-1;
int abId=-1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["User"]==null)
{
Response.Write("<script>alert('对不起,你没有登录');location.href='Login.aspx';</script>");
}
if (Request["page"] != null)
{
curpage = Convert.ToInt32(Request["page"]);
}
if(Request["abId"]!=null)
{
abId=Convert.ToInt32(Request["abId"]);
}
else
{
if(this.album.Items.Count!=0)
{
abId=Convert.ToInt32(this.album.Value);
}
}
if(Request["typeId"]!=null)
{
typeId=Convert.ToInt32(Request["typeId"]);
}
if(Request["keyword"]!=null)
{
keyword=Request["keyword"];
}
if(!this.IsPostBack)
{
this.txtSearch.Text=keyword;
BindAlbumType();
BindAlbum();
BindPhotos();
}
}
void BindPhotos()
{
Dal.PhotosMake pm=new Dal.PhotosMake();
int count;
DataTable dt=pm.FindWhere(curpage,PAGE_SIZE,out count,this.txtSearch.Text,Convert.ToInt32(this.album.Value),1,Convert.ToInt32(this.ddlAlbumType.Value));
this.dtlPhotos.DataSource=dt;
this.dtlPhotos.DataBind();
string urlstring = "&keyWord=" + Server.UrlEncode(this.txtSearch.Text) + "&abId=" +this.album.Value+"&typeId="+this.ddlAlbumType.Value;
if (curpage > 1)
{
this.HyperLink4.NavigateUrl = "?page=1"+urlstring;
this.HyperLink3.NavigateUrl = "?page=" + (curpage - 1)+urlstring;
}
if (curpage < count)
{
this.HyperLink2.NavigateUrl = "?page=" + (curpage + 1)+urlstring;
this.HyperLink1.NavigateUrl = "?page=" + count+urlstring;
}
this.Label1.Text ="当前第:"+curpage+" 页,共:"+count+" 页.";
this.ddlPage.Items.Clear();
for (int i = 1; i <= count; i++)
{
this.ddlPage.Items.Add(i.ToString());
}
this.ddlPage.SelectedValue = curpage.ToString();
this.ddlPage.Attributes.Add(
"onchange",
"location.href='?page='+this.value+'" + urlstring + "'"
);
}
void BindAlbumType()
{
this.album.Items.Clear();
Dal.AlbumTypeMake atm=new Com.SMS.Dal.AlbumTypeMake();
DataTable dt=atm.FindAll();
this.ddlAlbumType.DataSource=dt;
this.ddlAlbumType.DataTextField="typeName";
this.ddlAlbumType.DataValueField="abtId";
this.ddlAlbumType.DataBind();
this.ddlAlbumType.Items.Insert(0,"所有");
this.ddlAlbumType.Items[0].Value="-1";
this.ddlAlbumType.Value=typeId.ToString();
}
void BindAlbum()
{
Dal.AlbumMake am=new Com.SMS.Dal.AlbumMake();
DataTable dt=am.FindByType(Convert.ToInt32(this.ddlAlbumType.Value));
this.album.DataSource=dt;
this.album.DataTextField="alName";
this.album.DataValueField="abId";
this.album.DataBind();
this.album.Items.Insert(0,"所有");
this.album.Items[0].Value="-1";
this.album.Value=abId.ToString();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
abId=Convert.ToInt32(this.album.Value);
BindAlbum();
this.curpage=1;
BindPhotos();
// BindAlbum();
// this.album.SelectedIndex=1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -