addemployee.aspx.cs

来自「精通网络应用系统开发 光盘 该书是人民邮电出版社出版的」· CS 代码 · 共 86 行

CS
86
字号
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.Linq;
using System.Data;
using System.Collections.Generic;

public partial class AddEmployee : System.Web.UI.Page
{
	private int nEmployeeID = -1;

	private void Page_Load(object sender, System.EventArgs e)
	{		
		if (Request.Params["EmployeeID"] != null)
		{
			nEmployeeID = Int32.Parse(Request.Params["EmployeeID"].ToString());
		}
		if (!Page.IsPostBack)
		{
			///绑定控件的数据
			BindDepartmentData();
		}
	}

	private void BindDepartmentData()
	{
		///定义获取数据的类
		DepartmentM depart = new DepartmentM();
		Table<Department> recd = depart.GetDepartments();
		///设定控件的数据源
		DepartmentList.DataSource = recd;

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

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

	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)
		{
			///定义类
			EmployeeM employ = new EmployeeM();
			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('" + ASPNET35System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
			}
			catch (Exception ex)
			{
				///显示添加操作中的失败、错误信息
				Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
					+ ASPNET35System.RedirectErrorUrl(Request.RawUrl)
					+ "&ASPNET35System=" + ex.Message.Replace("\n", " "));
			}
		}
	}
}

⌨️ 快捷键说明

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