Beispiel #1
0
        public bool checkIn_HoaDon()
        {
            DV dV = dt.DVs.Where(s => s.MaDV == txtMaDVu.Text).FirstOrDefault();

            if (dV != null)
            {
                DanhSachDichVu danhSachDichVu = dt.DanhSachDichVus.Where(s => s.MaDanhSach == cmbMaDanhSach.Text).FirstOrDefault();
                if (danhSachDichVu != null)
                {
                    CT_PhieuThue cT_PhieuThue = dt.CT_PhieuThues.Where(s => s.SoPhieuThue == Convert.ToInt32(danhSachDichVu.SoPhieuThue)).
                                                FirstOrDefault();
                    if (cT_PhieuThue != null)
                    {
                        PhieuThuePhong phieuThuePhong = dt.PhieuThuePhongs.Where(s => s.MaPhieuThue == cT_PhieuThue.MaPhieuThue).FirstOrDefault();
                        if (phieuThuePhong != null)
                        {
                            string a = phieuThuePhong.MaPhieuThue.ToString();

                            HoaDon hoaDon = dt.HoaDons.Where(s => s.MaPhieuThue == phieuThuePhong.MaPhieuThue).FirstOrDefault();
                            if (hoaDon != null)
                            {
                                return(false);
                            }
                        }
                    }

                    //MessageBox.Show("Dịch Vụ Này đã được thanh toán trong hóa đơn! không xóa được");
                }
            }

            return(true);
        }
Beispiel #2
0
        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (txtMaNhanVien.Text != null)
            {
                PhieuThuePhong phieuThuePhong = dt.PhieuThuePhongs.Where(s => s.MaNhanVien == txtMaNhanVien.Text).FirstOrDefault();
                if (phieuThuePhong == null)
                {
                    DialogResult xoa = MessageBox.Show("bạn có muốn xóa không?", "", MessageBoxButtons.YesNo);
                    if (xoa == DialogResult.Yes)
                    {
                        var data = dt.xoanhanvienn(txtMaNhanVien.Text);
                    }
                }
                else
                {
                    MessageBox.Show("Không Thể Xóa !");
                }
            }
            else
            {
                MessageBox.Show("Bạn Chưa Chọn Nhân Viên Xóa");
            }

            dtgNhanVien.DataSource = new DataClasses1DataContext().NhanViens.ToList();
        }
        private void save_Click(object sender, EventArgs e)
        {
            if (i == 1)
            {
                if (txtMaKhachHang.Text == "" || cmbQuocTich.SelectedValue.ToString() == "" || txtTenKhachHang.Text == "" || txtCMND.Text == "" || cbGioiTinh.Text == "" || txtDiaChi.Text == "" || txtSdt.Text == "")
                {
                    MessageBox.Show("Bạn chưa nhập đầy đủ thông tin !", "Thông Báo", MessageBoxButtons.OK);
                }
                else
                {
                    KhachHang khachHang = dt.KhachHangs.Where(s => s.MaKhachHang == txtMaKhachHang.Text).FirstOrDefault();
                    if (khachHang != null)
                    {
                        MessageBox.Show("Khách Hàng đã tồn tại vui lòng nhập mã khách hàng khác !!");
                    }
                    else
                    {
                        DialogResult xoa = MessageBox.Show("bạn có muốn Thêm không?", "", MessageBoxButtons.YesNo);
                        if (xoa == DialogResult.Yes)
                        {
                            dt.themkhachhangs(txtMaKhachHang.Text, cmbQuocTich.SelectedValue.ToString(), txtTenKhachHang.Text, txtCMND.Text, cbGioiTinh.Text, txtDiaChi.Text, txtSdt.Text);

                            MessageBox.Show("Thêm Thành Công ?", "Thông Báo", MessageBoxButtons.OK);
                        }
                    }
                }
            }
            else if (i == 2)
            {
                if (txtMaKhachHang.Text == "" || cmbQuocTich.SelectedValue.ToString() == "" || txtTenKhachHang.Text == "" || txtCMND.Text == "" || cbGioiTinh.Text == "" || txtDiaChi.Text == "" || txtSdt.Text == "")
                {
                    MessageBox.Show("Bạn chưa nhập đầy đủ thông tin !", "Thông Báo", MessageBoxButtons.OK);
                }
                else
                {
                    PhieuThuePhong phieuThuePhong = dt.PhieuThuePhongs.Where(s => s.MaKhachHang == txtMaKhachHang.Text).FirstOrDefault();
                    if (phieuThuePhong != null)
                    {
                        MessageBox.Show(" Không cho sửa ?", "", MessageBoxButtons.OK);
                    }
                    DialogResult xoa = MessageBox.Show("bạn có muốn sửa không?", "", MessageBoxButtons.YesNo);
                    if (xoa == DialogResult.Yes)
                    {
                        var data = dt.suakhachhang(txtMaKhachHang.Text, cmbQuocTich.SelectedValue.ToString(), txtTenKhachHang.Text, txtCMND.Text, cbGioiTinh.Text, txtDiaChi.Text, txtSdt.Text);
                        MessageBox.Show("Sửa Thành Công ?", "Thông Báo", MessageBoxButtons.OK);
                    }
                }
            }
            KhachHangUser_Load(sender, e);
            btnLuu.Enabled = false;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            PhieuThuePhong ptp = db.PhieuThuePhongs.Find(txtPTP.Text);

            ptp.Xoa = 1;
            db.SaveChanges();
            MessageBox.Show("Đã xóa thành công phiếu thuê phòng này.");
            txtPTP.Text = "";
            DateTime date = DateTime.Now;

            txtNgayThue.Text = String.Format("{0:d/M/yyyy}", date);
            txtDMP.Text      = "";
            txtPhong.Text    = "";
            dgvKH.Rows.Clear();
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            PhieuThuePhong phieuThuePhong = dt.PhieuThuePhongs.Where(s => s.MaKhachHang == txtMaKhachHang.Text).FirstOrDefault();

            if (phieuThuePhong == null)
            {
                DialogResult xoa = MessageBox.Show("Bạn có muốn xóa không?", "", MessageBoxButtons.YesNo);
                if (xoa == DialogResult.Yes)
                {
                    var data = dt.xoakhachhang(txtMaKhachHang.Text);
                }
            }
            else
            {
                MessageBox.Show("Không xóa được !");
            }
            datagKhachhang.DataSource = new DataClasses1DataContext().KhachHangs.ToList();
        }
Beispiel #6
0
        public bool checkIn_HoaDon()
        {
            CT_PhieuThue cT_PhieuThue = dt.CT_PhieuThues.Where(s => s.SoPhieuThue == Convert.ToInt32(cmbSoPhieuNhan.SelectedValue.ToString())).
                                        FirstOrDefault();

            if (cT_PhieuThue != null)
            {
                PhieuThuePhong phieuThuePhong = dt.PhieuThuePhongs.Where(s => s.MaPhieuThue == cT_PhieuThue.MaPhieuThue).FirstOrDefault();
                if (phieuThuePhong != null)
                {
                    HoaDon hoaDon = dt.HoaDons.Where(s => s.MaPhieuThue == phieuThuePhong.MaPhieuThue).FirstOrDefault();
                    if (hoaDon != null)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #7
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            QLKS.Controller.Soluongkhach slk = new Controller.Soluongkhach();
            int dem = slk.SoLuongKhach();

            if (dataGridView1.Rows.Count > dem)
            {
                MessageBox.Show(String.Format("Một phòng chỉ được tối đa {0} người", dem.ToString()), dem.ToString());
            }
            else
            {
                try
                {
                    PhieuThuePhong PTP           = new PhieuThuePhong();
                    int            maPTP         = PTP.LapPhieuThuePhong(txtPhong.Text.ToString(), txtNgayBatDau.Text.ToString(), dataGridView1.Rows.Count - 1);
                    List <int>     dsmakhachhang = new List <int>();
                    int            makhachhang;

                    for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                    {
                        makhachhang = PTP.ThemKhachHang(dataGridView1.Rows[i].Cells[0].Value.ToString(),
                                                        dataGridView1.Rows[i].Cells[1].Value.ToString(),
                                                        dataGridView1.Rows[i].Cells[2].Value.ToString(),
                                                        dataGridView1.Rows[i].Cells[3].Value.ToString());
                        dsmakhachhang.Add(makhachhang);
                    }

                    foreach (int item in dsmakhachhang)
                    {
                        PTP.ThemChiTietPhieuThuePhong(item.ToString(), maPTP.ToString());
                    }
                    MessageBox.Show("Lặp Phiếu Thuê Phòng Thành Công");
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Lặp Phiếu Thuê Phòng Không Thành Công");
                    this.Close();
                }
            }
        }
        private void txtPTP_TextChanged(object sender, EventArgs e)
        {
            if (txtPTP.Text == "")
            {
                return;
            }
            dgvKH.Rows.Clear();
            PhieuThuePhong ptp = db.PhieuThuePhongs.Find(txtPTP.Text);
            Phong          ph  = db.Phongs.Find(ptp.MaPhong);
            DanhMucPhong   dmp = db.DanhMucPhongs.Find(ph.MaDanhMucPhong);

            txtDMP.Text      = dmp.TenDMP;
            txtPhong.Text    = ph.TenPhong;
            txtNgayThue.Text = string.Format("{0:d/M/yyyy}", ptp.NgayBatDauThue);
            var result = from c in db.CT_PhieuThuePhong
                         from d in db.KhachHangs
                         from a in db.LoaiKhachHangs
                         where (c.MaPhieuThuePhong == ptp.MaPhieuThuePhong &&
                                c.MaKhachHang == d.MaKhachHang &&
                                d.MaLoaiKhachHang == a.MaLoaiKhachHang)
                         select new
            {
                d.TenKhachHang,
                a.TenLoaiKhachHang,
                d.CMND,
                d.DiaChi
            };

            foreach (var i in result)
            {
                string[] row1 = new string[]
                {
                    i.TenKhachHang,
                    i.TenLoaiKhachHang,
                    i.CMND,
                    i.DiaChi
                };
                dgvKH.Rows.Add(row1);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            DateTime       ngbd      = Convert.ToDateTime(txtNgayThue.Text);
            var            count_ptp = from c in db.PhieuThuePhongs select c;
            PhieuThuePhong ptp       = new PhieuThuePhong()
            {
                MaPhieuThuePhong = "PTP" + (count_ptp.Count() + 1),
                MaPhong          = cbbP.SelectedValue.ToString(),
                NgayBatDauThue   = ngbd.Date,
                Xoa = 0
            };

            db.PhieuThuePhongs.Add(ptp);
            Phong pg = db.Phongs.Find(cbbP.SelectedValue.ToString());

            pg.TinhTrang = "Đang thuê";
            string maptp = "PTP" + (count_ptp.Count() + 1);

            for (int i = 0; i < dgvKH.Rows.Count; i++)
            {
                string cmnd     = dgvKH[2, i].Value.ToString();
                string loaikh   = dgvKH[1, i].Value.ToString();
                var    count_kh = from c in db.KhachHangs select c;

                var check_cmnd = from c in db.KhachHangs where c.CMND == cmnd select c;
                if (check_cmnd.Count() == 0)
                {
                    var       malkh = from c in db.LoaiKhachHangs where c.TenLoaiKhachHang == loaikh select c;
                    KhachHang kh    = new KhachHang();
                    kh.MaKhachHang  = "KH" + (count_kh.Count() + 1);
                    kh.TenKhachHang = dgvKH[0, i].Value.ToString();
                    kh.CMND         = cmnd;
                    kh.DiaChi       = dgvKH[3, i].Value.ToString();
                    foreach (var b in malkh)
                    {
                        kh.MaLoaiKhachHang = b.MaLoaiKhachHang;
                    }
                    db.KhachHangs.Add(kh);
                    var count_ct         = from c in db.CT_PhieuThuePhong select c;
                    CT_PhieuThuePhong ct = new CT_PhieuThuePhong()
                    {
                        MaCTPhieuThuePhong = "CTPTP" + (count_ct.Count() + 1),
                        MaPhieuThuePhong   = maptp,
                        MaKhachHang        = "KH" + (count_kh.Count() + 1)
                    };
                    db.CT_PhieuThuePhong.Add(ct);
                }
                else
                {
                    var kh = from c in db.KhachHangs where c.CMND == cmnd select c;
                    foreach (var a in kh)
                    {
                        var count_ct         = from c in db.CT_PhieuThuePhong select c;
                        CT_PhieuThuePhong ct = new CT_PhieuThuePhong()
                        {
                            MaCTPhieuThuePhong = "CTPTP" + (count_ct.Count() + 1),
                            MaPhieuThuePhong   = maptp,
                            MaKhachHang        = a.MaKhachHang
                        };

                        db.CT_PhieuThuePhong.Add(ct);
                    }
                }
                db.SaveChanges();
            }
            MessageBox.Show("Tạo phiếu thuê phòng thành công");
        }
        private void cmbMaPhieuThue_SelectedIndexChanged(object sender, EventArgs e)
        {
            string         mapt = cmbMaPhieuThue.Text.ToString();
            PhieuThuePhong ptp  = dt.PhieuThuePhongs.FirstOrDefault(p => p.MaPhieuThue == mapt);

            if (ptp != null)
            {
                cmbMaKH.SelectedValue = ptp.MaKhachHang;
                CT_PhieuThue cT_PhieuThue1 = dt.CT_PhieuThues.FirstOrDefault(p => p.MaPhieuThue == mapt);
                if (cT_PhieuThue1 != null)
                {
                    DanhSachDichVu danhSachDichVu = dt.DanhSachDichVus.Where(s => s.SoPhieuThue == cT_PhieuThue1.SoPhieuThue).FirstOrDefault();
                    if (danhSachDichVu != null)
                    {
                        string ds = danhSachDichVu.MaDanhSach;
                        txtDichVu.Text = danhSachDichVu.MaDanhSach.ToString();
                        DV dichVu = dt.DVs.Where(s => s.MaDanhSach == danhSachDichVu.MaDanhSach).FirstOrDefault();
                        if (dichVu != null)
                        {
                            LoaiDV loaiDV = dt.LoaiDVs.Where(s => s.MaLoaiDV == dichVu.MaLoaiDV).FirstOrDefault();
                            if (loaiDV != null)
                            {
                                TienDVResult tienDVResult = dt.TienDV(ds).FirstOrDefault();
                                txtTienDV.Text = tienDVResult.Column1.ToString();

                                // MessageBox.Show(tienDVResult.Column1.ToString());
                            }
                        }
                    }

                    else
                    {
                        txtTienDV.Text = "0";
                        txtDichVu.Text = "";
                    }
                }
            }

            CT_PhieuThue cT_PhieuThue = dt.CT_PhieuThues.FirstOrDefault(p => p.MaPhieuThue == mapt);



            if (cT_PhieuThue != null)
            {
                txtTienPhong.Text       = cT_PhieuThue.DonGia.ToString();
                dateNgayThuePhong.Value = Convert.ToDateTime(cT_PhieuThue.NgayNhanPhong.Value.ToString());

                ////   MessageBox.Show(date.ToString());
                //MessageBox.Show(date.ToString());

                DateTime date1 = new DateTime(dateNgayThuePhong.Value.Year, dateNgayThuePhong.Value.Month,
                                              dateNgayThuePhong.Value.Day, dateNgayThuePhong.Value.Hour, dateNgayThuePhong.Value.Minute, dateNgayThuePhong.Value.Second);

                DateTime date2 = new DateTime(dtNgayTraPhong.Value.Year, dtNgayTraPhong.Value.Month,
                                              dtNgayTraPhong.Value.Day, dtNgayTraPhong.Value.Hour, dtNgayTraPhong.Value.Minute, dtNgayTraPhong.Value.Second);

                TimeSpan diff1 = date2.Subtract(date1);



                if (diff1.Days < 1)
                {
                    txtSoNgay.Text = "1";
                }
                else if (diff1.Hours >= 1 && diff1.Days >= 1)
                {
                    txtSoNgay.Text = Convert.ToString(diff1.Days + 1);
                }

                else if (diff1.Hours < 1 && diff1.Days >= 1)
                {
                    txtSoNgay.Text = diff1.Days.ToString();
                }
                if (txtSoNgay.Text != null && txtTienPhong.Text != null)
                {
                    tt = Convert.ToInt32(txtSoNgay.Text) * Convert.ToDouble(txtTienPhong.Text);

                    txtTongTien.Text = tt.ToString();
                    if (txtTienDV.Text != "")
                    {
                        txtTongTien.Text = (Convert.ToInt32(txtTongTien.Text) + Convert.ToInt32(txtTienDV.Text)).ToString();
                    }
                }

                //
            }

            // MessageBox.Show(date.ToString());
        }