📄 deletedepartment.aspx.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 MisPersonnel.Components;
using System.Data.SqlClient;
namespace MisPersonnel.DesktopModules.Department
{
/// <summary>
/// DeletDepartment 的摘要说明。
/// </summary>
public class DeleteDepartment : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblLReceiver;
protected System.Web.UI.WebControls.TextBox DepartName;
protected System.Web.UI.WebControls.RequiredFieldValidator rfN;
protected System.Web.UI.WebControls.Label lblAdditionalNo;
protected System.Web.UI.WebControls.TextBox DepartNo;
protected System.Web.UI.WebControls.RequiredFieldValidator rfP;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox DepartDesn;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList ParentDepartList;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox Remark;
protected System.Web.UI.WebControls.Button DeleteDepartBtn;
protected System.Web.UI.WebControls.Button ReturnBtn;
private int nDepartmentID = -1;
private void Page_Load(object sender, System.EventArgs e)
{
///判断用户是否登陆
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
///判断用户是否是超级管理员
if(Components.User.IsAuthorityAdmin(Session["UserID"].ToString()) >= Components.User.USERTYPENORMAL)
{
Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
Response.Write("<script>history.back();</script>");
}
if(Request.Params["DepartmentID"] != null)
{
nDepartmentID = Int32.Parse(Request.Params["DepartmentID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindDepartParentData();
///绑定所有的数据
if(nDepartmentID > -1)
{
BindDepartData(nDepartmentID);
}
}
///添加删除确认对话框
DeleteDepartBtn.Attributes.Add("onclick","return confirm('" + MisSystem.OPERATIONDELETEMESSAGE + "');");
}
private void BindDepartParentData()
{
///定义获取数据的类
MisPersonnel.Components.Department depart = new MisPersonnel.Components.Department();
SqlDataReader recd = depart.GetDepartments();
///设定控件的数据源
ParentDepartList.DataSource = recd;
///设定控件的Text属性和Value属性
ParentDepartList.DataTextField = "DepartName";
ParentDepartList.DataValueField = "DepartmentID";
///绑定控件的数据
ParentDepartList.DataBind();
///关闭数据读取器和数据库的连接
recd.Close();
}
private void BindDepartData(int nDepartmentID)
{
///定义获取数据的类
MisPersonnel.Components.Department depart = new MisPersonnel.Components.Department();
SqlDataReader recd = depart.GetSingleDepartment(nDepartmentID);
///从获取的数据中读取数据
if(recd.Read())
{
DepartNo.Text = recd["DepartNo"].ToString();
DepartName.Text = recd["DepartName"].ToString();
DepartDesn.Text = recd["DepartDesn"].ToString();
Remark.Text = recd["Remark"].ToString();
///设置上级部门
SetListBoxItem(ParentDepartList,recd["ParentID"].ToString());
}
///关闭数据读取器和数据库的连接
recd.Close();
}
private void SetListBoxItem(DropDownList listBox,string ItemValue)
{
int index = 0;
foreach(ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if(item.Value.ToLower() == ItemValue.ToLower())
{
listBox.SelectedIndex = index++;
break;
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DeleteDepartBtn.Click += new System.EventHandler(this.DeleteDepartBtn_Click);
this.ReturnBtn.Click += new System.EventHandler(this.ReturnBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/Department/DepartmentManage.aspx");
}
private void DeleteDepartBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
///定义类User
MisPersonnel.Components.Department depart = new MisPersonnel.Components.Department();
try
{
///添加新用户
depart.DeleteDepartment(nDepartmentID);
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
}
catch(Exception ex)
{
///显示添加操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ MisSystem.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -