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

📄 roomuseradd.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.Odbc;
using System.Configuration;

namespace RoomMngSystem
{
	/// <summary>
	/// RoomUserAdd 的摘要说明。
	/// </summary>
	public class RoomUserAdd : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.TextBox TextBox3;
		protected System.Web.UI.WebControls.TextBox TextBox4;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.DropDownList DropDownList2;
		protected System.Data.OleDb.OleDbConnection oleDbConnection1;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Data.Odbc.OdbcConnection conn;
		protected System.Web.UI.WebControls.Button Button5;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.Button Button7;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.Image Image1;
		protected System.Web.UI.WebControls.Panel Panel2;
	
		private void InitDropdownList()
		{//初始化下拉列表框
			OdbcConnection conn = new OdbcConnection();
			conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
			conn.Open();
			OdbcCommand cmd=new OdbcCommand("select [index] from [unit]",conn);
			OdbcDataReader EqReader=cmd.ExecuteReader();
			while(EqReader.Read())
			{
				DropDownList1.Items.Add(EqReader.GetString(0));
			}
			conn.Close();
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string user;
			try
			{	
				user=Session["UserName"].ToString();				
			}
			catch
			{
				this.Response.Redirect("../Enter.aspx");
			}

			InitDropdownList();
		}

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

		}
		#endregion

		private void LinkButton1_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomUserMng.aspx");
		}

		private void LinkButton3_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomDataMng.aspx");
		}

		private void LinkButton2_Click(object sender, System.EventArgs e)
		{
			this.Response.Redirect("RoomSysMng.aspx");
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			TextBox1.Text="";
			TextBox2.Text="";
			TextBox3.Text="";
			TextBox4.Text="";
			DropDownList2.SelectedIndex=1;
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			if(TextBox3.Text==TextBox4.Text)
			{
				OdbcConnection conn = new OdbcConnection();
				conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
				string sqlcom;
				//打开数据连接
				conn.Open();
				try
				{
					sqlcom="insert into [userinfo](ID,pw,name,unit,type) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+DropDownList1.SelectedItem.Text+"','"+DropDownList2.SelectedItem.Value+"')";
					//定义命令对象
					OdbcCommand cmd = new OdbcCommand(sqlcom,conn);
					//执行SQL命令
					cmd.ExecuteNonQuery();
					Label7.Text="添加成功";
				}
				catch
				{
					Label7.Text="添加失败";
				}
				//关闭连接对象
				conn.Close();
			}
			else
			{
				Label7.Text="密码不一致,请重新输入";
				TextBox3.Text="";
				TextBox4.Text="";
			}
		}
	}
}

⌨️ 快捷键说明

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