📄 roomdataadd.aspx.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>
/// RoomDataAdd 的摘要说明。
/// </summary>
public class RoomDataAdd : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl P1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.DropDownList DropDownList4;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.DropDownList DropDownList5;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.DropDownList DropDownList6;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.DropDownList DropDownList7;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.DropDownList DropDownList8;
protected System.Web.UI.WebControls.Label Label13;
protected System.Web.UI.WebControls.DropDownList DropDownList9;
protected System.Web.UI.WebControls.Label Label14;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Label Label16;
protected System.Web.UI.WebControls.DropDownList DropDownList10;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button7;
protected System.Web.UI.WebControls.Button Button6;
protected System.Web.UI.WebControls.Button Button5;
protected System.Web.UI.WebControls.Label Label15;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Button Button2;
private void InitDropdownList1(System.Web.UI.WebControls.DropDownList listname,string tablename,string cellname)
{//初始化下拉列表框
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
conn.Open();
OdbcCommand cmd=new OdbcCommand("select ["+cellname+"] from ["+tablename+"]",conn);
listname.DataTextField=cellname;
listname.DataSource=cmd.ExecuteReader();
listname.DataBind();
conn.Close();
}
private void InitDropdownList2(System.Web.UI.WebControls.DropDownList listname,string tablename,string cellnamet,string cellnamev)
{//初始化下拉列表框
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
conn.Open();
OdbcCommand cmd=new OdbcCommand("select ["+cellnamet+"],["+cellnamev+"] from ["+tablename+"]",conn);
listname.DataTextField=cellnamet;
listname.DataValueField=cellnamev;
listname.DataSource=cmd.ExecuteReader();
listname.DataBind();
conn.Close();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string user;
try
{
user=Session["UserName"].ToString();
}
catch
{
this.Response.Redirect("../Enter.aspx");
}
//
InitDropdownList1(DropDownList1,"BuildingInfo","bno");
InitDropdownList2(DropDownList2,"unit","unit","index");
InitDropdownList2(DropDownList3,"using","using","index");
InitDropdownList2(DropDownList4,"water","water","index");
InitDropdownList2(DropDownList5,"elect","elect","index");
InitDropdownList2(DropDownList6,"net","net","index");
InitDropdownList2(DropDownList7,"phone","tel_info","tel_bit");
InitDropdownList2(DropDownList8,"unused","unused_info","unused_bit");
InitDropdownList2(DropDownList9,"sex","sex","index");
InitDropdownList2(DropDownList10,"multimedia","media","media_int");
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button5.Click += new System.EventHandler(this.LinkButton1_Click);
this.Button6.Click += new System.EventHandler(this.LinkButton2_Click);
this.Button7.Click += new System.EventHandler(this.LinkButton3_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.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="";
TextBox5.Text="";
}
private void Button1_Click(object sender, System.EventArgs e)
{
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
string sqlcom;
//打开数据连接
conn.Open();
try
{
sqlcom="insert into [roominfo](bno,rno,area,seatnum,unit,[using],water,elec,net,phone,charge,used,sex,memo,multimedia) values('"+DropDownList1.SelectedValue+"','"+TextBox1.Text+"',"+TextBox2.Text+","+TextBox3.Text+",'"+DropDownList2.SelectedValue+"',"+DropDownList3.SelectedValue+","+DropDownList4.SelectedValue+","+DropDownList5.SelectedValue+","+DropDownList6.SelectedValue+","+DropDownList7.SelectedValue+",'"+TextBox4.Text+"',"+DropDownList8.SelectedValue+","+DropDownList9.SelectedValue+",'"+TextBox5.Text+"',"+DropDownList10.SelectedValue+")";
//定义命令对象
OdbcCommand cmd = new OdbcCommand(sqlcom,conn);
//执行SQL命令
cmd.ExecuteNonQuery();
Label15.Text="添加成功";
}
catch
{
Label15.Text="添加失败";
}
//关闭连接对象
conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -