📄 updatesigntrain.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 System.Data.SqlClient;
using MisOfficeAffair.Components;
namespace MisOfficeAffair.DesktopModules.SignTrain
{
/// <summary>
/// UpdateSignTrain 的摘要说明。
/// </summary>
public class UpdateSignTrain : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.DropDownList TrainList;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox SignDate;
protected System.Web.UI.WebControls.RequiredFieldValidator rfS;
protected System.Web.UI.WebControls.RegularExpressionValidator reS;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.DropDownList EmployeeList;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.DropDownList StatusList;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox Remark;
protected System.Web.UI.WebControls.Button UpdateBtn;
protected System.Web.UI.WebControls.Button ReturnBtn;
private int nSignTrainID = -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["SignTrainID"] != null)
{
nSignTrainID = Int32.Parse(Request.Params["SignTrainID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindTrainData();
BindEmployeeData();
if(nSignTrainID > -1)
{
BindSignTrainData(nSignTrainID);
}
}
///设置添加按钮的可用性
UpdateBtn.Enabled = (TrainList.Items.Count <= 0
|| EmployeeList.Items.Count <= 0 || nSignTrainID <= -1) ? false : true;
}
private void BindTrainData()
{
///定义获取数据的类
MisOfficeAffair.Components.Train train = new MisOfficeAffair.Components.Train();
SqlDataReader rect = train.GetTrains();
///设定控件的数据源
TrainList.DataSource = rect;
///设定控件的Text属性和Value属性
TrainList.DataTextField = "Subject";
TrainList.DataValueField = "TrainID";
///绑定控件的数据
TrainList.DataBind();
///关闭数据读取器和数据库的连接
rect.Close();
}
private void BindEmployeeData()
{
///定义获取数据的类
MisOfficeAffair.Components.Employee employ = new MisOfficeAffair.Components.Employee();
SqlDataReader rece = employ.GetEmployees();
///设定控件的数据源
EmployeeList.DataSource = rece;
///设定控件的Text属性和Value属性
EmployeeList.DataTextField = "EmployName";
EmployeeList.DataValueField = "EmployeeID";
///绑定控件的数据
EmployeeList.DataBind();
///关闭数据读取器和数据库的连接
rece.Close();
}
private void BindSignTrainData(int nSignTrainID)
{
///定义获取数据的类
MisOfficeAffair.Components.SignTrain sign = new MisOfficeAffair.Components.SignTrain();
SqlDataReader recs = sign.GetSingleSignTrain(nSignTrainID);
///从获取的数据中读取数据
if(recs.Read())
{
SignDate.Text = Convert.ToDateTime(recs["SignDate"].ToString()).ToShortDateString();
Remark.Text = recs["Remark"].ToString();
///设置列表控件的选择值
MisSystem.SetListBoxItem(TrainList,recs["TrainID"].ToString());
MisSystem.SetListBoxItem(StatusList,recs["Status"].ToString());
MisSystem.SetListBoxItem(EmployeeList,recs["EmployeeID"].ToString());
}
///关闭数据读取器和数据库的连接
recs.Close();
}
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/SignTrain/SignTrainManage.aspx");
}
private void UpdateBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
///定义类
MisOfficeAffair.Components.SignTrain sign = new MisOfficeAffair.Components.SignTrain();
try
{
///修改操作
sign.UpdateSignTrain(nSignTrainID,
Int32.Parse(TrainList.SelectedValue),
Convert.ToDateTime(SignDate.Text.Trim()),
Int32.Parse(EmployeeList.SelectedValue),
Int32.Parse(StatusList.SelectedValue),
Remark.Text);
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch(Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ MisSystem.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.UpdateBtn.Click += new System.EventHandler(this.UpdateBtn_Click);
this.ReturnBtn.Click += new System.EventHandler(this.ReturnBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -