public List<Services> SelectListServiceBy_IDBookingRoom(int IDBookingRoom)
        {
            try
            {
                BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                List<int> aListIDService = aBookingRooms_ServicesBO.Select_ByIDBookingRooms(IDBookingRoom).Select(b => b.IDService).ToList();
                return this.SelectListService_ByListIDService(aListIDService);
            }
            catch (Exception ex)
            {

                throw new Exception("ServicesBO.SelectListServiceBy_IDBookingRoom\n" + ex.ToString());
            }
        }
        private void Save()
        {
            BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
            BookingRooms_Services aBookingRooms_Services;

            List<string> aList = aListSelected.Where(p => p.Tag == null || p.Tag == string.Empty).Select(p => p.Tag).ToList();

            if (aList.Count > 0)
            {
                MessageBox.Show("Có dịch vụ nào đó chưa được chọn người trả tiền");
            }
            else
            {
                for (int i = 0; i < aListSelected.Count; i++)
                {
                    aBookingRooms_Services = aBookingRooms_ServicesBO.Select_ByID(aListSelected[i].ID);
                    if (aBookingRooms_Services != null)
                    {
                        aBookingRooms_Services.Cost = aListSelected[i].Cost;
                        aBookingRooms_Services.Quantity = aListSelected[i].Quantity;
                        aBookingRooms_Services.PercentTax = aListSelected[i].PercentTax;
                        aBookingRooms_Services.Date = aListSelected[i].Date;
                        aBookingRooms_Services.Tag = aListSelected[i].Tag;
                        aBookingRooms_ServicesBO.Update(aBookingRooms_Services);

                    }
                    else
                    {
                        aBookingRooms_Services = new BookingRooms_Services();
                        aBookingRooms_Services.Info = "";
                        aBookingRooms_Services.Type = 1;
                        aBookingRooms_Services.Status = 1;
                        aBookingRooms_Services.Disable = false;
                        aBookingRooms_Services.IDBookingRoom = this.IDBookingRoom;
                        aBookingRooms_Services.IDService = aListSelected[i].IDService;
                        aBookingRooms_Services.Cost = aListSelected[i].Cost;
                        aBookingRooms_Services.Date = dtpDate.DateTime;
                        aBookingRooms_Services.CostRef_Services = aListSelected[i].CostRef_Services;
                        aBookingRooms_Services.PercentTax = 10;// de mac dinh
                        aBookingRooms_Services.Quantity = aListSelected[i].Quantity;
                        aBookingRooms_Services.Tag = aListSelected[i].Tag;
                        aBookingRooms_ServicesBO.Insert(aBookingRooms_Services);

                    }
                }
                foreach (BookingRooms_Services items in this.aListRemove)
                {
                    aBookingRooms_ServicesBO.Delete(items.ID);
                }

                if (this.afrmTsk_Payment_Step2 != null)
                {
                    this.afrmTsk_Payment_Step2.Reload();
                }

                MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }
        private void LoadServicesInRoom()
        {
            try
            {
                ServicesBO aServicesBO = new ServicesBO();
                BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                List<BookingRooms_Services> aListTemp = aBookingRooms_ServicesBO.Select_ByIDBookingRooms(this.IDBookingRoom);
                BookingRoom_ServiceEN aBookingRoom_ServiceEN;

                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aBookingRoom_ServiceEN = new BookingRoom_ServiceEN();
                    aBookingRoom_ServiceEN.ID = aListTemp[i].ID;
                    aBookingRoom_ServiceEN.Info = aListTemp[i].Info;
                    aBookingRoom_ServiceEN.Type = aListTemp[i].Type;
                    aBookingRoom_ServiceEN.Status = aListTemp[i].Status;
                    aBookingRoom_ServiceEN.Disable = aListTemp[i].Disable;
                    aBookingRoom_ServiceEN.IDBookingRoom = aListTemp[i].IDBookingRoom;
                    aBookingRoom_ServiceEN.IDService = aListTemp[i].IDService;
                    aBookingRoom_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
                    aBookingRoom_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;
                    aBookingRoom_ServiceEN.Cost = aListTemp[i].Cost == null ? aListTemp[i].CostRef_Services : aListTemp[i].Cost;
                    aBookingRoom_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
                    aBookingRoom_ServiceEN.Date = aListTemp[i].Date;
                    aBookingRoom_ServiceEN.PercentTax = aListTemp[i].PercentTax;
                    aBookingRoom_ServiceEN.Quantity = aListTemp[i].Quantity;
                    aBookingRoom_ServiceEN.Tag = aListTemp[i].Tag;
                    aListSelected.Add(aBookingRoom_ServiceEN);
                }
                dgvServiceInRoom.DataSource = aListSelected;
                dgvServiceInRoom.RefreshDataSource();

                CustomersBO aCustomersBO = new CustomersBO();

                lueUserInRoom.DataSource = aCustomersBO.SelectListCustomer_ByIDBookingRoom(this.IDBookingRoom);

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_BookingRooms_Services.grvRooms_RowClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     try
     {
         this.IsDataChange = true;
         int IDBookingRoomService = Convert.ToInt32(grvServiceInRoom.GetFocusedRowCellValue("ID"));
         List<BookingRoom_ServiceEN> aListTemp = aListSelected.Where(a => a.ID == IDBookingRoomService).ToList();
         if (aListTemp.Count > 0)
         {
             aListSelected.Remove(aListTemp[0]);
             dgvServiceInRoom.DataSource = aListSelected;
             dgvServiceInRoom.RefreshDataSource();
         }
         BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
         BookingRooms_Services aTemp = aBookingRooms_ServicesBO.Select_ByID(IDBookingRoomService);
         if (aTemp != null)
         {
             this.aListRemove.Add(aTemp);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmTsk_UseServices.btnDelete_ButtonClick\n" + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        //Hiennv
        private void txtAddToSubPaymentServicesR_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                TextEdit txtChooseService = (TextEdit)sender;
                int IDBookingRoomsService = Convert.ToInt32(viewServicesRoom.GetFocusedRowCellValue("IDBookingService"));
                BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                int IDBookingRoom = aBookingRooms_ServicesBO.Select_ByID(IDBookingRoomsService).IDBookingRoom;
                this.aNewPaymentEN.ChangeIndexSubPaymentServiceRoom(IDBookingRoom, IDBookingRoomsService, Convert.ToInt32(txtChooseService.EditValue));
                this.aNewPaymentEN.ListIndex.Add(Convert.ToInt32(txtChooseService.EditValue));

                this.LoadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_SplitBill_Step1.txtChooseService_EditValueChanged\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDeleteService_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.IsLockForm == false)
            {
                DialogResult result = MessageBox.Show("Xóa dịch vụ phòng đã sử dụng. Tiếp tục?", "Xóa dịch vụ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {

                    BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                    int IDBookingService = Convert.ToInt32(viewServicesR.GetFocusedRowCellValue("IDBookingService"));

                    aBookingRooms_ServicesBO.Delete(IDBookingService);
                    MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Reload();
                }
            }
            else
            {
                MessageBox.Show("Không thực hiện được chức năng này do form đang chế độ khóa");
            }
        }
        private void btnDeleteRoom_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.IsLockForm == false)
            {
                if (this.aNewPaymentEN.aListBookingRoomUsed.Count == 1)
                {
                    MessageBox.Show("Không thể xóa", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa phòng. Tiếp tục?", "Xóa phòng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                        BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        int IDDeletedBookingRoom = Convert.ToInt32(viewRooms.GetFocusedRowCellValue("ID"));
                        aBookingRooms_ServicesBO.DeleteListServiceUsed(IDDeletedBookingRoom);
                        aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(IDDeletedBookingRoom);
                        aBookingRoomsBO.Delete(IDDeletedBookingRoom);
                        MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Reload();

                    }
                }
            }
            else
            {
                MessageBox.Show("Không thực hiện được chức năng này do form đang chế độ khóa");
            }
        }
        private void btnDeleteBookingR_Click(object sender, EventArgs e)
        {
            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            BookingRsBO aBookingRsBO = new BookingRsBO();
            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            MenusBO aMenusBO = new MenusBO();
            Menus_FoodsBO aMenus_FoodsBO = new Menus_FoodsBO();
            try
            {
                MessageBox.Show("Chức năng này sẽ xóa tất cả các phòng và hóa đơn đặt phòng đã đặt!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (this.IDBookingH == 0)
                {
                    DialogResult result = MessageBox.Show("Xóa tất cả các phòng đã đặt. Tiếp tục?", "Xóa phòng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        foreach (BookingRoomUsedEN item in this.aNewPaymentEN.aListBookingRoomUsed)
                        {
                            aBookingRooms_ServicesBO.DeleteListServiceUsed(item.ID);
                            aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(item.ID);
                            aBookingRoomsBO.Delete(item.ID);
                        }
                        aCustomerGroups_CustomersBO.DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(this.IDBookingR);
                        aCustomerGroupsBO.Delete_ByID(Convert.ToInt32(this.aNewPaymentEN.IDCustomerGroup));
                        int ret =  aBookingRsBO.Delete(this.IDBookingR);

                        if (ret > 0)
                        {
                            MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa tất cả các phòng và hội trường đã đặt. Tiếp tục?", "Xóa hóa đơn", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {

                        foreach (BookingRoomUsedEN item in this.aNewPaymentEN.aListBookingRoomUsed)
                        {
                            aBookingRooms_ServicesBO.DeleteListServiceUsed(item.ID);
                            aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(item.ID);
                            aBookingRoomsBO.Delete(item.ID);
                        }
                        aCustomerGroups_CustomersBO.DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(this.IDBookingR);
                        aCustomerGroupsBO.Delete_ByID(Convert.ToInt32(this.aNewPaymentEN.IDCustomerGroup));
                        aBookingRsBO.Delete(this.IDBookingR);
                        foreach (BookingHallUsedEN item1 in this.aNewPaymentEN.aListBookingHallUsed)
                        {
                            aBookingHalls_ServicesBO.DeleteListServiceUsed(item1.ID);
                            aBookingHallsBO.Delete(item1.ID);
                            foreach (MenusEN aMenu in item1.aListMenuEN)
                            {
                                aMenusBO.Delete(aMenu.ID);
                                aMenus_FoodsBO.Delete_ByIDMenu(aMenu.ID);
                            }
                        }
                        int ret = aBookingHsBO.Delete(this.IDBookingH);
                        if (ret > 0)
                        {
                            MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

                this.Close();
                if (this.afrmMain != null)
                {
                    this.afrmMain.ReloadData();
                }
                else if (this.afrmMain_Halls != null)
                {
                    this.afrmMain_Halls.ReloadData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_UpdBookingHall.btnDeleteBookingRs\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDeleteService_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            DialogResult result = MessageBox.Show("Xóa dịch vụ phòng đã sử dụng. Tiếp tục?", "Xóa dịch vụ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {

                BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                int IDService = Convert.ToInt32(viewServices.GetFocusedRowCellValue("IDService"));
                DateTime DateUsed = Convert.ToDateTime(viewServices.GetFocusedRowCellValue("DateUsed"));
                aBookingRooms_ServicesBO.Delete(IDService, CurrentIDBookingRoom, DateUsed);
                MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Reload();
            }
        }
        //hiennv
        public bool PaymentRoom(PaymentEN aPaymentEN)
        {
            try
            {
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(aPaymentEN.IDBookingR);
                if (aBookingRs != null)
                {
                    aBookingRs.ID = aPaymentEN.IDBookingR;
                    aBookingRs.PayMenthod = aPaymentEN.PayMenthod;
                    aBookingRs.StatusPay = 3;
                    aBookingRs.Status = 8;
                    aBookingRs.DatePay = DateTime.Now;
                    aBookingRs.BookingMoney = 0;

                    aBookingRsBO.Update(aBookingRs);
                }

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                for (int i = 0; i < aPaymentEN.aListInfoDetailPaymentEN.Count; i++)
                {
                    if (aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.IDBookingR == aPaymentEN.IDBookingR)
                    {

                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.ID);
                        if (aBookingRooms != null)
                        {
                            aBookingRooms.ID = aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.ID;
                            aBookingRooms.PercentTax = aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.PercentTax;
                            decimal? cost = aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.Cost == null ? aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.CostRef_Rooms : aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.Cost;
                            aBookingRooms.Cost = cost;
                            aBookingRooms.Status = 8;
                            aBookingRooms.CheckOutActual = aPaymentEN.aListInfoDetailPaymentEN[i].CheckOut;
                            aBookingRooms.TimeInUse = Convert.ToDecimal(aPaymentEN.aListInfoDetailPaymentEN[i].DateInUse * 24 * 60);

                            aBookingRoomsBO.Update(aBookingRooms);
                        }

                        for (int j = 0; j < aPaymentEN.aListInfoDetailPaymentEN[i].aListService.Count; j++)
                        {
                            if (aPaymentEN.aListInfoDetailPaymentEN[i].aBookingRooms.ID == aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].IDBookingRoom)
                            {
                                BookingRooms_Services aBookingRooms_Services = aBookingRooms_ServicesBO.Select_ByID(aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].IDBookingRoomService);
                                if (aBookingRooms_Services != null)
                                {
                                    aBookingRooms_Services.ID = aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].IDBookingRoomService;
                                    aBookingRooms_Services.Quantity = aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].Quantity;
                                    aBookingRooms_Services.PercentTax = aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].PercentTax;
                                    aBookingRooms_Services.Cost = aPaymentEN.aListInfoDetailPaymentEN[i].aListService[j].Cost;
                                    aBookingRooms_Services.Status = 8;

                                    aBookingRooms_ServicesBO.Update(aBookingRooms_Services);
                                }
                            }

                        }

                    }

                }
                return true;

            }
            catch (Exception ex)
            {
                return false;
                throw new Exception(string.Format("ReceptionTaskBO.PaymentRoom\n" + ex.Message));
            }
        }