📄 addemployee.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;
//51aspx
namespace PMS.DesktopModules.EmployeeInfo
{
/// <summary>
/// AddEmployee 的摘要说明。
/// </summary>
public partial class AddEmployee : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
///判断用户是否登陆
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindDepartmentList();
PubName.Text = Session["UserID"].ToString();
PubDate.Text = System.DateTime.Now.Date.ToShortDateString();
}
}
private void BindDepartmentList()
{
///定义获取数据的类
PMS.Components.Department depart = new PMS.Components.Department();
DataTable DT = depart.GetDepartment();
///设定控件的数据源
DepartmentList.DataSource = DT;
///设定控件的Text属性和Value属性
DepartmentList.DataTextField = "DepartName";
DepartmentList.DataValueField = "DepartID";
///绑定控件的数据
DepartmentList.DataBind();
}
#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("EmployeeMng.aspx");
}
protected void AddBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
///定义类
PMS.Components.Employee employ = new PMS.Components.Employee();
if(employ.IsUnique(EmployID.Text.ToString()))
{
try
{
///添加操作
string str = "insert into [Employee] values('" + EmployID.Text.Trim() + "','" + EmployName.Text.Trim()+"'," + Int32.Parse(SexList.SelectedValue)+ ","
+ Int32.Parse(NationalityList.SelectedValue)+",'" + Convert.ToDateTime(Birthday.Text.Trim()) + "'," + Int32.Parse(PoliticalList.SelectedValue)+ ","
+ Int32.Parse(CultureList.SelectedValue) + "," + Int32.Parse(Maritallist.SelectedValue)+",'" + FamilyPlace.Text.Trim() + "','"
+ IdentityCard.Text.Trim() + "','" + Phone.Text.Trim() + "','" + Mobile.Text.Trim() + "','" + Convert.ToDateTime(HireDate.Text.Trim()) + "','"
+ Position.Text.Trim() + "'," + Int32.Parse(StateList.SelectedValue) +",'" + BankName.Text.Trim() + "','" + AccountNo.Text.Trim() + "','"
+ PubName.Text.Trim() + "','" + Convert.ToDateTime(PubDate.Text.Trim()) + "','" + DepartmentList.SelectedValue + "','" + Remark.Text.Trim() +"')";
if(employ.AddEmployee(str))
{
///显示操作结果信息
Response.Write ("<script>window.alert('" + "添加数据子项成功!!!" + "')</script>");
Response.Redirect("EmployeeMng.aspx",false);
}
}
catch(Exception ex)
{
///显示添加操作中的失败、错误信息
PMS.Common.SystemError.SystemLog(ex.Message) ;
Response.Redirect(ex.Message) ;
}
}
else
{
IsUnique.Visible = true;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -