private void btnCheckOut_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                AccountancyBO aAccountancyBO = new AccountancyBO();
                int IDBookingRoom = int.Parse(grvBookingRoom.GetFocusedRowCellValue("ID").ToString());
                DateTime CheckOutActual = DateTime.Parse(grvBookingRoom.GetFocusedRowCellValue("CheckOutActual").ToString());

                aAccountancyBO.CheckOut(IDBookingRoom, CheckOutActual);
                MessageBox.Show(" Đã check out xong ", "Thông báo", MessageBoxButtons.OK,MessageBoxIcon.Information);

                List<BookingRooms> aListTemp = new List<BookingRooms>();
                aListTemp = aBookingRoomsBO.Select_ByStatus_ByTime(DateTime.Now, Status);
                dgvBookingRooms.DataSource = this.GetListBookingRooms(aListTemp, this.aListRooms);
                dgvBookingRooms.RefreshDataSource();

                if (aListTemp.Count <= 0)
                {
                    if (this.afrmTsk_Check_StatusPay_Old != null)
                    {
                        this.afrmTsk_Check_StatusPay_Old.LoadListBookingR();
                        if (this.afrmTsk_Check_StatusPay_Old.afrmMain != null)
                        {
                            this.afrmTsk_Check_StatusPay_Old.afrmMain.ReloadData();
                            this.Close();
                        }
                    }

                    if(this.afrmMain !=null)
                    {
                        this.afrmMain.ReloadData();
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckOut - CheckOut Click \n " + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            try
            {
                if (dtpFrom.DateTime < dtpTo.DateTime)
                {
                    if (this.Status == 2)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        //cap nhat bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);

                        //aBookingRooms.CheckInPlan = DateTime.Now;
                        //aBookingRooms.CheckInActual = DateTime.Now;

                        aBookingRooms.CheckInPlan = dtpFrom.DateTime;
                        aBookingRooms.CheckInActual = dtpFrom.DateTime;

                        aBookingRooms.CheckOutPlan = dtpTo.DateTime;
                        aBookingRooms.CheckOutActual = dtpTo.DateTime;
                        //aBookingRooms.PriceType = "G1";
                        aBookingRooms.Status = 3;// 3= Da check in

                        aBookingRoomsBO.Update(aBookingRooms);

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(this.Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.Close();

                    }
                    else if (this.Status == 5)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        RoomsBO aRoomsBO = new RoomsBO();
                        AccountancyBO aAccountancyBO = new AccountancyBO();
                        //Check out giai doan pending
                        aAccountancyBO.CheckOut(this.IDBookingRoom, dtpFrom.DateTime);

                        //them moi mot bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);
                        BookingRooms aBookingRoomsAddNew = new BookingRooms();
                        aBookingRoomsAddNew.IDBookingR = IDBookingR;
                        aBookingRoomsAddNew.CodeRoom = CodeRoom;

                        aBookingRoomsAddNew.PercentTax = aBookingRooms.PercentTax;
                        aBookingRoomsAddNew.CostRef_Rooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).CostRef;
                        aBookingRoomsAddNew.Note = aBookingRooms.Note;

                        aBookingRoomsAddNew.CheckInPlan = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckInActual = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckOutPlan = dtpTo.DateTime;
                        aBookingRoomsAddNew.CheckOutActual = dtpTo.DateTime;
                        aBookingRoomsAddNew.PriceType = aBookingRooms.PriceType;
                        aBookingRoomsAddNew.Type = 1;

                        aBookingRoomsAddNew.BookingStatus = aBookingRooms.BookingStatus;

                        aBookingRoomsAddNew.Status = 3;// 3 = Da CheckIn

                        aBookingRoomsAddNew.StartTime = aBookingRooms.StartTime;
                        aBookingRoomsAddNew.EndTime = aBookingRooms.EndTime;
                        aBookingRoomsAddNew.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
                        aBookingRoomsAddNew.Color = aBookingRooms.Color;
                        aBookingRoomsAddNew.IsRecurring = aBookingRooms.IsRecurring;
                        aBookingRoomsAddNew.IsEditable = aBookingRooms.IsEditable;
                        aBookingRoomsAddNew.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
                        int ID = aBookingRoomsBO.Insert(aBookingRoomsAddNew);

                        if (ID > 0)
                        {
                            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom(this.IDBookingRoom);
                            BookingRoomsMembers aBookingRoomsMembers;
                            foreach (BookingRoomsMembers item1 in aListBookingRoomsMembers)
                            {
                                aBookingRoomsMembers = new BookingRoomsMembers();
                                aBookingRoomsMembers.IDBookingRoom = ID;
                                aBookingRoomsMembers.IDCustomer = item1.IDCustomer;
                                aBookingRoomsMembers.PurposeComeVietnam = item1.PurposeComeVietnam;
                                aBookingRoomsMembers.DateEnterCountry = item1.DateEnterCountry;
                                aBookingRoomsMembers.EnterGate = item1.EnterGate;
                                aBookingRoomsMembers.TemporaryResidenceDate = item1.TemporaryResidenceDate;
                                aBookingRoomsMembers.LimitDateEnterCountry = item1.LimitDateEnterCountry;
                                aBookingRoomsMembers.Organization = item1.Organization;
                                aBookingRoomsMembers.LeaveDate = item1.LeaveDate;

                                aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);

                            }
                        }

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                    }
                }
                else
                {
                    MessageBox.Show("Ngày giờ không hợp lệ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.btnCheckIn_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void InitData()
        {
            ItemChangeRoomEN aItemChangeRoomEN = new ItemChangeRoomEN();
            aItemChangeRoomEN.SetBookingRooms(this.aBookingRoom);

            if (aItemChangeRoomEN.GetStatusBookingRooms() < 3)
            {
                // Phong trang thai dat
            }
            else if (aItemChangeRoomEN.GetStatusBookingRooms() == 3) // Phong dang co nguoi o
            {
                // Thay doi thoi gian de check in
                //aItemChangeRoomEN.SetCheckInActual(dtpCheckIn.DateTime);
            }
            aItemChangeRoomEN.IsRootRoom = true;

            List<CustomerInfoEN> aListCustomer = (List<CustomerInfoEN>)this.dgvSelectCustomers.DataSource;
            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            BookingRoomsMembers aBookingRoomsMembers = new BookingRoomsMembers();
            for (int i = 0; i < aListCustomer.Count; i++)
            {
                aBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom_ByIDCustomer(this.aBookingRoom.ID, aListCustomer[i].ID);
                aListCustomer[i].LeaveDate = aBookingRoomsMembers.LeaveDate;
                aListCustomer[i].LimitDateEnterCountry = aBookingRoomsMembers.LimitDateEnterCountry;

                aListCustomer[i].PurposeComeVietnam = aBookingRoomsMembers.PurposeComeVietnam;
                aListCustomer[i].TemporaryResidenceDate = aBookingRoomsMembers.TemporaryResidenceDate;
                aListCustomer[i].DateEnterCountry = aBookingRoomsMembers.DateEnterCountry;
                aListCustomer[i].EnterGate = aBookingRoomsMembers.EnterGate;

            }
            aItemChangeRoomEN.AddCustomer(aListCustomer);

            AccountancyBO aAccountancyBO = new AccountancyBO();

            //aItemChangeRoomEN.SetCost(aAccountancyBO.CalculateCostRoom(lueRooms.EditValue.ToString(), this.aBookingRoom.PriceType, aBookingRs.CustomerType.GetValueOrDefault(0), aItemChangeRoomEN.GetAllCustomers().Count).GetValueOrDefault(0));

            this.aCurrentRoomInfo.SetAddTimeStart(null);
            this.aCurrentRoomInfo.SetAddTimeEnd(null);
            this.aCurrentRoomInfo.SetTimeInUsed(null);

            this.aCurrentRoomInfo.SetCheckInActual(dtpCheckIn.DateTime);
            this.aCurrentRoomInfo.SetCheckInPlan(dtpCheckIn.DateTime);
            this.aCurrentRoomInfo.SetCheckOutActual(dtpCheckOut.DateTime);
            this.aCurrentRoomInfo.SetCheckOutPlan(dtpCheckOut.DateTime);

            this.aChangeRoomEn.InsertItemChangeRooms(aItemChangeRoomEN);
            this.aCurrentRoomInfo = aItemChangeRoomEN;
        }
        private void lueRooms_EditValueChanged(object sender, EventArgs e)
        {
            if (this.IsReadyInitData == true)
            {
                // Luu lai thong tin cua chuyen phong cu truoc khi select phong moi
                this.aChangeRoomEn.UpdateItemChangeRooms(this.aCurrentRoomInfo);

                // Chuyen sang select phong moi bang thong tin trong aChangeRoomsEN
                this.aCurrentRoomInfo = this.aChangeRoomEn.GetItemChangeRooms(lueRooms.EditValue.ToString());

                // Get list customer for current room
                dgvSelectCustomers.DataSource = this.GetDataForSelectCustomerGridview(lueRooms.EditValue.ToString());

                if (this.aCurrentRoomInfo == null)
                {
                    //add them mot ItemChangeRooms moi
                    ItemChangeRoomEN aItemChangeRoomEN = new ItemChangeRoomEN();
                    //Kiem tra va danh dau xem phong vua chon co nam trong BookingR ban dau k?
                    //Viec nay lien quan den truong hop chuyen nguoi tu phong A -> B, (A,B cung thuoc BookingR)
                   List<BookingRooms> aList  = (new BookingRoomsBO()).Select_ByIDBookingRs(this.aBookingRs.ID).Where(p => p.CodeRoom == lueRooms.EditValue.ToString()).ToList();
                   int IsSelectRoomInBookingR = aList.Count;
                   int IDBookingRoom = 0;
                    if (IsSelectRoomInBookingR > 0)
                    {
                        aItemChangeRoomEN.IsRoomInBookingR = true;
                        IDBookingRoom = aList.Max(p => p.ID);
                        aItemChangeRoomEN.SetBookingRooms((new BookingRoomsBO()).Select_ByID(IDBookingRoom));
                    }
                    else
                    {
                        aItemChangeRoomEN.IsRoomInBookingR = false;
                        aItemChangeRoomEN.SetBookingRooms(this.aBookingRoom);
                    }
                    //-----------------------------------------------------------

                    aItemChangeRoomEN.SetAddTimeStart(null);
                    aItemChangeRoomEN.SetAddTimeEnd(null);
                    aItemChangeRoomEN.SetTimeInUsed(null);

                    aItemChangeRoomEN.SetCheckInActual(dtpCheckIn.DateTime);
                    aItemChangeRoomEN.SetCheckInPlan(dtpCheckIn.DateTime);
                    aItemChangeRoomEN.SetCheckOutActual(dtpCheckOut.DateTime);
                    aItemChangeRoomEN.SetCheckOutPlan(dtpCheckOut.DateTime);

                    aItemChangeRoomEN.SetTypeBookingRoom(1); // Khong tin chechIn som voi phong chuyen sang sau

                    aItemChangeRoomEN.SetCodeRoom(lueRooms.EditValue.ToString());

                    aItemChangeRoomEN.AddCustomer(this.GetDataForSelectCustomerGridview(lueRooms.EditValue.ToString()));

                    if (aItemChangeRoomEN.GetAllCustomers().Count > 0)
                    {
                        AccountancyBO aAccountancyBO = new AccountancyBO();
                        aItemChangeRoomEN.SetCost(aAccountancyBO.CalculateCostRoom(lueRooms.EditValue.ToString(), this.aBookingRoom.PriceType, aBookingRs.CustomerType.GetValueOrDefault(0), aItemChangeRoomEN.GetAllCustomers().Count).GetValueOrDefault(0));
                    }
                    else
                    {
                        aItemChangeRoomEN.SetCost(0);
                    }

                    this.aChangeRoomEn.InsertItemChangeRooms(aItemChangeRoomEN);
                    this.aCurrentRoomInfo = aItemChangeRoomEN;
                }
            }
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     AccountancyBO aAccountancyBO = new AccountancyBO();
     if (aCurrentRoomInfo.GetAllCustomers().Count <= 5)
     {
         ProcessChangeRoom();
     }
     else
     {
         MessageBox.Show("Phòng không được vượt quá 5 người");
     }
 }