📄 photo.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
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;
using WesternByte.MyBlog.Core.Blog;
using WesternByte.MyBlog.Core.Category;
using WesternByte.MyBlog.Core.Picture;
using Wuqi.Webdiyer;
namespace WesternByte.MyBlog.Blog
{
/// <summary>
/// Photo 的摘要说明。
/// </summary>
public class Photo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal pageTitle;
protected System.Web.UI.WebControls.Label title;
protected System.Web.UI.WebControls.DataList pictureList;
protected Wuqi.Webdiyer.AspNetPager pager;
protected CategoryDAO cDAO = new CategoryDAO();
protected PictureDAO pDAO = new PictureDAO();
protected BlogDAO bDAO = new BlogDAO();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
int BlogID = Convert.ToInt32(Page.Request.QueryString["BlogID"]);
int CategoryID = Convert.ToInt32(Page.Request.QueryString["CategoryID"]);
BlogVO blogVO = bDAO.Load(BlogID);
if(blogVO.Subject == null || blogVO.Subject == "")
{
blogVO.Subject = blogVO.Name;
}
pageTitle.Text = blogVO.Subject;
CategoryVO cVO = cDAO.Load(CategoryID);
title.Text = cVO.Name + "<br>" + cVO.Description;
if(!Page.IsPostBack)
{
pager.RecordCount = pDAO.LoadCount(BlogID,CategoryID);
BindData(BlogID,CategoryID);
}
}
private void BindData(int BlogID,int CategoryID)
{
//当前分类下所有图片列表
DataSet pDs = pDAO.LoadList(BlogID,CategoryID,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize);
pDs.Tables[0].Columns.Add("Image");
for(int i=0;i<pDs.Tables[0].Rows.Count;i++)
{
//图片路径
string imageWebPath = ConfigurationSettings.AppSettings["ImageWebPath"].ToString() + pDs.Tables[0].Rows[i]["BlogID"].ToString() + "/" + pDs.Tables[0].Rows[i]["CategoryID"].ToString();
pDs.Tables[0].Rows[i]["Image"] = imageWebPath + "/t_" + pDs.Tables[0].Rows[i]["ImageUrl"].ToString();
pDs.Tables[0].Rows[i]["ImageUrl"] = "View2.aspx?PictureID=" + pDs.Tables[0].Rows[i]["PictureID"].ToString() + "&BlogID=" + BlogID;
if(pDs.Tables[0].Rows[i]["Subject"].ToString().Length>8)
{
pDs.Tables[0].Rows[i]["Subject"] = pDs.Tables[0].Rows[i]["Subject"].ToString().Substring(0,8) + "…";
}
}
pictureList.DataSource = pDs.Tables[0].DefaultView;
pictureList.DataBind();
//动态设置用户自定义文本内容
pager.CustomInfoText="共"+pager.PageCount.ToString()+"页,当前为第"+pager.CurrentPageIndex.ToString()+"页";
}
protected void ChangePage(object src,PageChangedEventArgs e)
{
int BlogID = Convert.ToInt32(Page.Request.QueryString["BlogID"]);
int CategoryID = Convert.ToInt32(Page.Request.QueryString["CategoryID"]);
pager.CurrentPageIndex=e.NewPageIndex;
BindData(BlogID,CategoryID);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -