コード例 #1
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            try
            {
                string   where1   = "IDPhong = N'" + soPhongCu + "'";
                DateTime checkIn  = Convert.ToDateTime(SQLConnection.SelectOne("NgayDen", "PhieuDatPhong", where1));
                DateTime checkOut = Convert.ToDateTime(SQLConnection.SelectOne("NgayDi", "PhieuDatPhong", where1));
                int      diffDays = SoNgayO(checkIn, checkOut);

                string where2       = "IDPhong = N'" + cbPhongMoi.SelectedValue.ToString() + "'";
                int    tongPhongMoi = diffDays * Convert.ToInt32(SQLConnection.SelectOne("GiaPhong", "Phong", where2));


                string _IDPhieuDatPhong = SQLConnection.SelectOne("IDPhieuDatPhong", "PhieuDatPhong", where1);
                string where3           = "IDPhieuDatPhong = " + _IDPhieuDatPhong;
                int    phatDoiPhong     = int.Parse(SQLConnection.SelectOne("PhiDoiPhong", "PhieuDatPhong", where1)) + int.Parse(SQLConnection.SelectTS("TS_DoiPhongPhat"));
                int    soLanDoiPhong    = int.Parse(SQLConnection.SelectOne("SoLanDoiPhong", "PhieuDatPhong", where1)) + 1;

                string val = "PhiDoiPhong = " + phatDoiPhong + ", SoLanDoiPhong = " + soLanDoiPhong +
                             ", IDPhong = N'" + cbPhongMoi.SelectedValue.ToString() + "'" +
                             ", TongCong = " + tongPhongMoi;
                SQLConnection.Update("PhieuDatPhong", val, where3);

                string valTrong   = "TinhTrang = 0";
                string valCoNguoi = "TinhTrang = 1";
                SQLConnection.Update("Phong", valTrong, where1);
                SQLConnection.Update("Phong", valCoNguoi, where2);
                MessageBox.Show("Thành Công!", "Đổi phòng", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void btnDatPhong_Click(object sender, EventArgs e)
        {
            try
            {
                string _IDKhachHang = cbCMND.SelectedIndex == 0 ? tbCMND.Text : cbCMND.SelectedValue.ToString();
                bool   selectedCB   = cbCMND.SelectedIndex == 0 ? true : SQLConnection.isExist("KhachHang", "CMND", cbCMND.Text);
                if (selectedCB && tbCMND.Text.All(char.IsDigit) && tbSDT.Text.All(char.IsDigit) && tbDatCoc.Text.All(char.IsDigit) && tbSLNguoi.Text.All(char.IsDigit))
                {
                    if ((tbCMND.Text.Equals(string.Empty) || tbName.Text.Equals(string.Empty)) && cbCMND.SelectedIndex == 0)
                    {
                        MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: Thiếu thông tin", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        string _IDPhong         = cbSoPhong.Text;
                        string _IDMaGiamGia     = cbCoupon.SelectedIndex == 0 ? "NULL" : cbCoupon.Text;
                        string _IDPhieuDatPhong = SQLConnection.IncrID("PhieuDatPhong", "IDPhieuDatPhong").ToString();
                        //Insert Khách Hàng
                        if (cbCMND.SelectedIndex == 0)
                        {
                            string loaiKH    = cbType.SelectedIndex == 0 ? "0" : "1";
                            string insCol_KH = "IDKhachHang, TenKhachHang, CMND, SDT, Mail, LoaiKhachHang, IDPhieuDatPhong";
                            string insVal_KH = "'" + _IDKhachHang + "', N'" + tbName.Text + "', '" + tbCMND.Text + "', '" + tbSDT.Text + "', N'" +
                                               tbEmail.Text + "', " + loaiKH + ", " + _IDPhieuDatPhong;
                            SQLConnection.Insert("KhachHang", insCol_KH, insVal_KH);
                        }
                        //Insert Phiếu đặt phòng
                        string insCol_PDP = "IDPhong, IDKhachHang, SLNguoi, NgayDen, SoTienCoc, IDMaGiamGia, NgayDi, TongCong, IDPhieuDatPhong, PhiDoiPhong, Phi_DichVu, Phi_MonAn, SoLanDoiPhong, DaThanhToan";
                        string insVal_PDP = "'" + _IDPhong + "', " + "'" + _IDKhachHang + "', " +
                                            "" + tbSLNguoi.Text + ", '" + DateTime.Now.ToString() + "', " + tbDatCoc.Text + ", " +
                                            "'" + _IDMaGiamGia + "', '" + dtpNgayDi.Value.ToString() + "', " + lblTongTien.Text + ", " + _IDPhieuDatPhong + ", 0, 0, 0, 0, 0";
                        SQLConnection.Insert("PhieuDatPhong", insCol_PDP, insVal_PDP);

                        if (cbCMND.SelectedIndex != 0)
                        {
                            SQLConnection.Update("KhachHang", "IDPhieuDatPhong = " + _IDPhieuDatPhong, "IDKhachHang = " + _IDKhachHang);
                        }

                        string updateVal   = "TinhTrang = 1";
                        string updateWhere = "IDPhong LIKE '" + _IDPhong + "'";
                        SQLConnection.Update("Phong", updateVal, updateWhere);

                        MessageBox.Show("Thành Công!", "Đặt phòng", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: Sai định dạng", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: " + ex.Message, "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            SQLConnection.Update("PhieuDatPhong", "DaThanhToan = 1", "IDPhieuDatPhong = " + _IDPhieuDatPhong);
            SQLConnection.Update("Phong", "TinhTrang = 0", "IDPHONG LIKE '" + soPhongDat + "'");
            SQLConnection.Update("KhachHang", "IDPhieuDatPhong = NULL", "IDKhachHang LIKE '" + _IDKhachHang + "'");
            try
            {
                SQLConnection.Delete("Add_DichVu", "IDPhieuDatPhong = " + _IDPhieuDatPhong);
                SQLConnection.Delete("Add_MonAn", "IDPhieuDatPhong = " + _IDPhieuDatPhong);
            }
            catch { }
            InsertDTNgay();
            CreateDTThang();
            DialogResult result = MessageBox.Show("Thanh toán thành công!", "Thanh Toán", MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (result == DialogResult.OK)
            {
                this.Close();
            }
        }