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

📄 addoreditcontent.aspx.cs

📁 计算机学院网站及管理系统
💻 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 System.Data.SqlClient;
using System.IO;

namespace ComputerWeb
{
	/// <summary>
	/// Summary description for AddOrEditContent.
	/// </summary>
	public class AddOrEditContent : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox Title;
		protected System.Web.UI.WebControls.TextBox ContentTextBox;
		protected System.Web.UI.WebControls.Button SubmitBtn;
		protected System.Web.UI.WebControls.LinkButton UploadFile;

		private int nContentID        = 0;
		private static int nFlag      = 0;
		private string operation      = "";
 
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Request.Params["ContentID"] != null)
			{
				nContentID = Int32.Parse(Request.Params["ContentID"].ToString());
			}
			if(Request.Params["Operation"] != null)
			{
				operation = Request.Params["Operation"].ToString();
			}
			if(!Page.IsPostBack)
			{
				nFlag = 0;
                GlobalVars.FilePictureID.Clear();

				BindContentData();
			}
		}

		private void BindContentData()
		{
			if(nContentID > 0)
			{
				ContentDB content = new ContentDB();
				SqlDataReader recc = content.GetSingleContent(nContentID);

				while(recc.Read())
				{
					Title.Text = recc["Title"].ToString();
					ContentTextBox.Text = recc["Content"].ToString();					
				}
				recc.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.UploadFile.Click += new System.EventHandler(this.UploadFile_Click);
			this.SubmitBtn.Click += new System.EventHandler(this.SubmitBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void SubmitBtn_Click(object sender, System.EventArgs e)
		{
			ContentDB content = new ContentDB();

			if(nContentID == 0)
			{
				AddContent();				
			}
			else
			{
				if((nContentID > 0)&&(operation.ToLower() == "update"))
				{
					UpdateContent();
				}
				else
				{
					if((nContentID > 0) &&(operation.ToLower() == "delete"))
					{
						DeleteContent();
					}
				}
			}

			if(nContentID > 0)
			{
				PictureDB picture = new PictureDB();
				
				for(int i = 0; i < GlobalVars.FilePictureID.Count -1; i++)
				{
					picture.UpdatePicture(Int32.Parse(GlobalVars.FilePictureID[i].ToString()),nContentID);
				}

				int nFlagTemp = 0;
				if(GlobalVars.FilePictureID.Count > 0)
				{ 
					nFlagTemp = Int32.Parse(GlobalVars.FilePictureID[GlobalVars.FilePictureID.Count -1].ToString());
				}
				
				switch(nFlag)
				{
					case 0:
					{
						content.UpdateFileFlag(nContentID,nFlagTemp);
						break;
					}
					case 1:
					{
						if(nFlagTemp > nFlag)
						{
							content.UpdateFileFlag(nContentID,3);
						}
						else
						{
							content.UpdateFileFlag(nContentID,1);
						}
						break;
					}
					case 2:
					{
						if(nFlagTemp == 2 || nFlagTemp == 0)
						{
							content.UpdateFileFlag(nContentID,2);
						}
						else
						{
							content.UpdateFileFlag(nContentID,3);
						}
						break;
					}
					case 3:
					{
						content.UpdateFileFlag(nContentID,3);
						break;
					}
					default:
					{
						break;
					}
				}
			}			
			Response.Redirect("~/admin/ManageContent.aspx");			
		}

		/// <summary>
		/// 添加新的内容
		/// </summary>
		private void AddContent()
		{
			int[] allID = ManageContent.allId;

			ContentDB content = new ContentDB();

			if((allID[0] > 0)||(allID[1] > 0)||(allID[2] > 0))
			{
				if(Title.Text.Trim() != "")
				{
					try
					{
						nContentID = content.AddContent(Title.Text.Trim(),ContentTextBox.Text,
							Int32.Parse(Session["UserID"].ToString()),
							allID[0],
							allID[1],
							allID[2]
							);
						
						Response.Write("<script>alert(\"添加成功!\");</script>");
					}
					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>");
				}
			}
			
		}

		/// <summary>
		/// 修改所选的内容
		/// </summary>
		private void UpdateContent()
		{
			ContentDB content = new ContentDB();

			if(Title.Text.Trim() != "")
			{				
				try
				{
					content.UpdateContent(nContentID,Title.Text.Trim(),ContentTextBox.Text);
					
					Response.Write("<script>alert(\"成功更新!\")</script>");
				}
				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>");
			}				
		}

		private void DeleteContent()
		{
			ContentDB content = new ContentDB();

			try
			{
				content.DeleteContent(nContentID);
				Response.Write("<script>alert(\"成功删除!\")</script>");
			}
			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"," "));
			}			
		}

		private void UploadFile_Click(object sender, System.EventArgs e)
		{
			Response.Write("<script>window.open('UpLoadFile.aspx','上载图片或附件','height=350,width=400,toolbar=no,menubar=no,scrollbar=yes,resizable=yes,location=no,status=yes,left=0');</script>");
		}

	}
}

⌨️ 快捷键说明

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