//Load lai du lieu cho cac control moi khi select vao 1 phong moi
        // Ngoc - done
        private void LoadDataCurrentRoomForControl()
        {
            if (this.aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == this.CurrentIDBookingRoom).ToList().Count > 0)
            {
                BookingRoomUsedEN aBookingRoomUsedEN = this.aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == this.CurrentIDBookingRoom).ToList()[0];
                /*Ghi chu TypeBookingRooms
                 * Type = 2: //Tính checkin sớm , không tính checkout muộn.
                 * Type = 0: //Không tính checkIn sớm và checkout muộn.
                 * Type = 3: //Tính checkin sớm và Checkout muộn
                 * Type = 1: //Không tính checkin sớm , tính checkout muộn
                 */
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();

                if (aBookingRoomUsedEN.Status == 1 || aBookingRoomUsedEN.Status == 2)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInPlan;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutPlan;

                    txtNumberDate.Text = ""; // Phong chua su dung
                    txtAddTimeEnd.Text = "";
                    txtAddTimeStart.Text = "";

                    lblCI.Text = "CI dự kiến";
                    lblCO.Text = "CO dự kiến";
                    lblCaptionStatusRoom.Text = ("Phòng " + aBookingRoomUsedEN.RoomSku + " đang ở trạng thái đặt").ToUpper();

                }
                else if (aBookingRoomUsedEN.Status == 3)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutPlan;

                    txtNumberDate.Text = aReceptionTaskBO.GetTimeInUsed(aBookingRoomUsedEN.CheckInActual, aBookingRoomUsedEN.CheckOutPlan).ToString();

                    txtAddTimeEnd.Text = aReceptionTaskBO.GetAddTimeEnd(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckOutPlan).ToString();
                    txtAddTimeStart.Text = aReceptionTaskBO.GetAddTimeStart(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckInActual).ToString();
                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO dự kiến";
                    lblCaptionStatusRoom.Text = ("Phòng " + aBookingRoomUsedEN.RoomSku + " đang có người ở").ToUpper();
                }
                else if (aBookingRoomUsedEN.Status == 5)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutPlan;

                    txtNumberDate.Text = aReceptionTaskBO.GetTimeInUsed(aBookingRoomUsedEN.CheckInActual, aBookingRoomUsedEN.CheckOutPlan).ToString();
                    txtAddTimeEnd.Text = aReceptionTaskBO.GetAddTimeEnd(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckOutPlan).ToString();
                    txtAddTimeStart.Text = aReceptionTaskBO.GetAddTimeStart(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckInActual).ToString();

                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO dự kiến";
                    lblCaptionStatusRoom.Text = ("Phòng " + aBookingRoomUsedEN.RoomSku + " đang khóa").ToUpper();
                }
                else if (aBookingRoomUsedEN.Status == 7)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutActual;

                    txtNumberDate.Text = aReceptionTaskBO.GetTimeInUsed(aBookingRoomUsedEN.CheckInActual, aBookingRoomUsedEN.CheckOutActual).ToString();
                    txtAddTimeEnd.Text = aReceptionTaskBO.GetAddTimeEnd(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckOutActual).ToString();
                    txtAddTimeStart.Text = aReceptionTaskBO.GetAddTimeStart(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckInActual).ToString();

                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO thực tế";
                    lblCaptionStatusRoom.Text = ("Phòng " + aBookingRoomUsedEN.RoomSku + " đã checkout nhưng chưa thanh toán").ToUpper();
                }
                else if (aBookingRoomUsedEN.Status == 8)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutActual;

                    // Neu phong da dc thanh toan tuc la thong tin phong da chot. Vay lay thong tin nay de hien thi
                    txtNumberDate.Text = (aBookingRoomUsedEN.TimeInUse.GetValueOrDefault(0)/(24*60)).ToString();
                    txtAddTimeEnd.Text = aBookingRoomUsedEN.AddTimeEnd.ToString();
                    txtAddTimeStart.Text = aBookingRoomUsedEN.AddTimeStart.ToString();

                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO thực tế";
                    lblCaptionStatusRoom.Text = ("Phòng " + aBookingRoomUsedEN.RoomSku + " đã thanh toán").ToUpper();
                }
                lblSkuRooms.Text = aBookingRoomUsedEN.RoomSku;

                txtPercentTax_Room.Text = Convert.ToString(aBookingRoomUsedEN.PercentTax);
                lblMoneyRoom.Text = String.Format("{0:0,0} (VND)", this.aNewPaymentEN.GetOnlyMoneyRoom(aBookingRoomUsedEN.ID));

                if (string.IsNullOrEmpty(aBookingRoomUsedEN.Cost.ToString()) == false)
                {
                    txtBookingRoomsCost.EditValue = aBookingRoomUsedEN.Cost;
                }
                else
                {
                    txtBookingRoomsCost.EditValue = aAccountancyBO.CalculateCostRoom(this.CurrentIDBookingRoom, aBookingRoomUsedEN.PriceType, this.aNewPaymentEN.CustomerType.GetValueOrDefault(0), this.aNewPaymentEN.GetNumberCustomerInRoom(this.CurrentIDBookingRoom));
                }
                // Danh sách khách
                dgvCustomers.DataSource = aBookingRoomUsedEN.ListCustomer;
                dgvCustomers.RefreshDataSource();
                // Danh sách dịch vụ
                dgvServicesR.DataSource = aNewPaymentEN.GetListServiceUsedInRoom(aBookingRoomUsedEN.ID);
                dgvServicesR.RefreshDataSource();
                //-----------Ngoc bổ sung --------------
                CustomersBO aCustomersBO = new CustomersBO();
                lueUserInBookingR.DataSource = aCustomersBO.SelectListCustomer_ByIDBookingRoom(this.CurrentIDBookingRoom);
                //-----------Ngoc bổ sung --------------

                lblTotalMoneyServiceR.Text = String.Format("{0:0,0} (VND)", this.aNewPaymentEN.GetMoneyListServiceUsedInARoom(aBookingRoomUsedEN.ID));
            }
                //=========================================
                //=========================================
                //=========================================
                // Load lai  control khac

                //-------------- Phòng ---------------------
                //Thong tin nguoi dat
                lblNameCompany_BookingR.Text = this.aNewPaymentEN.NameCompany;
                lblNameCustomerGroup_BookingR.Text = this.aNewPaymentEN.NameCustomerGroup;
                lblNameCustomer_BookingR.Text = this.aNewPaymentEN.NameCustomer;
                txtAddressR.Text = this.aNewPaymentEN.AddressCompany;
                txtTaxNumberCodeR.Text = this.aNewPaymentEN.TaxNumberCodeCompany;

                // Thông tin hóa đơn
                txtInvoiceNumberR.Text = this.aNewPaymentEN.InvoiceNumber;
                dtpAcceptDateR.DateTime = this.aNewPaymentEN.AcceptDate.GetValueOrDefault(Convert.ToDateTime("01/01/1900"));
                dtpInvoiceDateR.DateTime = this.aNewPaymentEN.InvoiceDate.GetValueOrDefault(Convert.ToDateTime("01/01/1900"));
                // Trang thai, hinh thuc thanh toan
                lueBookingR_Paymethod.Properties.DataSource = CORE.CONSTANTS.ListPayMethods;
                lueBookingR_Paymethod.Properties.DisplayMember = "Name";
                lueBookingR_Paymethod.Properties.ValueMember = "ID";
                lueBookingR_Paymethod.EditValue = CORE.CONSTANTS.SelectedPayMethod(Convert.ToInt32(this.aNewPaymentEN.PayMenthodR)).ID;
                //--------------------------------------------------------------
                // Thong tin gia tiền, đặt trước
                lblTotalMoneyRooms.Text = String.Format("{0:0,0}", this.aNewPaymentEN.GetMoneyRooms());
                txtBookingRMoney.EditValue = this.aNewPaymentEN.BookingRMoney;
                lblTotalMoneyR.Text = String.Format("{0:0,0}", this.aNewPaymentEN.GetMoneyRooms() - this.aNewPaymentEN.BookingRMoney);
                // Bang danh sach phong
                dgvRooms.DataSource = this.aNewPaymentEN.aListBookingRoomUsed;
                dgvRooms.RefreshDataSource();
        }
        // ===============================================================================
        // Khoi tao doi tuong Payment
        private void InitData(int IDBookingR, int IDBookingH)
        {
            CompaniesBO aCompaniesBO = new CompaniesBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingRsBO aBookingRsBO = new BookingRsBO();
            BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
            CustomersBO aCustomersBO = new CustomersBO();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            RoomsBO aRoomsBO = new RoomsBO();
            HallsBO aHallsBO = new HallsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            FoodsBO aFoodsBO = new FoodsBO();
            ExtraCostBO aExtraCostBO = new ExtraCostBO();
            List<int> aListIndexTemp = new List<int>();
            BookingHs aBookingHs = new BookingHs();
            BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
            if (this.IDBookingH > 0)
            {
                aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
            }
            else
            {
                BookingRs_BookingHs aItem = (new BookingRs_BookingHsBO()).Select_ByIDBookingR(this.IDBookingR);
                if (aItem != null)
                {
                    this.IDBookingH = aItem.IDBookingH.GetValueOrDefault(0);
                    aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
                }

            }

            // Truyen du lieu chung cua NewPayment
            if (aBookingRs != null)
            {
                aNewPaymentEN.IDBookingR = aBookingRs.ID;
                aNewPaymentEN.IDCustomer = aBookingRs.IDCustomer;
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                if (aCustomers != null)
                {
                    aNewPaymentEN.NameCustomer = aCustomers.Name;
                }
                aNewPaymentEN.IDSystemUser = aBookingRs.IDSystemUser;
                SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingRs.IDSystemUser);
                if (aSystemUsers != null)
                {
                    aNewPaymentEN.NameSystemUser = aSystemUsers.Name;
                }
                aNewPaymentEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                if (aCustomerGroups != null)
                {
                    aNewPaymentEN.NameCustomerGroup = aCustomerGroups.Name;
                    aNewPaymentEN.IDCompany = aCustomerGroups.IDCompany;
                    Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                    if (aCompanies != null)
                    {
                        aNewPaymentEN.NameCompany = aCompanies.Name;
                        aNewPaymentEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        aNewPaymentEN.AddressCompany = aCompanies.Address;
                    }
                }
                aNewPaymentEN.PayMenthodR = aBookingRs.PayMenthod;
                aNewPaymentEN.CreatedDate_BookingR = aBookingRs.CreatedDate;
                aNewPaymentEN.CustomerType = aBookingRs.CustomerType;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.StatusPay = aBookingRs.StatusPay;
                aNewPaymentEN.BookingRMoney = aBookingRs.BookingMoney;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.AcceptDate = aBookingRs.AcceptDate;
                aNewPaymentEN.InvoiceDate = aBookingRs.InvoiceDate;
                aNewPaymentEN.InvoiceNumber = aBookingRs.InvoiceNumber;

                // Truyen du lieu cho List BookingRoom cua NewPayment
                List<BookingRooms> aListBookingRooms = aBookingRoomBO.Select_ByIDBookingRs(this.IDBookingR);
                if (aListBookingRooms.Count > 0)
                {
                    BookingRoomUsedEN aBookingRoomUsedEN;

                    foreach (BookingRooms item in aListBookingRooms)
                    {
                        aBookingRoomUsedEN = new BookingRoomUsedEN();
                        aBookingRoomUsedEN.SetValue(item);
                        aBookingRoomUsedEN.ListCustomer = aCustomersBO.SelectListCustomer_ByIDBookingRoom(item.ID);
                        Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);
                        if (aRooms != null)
                        {
                            aBookingRoomUsedEN.RoomSku = aRooms.Sku;
                        }
                        else
                        {
                            aBookingRoomUsedEN.RoomSku = string.Empty;
                        }
                        if (item.Status == 8 || item.Status == 7)
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutActual));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutActual) * 24 * 60);
                        }
                        else
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutPlan));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutPlan) * 24 * 60);

                        }
                        decimal? cost = 0;
                        if (item.Cost == null)
                        {
                            cost = item.CostRef_Rooms;
                            aBookingRoomUsedEN.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRoomUsedEN.PriceType, aBookingRoomUsedEN.ListCustomer.Count).ExtraValue);
                        }
                        else
                        {
                            cost = item.Cost;
                            aBookingRoomUsedEN.Cost = cost;
                        }
                        List<ServiceUsedEN> aListServiceRTemp = aReceptionTaskBO.GetListServiceUsedInRoom_ByIDBookingRoom(item.ID);
                        foreach (ServiceUsedEN aTemp in aListServiceRTemp)
                        {
                            aBookingRoomUsedEN.ListServiceUsed.Add(aTemp);
                            aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                        }
                        aListIndexTemp.Add(Convert.ToInt32(aBookingRoomUsedEN.IndexSubPayment));
                        aNewPaymentEN.aListBookingRoomUsed.Add(aBookingRoomUsedEN);
                    }
                }

                //====================================================================================================
                //====================================================================================================
                //====================================================================================================
                // Brucelee Thanh sửa ngày 04/06/2015
                //
                //---------------
                // Lỗi sai điều kiện câu lệnh if khiến aBookingHs truyền dữ liệu CustomerType sai cho NewPaymentEN
                //---------------
                // Ban đầu : if (aBookingHs != null)
                //-------------------------------------
                if (aBookingHs.ID > 0)
                {
                    aNewPaymentEN.IDBookingH = aBookingHs.ID;
                    aNewPaymentEN.PayMenthodH = aBookingHs.PayMenthod;
                    aNewPaymentEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                    aNewPaymentEN.CustomerType = aBookingHs.CustomerType;
                    aNewPaymentEN.Status_BookingH = aBookingHs.Status;
                    aNewPaymentEN.BookingHMoney = aBookingHs.BookingMoney;
                    // Truyen du lieu cho List BookingHall cua NewPayment
                    List<BookingHalls> aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(this.IDBookingH);
                    if (aListBookingHalls != null)
                    {
                        BookingHallUsedEN aBookingHallUsedEN;
                        foreach (BookingHalls item in aListBookingHalls)
                        {
                            aBookingHallUsedEN = new BookingHallUsedEN();
                            aBookingHallUsedEN.SetValue(item);
                            Halls aHalls = aHallsBO.Select_ByCodeHall(item.CodeHall, 1);
                            if (aHalls != null)
                            {
                                aBookingHallUsedEN.HallSku = aHalls.Sku;
                            }
                            else
                            {
                                aBookingHallUsedEN.HallSku = string.Empty;
                            }
                            aBookingHallUsedEN.CustomerType = aBookingHs.CustomerType;
                            aBookingHallUsedEN.BookingTypeBookingH = aBookingHs.BookingType;
                            aBookingHallUsedEN.StatusPayBookingH = aBookingHs.StatusPay;
                            aBookingHallUsedEN.LevelBookingH = aBookingHs.Level;
                            aBookingHallUsedEN.aListMenuEN = aReceptionTaskBO.GetListMenus_ByIDBookingHall(item.ID);

                            aListIndexTemp.Add(Convert.ToInt32(aBookingHallUsedEN.IndexSubPayment));
                            List<ServiceUsedEN> aListServiceTemp = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(item.ID);
                            foreach (ServiceUsedEN aTemp in aListServiceTemp)
                            {
                                aBookingHallUsedEN.aListServiceUsed.Add(aTemp);
                                aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                            }
                            aNewPaymentEN.aListBookingHallUsed.Add(aBookingHallUsedEN);
                        }
                    }
                }
                aNewPaymentEN.ListIndex = aListIndexTemp.Distinct().ToList();
            }
        }
        public void CheckOut(int IDBookingRoom)
        {
            try
            {
                RoomsBO aRoomsBO = new RoomsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
                List<BookingRoomsMembers> aListCus = aBookingRoomsMembersBO.Select_ByIDBookingRoom(IDBookingRoom);
                aBookingRooms.CheckOutActual = DateTime.Now;
                aBookingRooms.Status = 7;
                aBookingRooms.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckInActual));
                aBookingRooms.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckOutActual));
                aBookingRooms.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(aBookingRooms.CheckInActual, aBookingRooms.CheckOutActual) * 24 * 60);
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1);
                if (aRooms != null)
                {
                    if (aBookingRooms.Cost == null)
                    {
                        decimal? cost = 0;
                        cost = aBookingRooms.CostRef_Rooms;
                        aBookingRooms.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRooms.PriceType, aListCus.Count).ExtraValue);
                    }
                }

                aBookingRoomsBO.Update(aBookingRooms);
            }
            catch (Exception ex)
            {

                throw new Exception("AccountancyBO.CheckOut\n" + ex.ToString());
            }
        }
        //Load lai du lieu cho cac control moi khi select vao 1 phong moi
        // Ngoc - done
        private void LoadDataCurrentRoomForControl()
        {
            if (this.aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == this.CurrentIDBookingRoom).ToList().Count > 0)
            {
                BookingRoomUsedEN aBookingRoomUsedEN = this.aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == this.CurrentIDBookingRoom).ToList()[0];
                /*Ghi chu TypeBookingRooms
                 * Type = 2: //Tính checkin sớm , không tính checkout muộn.
                 * Type = 0: //Không tính checkIn sớm và checkout muộn.
                 * Type = 3: //Tính checkin sớm và Checkout muộn
                 * Type = 1: //Không tính checkin sớm , tính checkout muộn
                 */
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                this.ShowControlAutoCost(aBookingRoomUsedEN.Type.GetValueOrDefault(0));

                if (aBookingRoomUsedEN.Status == 1 || aBookingRoomUsedEN.Status == 2)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInPlan;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutPlan;

                    txtNumberDate.Text = "" ; // Phong chua su dung
                    txtAddTimeEnd.Text = "";
                    txtAddTimeStart.Text = "";

                    lblCI.Text = "CI dự kiến";
                    lblCO.Text = "CO dự kiến";

                }
                else if (aBookingRoomUsedEN.Status == 3 || aBookingRoomUsedEN.Status == 4 || aBookingRoomUsedEN.Status == 5)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutPlan;

                    txtNumberDate.Text = aReceptionTaskBO.GetTimeInUsed(aBookingRoomUsedEN.CheckInActual, aBookingRoomUsedEN.CheckOutPlan).ToString();

                    txtAddTimeEnd.Text = aReceptionTaskBO.GetAddTimeEnd(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckOutPlan).ToString();
                    txtAddTimeStart.Text = aReceptionTaskBO.GetAddTimeStart(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckInActual).ToString();
                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO dự kiến";
                }
                else if (aBookingRoomUsedEN.Status == 8 || aBookingRoomUsedEN.Status == 7)
                {
                    dtpCheckInActual.DateTime = aBookingRoomUsedEN.CheckInActual;
                    dtpCheckOutActual.DateTime = aBookingRoomUsedEN.CheckOutActual;

                    txtNumberDate.Text = aReceptionTaskBO.GetTimeInUsed(aBookingRoomUsedEN.CheckInActual, aBookingRoomUsedEN.CheckOutActual).ToString();
                    txtAddTimeEnd.Text = aReceptionTaskBO.GetAddTimeEnd(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckOutActual).ToString();
                    txtAddTimeStart.Text = aReceptionTaskBO.GetAddTimeStart(aBookingRoomUsedEN.Type.GetValueOrDefault(0), aBookingRoomUsedEN.CheckInActual).ToString();
                    lblCI.Text = "CI thực tế";
                    lblCO.Text = "CO thực tế";
                }

                lblSkuRooms.Text = aBookingRoomUsedEN.RoomSku;

                txtPercentTax_Room.Text = Convert.ToString(aBookingRoomUsedEN.PercentTax);
                lblMoneyRoom.Text = String.Format("{0:0,0} (VND)", this.aNewPaymentEN.GetMoneyARoom(aBookingRoomUsedEN.ID));

                if (string.IsNullOrEmpty(aBookingRoomUsedEN.Cost.ToString()) == false)
                {
                    txtBookingRoomsCost.EditValue = aBookingRoomUsedEN.Cost;
                }
                else
                {
                    txtBookingRoomsCost.EditValue = aAccountancyBO.CalculateCostRoom(this.CurrentIDBookingRoom, aBookingRoomUsedEN.PriceType, this.aNewPaymentEN.CustomerType.GetValueOrDefault(0), this.aNewPaymentEN.GetNumberCustomerInRoom(this.CurrentIDBookingRoom));
                }
                // Danh sách khách
                dgvCustomers.DataSource = aBookingRoomUsedEN.ListCustomer;
                dgvCustomers.RefreshDataSource();
                // Danh sách dịch vụ
                dgvServices.DataSource = aNewPaymentEN.GetListServiceUsedInRoom(aBookingRoomUsedEN.ID);
                dgvServices.RefreshDataSource();
                lblTotalMoneyService.Text = String.Format("{0:0,0} (VND)", this.aNewPaymentEN.GetMoneyListServiceUsedInARoom(aBookingRoomUsedEN.ID));
                //=========================================
                // Load lai  control khac
                this.LoadData();
            }
        }
        //Ngoc
        public int CheckOutFirstRoom(int IDBookingRoom, DateTime CheckOut)
        {
            try
            {
                /*Ghi chu TypeBookingRooms
                *
                * Type = 2: //Tính checkin sớm , không tính checkout muộn.
                * Type = 0: //Không tính checkIn sớm và checkout muộn.
                * Type = 3: //Tính checkin sớm và Checkout muộn
                * Type = 1: //Không tính checkin sớm , tính checkout muộn
                */
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);

                if (aBookingRooms != null)
                {
                    aBookingRooms.CheckOutActual = CheckOut;
                    int updateType = -1;
                    if (aBookingRooms.Type == 2)
                    {
                        updateType = 2;
                    }
                    else if (aBookingRooms.Type == 0)
                    {
                        updateType = 0;
                    }
                    else if (aBookingRooms.Type == 3)
                    {
                        updateType = 2;
                    }
                    else if (aBookingRooms.Type == 1)
                    {
                        updateType = 0;
                    }
                    else
                    {
                        updateType = 3;
                    }
                    aBookingRooms.Type = updateType;
                    aBookingRooms.Status = 7;//da checkout nhung chua thanh toan
                    aBookingRooms.TimeInUse = decimal.Parse(aReceptionTaskBO.GetTimeInUsed(aBookingRooms.CheckInActual, CheckOut).ToString());
                    aBookingRooms.AddTimeStart = aReceptionTaskBO.GetAddTimeStart(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckInActual);
                    aBookingRooms.AddTimeEnd =  aReceptionTaskBO.GetAddTimeEnd(aBookingRooms.Type.GetValueOrDefault(0), CheckOut);

                    return aBookingRoomsBO.Update(aBookingRooms);

                }
                else
                {
                    return 0;
                }

            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        public int CheckOut(int IDBookingRoom, DateTime CheckOut)
        {
            try
            {
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
                if (aBookingRooms != null)
                {
                    aBookingRooms.CheckOutActual = CheckOut;
                    aBookingRooms.Status = 7;//da checkout nhung chua thanh toan
                    aBookingRooms.TimeInUse = decimal.Parse(aReceptionTaskBO.GetTimeInUsed(aBookingRooms.CheckInActual, CheckOut).ToString());
                    aBookingRooms.AddTimeStart = aReceptionTaskBO.GetAddTimeStart(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckInActual);
                    aBookingRooms.AddTimeEnd = aReceptionTaskBO.GetAddTimeEnd(aBookingRooms.Type.GetValueOrDefault(0), CheckOut);
                    return aBookingRoomsBO.Update(aBookingRooms);
                }
                else
                {
                    return 0;
                }

            }
            catch (Exception ex)
            {
                return 0;
            }
        }