⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picturemanage.aspx.cs

📁 计算机学院网站及管理系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 ComputerWeb
{
	/// <summary>
	/// Summary description for ManageImage.
	/// </summary>
	public class ManageImage : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ListBox PictureList;
		protected System.Web.UI.WebControls.ImageButton deleteBtn;
		protected System.Web.UI.WebControls.ListBox ContentList;
	
		private void Page_Load(object sender, System.EventArgs e)
		{	
			if(!Page.IsPostBack)
			{
				BindData();
			}
		}

		private void BindData()
		{
			ContentDB content = new ContentDB();
			SqlDataReader recc = content.GetContents();

			while(recc.Read())
			{
				if(Int32.Parse(recc["FileFlag"].ToString()) >= 1)
				{
					ListItem listItem = new ListItem(recc["Title"].ToString(),recc["ContentID"].ToString());
					ContentList.Items.Add(listItem);
				}
			}
			recc.Close();

			if(ContentList.Items.Count > 0)
			{
				BindPicture(Int32.Parse(ContentList.Items[0].Value));
			}
		}

		private void BindPicture(int nContentID)
		{			
			//绑定图片数据
			PictureList.Items.Clear();

			//绑定图片数据
			PictureDB picture = new PictureDB();
			SqlDataReader recp = picture.GetPictureByCont(nContentID);

			while(recp.Read())
			{
				PictureList.Items.Add(new ListItem(recp["Title"].ToString(),recp["PictureID"].ToString()));
			}	
			recp.Close();

			SqlDataReader recf = picture.GetFileByCont(nContentID);
			while(recf.Read())
			{
				PictureList.Items.Add(new ListItem(recf["Title"].ToString(),recf["PictureID"].ToString()));
			}	
			recf.Close();					
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.ContentList.SelectedIndexChanged += new System.EventHandler(this.ContentList_SelectedIndexChanged);
			this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.deleteBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion		

		private void ContentList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(ContentList.SelectedIndex > -1)
			{
				BindPicture(Int32.Parse(ContentList.SelectedValue));
			}
		}

		private void deleteBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			PictureDB picture = new PictureDB();
			if(PictureList.SelectedIndex > -1)
			{
				try
				{
					picture.DeletePicture(Int32.Parse(PictureList.SelectedValue));
					PictureList.Items.Remove(PictureList.SelectedItem);				

					int nFlagTemp = 0;
					ContentDB content = new ContentDB();			

					if(PictureList.Items.Count > 0)
					{						
						SqlDataReader recf = picture.GetFileByCont(Int32.Parse(ContentList.SelectedValue));
						if(recf.HasRows == true)
						{
							nFlagTemp = 2;
						}
						recf.Close();

						SqlDataReader recp = picture.GetPictureByCont(Int32.Parse(ContentList.SelectedValue));
						if(recp.HasRows == true)
						{
							if(nFlagTemp > 0)
							{
								nFlagTemp = 3;
							}
							else
							{
								nFlagTemp = 1;
							}								
						}	
						recp.Close();
					}				
				
					content.UpdateFileFlag(Int32.Parse(ContentList.SelectedValue),nFlagTemp);
					BindPicture(Int32.Parse(ContentList.SelectedValue));				
				}
				catch(Exception ex)
				{
					string sRawURL = Request.RawUrl;

					if(sRawURL.IndexOf("?") > -1)
					{
						sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
					}
					Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
				}
			}
			else
			{
				Response.Write("<script>alert(\"请选择要删除的图片!\")</script>");
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -