?? updateproject.aspx.cs
字號(hào):
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 UpdateProject : System.Web.UI.Page
{
int nProjectID = -1;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["ProjectID"] != null)
{
nProjectID = Int32.Parse(Request.Params["ProjectID"].ToString());
}
if (!Page.IsPostBack)
{
///綁定控件的數(shù)據(jù)
BindDepartmentData();
BindEmployeeData();
///綁定所有的數(shù)據(jù)
if (nProjectID > -1)
{
BindProjectData(nProjectID);
}
}
}
private void BindEmployeeData()
{
///定義獲取數(shù)據(jù)的類
Employee employee = new Employee();
SqlDataReader recu = employee.GetEmployees();
///設(shè)定控件的數(shù)據(jù)源
EmployeeList.DataSource = recu;
///設(shè)定控件的Text屬性和Value屬性
EmployeeList.DataTextField = "EmployName";
EmployeeList.DataValueField = "EmployeeID";
///綁定控件的數(shù)據(jù)
EmployeeList.DataBind();
///關(guān)閉數(shù)據(jù)讀取器和數(shù)據(jù)庫的連接
recu.Close();
}
private void BindDepartmentData()
{
///定義獲取數(shù)據(jù)的類
OfficeAutomatization.Department depart = new OfficeAutomatization.Department();
SqlDataReader recd = depart.GetDepartments();
///設(shè)定控件的數(shù)據(jù)源
DepartmentList.DataSource = recd;
///設(shè)定控件的Text屬性和Value屬性
DepartmentList.DataTextField = "Name";
DepartmentList.DataValueField = "DepartmentID";
///綁定控件的數(shù)據(jù)
DepartmentList.DataBind();
///關(guān)閉數(shù)據(jù)讀取器和數(shù)據(jù)庫的連接
recd.Close();
}
private void BindProjectData(int nProjectID)
{
///定義獲取數(shù)據(jù)的類
Project project = new Project();
SqlDataReader recp = project.GetSingleProject(nProjectID);
///從獲取的數(shù)據(jù)中讀取數(shù)據(jù)
if (recp.Read())
{
Name.Text = recp["DepartName"].ToString();
Desn.Text = recp["DepartDesn"].ToString();
CreateDate.Text = DateTime.Parse(recp["CreateDate"].ToString()).ToShortDateString();
StartDate.Text = DateTime.Parse(recp["StartDate"].ToString()).ToShortDateString();
EndDate.Text = DateTime.Parse(recp["EndDate"].ToString()).ToShortDateString();
///設(shè)置上級(jí)部門
ASPNET2System.SetListBoxItem(DepartmentList, recp["DepartmentID"].ToString());
ASPNET2System.SetListBoxItem(EmployeeList, recp["EmployeeID"].ToString());
ASPNET2System.SetListBoxItem(StateList, recp["State"].ToString());
}
///關(guān)閉數(shù)據(jù)讀取器和數(shù)據(jù)庫的連接
recp.Close();
}
protected void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳轉(zhuǎn)到管理頁面
Response.Redirect("~/DesktopModules/Project/ProjectManage.aspx");
}
protected void UpdateBtn_Click(object sender, System.EventArgs e)
{
if (Page.IsValid == true)
{
///定義類User
///定義類
Project project = new Project();
try
{
///添加操作
project.UpdateProject(nProjectID,Name.Text.Trim(),Desn.Text,
Int32.Parse(EmployeeList.SelectedValue),
DateTime.Parse(StartDate.Text.Trim()),
DateTime.Parse(EndDate.Text.Trim()),
Int32.Parse(DepartmentList.SelectedValue),
Int32.Parse(StateList.SelectedValue));
///顯示操作結(jié)果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///顯示添加操作中的失敗、錯(cuò)誤信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -