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

📄 modify.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
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
//   此文件包含下面的类:
//       Modify
//
// 作者:     王保健
// 时间:     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 Modify.
	/// </summary>
	public class Modify : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox txtQuestionID;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.TextBox txtSubject;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.TextBox txtAnswer;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.RadioButtonList rblMulti;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.TextBox txtPWD;
		protected System.Web.UI.WebControls.Button btnReset;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!this.IsPostBack)
			{
				//获取调查问题编号。
				string QuestionID=Request["ID"];  
				//把调查问题编号显示在页面上。
				txtQuestionID.Text=Request["ID"];

                //创建数据库连接
				SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
				conn.Open();  //打开数据库连接

                //strAnswer用来从Answers表中获取给定QuestionID的所有答案信息的SQL语句。
				string strAnswer="Select Answer_ID,Answer,Got from Answers where Question_ID='"+QuestionID+"'";
				//strQuestion用来从Questions表中获得问题信息的SQL语句。
				string strQuestion= "Select Question_Subject,Multi from Questions where Question_ID='"+QuestionID+"'";
		
				//创建SQL命令。
				SqlCommand myComm=new SqlCommand(strQuestion,conn);
                //执行strQuestion语句,获得SqlDataReader。
				SqlDataReader dr=myComm.ExecuteReader();
				if (dr.Read())
				{
					//取得问题主题并显示在页面上。
					txtSubject.Text=dr.GetString(0);
					//判断是单选题还是多选题,并显示在页面上。
					if(dr.GetBoolean(1))
						rblMulti.Items[1].Selected=true;
					else
						rblMulti.Items[0].Selected=true;
				
				}
				else
				{
					Response.Write("对不起,没有找到你的问题编号,请检查!");                		
				}
				//关闭SqlDataReader
				dr.Close();

				//创建SQL命令。
				SqlCommand comm=new SqlCommand(strAnswer,conn);
				 //执行strAnswer语句,获得SqlDataReader。
				SqlDataReader drA=comm.ExecuteReader();

				while (drA.Read())
				{
					//把答案信息一行一行显示在txtAnswer中。
					txtAnswer.Text += drA.GetString(1) + Convert.ToChar(13);
				}
				//关闭SqlDataReader
				drA.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.btnReset.Click += new System.EventHandler(this.btnReset_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			string[] a;
			string strAnSQL;
			string b;
			SqlCommand AnComm;

			if (txtPWD.Text==ConfigurationSettings.AppSettings["Admin.Password"])
			{
				string strSQLQ= "update  Questions set Question_Subject='"+txtSubject.Text+"',Multi='"+rblMulti.SelectedItem.Value +"' where Question_ID='"+txtQuestionID.Text+"'";
				string strSQLA="Delete Answers where Question_ID='"+txtQuestionID.Text+"'";

				SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
				conn.Open();
				try
				{
			
					//修改问题		
					SqlCommand comm=new SqlCommand(strSQLQ,conn);
					comm.ExecuteNonQuery();
			
		
					//删除答案
					//方法:我们先把数据库中的要修改的问题的答案全部删除,然后增加新的答案。
					SqlCommand commA=new SqlCommand(strSQLA,conn);
					commA.ExecuteNonQuery();

					//下面是增加答案的程序
					a = txtAnswer.Text.Split(Convert.ToChar(13));
			
					for(int i=0;i<=a.Length-1;i++)
					{
						b=a[i].Trim();
						
						if (!(b==""))
						{
							strAnSQL="insert into Answers(Question_ID,Answer)values('"+txtQuestionID.Text+"','"+b+"')";
							AnComm=new SqlCommand(strAnSQL,conn);
							AnComm.ExecuteNonQuery();
						}
						
					}
					Response.Write("你的数据已经录入,请点击<a href=vote.aspx?ID="+txtQuestionID.Text +">此处</a>查看你的调查系统。");
				}
				catch (Exception ex)
				{
					Response.Write(ex);
				}
				conn.Close();
			}
			else
			{
				Response.Write("你的密码错误!");
			}
			Response.End();
		}

		private void btnReset_Click(object sender, System.EventArgs e)
		{
			txtQuestionID.Text = "";
			txtSubject.Text = "";
			txtAnswer.Text="";

		}
	}
}

⌨️ 快捷键说明

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