public void LoadServiceInBookingHall(int IDBookHall)
        {
            try
            {
                ServicesBO aServicesBO = new ServicesBO();
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                List<BookingHalls_Services> aListTemp = aBookingHalls_ServicesBO.Select_ByIDBookingHall(IDBookHall);
                BookingHall_ServiceEN aBookingHall_ServiceEN;
                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aBookingHall_ServiceEN = new BookingHall_ServiceEN();
                    aBookingHall_ServiceEN.ID = aListTemp[i].ID;
                    aBookingHall_ServiceEN.Info = aListTemp[i].Info;
                    aBookingHall_ServiceEN.Type = aListTemp[i].Type;
                    aBookingHall_ServiceEN.Status = aListTemp[i].Status;
                    aBookingHall_ServiceEN.Disable = aListTemp[i].Disable;
                    aBookingHall_ServiceEN.IDBookingHall = aListTemp[i].IDBookingHall;
                    aBookingHall_ServiceEN.IDService = aListTemp[i].IDService;
                    aBookingHall_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
                    aBookingHall_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;
                    aBookingHall_ServiceEN.Cost = aListTemp[i].Cost == null ? aListTemp[i].CostRef_Services : aListTemp[i].Cost;
                    aBookingHall_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
                    aBookingHall_ServiceEN.Date = aListTemp[i].Date;
                    aBookingHall_ServiceEN.PercentTax = aListTemp[i].PercentTax;
                    aBookingHall_ServiceEN.Quantity = aListTemp[i].Quantity;
                    aListSelected.Add(aBookingHall_ServiceEN);
                }
                dgvServiceInHall.DataSource = aListSelected;
                dgvServiceInHall.RefreshDataSource();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_BookingHalls_Services.grvHalls_RowClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
 private void grvListBookingHalls_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
 {
     int IDBookingHall = Convert.ToInt32(grvListBookingHalls.GetFocusedRowCellValue("ID"));
     ServicesBO aServicesBO = new ServicesBO();
     BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
     List<BookingHall_ServiceEN> aListBookingHall_ServiceEN = new List<BookingHall_ServiceEN>();
     List<BookingHalls_Services> aListTemp = aBookingHalls_ServicesBO.Select_ByIDBookingHall(IDBookingHall);
     BookingHall_ServiceEN aBookingHall_ServiceEN;
     for (int i = 0; i < aListTemp.Count; i++)
     {
         aBookingHall_ServiceEN = new BookingHall_ServiceEN();
         aBookingHall_ServiceEN.ID = aListTemp[i].ID;
         aBookingHall_ServiceEN.Info = aListTemp[i].Info;
         aBookingHall_ServiceEN.Type = aListTemp[i].Type;
         aBookingHall_ServiceEN.Status = aListTemp[i].Status;
         aBookingHall_ServiceEN.Disable = aListTemp[i].Disable;
         aBookingHall_ServiceEN.IDBookingHall = aListTemp[i].IDBookingHall;
         aBookingHall_ServiceEN.IDService = aListTemp[i].IDService;
         aBookingHall_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
         aBookingHall_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;
         aBookingHall_ServiceEN.Cost = aListTemp[i].CostRef_Services;
         aBookingHall_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
         aBookingHall_ServiceEN.Date = aListTemp[i].Date;
         aBookingHall_ServiceEN.PercentTax = aListTemp[i].PercentTax;
         aBookingHall_ServiceEN.Quantity = aListTemp[i].Quantity;
         aListBookingHall_ServiceEN.Add(aBookingHall_ServiceEN);
     }
     dgvServiceInBookingHall.DataSource = aListBookingHall_ServiceEN;
     dgvServiceInBookingHall.RefreshDataSource();
 }
        //Hiennv
        private void btnPayment_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(lueIndexSub.Text) == true)
                {
                    lueIndexSub.Focus();
                    MessageBox.Show("Vui lòng chọn phiếu thanh toán!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                    foreach (ServicesHallsEN aServicesHallsEN in this.aListServices)
                    {
                        BookingHalls_Services aBookingHalls_Services = aBookingHalls_ServicesBO.Select_ByID(aServicesHallsEN.IDBookingHallService);
                        if (aBookingHalls_Services != null && aBookingHalls_Services.Status != 8)
                        {
                            aBookingHalls_Services.ID = aServicesHallsEN.IDBookingHallService;
                            aBookingHalls_Services.Quantity = aServicesHallsEN.Quantity;
                            aBookingHalls_Services.PercentTax = aServicesHallsEN.PercentTax;
                            aBookingHalls_Services.Cost = aServicesHallsEN.Cost;
                            aBookingHalls_Services.Status = 8;// da thanh toan
                            aBookingHalls_ServicesBO.Update(aBookingHalls_Services);
                        }
                    }

                    BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                    foreach (HallsEN aHallsEN in this.aListHalls)
                    {
                        BookingHalls aBookingHalls = aBookingHallsBO.Select_ByID(aHallsEN.IDBookingHall);
                        if (aBookingHalls != null && aBookingHalls.Status != 8)
                        {
                            aBookingHalls.ID = aHallsEN.IDBookingHall;
                            aBookingHalls.PercentTax = aHallsEN.PercentTax;
                            aBookingHalls.Cost = aHallsEN.Cost;
                            aBookingHalls.Status = 8;//da thanh toan
                            aBookingHallsBO.Update(aBookingHalls);
                        }
                    }
                    BookingHsBO aBookingHsBO = new BookingHsBO();
                    BookingHs aBookingHs = aBookingHsBO.Select_ByID(this.aPaymentHallsEN.IDBookingH);
                    List<BookingHalls> aListBookingHalls = aBookingHallsBO.Select_ByIDBookingH_ByStatus(this.aPaymentHallsEN.IDBookingH,8);
                    if (aListBookingHalls.Count < 1)
                    {
                        aBookingHs.ID = aPaymentHallsEN.IDBookingH;
                        aBookingHs.PayMenthod = this.aPaymentHallsEN.PayMenthod;
                        aBookingHs.StatusPay = 3;
                        aBookingHs.Status = 8;
                        btnPayment.Enabled = false;
                    }
                    aBookingHs.BookingMoney = this.aPaymentHallsEN.GetBookingMoney();
                    aBookingHsBO.Update(aBookingHs);

                    MessageBox.Show("Thanh toán thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_SplitBillHalls_Step2_Load.btnPayment_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void txtChooseService_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                TextEdit txtChooseService = (TextEdit)sender;
                int IDBookingHallsService = Convert.ToInt32(viewServicesHall.GetFocusedRowCellValue("IDBookingService"));
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                int IDBookingHall = aBookingHalls_ServicesBO.Select_ByID(IDBookingHallsService).IDBookingHall;
                this.aNewPaymentEN.ChangeIndexSubPaymentServiceHall(IDBookingHall, IDBookingHallsService, Convert.ToInt32(txtChooseService.EditValue));
                this.aNewPaymentEN.ListIndex.Add(Convert.ToInt32(txtChooseService.EditValue));

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

                    BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                    int IDBookingService = Convert.ToInt32(viewServicesH.GetFocusedRowCellValue("IDBookingService"));

                    aBookingHalls_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 btnDeleteHall_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.IsLockForm == false)
            {
                if (this.aNewPaymentEN.aListBookingRoomUsed.Count == 0 && this.aNewPaymentEN.aListBookingHallUsed.Count == 1)
                {
                    MessageBox.Show("Không thể xóa vì hóa đơn này sẽ rỗng. Hãy sử dụng chức năng xóa cả hóa đơn trong tình huống này", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa hội trường/tiệc. Tiếp tục?", "Xóa Xóa hội trường/tiệc", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {

                        BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                        BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                        int IDDeletedBookingHall = Convert.ToInt32(viewHalls.GetFocusedRowCellValue("ID"));
                        aBookingHalls_ServicesBO.DeleteListServiceUsed(IDDeletedBookingHall);

                        aBookingHallsBO.Delete(IDDeletedBookingHall);
                        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 grvListBookingHalls_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
 {
     try
     {
         int IDBookingHall = Convert.ToInt32(grvListBookingHalls.GetFocusedRowCellValue("ID"));
         ServicesBO aServicesBO = new ServicesBO();
         BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
         List<BookingHall_ServiceEN> aListBookingHall_ServiceEN = new List<BookingHall_ServiceEN>();
         List<BookingHalls_Services> aListTemp = aBookingHalls_ServicesBO.Select_ByIDBookingHall(IDBookingHall);
         BookingHall_ServiceEN aBookingHall_ServiceEN;
         for (int i = 0; i < aListTemp.Count; i++)
         {
             aBookingHall_ServiceEN = new BookingHall_ServiceEN();
             aBookingHall_ServiceEN.ID = aListTemp[i].ID;
             aBookingHall_ServiceEN.Info = aListTemp[i].Info;
             aBookingHall_ServiceEN.Type = aListTemp[i].Type;
             aBookingHall_ServiceEN.Status = aListTemp[i].Status;
             aBookingHall_ServiceEN.Disable = aListTemp[i].Disable;
             aBookingHall_ServiceEN.IDBookingHall = aListTemp[i].IDBookingHall;
             aBookingHall_ServiceEN.IDService = aListTemp[i].IDService;
             aBookingHall_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
             aBookingHall_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;
             aBookingHall_ServiceEN.Cost = aListTemp[i].CostRef_Services;
             aBookingHall_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
             aBookingHall_ServiceEN.Date = aListTemp[i].Date;
             aBookingHall_ServiceEN.PercentTax = aListTemp[i].PercentTax;
             aBookingHall_ServiceEN.Quantity = aListTemp[i].Quantity;
             aListBookingHall_ServiceEN.Add(aBookingHall_ServiceEN);
         }
         dgvServiceInBookingHall.DataSource = aListBookingHall_ServiceEN;
         dgvServiceInBookingHall.RefreshDataSource();
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmTsk_UnpayBookingHs.grvListBookingHalls_RowClick\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void Save()
        {
            BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
            BookingHalls_Services aBookingHalls_Services;
            for (int i = 0; i < aListSelected.Count; i++)
            {
                aBookingHalls_Services = aBookingHalls_ServicesBO.Select_ByID(aListSelected[i].ID);
                if (aBookingHalls_Services != null)
                {
                    aBookingHalls_Services.Cost = aListSelected[i].Cost;
                    aBookingHalls_Services.Quantity = aListSelected[i].Quantity;
                    aBookingHalls_Services.PercentTax = aListSelected[i].PercentTax;
                    aBookingHalls_Services.Date = aListSelected[i].Date;

                    aBookingHalls_ServicesBO.Update(aBookingHalls_Services);
                }
                else
                {
                    aBookingHalls_Services = new BookingHalls_Services();
                    aBookingHalls_Services.Info = "";
                    aBookingHalls_Services.Type = 1;
                    aBookingHalls_Services.Status = 1;
                    aBookingHalls_Services.Disable = false;
                    aBookingHalls_Services.IDBookingHall = this.IDBookingHall;
                    aBookingHalls_Services.IDService = aListSelected[i].IDService;
                    aBookingHalls_Services.Cost = aListSelected[i].Cost;
                    aBookingHalls_Services.Date = dtpDate.DateTime;
                    aBookingHalls_Services.CostRef_Services = aListSelected[i].CostRef_Services;
                    aBookingHalls_Services.PercentTax = 10;// de mac dinh
                    aBookingHalls_Services.Quantity = aListSelected[i].Quantity;
                    aBookingHalls_ServicesBO.Insert(aBookingHalls_Services);
                }
            }
            foreach (BookingHalls_Services items in this.aListRemove)
            {
                aBookingHalls_ServicesBO.Delete(items.ID);
            }

            if (this.afrmTsk_Payment_Step2 != null)
            {
                if (aNewPayment.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList().Count > 0)
                {
                    aNewPayment.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList()[0].aListServiceUsed.Clear();
                    aNewPayment.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList()[0].aListServiceUsed = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(IDBookingHall);

                }
                this.afrmTsk_Payment_Step2.Reload();
            }
            if (this.afrmTsk_UpdBookingHall != null)
            {
                if (aNewPaymentH.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList().Count > 0)
                {
                    aNewPaymentH.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList()[0].aListServiceUsed.Clear();
                    aNewPaymentH.aListBookingHallUsed.Where(a => a.ID == IDBookingHall).ToList()[0].aListServiceUsed = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(IDBookingHall);

                }
                this.afrmTsk_UpdBookingHall.Reload(this.aNewPaymentH);
            }

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

            this.Close();
        }
        //Hiennv
        private void btnCancel_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                int IDService = Convert.ToInt32(grvServiceInHall.GetFocusedRowCellValue("IDService"));
                List<BookingHall_ServiceEN> aListTemp = aListSelected.Where(a => a.IDService == IDService).ToList();
                if (aListTemp.Count > 0)
                {
                    aListSelected.Remove(aListTemp[0]);
                }

                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                BookingHalls_Services aTemp = aBookingHalls_ServicesBO.Select_ByIDService_ByIDBookingHall(IDService, this.IDBookingHall);
                if (aTemp != null)
                {
                    BookingHalls_Services aBookingHalls_Services = new BookingHalls_Services();
                    aBookingHalls_Services.IDBookingHall = this.IDBookingHall;
                    aBookingHalls_Services.IDService = IDService;
                    this.aListRemove.Add(aBookingHalls_Services);
                }

                dgvServiceInHall.DataSource = aListSelected;
                dgvServiceInHall.RefreshDataSource();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_BookingHalls_Services.btnCancel_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
        private void btnDeleteServiceHall_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            DialogResult result = MessageBox.Show("Xóa dịch vụ hội trường đã sử dụng. Tiếp tục?", "Xóa dịch vụ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {

                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                int IDService = Convert.ToInt32(viewServices.GetFocusedRowCellValue("IDService"));
                DateTime DateUsed = Convert.ToDateTime(viewServices.GetFocusedRowCellValue("Date"));
                aBookingHalls_ServicesBO.Delete(IDService, CurrentIDBookingHall, DateUsed);
                MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Reload();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
            BookingHalls_Services aBookingHalls_Services;
            for (int i = 0; i < aListSelected.Count; i++)
            {
                aBookingHalls_Services = aBookingHalls_ServicesBO.Select_ByID(aListSelected[i].ID);
                if (aBookingHalls_Services != null)
                {
                    aBookingHalls_Services.Cost = aListSelected[i].Cost;
                    aBookingHalls_Services.Quantity = aListSelected[i].Quantity;
                    aBookingHalls_ServicesBO.Update(aBookingHalls_Services);
                }
                else
                {
                    aBookingHalls_Services = new BookingHalls_Services();
                    aBookingHalls_Services.Info = "";
                    aBookingHalls_Services.Type = 1;
                    aBookingHalls_Services.Status = 1;
                    aBookingHalls_Services.Disable = false;
                    aBookingHalls_Services.IDBookingHall = this.IDBookingHall;
                    aBookingHalls_Services.IDService = aListSelected[i].IDService;
                    aBookingHalls_Services.Cost = aListSelected[i].Cost;
                    aBookingHalls_Services.Date = DateTime.Now;
                    aBookingHalls_Services.CostRef_Services = aListSelected[i].CostRef_Services;
                    aBookingHalls_Services.PercentTax = 10;// de mac dinh
                    aBookingHalls_Services.Quantity = aListSelected[i].Quantity;
                    aBookingHalls_ServicesBO.Insert(aBookingHalls_Services);
                }
            }
            foreach (BookingHalls_Services items in this.aListRemove)
            {
                aBookingHalls_ServicesBO.Delete(items.IDService, items.IDBookingHall);
            }

            if (afrmTsk_PaymentHall != null)
            {
                this.afrmTsk_PaymentHall.LoadListHall();
            }
            MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.Close();
        }
        //hiennv
        public bool PaymentHall(PaymentHallsEN aPaymentHallsEN)
        {
            try
            {
                BookingHsBO aBookingHsBO = new BookingHsBO();
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                BookingHs aBookingHs = aBookingHsBO.Select_ByID(aPaymentHallsEN.IDBookingH);
                aBookingHs.PayMenthod = aPaymentHallsEN.PayMenthod;
                aBookingHs.DatePay = DateTime.Now;
                aBookingHs.StatusPay = 3;//da thanh toan
                aBookingHs.Status = 8;//da thanh toan toan bo
                aBookingHs.BookingMoney = 0;

                aBookingHsBO.Update(aBookingHs);
                foreach (InfoDetailPaymentHallsEN aInfoDetailPaymentHallsEN in aPaymentHallsEN.aListInfoDetailPaymentHallsEN)
                {
                    if (aInfoDetailPaymentHallsEN.aBookingHalls.IDBookingH == aPaymentHallsEN.IDBookingH)
                    {
                        BookingHalls aBookingHalls = aBookingHallsBO.Select_ByID(aInfoDetailPaymentHallsEN.aBookingHalls.ID);
                        aBookingHalls.Cost = aInfoDetailPaymentHallsEN.aBookingHalls.Cost;
                        aBookingHalls.PercentTax = aInfoDetailPaymentHallsEN.aBookingHalls.PercentTax;
                        aBookingHalls.Status = 8;// da thanh toan

                        aBookingHallsBO.Update(aBookingHalls);
                        foreach (ServicesHallsEN aServicesHallsEN in aInfoDetailPaymentHallsEN.aListServicesHallsEN)
                        {
                            if (aServicesHallsEN.IDBookingHall == aInfoDetailPaymentHallsEN.aBookingHalls.ID)
                            {
                                BookingHalls_Services aBookingHalls_Services = aBookingHalls_ServicesBO.Select_ByIDService_ByIDBookingHall(aServicesHallsEN.IDService, aInfoDetailPaymentHallsEN.aBookingHalls.ID);
                                aBookingHalls_Services.Cost = aServicesHallsEN.Cost;
                                aBookingHalls_Services.Quantity = aServicesHallsEN.Quantity;
                                aBookingHalls_Services.PercentTax = aServicesHallsEN.PercentTax;
                                aBookingHalls_Services.Status = 8;//da thanh toan
                                aBookingHalls_ServicesBO.Update(aBookingHalls_Services);
                            }

                        }

                    }
                }
                return true;

            }
            catch (Exception ex)
            {
                return false;
                throw new Exception(string.Format("ReceptionTaskBO.PaymentHall\n" + ex.Message));
            }
        }
        //Linhting - Book hội trường mới
        public int NewBookHall(NewBookingHEN aNewBookingHEN)
        {
            try
            {
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();

                //Tạo BookingH mới
                BookingHs aBookingHs = new BookingHs();

                aBookingHs.CreatedDate = aNewBookingHEN.CreatedDate;
                aBookingHs.CustomerType = aNewBookingHEN.CustomerType;
                aBookingHs.BookingType = aNewBookingHEN.BookingType;
                aBookingHs.Note = aNewBookingHEN.Note;
                aBookingHs.IDGuest = 0;
                aBookingHs.StatusPay = aNewBookingHEN.StatusPay;
                aBookingHs.BookingMoney = aNewBookingHEN.BookingMoney;
                aBookingHs.Status = aNewBookingHEN.Status;
                aBookingHs.Type = aNewBookingHEN.Type;
                aBookingHs.Disable = aNewBookingHEN.Disable;
                aBookingHs.Level = aNewBookingHEN.Level;
                aBookingHs.Subject = aNewBookingHEN.Subject;
                aBookingHs.IDCustomerGroup = aNewBookingHEN.IDCustomerGroup;
                aBookingHs.IDCustomer = aNewBookingHEN.IDCustomer;
                aBookingHs.IDSystemUser = aNewBookingHEN.IDSystemUser;
                aBookingHs.Description = aNewBookingHEN.Description;

                //Tạo BookingHall mới
                BookingHsBO aBookingHsBO = new BookingHsBO();
                int IDBookingH = aBookingHsBO.InsertUnSync(aBookingHs);

                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                BookingHalls aBookingHall;
                for (int i = 0; i < aNewBookingHEN.aListBookingHallUsed.Count; i++)
                {
                    aBookingHall = new BookingHalls();
                    aBookingHall.IDBookingH = IDBookingH;
                    aBookingHall.CodeHall = aNewBookingHEN.aListBookingHallUsed[i].CodeHall;
                    aBookingHall.Cost = aNewBookingHEN.aListBookingHallUsed[i].Cost;
                    aBookingHall.PercentTax = 10; //Để tạm thuế = 10%
                    aBookingHall.CostRef_Halls = aNewBookingHEN.aListBookingHallUsed[i].CostRef_Halls;
                    aBookingHall.Date = aNewBookingHEN.aListBookingHallUsed[i].Date;
                    aBookingHall.LunarDate = aNewBookingHEN.aListBookingHallUsed[i].LunarDate;
                    aBookingHall.BookingStatus = aNewBookingHEN.aListBookingHallUsed[i].BookingStatus;
                    aBookingHall.Unit = aNewBookingHEN.aListBookingHallUsed[i].Unit;
                    aBookingHall.TableOrPerson = aNewBookingHEN.aListBookingHallUsed[i].TableOrPerson;
                    aBookingHall.Note = aNewBookingHEN.aListBookingHallUsed[i].Note;
                    aBookingHall.Status = aNewBookingHEN.aListBookingHallUsed[i].Status;
                    aBookingHall.StartTime = aNewBookingHEN.aListBookingHallUsed[i].StartTime;
                    aBookingHall.EndTime = aNewBookingHEN.aListBookingHallUsed[i].EndTime;
                    aBookingHall.Location = aNewBookingHEN.aListBookingHallUsed[i].Location;
                    aBookingHall.Color = aNewBookingHEN.aListBookingHallUsed[i].Color;

                    aBookingHallsBO.InsertUnSync(aBookingHall);
                    int IDBookingHall = aBookingHall.ID;
                    // Thêm dịch vụ đã chọn vào hội trường
                    foreach (ServiceUsedEN aTemp in aNewBookingHEN.aListBookingHallUsed[i].aListServiceUsed)
                    {
                        BookingHalls_Services aBookingHalls_Services = new BookingHalls_Services();
                        aBookingHalls_Services.Info = "";
                        aBookingHalls_Services.Type = 1;
                        aBookingHalls_Services.Status = 1;
                        aBookingHalls_Services.Disable = false;
                        aBookingHalls_Services.IDBookingHall = aBookingHall.ID;
                        aBookingHalls_Services.IDService = aTemp.IDService;
                        aBookingHalls_Services.Cost = aTemp.Cost;
                        aBookingHalls_Services.Date = aTemp.DateUsed;
                        aBookingHalls_Services.CostRef_Services = aTemp.CostRef_Service;
                        aBookingHalls_Services.PercentTax = 10;// de mac dinh
                        aBookingHalls_Services.Quantity = aTemp.Quantity;
                        aBookingHalls_ServicesBO.Insert(aBookingHalls_Services);

                    }
                    // Thêm thực đơn vào hội trường
                    foreach (MenusEN aMenuEN in aNewBookingHEN.aListBookingHallUsed[i].aListMenuEN)
                    {
                        aMenuEN.IDBookingHall = IDBookingHall;
                        aMenuEN.Type = 1; // type =1 ; thuc don mau ; Type 2: thuc don moi
                        aMenuEN.Status = 1; // de tam
                        aMenuEN.Disable = false; // de tam
                        aMenuEN.IDSystemUser = 1;//Khi kinh doanh thêm thực đơn mặc định trạng thái là 0 - đã xác nhận thực đơn
                        this.CreateMenus(aMenuEN);
                    }

                }

                return IDBookingH;

            }
            catch (Exception ex)
            {

                throw new Exception("ReceptionTaskBO.NewBookHall\n" + ex.ToString());
            }
        }
        public void LoadServiceInBookingHall(int IDBookingHall)
        {
            try
            {
                ServicesBO aServicesBO = new ServicesBO();
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                List<BookingHalls_Services> aListTemp = aBookingHalls_ServicesBO.Select_ByIDBookingHall(IDBookingHall);
                BookingHall_ServiceEN aBookingHall_ServiceEN;
                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aBookingHall_ServiceEN = new BookingHall_ServiceEN();
                    aBookingHall_ServiceEN.ID = aListTemp[i].ID;
                    aBookingHall_ServiceEN.Info = aListTemp[i].Info;
                    aBookingHall_ServiceEN.Type = aListTemp[i].Type;
                    aBookingHall_ServiceEN.Status = aListTemp[i].Status;
                    aBookingHall_ServiceEN.Disable = aListTemp[i].Disable;
                    aBookingHall_ServiceEN.IDBookingHall = aListTemp[i].IDBookingHall;
                    aBookingHall_ServiceEN.IDService = aListTemp[i].IDService;
                    aBookingHall_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
                    aBookingHall_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;

                    aBookingHall_ServiceEN.Cost = aListTemp[i].Cost == null ? aListTemp[i].CostRef_Services : aListTemp[i].Cost;
                    aBookingHall_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
                    aBookingHall_ServiceEN.Date = aListTemp[i].Date;
                    aBookingHall_ServiceEN.PercentTax = aListTemp[i].PercentTax;
                    aBookingHall_ServiceEN.Quantity = aListTemp[i].Quantity;

                    aBookingHall_ServiceEN.Tag = aListTemp[i].Tag;

                    aListSelected.Add(aBookingHall_ServiceEN);
                }
                dgvServiceInHall.DataSource = aListSelected;
                dgvServiceInHall.RefreshDataSource();

                CustomersBO aCustomersBO = new CustomersBO();
                BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
                List<Customers> aListCustomerRoom = new List<Customers>();
                List<Customers> aListCustomerHall = aCustomersBO.SelectListCustomer_ByIDBookingH(this.IDBookingHall);
                if (this.aNewPayment != null)
                {
                    if (this.aNewPayment.IDBookingR > 0)
                    {
                       aListCustomerRoom = aCustomersBO.SelectListCustomer_ByIDBookingR(this.aNewPayment.IDBookingR.GetValueOrDefault(0));
                    }
                }
                aListCustomerHall.AddRange(aListCustomerRoom);
                lueUserInHall.DataSource = aListCustomerHall;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_BookingHalls_Services.grvHalls_RowClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }