edithtml.aspx.cs

来自「三层架构的.net源码三层架构的.net源码」· CS 代码 · 共 113 行

CS
113
字号
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 MyStarterKit.Portal.Web
{
	/// <summary>
	/// EditHtml 的摘要说明。
	/// </summary>
	public class EditHtml : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox DesktopText;
		protected System.Web.UI.WebControls.TextBox MobileSummary;
		protected System.Web.UI.WebControls.TextBox MobileDetails;
		protected System.Web.UI.WebControls.LinkButton updateButton;
		protected System.Web.UI.WebControls.LinkButton cancelButton;
	
		int moduleId = 0;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 所属模块Id
			moduleId = Int32.Parse(Request.Params["Mid"]);

			// 验证用户是否可修改
			if (PortalSecurity.HasEditPermissions(moduleId) == false) 
			{
				Response.Redirect("~/Admin/EditAccessDenied.aspx");
			}

			if (!Page.IsPostBack) 
			{
				HtmlTextDB text = new HtmlTextDB();
				SqlDataReader dr = text.GetHtmlText(moduleId);
            
				if (dr.Read()) 
				{

					DesktopText.Text = Server.HtmlDecode((String) dr["DesktopHtml"]);
					MobileSummary.Text = Server.HtmlDecode((String) dr["MobileSummary"]);
					MobileDetails.Text = Server.HtmlDecode((String) dr["MobileDetails"]);
				}
				else 
				{
            
					DesktopText.Text = "添加内容……";
					MobileSummary.Text = "添加内容……";
					MobileDetails.Text = "添加内容……";
				}
            
				dr.Close();

				// 存储上次请求页Url
				ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();		
			}
		}

		/// <summary>
		/// 更新
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void UpdateBtn_Click(Object sender, EventArgs e) 
		{
			HtmlTextDB text = new HtmlTextDB();
			text.UpdateHtmlText(moduleId, Server.HtmlEncode(DesktopText.Text), Server.HtmlEncode(MobileSummary.Text), Server.HtmlEncode(MobileDetails.Text));
			Response.Redirect((String) ViewState["UrlReferrer"]);
		}

		/// <summary>
		/// 取消
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void CancelBtn_Click(Object sender, EventArgs e) 
		{
			// 返回上次请求页
			Response.Redirect((String) ViewState["UrlReferrer"]);
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.updateButton.Click += new System.EventHandler(this.UpdateBtn_Click);
			this.cancelButton.Click += new System.EventHandler(this.CancelBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

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