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 Common;
using WebMessageBox;
using hqgl.user;
public partial class general_dormitory_hum_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        userchuli uch = new userchuli();
        uch.user_yanzheng();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string mm = "select * from std_inf where 身份证号='#身份证号#'";
        mm = mm.Replace("#身份证号#", TextBox4.Text);
        DbHelper db = new DbHelper();
        object res=db.ExecuteScalar(mm);
        if (res != null)
            MessageBox.Show("此人已入住", "hum_add.aspx");
        string sql = "select 可住人数-入住人数 from room_view where 房间号='#房间号#'";
        sql = sql.Replace("#房间号#", TextBox7.Text);
        
        object count=db.ExecuteScalar(sql);
        if (count==null||Convert.ToInt32(count)<=0)
               MessageBox.Show("房间已满", "hum_add.aspx");
        else
         {
             sql = "insert into std_inf values('#身份证号#' ,'#姓名#', '#性别#','#班号#', '#手机号#', #入住时间# ,'#房间号#')";
            sql = sql.Replace("#姓名#", TextBox1.Text);
            sql = sql.Replace("#性别#", DropDownList1.SelectedValue);
            sql = sql.Replace("#班号#", TextBox3.Text);
            sql = sql.Replace("#身份证号#", TextBox4.Text);
            sql = sql.Replace("#手机号#", TextBox5.Text);
            sql = sql.Replace("#房间号#", TextBox7.Text);
            sql = sql.Replace("#入住时间#", Request["birthday"]);
            db.ExecuteSqlNonQuery(sql);
            MessageBox.Show("添加成功", "hum_add.aspx");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
         string mm = "select * from std_inf where 身份证号='#身份证号#'";
        mm = mm.Replace("#身份证号#", TextBox8.Text);
        DbHelper db = new DbHelper();
        object res=db.ExecuteScalar(mm);
        if (res != null)
        {
            mm = "delete from std_inf where 身份证号='#身份证号#'";
            mm = mm.Replace("#身份证号#", TextBox8.Text);
            db.ExecuteSqlNonQuery(mm);
            MessageBox.Show("迁出成功", "hum_add.aspx");
        }
        else
            MessageBox.Show("查无此人", "hum_add.aspx");
    }
}
