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

📄 addquestion.aspx.cs

📁 网上自动答疑系统(C#)
💻 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;

namespace dayi
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtSubject;
		protected System.Web.UI.WebControls.TextBox txtKeyWord;
		protected System.Web.UI.WebControls.DropDownList listType;
		protected System.Web.UI.WebControls.Button Button1;
		protected FreeTextBoxControls.FreeTextBox FreeTextBox1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.Button btnAddQuestion;

		dayi.controlDatabase cd=new dayi.controlDatabase();

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["userName"].ToString()=="")
			{
				//身份验证
				Response.Redirect("err.aspx?err=没有权限,可能没有登录");
			}
			if(!this.IsPostBack)
			{
				cd.bindToDropDownList(0,this.listType);
			}	
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnAddQuestion.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		public string subject
		{
			//得到标题
			get
			{
				return this.txtSubject.Text.Trim();
			}
		}

		public string keyWord
		{
			//得到关键字
			get
			{
				return this.txtKeyWord.Text.Trim();
			}
		}
		
		public string content
		{
			//得到内容
			get
			{
				return this.FreeTextBox1.Text;
			}
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			//添加文章并得到关键字
			string subject=this.txtSubject.Text.Trim().Replace("'","‘");
			string keyword=this.txtKeyWord.Text.Trim().Replace("'","‘");
			keyword=keyword.Replace(",",",");
			string[] pathid=this.listType.SelectedValue.Split(new char[]{'#'});
			int parentID=int.Parse(pathid[0]);
			int rootID=int.Parse(pathid[1]);

			try
			{
				string selectString="";
				//如果添加的次目录,则其根ID为根目录的ID
				if(rootID==0)
				{
					rootID=parentID;
				}

				string boardPath=pathid[2];
				string content=this.FreeTextBox1.Text.Replace("'","‘");
				string askUser=Session["userName"].ToString();
				selectString="insert questions(subject,keyword,content,askuser,rootID,parentID,boardPath) values('";
				selectString+=subject+"','"+keyword+"','"+content+"','"+askUser+"',"+rootID+","+parentID+",'"+boardPath+"')";

				cd.updateDatabase(selectString);

				if(cd.getSystemPara("searchType").ToString().Trim()=="fullText")
				{
					//填充全文索引
					//从数据库中得到数据库更新多少次后填充
					int count=Convert.ToInt32(cd.getSystemPara("countBeforeFullText"));
					Application["updateCount"]=Convert.ToInt32(Application["updateCount"])+1;
					if(Convert.ToInt32(Application["updateCount"])==count)
					{
						Application["updateCount"]=0;
						cd.execProcedure("startFull");
					}
				}

				//得到查询关键字词字符串
				keyword+=","+subject;
				bool wordbookAllow=(bool)cd.getSystemPara("wordbookAllow");
				if(wordbookAllow)
				{
					string searchType=cd.getSystemPara("wordbookType").ToString();
					if(searchType=="subject")
					{
						keyword+=","+cd.scanWordbook(subject);
					}
					else if(searchType=="content")
					{
						keyword+=","+cd.scanWordbook(content);
					}
					else if(searchType=="all")
					{
						keyword+=","+cd.scanWordbook(subject+" "+content);
					}
				}
				keyword=keyword.Trim();
				while(keyword.EndsWith(","))
					keyword=keyword.Substring(0,keyword.Length-1);
				while(keyword.StartsWith(","))
					keyword=keyword.Substring(1);

				//得到自动搜索返回类型
				string type=cd.getSystemPara("autoAnswerType").ToString().Trim();
				if(type=="all")
					type="0";
				else
					type=rootID.ToString();

				//转到自动回答页
				Response.Redirect("autoAnswer.aspx?type="+type+"&keyword="+keyword);
			}
			catch(Exception ee)
			{
				this.txtSubject.Text=ee.Message;
			}
		}
	}
}

⌨️ 快捷键说明

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