代码解释: 其中“查询”按钮的关键代码如下: protected void Page_Load(object sender, EventArgs e) { i 20

其中“预定”按钮的关键代码如下:SqlConnectionconn=BaseClass.DBCon();conn.Open();SqlCommandcmd=newSqlC... 其中“预定”按钮的关键代码如下:
SqlConnection conn = BaseClass.DBCon();
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from db_Room where RoomID='" + DropDownList1.SelectedValue.ToString().Trim() + "' and RoomState='空闲'", conn);
int t = Convert.ToInt32(cmd.ExecuteScalar());
if (t < 0)
{
MessageBox.Show("此房间有人预定或入住或不存在");
return;
}
else
{
string str = "insert into db_Scheduled (Name,Sex,Tel,RoomID,ScheduledDate,LeaveDate) values('" + TextBox1.Text.Trim() + "','" + DropDownList2.SelectedValue.ToString().Trim() + "','" + TextBox2.Text.Trim() + "','" + DropDownList1.SelectedValue.ToString().Trim() + "','" + TextBox4.Text.Trim() + "','" + TextBox5.Text.Trim() + "')";
BaseClass.OperateData(str);
string str1 = "update db_Room set RoomState='预定' where RoomID='" + DropDownList1.SelectedValue.ToString().Trim() + "'";
BaseClass.OperateData(str1);
Session["State"]="预定";
Response.Write("<script>alert('房间预定成功');location='Default.aspx'</script>");
}
求各位高手帮帮忙,毕业答辩急用阿。解释代码的意思,大致怎么运作的。谢谢各位了,好人走好运~~
其中“查询”按钮的关键代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strsql = "select * from db_Room order by RID desc";
BaseClass.BindDG(GridView1, "RID", strsql, "Room");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
string strsql = "select * from db_Room order by RID desc";
BaseClass.BindDG(GridView1, "RID", strsql, "Room");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
展开
 我来答
huangpeng0419
2012-05-19 · TA获得超过357个赞
知道小有建树答主
回答量:569
采纳率:100%
帮助的人:297万
展开全部
第一段
功能: 房间预定
实现:首先验证某某选择的房间有木有被人预定(即是否空闲),有则提示("此房间有人预定或入住或不存在"),木有则预定给当前要预定的人。
SqlConnection conn = BaseClass.DBCon(); // 获取连接对象
conn.Open(); // 打开连接
SqlCommand cmd = new SqlCommand("select count(*) from db_Room where RoomID='" + DropDownList1.SelectedValue.ToString().Trim() + "' and RoomState='空闲'", conn); // 设置命令
int t = Convert.ToInt32(cmd.ExecuteScalar()); // 执行命令
if (t < 0)
{
MessageBox.Show("此房间有人预定或入住或不存在");
return;
}
else
{
string str = "insert into db_Scheduled (Name,Sex,Tel,RoomID,ScheduledDate,LeaveDate) values('" + TextBox1.Text.Trim() + "','" + DropDownList2.SelectedValue.ToString().Trim() + "','" + TextBox2.Text.Trim() + "','" + DropDownList1.SelectedValue.ToString().Trim() + "','" + TextBox4.Text.Trim() + "','" + TextBox5.Text.Trim() + "')";
BaseClass.OperateData(str); //插入某人的预定信息
string str1 = "update db_Room set RoomState='预定' where RoomID='" + DropDownList1.SelectedValue.ToString().Trim() + "'"; // 更新房间的状态
BaseClass.OperateData(str1);
Session["State"]="预定"; // 写入session记录
Response.Write("<script>alert('房间预定成功');location='Default.aspx'</script>");
}

// 第二段
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) // 验证回发状态(页面的第一次请求IsPostBack==false) 后在页面点按钮或啥的的提交操作为回发 即 IsPostBack==true
{
string strsql = "select * from db_Room order by RID desc";
BaseClass.BindDG(GridView1, "RID", strsql, "Room"); // 绑定房间信息绑定到GridView控件上。
}
}
// GridView控件分页操作
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
string strsql = "select * from db_Room order by RID desc";
BaseClass.BindDG(GridView1, "RID", strsql, "Room");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式