⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assignproject.aspx.cs

📁 当今世界的高校的教学评估体系已经有了一定的发展
💻 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 System.Data.SqlClient;
using OfficeAutomatization;

public partial class AssignProject : System.Web.UI.Page
{
	private 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)
		{
			///绑定所有的数据
			if (nProjectID > -1)
			{
				BindProjectData(nProjectID);
				BindDepartmentData();
				if (DepartmentList.Items.Count > 0)
				{
					BindEmployeeData(Int32.Parse(DepartmentList.SelectedValue));
				}
				else
				{
					EmployeeList.Items.Clear();
				}
			}
			else
			{
			    AssignEmployeeBtn.Enabled = false;
			    SureBtn.Enabled = false;
			    deleteBtn.Enabled = false;
			}
		}
	}

	private void BindProjectData(int nProjectID)
	{
		///定义获取数据的类
		Project project = new Project();
		SqlDataReader recp = project.GetSingleProject(nProjectID);

		///从获取的数据中读取数据
		if (recp.Read())
		{
			Name.Text = "项目:" + recp["DepartName"].ToString() + "的人员分配如下:";
		}
		///关闭数据读取器和数据库的连接
		recp.Close();
	}

	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();

		if (DepartmentList.Items.Count > 0)
		{
			DepartmentList.SelectedIndex = 0;
		}
	}

	private void BindEmployeeData(int nDepartmentID)
	{
		///定义获取数据的类
		Employee employee = new Employee();
		SqlDataReader recu = employee.GetEmployeeByDepartment(nDepartmentID);

		///设定控件的数据源
		EmployeeList.DataSource = recu;

		///设定控件的Text属性和Value属性
		EmployeeList.DataTextField = "EmployName";
		EmployeeList.DataValueField = "EmployeeID";

		///绑定控件的数据
		EmployeeList.DataBind();

		///关闭数据读取器和数据库的连接
		recu.Close();
	}

	protected void deleteBtn_Click(object sender, ImageClickEventArgs e)
	{
		if (AssignEmployeeList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}
		
		///定义类Project
		ProjectEmployee pe = new ProjectEmployee();
		try
		{
			///删除员工
			pe.DeleteProjectEmployee(nProjectID,Int32.Parse(EmployeeList.SelectedValue));
			AssignEmployeeList.Items.Remove(AssignEmployeeList.SelectedItem);

			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
		}
		catch (Exception ex)
		{
			///显示删除操作中的失败、错误信息
			Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
				+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
				+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
		}
	}

	protected void SureBtn_Click(object sender, EventArgs e)
	{
		///定义类Project
		ProjectEmployee pe = new ProjectEmployee();
		try
		{
			///删除员工
			foreach (ListItem item in AssignEmployeeList.Items)
			{
				pe.AddProjectEmployee(nProjectID, Int32.Parse(EmployeeList.SelectedValue));
			}

			///显示操作结果信息
			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", " "));
		}
	}

	protected void ReturnBtn_Click(object sender, EventArgs e)
	{
		///跳转到管理页面
		Response.Redirect("~/DesktopModules/Project/ProjectManage.aspx");
	}

	protected void DepartmentList_SelectedIndexChanged(object sender, EventArgs e)
	{
		///重新绑定EmployeeList控件的数据
		if (DepartmentList.SelectedIndex > -1)
		{
			BindEmployeeData(Int32.Parse(DepartmentList.SelectedValue));
		}
		else
		{
			EmployeeList.Items.Clear();
		}
	}

	protected void AssignEmployeeBtn_Click(object sender, EventArgs e)
	{
		if (EmployeeList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}

		///如果该员工未被分配,则分配员工到该项目中
		if (ASPNET2System.IsExistItem(AssignEmployeeList, EmployeeList.SelectedItem.Text) == false)
		{
			AssignEmployeeList.Items.Add(EmployeeList.SelectedItem);
			AssignEmployeeList.SelectedIndex = -1;
		}
		else
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('你分配的员工已经存在,请分配其他的员工!')</script>");			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -