📄 browsephoto.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;
using Utils;
using Model;
namespace AlbumOL
{
/// <summary>
/// BrowsePhoto 的摘要说明。
/// </summary>
public class BrowsePhoto : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbAlias;
protected System.Web.UI.WebControls.Panel pWelcome;
protected System.Web.UI.WebControls.Panel pCategory;
protected System.Web.UI.WebControls.Label lbCatName;
protected System.Web.UI.WebControls.Button btnUpdate;
protected System.Web.UI.WebControls.Button btnDel;
protected System.Web.UI.WebControls.Panel pCategoryEdit;
protected System.Web.UI.WebControls.TextBox tbCatName;
protected System.Web.UI.WebControls.Button btnOK;
protected System.Web.UI.WebControls.Button btnCancel;
protected System.Web.UI.WebControls.DataList dlPhoto;
protected System.Web.UI.WebControls.Panel p1;
protected System.Web.UI.WebControls.Button btnAddPhoto;
private string _catName;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
WebUtils.CheckUser();
lbAlias.Text = (User as MyPrincipal).Name;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
this.btnAddPhoto.Click += new System.EventHandler(this.btnAddPhoto_Click);
this.Load += new System.EventHandler(this.Page_Load);
this.PreRender += new System.EventHandler(this.BrowsePhoto_PreRender);
}
#endregion
private void BrowsePhoto_PreRender(object sender, System.EventArgs e)
{
int idCat = Int32.Parse(Request.Params["cat"]);
IModel model = new CategoryModel();
DSPhoto ds = model.LoadByPrimaryKey(idCat) as DSPhoto;
PhotoModel modelPhoto = new PhotoModel(ds);
modelPhoto.LoadByCategory(ds.Category.FindByCategoryID(idCat));
if(ds.Tables["Category"].Rows.Count > 0)
{
_catName = ds.Tables["Category"].Rows[0]["CategoryName"].ToString();
}
if(ds.Tables["Photo"].Select("CategoryID="+idCat).Length > 0)
{
btnDel.Enabled = false;
}
else
{
btnDel.Enabled = true;
}
dlPhoto.DataSource = ds.Tables["Photo"];
this.DataBind();
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
this.pCategoryEdit.Visible = true;
this.pCategory.Visible = false;
}
private void btnOK_Click(object sender, System.EventArgs e)
{
if(this.tbCatName.Text.Trim().Length>0)
{
int idCat = Int32.Parse(Request.Params["cat"]);
Model.Model model = new CategoryModel();
model.LoadByPrimaryKey(idCat);
DSPhoto ds = model.DataSet as DSPhoto;
ds.Category.FindByCategoryID(idCat).CategoryName = tbCatName.Text.Trim();
model.Save(ds);
}
this.pCategoryEdit.Visible = false;
this.pCategory.Visible = true;
}
private void btnDel_Click(object sender, System.EventArgs e)
{
int idCat = Int32.Parse(Request.Params["cat"]);
Model.Model model = new CategoryModel();
model.LoadByPrimaryKey(idCat);
DSPhoto ds = model.DataSet as DSPhoto;
ds.Category.FindByCategoryID(idCat).Delete();
model.Save(ds);
this.Response.Redirect("ListCategories.aspx", true);
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.pCategoryEdit.Visible = false;
this.pCategory.Visible = true;
}
private void btnAddPhoto_Click(object sender, System.EventArgs e)
{
int idCat = Int32.Parse(Request.Params["cat"]);
Response.Redirect("ViewPhoto.aspx?photo=-1&cat=" + idCat, true);
}
public string CategoryName
{
get
{
return _catName;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -