📄 deletetrain.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.Train
{
/// <summary>
/// DeleteTrain 的摘要说明。
/// </summary>
public class DeleteTrain : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblLReceiver;
protected System.Web.UI.WebControls.TextBox Subject;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.DropDownList TypeList;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.TextBox Place;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox AttendStartDate;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox AttendEndDate;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox StartDate;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.TextBox EndDate;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox Cost;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox Detail;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox Remark;
protected System.Web.UI.WebControls.Button DeleteBtn;
protected System.Web.UI.WebControls.Button ReturnBtn;
private int nTrainID = -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["TrainID"] != null)
{
nTrainID = Int32.Parse(Request.Params["TrainID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindTypeData();
if(nTrainID > -1)
{
BindTrainData(nTrainID);
}
}
///设置添加按钮的可用性
DeleteBtn.Enabled = (TypeList.Items.Count <= 0 || nTrainID <= -1) ? false : true;
///添加删除确认对话框
DeleteBtn.Attributes.Add("onclick","return confirm('" + MisSystem.OPERATIONDELETEMESSAGE + "');");
}
private void BindTypeData()
{
///定义获取数据的类
MisOfficeAffair.Components.Type type = new MisOfficeAffair.Components.Type();
SqlDataReader rect = type.GetTypes();
///设定控件的数据源
TypeList.DataSource = rect;
///设定控件的Text属性和Value属性
TypeList.DataTextField = "Name";
TypeList.DataValueField = "TypeID";
///绑定控件的数据
TypeList.DataBind();
///关闭数据读取器和数据库的连接
rect.Close();
}
private void BindTrainData(int nTrainID)
{
///定义获取数据的类
MisOfficeAffair.Components.Train train = new MisOfficeAffair.Components.Train();
SqlDataReader rect = train.GetSingleTrain(nTrainID);
///从获取的数据中读取数据
if(rect.Read())
{
Subject.Text = rect["Subject"].ToString();
Place.Text = rect["Place"].ToString();
AttendStartDate.Text = Convert.ToDateTime(rect["AttendStartDate"].ToString()).ToShortDateString();
AttendEndDate.Text = Convert.ToDateTime(rect["AttendEndDate"].ToString()).ToShortDateString();
StartDate.Text = Convert.ToDateTime(rect["StartDate"].ToString()).ToShortDateString();
EndDate.Text = Convert.ToDateTime(rect["EndDate"].ToString()).ToShortDateString();
Cost.Text = rect["Cost"].ToString();
Detail.Text = rect["Detail"].ToString();
Remark.Text = rect["Remark"].ToString();
///设置列表控件的数据
MisSystem.SetListBoxItem(TypeList,rect["TypeID"].ToString());
}
///关闭数据读取器和数据库的连接
rect.Close();
}
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/Train/TrainManage.aspx");
}
private void DeleteBtn_Click(object sender, System.EventArgs e)
{
///定义类
MisOfficeAffair.Components.Train train = new MisOfficeAffair.Components.Train();
try
{
///删除操作
train.DeleteTrain(nTrainID);
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONDELETESUCCESSMESSAGE + "')</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.DeleteBtn.Click += new System.EventHandler(this.DeleteBtn_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 + -