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

📄 userquestion.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;
using System.Text;

namespace dayi
{
	/// <summary>
	/// userQuestion 的摘要说明。
	/// </summary>
	public class userQuestion : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblQuestionList;
	
		dayi.controlDatabase cd=new controlDatabase();

		private string showAllQuestion(string type,int pageCount,int curPage)
		{
			//显示所有问题
			//pageCount:一页多少条记录
			//curpage:当前页数

			StringBuilder returnValue=new StringBuilder();

			string image="<img src='images/file.gif'>";
			string viewQuestionListPage="<a href=userQuestion.aspx?type="+type;
			string viewQuestionPage="<a href=showQuestion.aspx?questionID=";

			string sql="select * from [questions] where askUser='"+Session["userName"].ToString()+"' order by id desc";
			if(type=="ok")
			{
				sql="select * from [questions] where askUser='"+Session["userName"].ToString()+"' and answered='1' order by id desc";
			}
			else if(type=="no")
			{
				sql="select * from [questions] where askUser='"+Session["userName"].ToString()+"' and answered='0' order by id desc";
			}
			try
			{
				DataTable dt=cd.getDataTable(sql);
				int totalRec=dt.Rows.Count;
				int totalPage=(totalRec+pageCount-1)/pageCount;
				if(curPage<1)
					curPage=1;
				if(curPage>totalPage)
					curPage=totalPage;
				int startRec=(curPage-1)*pageCount;

				DataRow row;
				int curLine=0;//当前行
				string subject="";
				string answered="0";
				string questionid="";
			
				string manage="";
				returnValue.Append("<table width=\"450\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#6f8cb8\"><tr><td background=\"images/BG1.GIF\" height=\"15\" colspan=\"2\"><img src=\"images/support.gif\" width=\"15\" height=\"17\"><b><font color=white size=2>问题列表</font></b></td></tr>");
				if(totalRec>0)
				{
					for(int i=0;i<pageCount;i++)
					{
						curLine=startRec+i;
						if(curLine<totalRec)
						{
							row=dt.Rows[i];
							subject=row["subject"].ToString().Trim();
							answered=row["answered"].ToString().Trim();
							questionid=row["id"].ToString().Trim();
							if(answered=="0")//未答
								manage="<a href=modifyQuestion.aspx?from=user&questionid="+questionid+">修改</a>|<a href=deleteQuestion.aspx?from=user&type=all&questionid="+questionid+">删除</a>";
							else
								manage=viewQuestionPage+questionid+" target=\"_blank\">查看</a>";

							returnValue.Append("<tr bgcolor=\"#FFFFFF\"><td width=\"327\">"+image+viewQuestionPage+questionid+" target=\"_blank\">"+subject+"</a></td><td width=\"116\" align=\"center\">"+manage+"</td></tr>");
						}
						else
							break;
					}
				}
				else
				{
					returnValue.Append("<tr  bgcolor=\"#FFFFFF\"><td><img src=\"images/dot012.gif\" width=\"16\" height=\"13\">没有该类问题</td></tr>");
				}
				returnValue.Append("</table>");
				if(totalPage>1)
				{
					returnValue.Append(cd.showPageString(viewQuestionListPage,curPage,totalPage,pageCount,totalRec));
				}

				return returnValue.ToString();
			}
			catch(Exception ee)
			{
				Response.Redirect("err.aspx?err="+ee.Message);
				return "";
			}
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			//显示所有问题
			try
			{
				if(Session["userName"].ToString()=="")
				{
					Response.Redirect("err.aspx?err=没有权限,可能没有登录系统");
				}
				int curPage=1;
				if(Request.QueryString["page"]!=null)
				{
					curPage=Convert.ToInt32(Request.QueryString["page"]);
				}
				string type="";
				if(Request.QueryString["type"]!=null)
				{
					type=Request.QueryString["type"].ToString();
				}
				
				this.lblQuestionList.Text=this.showAllQuestion(type,20,curPage);
			}
			catch(Exception)
			{
				Response.Redirect("err.aspx?err=显示问题列表时出错");
			}
		}

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

		}
		#endregion

	}
}

⌨️ 快捷键说明

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