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

📄 solutequestion.aspx.cs

📁 这是一个管理系统的源码
💻 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;

namespace Service
{
	/// <summary>
	/// Summary description for SoluteQuestion.
	/// </summary>
	public partial class SoluteQuestion : System.Web.UI.Page
	{
	
		private int nQuestionID = 0;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["UserID"] == null)
			{
				Response.Redirect("~/Default.aspx");
			}
			else
			{
				String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString()));
				if(sUserRoleName.IndexOf("Monitor") == -1)
				{
					Response.Redirect("~/Default.aspx");
				}
			}

			if(Request.QueryString["QuestionID"] != null)
			{
				nQuestionID = Int32.Parse(Request.QueryString["QuestionID"].ToString());
			}

			if(!Page.IsPostBack)
			{
				if(nQuestionID > 0)
				{
					BindData();

					SubmitBtn.Enabled = false;
				}
			}
		}

		private void BindData()
		{
			QuestionDB question = new QuestionDB();
			SqlDataReader recq = question.GetSingleQuestion(nQuestionID);

			while(recq.Read())
			{
				Title.Text = recq["Title"].ToString();
				Body.Text  = recq["Question"].ToString();
			}
			recq.Close();

			EmployeeDB employee = new EmployeeDB();
			SqlDataReader rece = employee.GetEmployees();

			EmployeeList.DataSource = rece;
			EmployeeList.DataTextField = "EmployeeName";
			EmployeeList.DataValueField = "ID";
			EmployeeList.DataBind();

			rece.Close();

			EmployeeQuestionDB employeeQ = new EmployeeQuestionDB();
			SqlDataReader receq = employeeQ.GetEmployeeByQuestion(nQuestionID);

			QuestionEmpList.DataSource = receq;
			QuestionEmpList.DataTextField = "EmployeeName";
			QuestionEmpList.DataValueField = "EmployeeID";
			QuestionEmpList.DataBind();

			receq.Close();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.deleteBtn_Click);

		}
		#endregion

		protected void AddEmployee_Click(object sender, System.EventArgs e)
		{
			if(EmployeeList.SelectedIndex > -1)
			{
				if(IsExistData(QuestionEmpList,EmployeeList.SelectedItem) == false)
				{
					QuestionEmpList.Items.Add(EmployeeList.SelectedItem);
				}
				else
				{
					Response.Write("<script>alert(\"你选择的数据项已经存在!\")</script>");
				}

				SetSubmitEnabled();
			}

			//清空列表的所有选项
			ClearSelected(QuestionEmpList);
		}

		private void deleteBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if(QuestionEmpList.SelectedIndex > -1)
			{
				QuestionEmpList.Items.Remove(QuestionEmpList.SelectedItem);

				SetSubmitEnabled();
			}
			else
			{
				Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
			}
		}

		private bool IsExistData(ListBox listBox,ListItem listItem)
		{
			bool isExist = false;

			if(listBox.Items.Count > 0)
			{
				for(int i = 0; i< listBox.Items.Count; i++)
				{
					if(listItem.Text == listBox.Items[i].Text)
					{
						isExist = true;
						break;
					}
				}
			}
			return(isExist);
		}

		protected void SubmitBtn_Click(object sender, System.EventArgs e)
		{
			EmployeeQuestionDB employeeR = new EmployeeQuestionDB();
			EmployeeDB         employee  = new EmployeeDB();
			QuestionDB question = new QuestionDB();
			
			//添加工作人员初始化
			employeeR.DeleteEmployeeQuestion(nQuestionID);

			for(int i = 0; i < QuestionEmpList.Items.Count; i++)
			{
				try
				{				
					employeeR.AddEmployeeQuestion(nQuestionID,Int32.Parse(QuestionEmpList.Items[i].Value));
					employee.UpdateRepairCount(Int32.Parse(QuestionEmpList.Items[i].Value));

				}
				catch(Exception ex)
				{
					string sRawURL = Request.RawUrl;

					if(sRawURL.IndexOf("?") > -1)
					{
						sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
					}				
					Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
				}
			}
				
			try
			{
				question.UpdateQuestionState(nQuestionID,1);
			}
			catch(Exception ex)
			{
				string sRawURL = Request.RawUrl;

				if(sRawURL.IndexOf("?") > -1)
				{
					sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
				}				
				Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
			}

			Response.Write("<script>alert(\"提交成功!\");</script>");
		}

		private void ClearSelected(ListBox listBox)
		{
			for(int i = 0; i < listBox.Items.Count; i++)
			{
				listBox.Items[i].Selected = false;
			}
		}

		private void SetSubmitEnabled()
		{
			if(QuestionEmpList.Items.Count > 0)
			{
				SubmitBtn.Enabled = true;
			}
			else
			{
				SubmitBtn.Enabled = false;
			}
		}

		protected void TypeErrorBtn_Click(object sender, System.EventArgs e)
		{
			QuestionDB question = new QuestionDB();

			try
			{
				question.UpdateQuestionState(nQuestionID,3);
			}
			catch(Exception ex)
			{
				string sRawURL = Request.RawUrl;

				if(sRawURL.IndexOf("?") > -1)
				{
					sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
				}				
				Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
			}

			Response.Write("<script>alert(\"提交成功!\");</script>");
		}
	}
}

⌨️ 快捷键说明

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