📄 addroom.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class addroom : System.Web.UI.Page
{
SqlConnection cn;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Convert.ToString(Session["role"]) == "普通用户")
{
Response.Write("<script language='javascript'>alert('非常抱歉!您不是"管理员",不能进入该页面!^_^');window.location.href='Default.aspx'</script>");
}
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string adminname = args.Value;
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("select count(*)from room where roomname='" + adminname + "'", cn);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
cn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
int count = Convert.ToInt32(this.txtcount .Text .Trim());
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("insert into room(roomname,roompos,pcount,note)values('" + this.txtname.Text.ToString().Trim() + "','" + this.txtaddr.Text.ToString().Trim() + "','"+count+"','"+this.txtnote .Text .Trim ()+"')", cn);
cmd.ExecuteNonQuery();
this.HyperLink1.Visible = true;
this.Labmessage.Text = "添加会议室成功";
}
catch
{
this.Labmessage.Text = "服务器忙,请一会在试!";
}
finally
{
cn.Close();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.txtname.Text = "";
this.txtaddr.Text = "";
this.txtnote.Text = "";
this.txtname.Focus();
this.txtcount.Text = "";
this.Labmessage.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -