📄 addemployee.aspx.cs
字号:
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 OfficeAutomatization;
using System.Data.SqlClient;
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()
{
///定义获取数据的类
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 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)
{
///定义类
Employee employ = new 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('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///显示添加操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -