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

📄 producequestion.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 ProduceQuestion.
	/// </summary>
	public partial class ProduceQuestion : System.Web.UI.Page
	{

		private static int[] ArrayID = new int[4];
		public String sOperation = "";
		public String sLinkName  = "";
	
		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("Valid") == -1 && sUserRoleName.IndexOf("Normal") == -1)
				{
					Response.Redirect("~/Default.aspx");
				}
			}
			if(!Page.IsPostBack)
			{
				BindDirectionData();

				if(DirectionList.Items.Count > 0)
				{
					BindChannelData(Int32.Parse(DirectionList.SelectedValue));
				}

				if(ChannelList.Items.Count > 0)
				{
					BindTopicData(Int32.Parse(ChannelList.SelectedValue));
				}

				if(TopicList.Items.Count > 0)
				{
					BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
				}
			}
			if(Request.Params["LinkID"] != null)
			{
				GetLinkName(Request.Params["LinkID"].ToString());
			}
		}

		private void GetLinkName(String sLinkID)
		{
			String[] aName = new String[2];
			aName = GlobalVarables.GetLinkName(sLinkID);

			sOperation = aName[0].ToString();
			sLinkName  = aName[1].ToString();
		}

		private void BindDirectionData()
		{
			DirectionList.Items.Clear();

			DirectionDB dir = new DirectionDB();
			SqlDataReader recd = dir.GetDirections();

			DirectionList.DataSource = recd;
			DirectionList.DataTextField = "DirectionName";
			DirectionList.DataValueField = "ID";
			DirectionList.DataBind();

			recd.Close();
		}

		private void BindChannelData(int nDirectionID)
		{
			ChannelList.Items.Clear();

			ChannelDB channel = new ChannelDB();
			SqlDataReader recc = channel.GetChannels(nDirectionID);

			ChannelList.DataSource = recc;
			ChannelList.DataTextField = "ChannelName";
			ChannelList.DataValueField = "ID";
			ChannelList.DataBind();

			recc.Close();
		}

		private void BindTopicData(int nChannelID)
		{
			TopicList.Items.Clear();

			TopicDB topic = new TopicDB();
			SqlDataReader recc = topic.GetTopics(nChannelID);

			TopicList.DataSource = recc;
			TopicList.DataTextField = "TopicName";
			TopicList.DataValueField = "ID";
			TopicList.DataBind();

			recc.Close();
		}

		private void BindSubTopicData(int nTopicID)
		{
			SubTopicList.Items.Clear();

			SubTopicDB subtopic = new SubTopicDB();
			SqlDataReader recs = subtopic.GetSubtopics(nTopicID);

			SubTopicList.DataSource = recs;
			SubTopicList.DataTextField = "SubTopicName";
			SubTopicList.DataValueField = "ID";
			SubTopicList.DataBind();

			recs.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()
		{    

		}
		#endregion

		protected void SubmitBtn_Click(object sender, System.EventArgs e)
		{
			if(Title.Text.Length > 0)
			{
				QuestionDB question = new QuestionDB();

				int[] arrayID = GetAllID();
			    
				try
				{
					question.AddQuestion
						(
						CleanString.InputText(Title.Text.Trim(),50),
						CleanString.InputText(Body.Text,Body.Text.Length),
						Int32.Parse(Session["UserID"].ToString()),
						arrayID[0],
						arrayID[1],
						arrayID[2],
						arrayID[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"," "));
				}
			     
			    Title.Text = "";
				Body.Text  = "";
				Response.Write("<script>alert(\"报修问题成功!\")</script>");
			}
			else
			{
				Response.Write("<script>alert(\"报修问题的标题不能为空!\")</script>");
			}
		}

		private int[] GetAllID()
		{
			if(SubTopicList.Items.Count > 0)
			{
				ArrayID[3] = Int32.Parse(SubTopicList.SelectedValue);
				ArrayID[0] = ArrayID[1] = ArrayID[2] = 0;
			}
			else
			{
				if(TopicList.Items.Count > 0)
				{
					ArrayID[2] = Int32.Parse(TopicList.SelectedValue);
					ArrayID[0] = ArrayID[1] = ArrayID[3] = 0;
				}
				else
				{
					if(ChannelList.Items.Count > 0)
					{
						ArrayID[1] = Int32.Parse(ChannelList.SelectedValue);
						ArrayID[0] = ArrayID[2] = ArrayID[3] = 0;
					}
					else
					{
						if(DirectionList.Items.Count > 0)
						{
							ArrayID[0] = Int32.Parse(DirectionList.SelectedValue);
							ArrayID[1] = ArrayID[2] = ArrayID[3] = 0;
						}
					}
				}
			}

			return(ArrayID);
		}

		protected void Resetbtn_Click(object sender, System.EventArgs e)
		{
			Title.Text = "";
			Body.Text  = "";
		}

		protected void DirectionList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(DirectionList.Items.Count > 0)
			{
				BindChannelData(Int32.Parse(DirectionList.SelectedValue));
			}

			if(ChannelList.Items.Count > 0)
			{
				BindTopicData(Int32.Parse(ChannelList.SelectedValue));
			}
			else
			{
				TopicList.Items.Clear();
			}

			if(TopicList.Items.Count > 0)
			{
				BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
			}
			else
			{
				SubTopicList.Items.Clear();
			}
		}

		protected void ChannelList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(ChannelList.Items.Count > 0)
			{
				BindTopicData(Int32.Parse(ChannelList.SelectedValue));
			}

			if(TopicList.Items.Count > 0)
			{
				BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
			}
			else
			{
				SubTopicList.Items.Clear();
			}
		}

		protected void TopicList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(TopicList.Items.Count > 0)
			{
				BindSubTopicData(Int32.Parse(TopicList.SelectedValue));
			}
			else
			{
				SubTopicList.Items.Clear();
			}
		}
	}
}

⌨️ 快捷键说明

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