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

📄 vote.aspx.cs

📁 This is not a very mean things
💻 CS
字号:
//-----------------------------------------------------------------------------
//
// WebExpert.NET 1.0 
//
// (c) 2003, www.AspCool.com. All rights reserved.
// ASP酷技术网版权所有
//
// 该源码下载自:http://www.51aspx.com
// 邮箱:tim@aspcool.com
//
// 版权声明:本程序仅供学习使用,你也可以修改后在网站上使用,但使用时必
// 须保留ASP酷技术网(www.AspCool.com)的版权信息和链接。本程序随《ASP.NET
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
//   此文件包含下面的类:
//       vote
//
// 作者:     王保健
// 时间:     2003/09/15
//
//-----------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;

namespace vote
{
	/// <summary>
	/// Summary description for vote.
	/// </summary>
	public class vote : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.CheckBoxList cblAnswer;
		protected System.Web.UI.WebControls.RadioButtonList rblAnswer;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Button btnView;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv;
		protected System.Web.UI.WebControls.Label lblQuestion;

	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!this.IsPostBack) 
			{
				LoadData();				
			}
			
		}
		private void LoadData()
		{
			string QuestionID;
			bool Multi=false;
			bool bl=false;
			QuestionID=Request["ID"];
			// 定义字符串strQuestion,其作用是用来查询问题标题和,是单选还是多选。
			string strQuestion= "Select Question_Subject,Multi from Questions where Question_ID='"+QuestionID+"'";
		
			SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			conn.Open();   //打开数据库连接
			SqlCommand myComm=new SqlCommand(strQuestion,conn);

			SqlDataReader dr=myComm.ExecuteReader();
			if (dr.Read())
			{
				lblQuestion.Text=dr.GetString(0);
				Multi=dr.GetBoolean(1);
				bl=true;
			}
			else
			{
				Response.Write("对不起,没有找到你的问题编号,请检查!");                		
			}
			dr.Close();

			//显示答案
			if (bl)
			{
				string strAnswer = "Select Answer_ID,Answer from Answers where Question_ID='"+QuestionID+"'";

				//使用DataReader的方法。
				SqlCommand AnComm = new SqlCommand(strAnswer,conn);
				SqlDataReader AnDr = AnComm.ExecuteReader(CommandBehavior.CloseConnection);
				if(Multi)
				{									
					cblAnswer.Visible = true;
                    cblAnswer.DataSource = AnDr;
					cblAnswer.DataTextField = "Answer";
					cblAnswer.DataValueField = "Answer_ID";
					cblAnswer.DataBind();
					rblAnswer.Visible = false;					
				}
				else
				{			
					rblAnswer.Visible = true;
					rblAnswer.DataSource = AnDr;
					rblAnswer.DataTextField = "Answer";
					rblAnswer.DataValueField = "Answer_ID";
					rblAnswer.DataBind();
					cblAnswer.Visible = false;			
				}
				
				//结束使用DataReader.
				AnDr.Close();			
			}
			//答案显示结束			
			conn.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.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion


		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			if (rblAnswer.Visible==true )
			{
				Got(Convert.ToInt32(rblAnswer.SelectedItem.Value));	
			}
			else
			{
				for (int i=0;i<cblAnswer.Items.Count;i++)
				{
					if (cblAnswer.Items[i].Selected)
					{
						Got(Convert.ToInt32(cblAnswer.Items[i].Value));		
						
					}
				}
			}		
		}

		private void Got(int id)
		{
			string strAdd= "update Answers set Got=Got+1 where Answer_ID="+id;
		
			SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			conn.Open();
			SqlCommand AddComm=new SqlCommand(strAdd,conn);
			AddComm.ExecuteNonQuery();			
			conn.Close();			
		}		
	}
}

⌨️ 快捷键说明

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