addemployee.aspx.cs
来自「MIS系统开发与应用配套的源代码」· CS 代码 · 共 127 行
CS
127 行
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.Employee
{
/// <summary>
/// AddEmployee 的摘要说明。
/// </summary>
public partial class AddEmployee : System.Web.UI.Page
{
private int nEmployeeID = -1;
protected 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["EmployeeID"] != null)
{
nEmployeeID = Int32.Parse(Request.Params["EmployeeID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindDepartmentData();
}
}
private void BindDepartmentData()
{
///定义获取数据的类
MisPersonnel.Components.Department depart = new MisPersonnel.Components.Department();
SqlDataReader recd = depart.GetDepartments();
///设定控件的数据源
DepartmentList.DataSource = recd;
///设定控件的Text属性和Value属性
DepartmentList.DataTextField = "DepartName";
DepartmentList.DataValueField = "DepartmentID";
///绑定控件的数据
DepartmentList.DataBind();
///关闭数据读取器和数据库的连接
recd.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/Employee/EmployeeManage.aspx?EmployeeID=" + nEmployeeID);
}
protected void AddBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
///定义类
MisPersonnel.Components.Employee employ = new MisPersonnel.Components.Employee();
try
{
///添加操作
employ.AddEmployee(EmployName.Text.Trim(),EmployNo.Text.Trim(),
Int32.Parse(SexList.SelectedValue),Nationality.Text.Trim(),
Convert.ToDateTime(Birthday.Text.Trim()),Political.Text,
MisCulture.Text.Trim(),Int32.Parse(Maritallist.SelectedValue),
FamilyPlace.Text,IdentityCard.Text.Trim(),Phone.Text.Trim(),
Mobile.Text,Convert.ToDateTime(HireDate.Text.Trim()),Position.Text,
Int32.Parse(StateList.SelectedValue),BankName.Text,
AccountNo.Text,PubName.Text,Int32.Parse(DepartmentList.SelectedValue),
Remark.Text);
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONADDSUCCESSMESSAGE + "')</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 + =
减小字号Ctrl + -
显示快捷键?