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

📄 articleadmin.ascx.cs

📁 这是我编的一小软件。请等级等待指教。呵呵。ASP的
💻 CS
字号:
namespace Seaskyer.WebApp.skyNews.Pages.UserMSC
{
	using System;
	using System.Collections;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using Seaskyer.FSO;
	using Seaskyer.Strings;

	/// <summary>
	///		ArticleAdmin : 管理新闻。
	/// </summary>
	public class ArticleAdmin : basePage
	{
		protected DataGrid DataGrid1;
		protected Label label1 ,pageLabel;
		protected System.Web.UI.WebControls.DropDownList ClassID;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if( !power.GPB("Admin") )
			{
				base.strError.Add(lang["sharePage", "denyViewErrorInfo"]);
				return;
			}

			this.initPage();

			if( !Page.IsPostBack )
			{
				ci.GetClassDropDownListOptions(ClassID, Request.QueryString["cid"], "EnableAdd = 1");
				ClassID.Attributes.Add("onchange", "location.href='/skyNews/UserMSC/ArticleAdmin.aspx?cid=' + this.options[this.selectedIndex].value;");
				this.BindData();
			}
		}

		#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

		/// <summary>
		/// 初始化页面
		/// </summary>
		void initPage()
		{
			label1.Visible			= false;
			pageLabel.Visible		= false;
			DataGrid1.Visible		= false;
		}

		void BindData()
		{
			if( Object.Equals(Request.QueryString["type"], null)  || Object.Equals(Request.QueryString["type"], "") )
			{
				// 非搜索页面数据绑定
				this.GridBind();
			}
			else
			{
				// 搜索页面数据绑定
				this.SearchGridBind();
			}
		}

		#region 绑定数据
		void GridBind()
		{

//			string condition = "";
//			string cidParame = "";
//			if( !Object.Equals(Request.QueryString["cid"], null) && !Object.Equals(Request.QueryString["cid"], "") )
//			{
//				condition = "WHERE classid IN (" + base.GetClassInfo(int.Parse(Request.QueryString["cid"]), "allChildClass") + ")";
//				cidParame = "cid=" + Request.QueryString["cid"];
//			}
//
//			strCmd = String.Format(user.GetCommand("Article_SELECT"), condition);
//			base.returnSplitInfo(strCmd);
//
//			if( !Object.Equals(base.indexSTR , "") )
//			{
//				strCmd = String.Format(user.GetCommand("Article_SELECT_STR"), base.indexSTR);
//				base.BindInfo_SplitPageDataGrid(DataGrid1, base.indexSTR, strCmd, "");
//
//				// 分页
//				pageLabel.Text			= 
//					String.Format( user.GetAppInfo("splitPageInfo", "sharePage"), 
//					base.PageIndex, 
//					base.pageNum, 
//					base.PageSize, 
//					base.totalRecord, 
//					user.SplitPages(base.basePath + base.Parame + "=MSC^ArticleAdmin&" + cidParame + "&", base.PageIndex, base.pageNum, base.totalRecord )
//					);
//
//				pageLabel.Visible		= true;
//				delBtn.Visible			= true;
//			}
//			else
//			{
//				label1.Text = "还没有添加任何新闻"; label1.ForeColor = Color.Red;
//				label1.Visible = true;
//			}


			string condition = "";
			string cidParame = "";
			if( user.CheckValiable(Request.QueryString["cid"]) )
			{
				if( Function.Str.IsNum(Request.QueryString["cid"]) )
				{
					condition = "WHERE Article.ClassID IN (" + ci[Request.QueryString["cid"], "ChildCollection"] + ")";
					cidParame = "cid=" + Request.QueryString["cid"] + "&";
				}
			}

			dp.CommandText = string.Format(cmd["Article", "COUNT"], condition);
			bind.totalRecord = dp.ScalarSQL();

			if( bind.totalRecord == 0 )
			{
				label1.Text = "当前还没有添加任何新闻"; label1.ForeColor = Color.Red;
				label1.Visible = true;
			}
			else
			{
				//dp.CommandText = "SELECT Article.*, aClass.className FROM [Article], [aClass] WHERE (Article.classid = aClass.classID) ORDER BY Article.ArticleID DESC";
				dp.CommandText = Function.ConstructSplitSQL("Article", "ArticleID", "[Article] LEFT OUTER JOIN [aClass] ON (Article.classid = aClass.classID)", bind.PageIndex, bind.PageSize, "Article.*, aClass.className", 1, condition.Replace("WHERE ", ""));

				//dp.CommandText = string.Format(cmd["Article", "SELECT"], condition);
				bind.BindInfo_DataGrid(DataGrid1, dp, "");

				pageLabel.Text	=  base.GetSplitPageString("/skyNews/UserMSC/ArticleAdmin.aspx?" + cidParame);
				pageLabel.Visible		= true;
			}
		}
		#endregion

		#region 去掉DataGrid1的EnableViewState属性,减少发向客户端的数据
		protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
		{
			//DataGrid1.Controls[0].EnableViewState = false;
		}
		#endregion

		#region 响应删除事件
		protected void Delete_OnClick(object sender, EventArgs e)
		{

			if( Object.Equals(Request.Form["chk"], null) || Object.Equals(Request.Form["chk"], "") )
			{
				label1.Text = "请先选中要删除的记录(可多选)"; label1.ForeColor = Color.Red;
			}
			else
			{
				string delid = Request.Form["chk"].ToString();
				
				dp.CommandText = String.Format(cmd["Article", "DELETE"], delid);
				int delNum = dp.NonQuerySQL();
				if( delNum > 0)
				{
					label1.Text = delNum + "条新闻删除成功!"; label1.ForeColor = Color.BlueViolet;
					this.BindData();
				}
				else
				{
					label1.Text = "删除失败 ..."; label1.ForeColor = Color.Red;
				}
			}
			label1.Visible = true;

		}
		#endregion

		#region 初始化DataGrid中子控件的属性
		protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
		{
			if(e.Item.ItemIndex >= 0)
			{
				e.Item.Attributes.Add("onmouseover","this.className='tdbg-dark';");
				e.Item.Attributes.Add("onmouseout","this.className='tdbg';");
			}
		}
		#endregion

		#region 响应搜索事件
		void SearchGridBind()
		{
			if( !Object.Equals(Request.QueryString["key"], null) && !Object.Equals(Request.QueryString["key"], "") )
			{
//				searchLabel.Text	= "搜索关键字 &nbsp; <font color=red>" + Request.QueryString["key"] + "</font>";
//				searchLabel.Visible = true;
			}

//			strCmd = String.Format(user.GetCommand("Article_SELECT_SEARCH"), Request.QueryString["type"], Request.QueryString["key"]);
//			Hashtable ht = dp.SplitPageInfo(strCmd, base.PageIndex ,base.PageSize);
//			base.totalRecord	= int.Parse(ht["totalRecord"].ToString());
//			base.pageNum		= int.Parse(ht["pageNum"].ToString());
//			base.indexSTR		= ht["indexStrs"].ToString();
//			ht.Clear();
//
//			if( !Object.Equals(base.indexSTR , "") )
//			{
//				strCmd = String.Format(user.GetCommand("Article_SELECT_STR"), base.indexSTR);
//				DataTable dt = dp.DataTableSQL(strCmd);
//
//				DataGrid1.DataSource	= dt.DefaultView;
//				DataGrid1.DataBind();
//				DataGrid1.Visible		= true;
//				dt.Clear();
//				dt.Dispose();
//
//				// 分页
//				pageLabel.Text			= 
//					String.Format( user.GetAppInfo("splitPageInfo", "sharePage"), 
//					base.PageIndex, 
//					base.pageNum, 
//					base.PageSize, 
//					base.totalRecord, 
//					user.SplitPages(base.basePath + base.Parame + "=MSC^ArticleAdmin&type=" + Request.QueryString["type"] + "&key=" + Request.QueryString["key"] + "&", base.PageIndex, base.pageNum, base.totalRecord)
//					);
//				pageLabel.Visible		= true;
//				delBtn.Visible			= true;
//			}
//			else
//			{
//				label1.Text = "您搜索的内容不存在"; label1.ForeColor = Color.Red;
//				label1.Visible = true;
//			}
		}
		#endregion

//		/// <summary>
//		/// 获取分类下拉菜单列表
//		/// </summary>
//		/// <param name="cid">指定分类</param>
//		protected string GetClassList(string cid)
//		{
//			string strResult = "";
//
//			DataTable dt = this.returnClassCacheTable("canAdd = 1", "orderID ASC", 0);
//
//			for( int i = 0; i < dt.Rows.Count; i++ )
//			{
//				strResult += "<option value=\"" + dt.Rows[i]["classID"].ToString() + "\" " + (cid == dt.Rows[i]["classID"].ToString() ? "selected" : "") + ">";
//
//				int m = 0;
//				while( m < int.Parse(dt.Rows[i]["depth"].ToString()) )
//				{
//					strResult += "│";
//					m++;
//				}
//
//				if( dt.Rows[i]["LastNode"].ToString() == "1" )
//					strResult += "└";
//				else
//					strResult += "├";
//
//				strResult += dt.Rows[i]["className"].ToString() + " (" + dt.Rows[i]["articleNum"].ToString() + ")</option>";
//			}
//
//			return strResult;
//		}
	}
}

⌨️ 快捷键说明

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