示例#1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            String sql;

            if (newguess)
            {
                sql = String.Format("Insert into KhachHang (Ten,NgaySinh,GioiTinh,DiaChi,SDT) values('{0}','{1}','{2}','{3}','{4}')", txtTen.Text, txtNgaySinh.Text, DropDownList1.SelectedItem.Text, txtDiaChi.Text, txtSDT.Text);
                DungChung.ThemSuaXoaQuery(sql);
                sql = String.Format("select ID from KhachHang where SDT = '{0}'", txtSDT.Text);
                id  = lastid(sql);
            }
            sql = String.Format("INSERT into DatPhong (IDKhachHang,IDPhong,NgayDen,NgayDI) values({0},{1},'{2}','{3}')", id, Request.QueryString["id"], Request.QueryString["NgayNhan"], Request.QueryString["NgayTra"]);
            DungChung.ThemSuaXoaQuery(sql);
            String lastidDatPhong = lastid("Select TOP 1 ID FROM DatPhong ORDER BY id DESC");

            sql = String.Format("INSERT into HoaDon (IDDatPhong,TongSoTien) values({0},{1})", lastidDatPhong, lbChiPhi.Text);
            DungChung.ThemSuaXoaQuery(sql);
            Response.Write("<script>alert('Đặt phòng thành công')</script>");
            thongbao.Visible = true;
            thongtin.Visible = false;
            sql = String.Format(@"SELECT LoaiPhong.SoGiuong
                            FROM LoaiPhong INNER JOIN Phong ON LoaiPhong.ID = Phong.IDLoaiPhong
                            WHERE(((Phong.SoPhong) = {0}));", lbSoPhong.Text);
            DataTable tbl = DungChung.XemQuery(sql);

            Labeltenkhachhang.Text = txtTen.Text;
            labelSDT.Text          = txtSDT.Text;
            labelngaynhan.Text     = Request.QueryString["NgayNhan"].ToString();
            labelngaytra.Text      = Request.QueryString["NgayTra"].ToString();
            labelsonguoi.Text      = tbl.Rows[0]["SoGiuong"].ToString();
            labelthanhtien.Text    = lbChiPhi.Text;
        }
        public void fillgrid()
        {
            String    sql = String.Format(@"SELECT Phong.ID, Phong.SoPhong, LoaiPhong.TenLoaiPhong, LoaiPhong.SoGiuong, LoaiPhong.DonGia
                                         FROM LoaiPhong INNER JOIN Phong ON LoaiPhong.ID = Phong.IDLoaiPhong
                                         WHERE (((Phong.ID) Not In (Select DatPhong.IDPhong From DatPhong Where (DatPhong.NgayDen <= #{0}# AND DatPhong.NgayDi >= #{0}#)
                                         OR (DatPhong.NgayDen <= #{1}# AND DatPhong.NgayDi >= #{1}#) )) 
                                         AND ((LoaiPhong.SoGiuong)={2}));", Request.QueryString["NgayNhan"].ToString(), Request.QueryString["NgayTra"].ToString(), Request.QueryString["SoNguoi"].ToString());
            DataTable tbl = DungChung.XemQuery(sql);

            dgvPhong.DataSource = tbl;
            dgvPhong.DataBind();
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(Request.QueryString["NgayNhan"]) || String.IsNullOrEmpty(Request.QueryString["NgayTra"]) || String.IsNullOrEmpty(Request.QueryString["SDT"]) || String.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    baoloi();
                }
                else
                {
                    String Sql = String.Format(@"SELECT Phong.ID
                                                 FROM Phong
                                                 Where Phong.ID = {2} AND Phong.ID NOT IN (Select IDPhong from DatPhong Where (NgayDen <= #{0}#  AND NgayDi >=  #{0}#) AND (NgayDen <= #{1}#  AND NgayDi >=  #{1}#))", Request.QueryString["NgayNhan"].ToString(), Request.QueryString["NgayTra"].ToString(), Request.QueryString["id"].ToString());
                    if (DungChung.XemQuery(Sql).Rows.Count == 0)
                    {
                        baoloi();
                    }
                    else
                    {
                        DateTime NgayNhan  = DateTime.ParseExact(Request.QueryString["NgayNhan"].ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        DateTime NgayTra   = DateTime.ParseExact(Request.QueryString["NgayTra"].ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        int      totaldate = totalday(NgayNhan, NgayTra);
                        Sql = String.Format(@"SELECT Phong.SoPhong, LoaiPhong.DonGia * {0} as Gia, LoaiPhong.ID
                                                FROM LoaiPhong INNER JOIN Phong ON LoaiPhong.ID = Phong.IDLoaiPhong
                                                WHERE(((Phong.ID) = {1}));", totaldate.ToString(), Request.QueryString["id"]);
                        DataTable tb1 = DungChung.XemQuery(Sql);
                        lbChiPhi.Text  = tb1.Rows[0]["Gia"].ToString();
                        lbSoNgay.Text  = totaldate.ToString();
                        lbSoPhong.Text = tb1.Rows[0]["SoPhong"].ToString();


                        Sql = String.Format("Select * From KhachHang where SDT = '{0}'", Request.QueryString["SDT"].ToString());
                        DataTable tb = DungChung.XemQuery(Sql);


                        if (tb.Rows.Count != 0)
                        {
                            id               = tb.Rows[0]["ID"].ToString();
                            txtTen.Text      = tb.Rows[0]["Ten"].ToString();
                            txtNgaySinh.Text = tb.Rows[0]["NgaySinh"].ToString();
                            txtDiaChi.Text   = tb.Rows[0]["DiaChi"].ToString();
                            DropDownList1.SelectedItem.Text = tb.Rows[0]["GioiTinh"].ToString();
                            txtSDT.Text            = tb.Rows[0]["SDT"].ToString();
                            txtTen.ReadOnly        = true;
                            txtNgaySinh.ReadOnly   = true;
                            txtDiaChi.ReadOnly     = true;
                            DropDownList1.Enabled  = false;
                            DropDownList1.CssClass = "form-control";
                            txtSDT.ReadOnly        = true;
                            newguess = false;
                        }
                        else
                        {
                            txtSDT.Text = Request.QueryString["SDT"].ToString();
                        }
                    }
                }
            }
            catch (Exception)
            {
                baoloi();
            }
        }
示例#4
0
        public static String lastid(String sql)
        {
            DataTable tb1 = DungChung.XemQuery(sql);

            return(tb1.Rows[0]["id"].ToString());
        }