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

📄 bulletin_admin.aspx.cs

📁 人力资源管理系统 读者须安装好IIS和Microsoft Visual Stutio.NET相关开发环境
💻 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 HRAdmin.BLL ;
using HRAdmin.COMMON ;

namespace HRAdmin.USL
{
	/// <summary>
	/// Bulletin_Admin 的摘要说明。
	/// </summary>
	public class Bulletin_Admin : System.Web.UI.Page
	{
		#region 控件和变量
		protected System.Web.UI.WebControls.CheckBox cb_Valid;
		protected System.Web.UI.WebControls.TextBox tb_SearchTitle;
		protected System.Web.UI.WebControls.TextBox tb_SearchCalidFrom;
		protected System.Web.UI.WebControls.TextBox tb_SearchValidTo;
		protected System.Web.UI.WebControls.Button bSearch;
		protected System.Web.UI.WebControls.Button bClear_s;
		protected System.Web.UI.WebControls.DataGrid dg;
		protected System.Web.UI.WebControls.Button bModify;
		protected System.Web.UI.HtmlControls.HtmlImage Img2;
		protected System.Web.UI.HtmlControls.HtmlImage Img1;
		protected System.Web.UI.WebControls.Button bDelete;
		protected System.Web.UI.HtmlControls.HtmlInputHidden h_ID;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Button b_Add;
		private DataTable dtBulletin = null ;
		#endregion
	
		#region Page_Load

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 获取公告信息表
			dtBulletin = (DataTable)Session["dtBulletin"] ;
			if(dtBulletin==null)
			{
				//若公告信息表为空,新建一个
				dtBulletin = new DataTable() ;
			}
			
			if(!IsPostBack)
			{
				InitData() ;
				//为删除按钮添加确认对话框
				CommHandler.AddConfirm(this.bDelete,"确定要删除此公告信息吗?") ;
			}

			//为表格绑定数据源
			BindDg() ;
		}

		/// <summary>
		/// 初始化界面
		/// </summary>
		private void InitData()
		{
			//界面初始化时,时间默认为当天
			this.tb_SearchCalidFrom.Text = CommHandler.Today() ;
			this.tb_SearchValidTo.Text = CommHandler.Today() ;
			this.tb_SearchTitle.Text = "" ;

			//CheckBox置为选中状态
			this.cb_Valid.Checked = true ;
			//查询有效公告信息
			SearchValid() ;

			//清空表格的选中状态
			dg.SelectedIndex = -1 ;
		}

		/// <summary>
		/// 为表格绑定数据源
		/// </summary>
		private void BindDg()
		{
			if(dtBulletin == null)
			{
				dtBulletin = new DataTable() ;
			}

			dg.DataSource = dtBulletin ;
			dg.DataBind() ;
		}
		#endregion

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.cb_Valid.CheckedChanged += new System.EventHandler(this.cb_Valid_CheckedChanged);
			this.bSearch.Click += new System.EventHandler(this.bSearch_Click);
			this.bClear_s.Click += new System.EventHandler(this.bClear_s_Click);
			this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
			this.bModify.Click += new System.EventHandler(this.bModify_Click);
			this.bDelete.Click += new System.EventHandler(this.bDelete_Click);
			this.b_Add.Click += new System.EventHandler(this.b_Add_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region 查询有效的公告信息
		private void cb_Valid_CheckedChanged(object sender, System.EventArgs e)
		{
			//如果CheckBox处于选中状态
			if(cb_Valid.Checked)
			{
				SearchValid() ;
			}
		}

		/// <summary>
		/// 查询当前有效的公告信息
		/// </summary>
		private void SearchValid()
		{
			//调用业务层的查询方法
			dtBulletin = BulletinInfo.GetValidBulletin() ;

			//将查询结果放入Session中
			Session["dtBulletin"] = dtBulletin ;	
	
			//绑定表格
			BindDg() ;
		}
		#endregion

		#region 查询按钮
		private void bSearch_Click(object sender, System.EventArgs e)
		{
			//查询条件
			string title = tb_SearchTitle.Text.Trim() ;
			string start = tb_SearchCalidFrom.Text.Trim() ;
			string end = tb_SearchValidTo.Text.Trim() ;

			//CheckBox置为非选中状态
			this.cb_Valid.Checked = false ;

			//调用查询方法
			dtBulletin = BulletinInfo.GetBulletin(title,start,end) ;

			//将查询结果放入Session中
			Session["dtBulletin"] = dtBulletin ;	
	
			//绑定表格
			BindDg() ;
		}
		#endregion

		#region 清空
		private void bClear_s_Click(object sender, System.EventArgs e)
		{
			//重新初始化画面
			InitData() ;
		}
		#endregion

		#region 修改按钮
		private void bModify_Click(object sender, System.EventArgs e)
		{
			//获取公告信息ID
			string id = h_ID.Value.Trim() ;

			if(id == "")
			{
				CommHandler.Alert(Page,"请在表格中选择要修改的行!") ;
				return ;
			}

			string url = ".\\Bulletin_Edit.aspx?BULLETINID="+id ;

			//将页面定向到修改申请页面			
			Page.Response.Redirect(url) ;
		
		}
		#endregion

		#region 删除按钮
		private void bDelete_Click(object sender, System.EventArgs e)
		{
			//获取要删除的BulletinID
			string id = h_ID.Value.Trim() ;

			//BulletinID为空时,提示操作员,并返回
			if(id == "")
			{
				CommHandler.Alert(Page,"请在表格中选择要删除的行!") ;
				return ;
			}
					
			//调用删除方法
			int ret = BulletinInfo.DeleteBulletin(id) ;
			if(ret > 0)
			{
				//删除成功
                CommHandler.Alert(Page,"公告信息删除成功!") ;
				//重新初始化界面
				InitData() ;
			}
		}
		#endregion

		#region 表格的选中事件
		private void dg_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			int row = e.Item.ItemIndex ; 

			if(dtBulletin.Rows.Count > row)
			{
				h_ID.Value = dtBulletin.Rows[row]["bulletinid"].ToString() ;
			}
		}
		#endregion

		private void b_Add_Click(object sender, System.EventArgs e)
		{
			string url = ".\\Bulletin_Add.aspx" ;

			//将页面定向到修改申请页面			
			Page.Response.Redirect(url) ;		
		}
		
	}
}

⌨️ 快捷键说明

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