コード例 #1
0
        //public void functionGetThongTinDangNhap(NHANVIEN nhanVien)
        //{
        //    this.nhanVien = nhanVien;
        //}

        public void LoadPhong()
        {
            flowBody.Controls.Clear();
            PhongBUS phongBUS = new PhongBUS();

            PhongDTO[] phongs = phongBUS.LayDanhSachPhong();

            PhieuThuePhongBUS phieuThuePhongBUS = new PhieuThuePhongBUS();

            PhieuThuePhongDTO[] phieuThuePhongs = phieuThuePhongBUS.LayDanhSachPhieuThuePhongTrangThai1Va2();

            KhachHangBUS khachHangBUS = new KhachHangBUS();

            int i;
            int j, coTrongPhieuThuePhong = 0;
            int numberPhong           = phongBUS.LaySoLuongPhongLonNhatTrongCacTang();
            int with_sizeCustomePhong = flowBody.Size.Width / numberPhong - numberPhong - 1;

            for (i = 0; i < phongs.Length; i++)
            {
                // khai báo control customePhong
                CustomePhong customePhong = new CustomePhong(phongs[i]);
                customePhong.Size = new Size(with_sizeCustomePhong, customePhong.Size.Height);

                coTrongPhieuThuePhong = 0;

                for (j = 0; j < phieuThuePhongs.Length; j++)
                {
                    if (phongs[i].Ma == phieuThuePhongs[j].MaPhong)
                    {
                        coTrongPhieuThuePhong = 1;

                        if (phieuThuePhongs[j].TrangThai == 1)
                        // khách hàng chưa nhận phòng
                        {
                            PhieuThuePhongDTO phieuThuePhongKiemTra = phieuThuePhongBUS.CoPhaiPhongCoNguoiDangO(phongs[i].Ma);
                            if (phieuThuePhongKiemTra != null)
                            {
                                string       strtime      = String.Format("{0:MM/dd/yyyy HH:mm}", phieuThuePhongKiemTra.ThoiGianTraPhong);
                                KhachHangDTO khachHang    = khachHangBUS.LayKhachHangCoMaSo(phieuThuePhongKiemTra.MaKhachHang);
                                string       tenKhachHang = "";

                                if (khachHang != null)
                                {
                                    tenKhachHang = khachHang.Ten;
                                }

                                customePhong.ThayDoiTrangThaiDangO(strtime, tenKhachHang);

                                // kiểm tra khách hàng có quá hạn hay không
                                int time = (int)(DateTime.Now - phieuThuePhongKiemTra.ThoiGianTraPhong).TotalMinutes;
                                if (time > 0)
                                {
                                    if (time < 60) // nhỏ hơn 60 phút
                                    {
                                        strtime = time + " phút ";
                                    }
                                    else if (time < 60 * 24) // nhỏ hơn 24h
                                    {
                                        strtime = time / 60 + " giờ ";
                                    }
                                    else // lớn hơn 24h
                                    {
                                        strtime = time / (60 * 24) + " ngày ";
                                    }
                                    strtime += String.Format("{0:MM/dd/yyyy HH:mm}", phieuThuePhongKiemTra.ThoiGianTraPhong);
                                    customePhong.ThayDoiTrangThaiQuaHan(strtime, tenKhachHang);
                                }
                            }
                            else
                            {
                                string       time         = String.Format("{0:MM/dd/yyyy HH:mm}", phieuThuePhongs[j].ThoiGianNhanPhong);
                                KhachHangDTO khachHang    = khachHangBUS.LayKhachHangCoMaSo(phieuThuePhongs[j].MaKhachHang);
                                string       tenKhachHang = "";

                                if (khachHang != null)
                                {
                                    tenKhachHang = khachHang.Ten;
                                }
                                customePhong.ThayDoiTrangThaiDaDat(time, tenKhachHang);
                            }
                        }
                        else if (phieuThuePhongs[j].TrangThai == 2)
                        // khách hàng đã nhận phòng
                        {
                            string       strtime      = String.Format("{0:MM/dd/yyyy HH:mm}", phieuThuePhongs[j].ThoiGianTraPhong);
                            KhachHangDTO khachHang    = khachHangBUS.LayKhachHangCoMaSo(phieuThuePhongs[j].MaKhachHang);
                            string       tenKhachHang = "";

                            if (khachHang != null)
                            {
                                tenKhachHang = khachHang.Ten;
                            }

                            customePhong.ThayDoiTrangThaiDangO(strtime, tenKhachHang);

                            // kiểm tra khách hàng có quá hạn hay không
                            int time = (int)(DateTime.Now - phieuThuePhongs[j].ThoiGianTraPhong).TotalMinutes;
                            if (time > 0)
                            {
                                if (time < 60) // nhỏ hơn 60 phút
                                {
                                    strtime = time + " phút ";
                                }
                                else if (time < 60 * 24) // nhỏ hơn 24h
                                {
                                    strtime = time / 60 + " giờ ";
                                }
                                else // lớn hơn 24h
                                {
                                    strtime = time / (60 * 24) + " ngày ";
                                }
                                strtime += String.Format("{0:MM/dd/yyyy HH:mm}", phieuThuePhongs[j].ThoiGianTraPhong);
                                customePhong.ThayDoiTrangThaiQuaHan(strtime, tenKhachHang);
                            }
                        }

                        break;
                    }
                }

                if (coTrongPhieuThuePhong == 0)
                {
                    customePhong.ThayDoiTrangThaiTrong();
                }

                customePhong.EventDatPhong       += CustomePhong_EventDatPhong;
                customePhong.EventNhanPhong      += CustomePhong_EventNhanPhong;
                customePhong.EventThanhToanPhong += CustomePhong_EventThanhToanPhong;

                flowBody.Controls.Add(customePhong);
            }
        }