departmentmanage.aspx.cs

来自「《精通ASP.NET2.0网络应用系统开发》书中的源码」· CS 代码 · 共 89 行

CS
89
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using OfficeAutomatization;

public partial class DepartmentManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!Page.IsPostBack)
		{
			///绑定控件的数据
			BindDepartmentData();
		}
    }

	private void BindDepartmentData()
	{
		///定义获取数据的类
		OfficeAutomatization.Department depart = new OfficeAutomatization.Department();
		SqlDataReader recd = depart.GetDepartments();

		///设定控件的数据源
		DepartmentList.DataSource = recd;

		///设定控件的Text属性和Value属性
		DepartmentList.DataTextField = "Name";
		DepartmentList.DataValueField = "DepartmentID";

		///绑定控件的数据
		DepartmentList.DataBind();

		///关闭数据读取器和数据库的连接
		recd.Close();
	}

	protected void updateBtn_Click(object sender,ImageClickEventArgs e)
	{
		if (DepartmentList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}
		///跳转到修改页面
		Response.Redirect("~/DesktopModules/Department/UpdateDepartment.aspx?DepartmentID=" + DepartmentList.SelectedValue);
	}

	protected void AddBtn_Click(object sender,EventArgs e)
	{
		///跳转到添加页面
		Response.Redirect("~/DesktopModules/Department/AddDepartment.aspx");
	}

	protected void deleteBtn_Click(object sender,ImageClickEventArgs e)
	{
		if (DepartmentList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}
		///定义类
		OfficeAutomatization.Department depart = new OfficeAutomatization.Department();
		try
		{
			///删除数据
			depart.DeleteDepartment(Int32.Parse(DepartmentList.SelectedValue));
			///重新绑定数据
			BindDepartmentData();
		}
		catch (Exception ex)
		{
			///显示删除操作中的失败、错误信息
			Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
				+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
				+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
		}
	}
}

⌨️ 快捷键说明

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