//Author: Linhting
 public int Insert(BookingHalls_Services BookingHalls_Services)
 {
     try
     {
         aDatabaseDA.BookingHalls_Services.Add(BookingHalls_Services);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("BookingHalls_ServicesBO.Insert:" + ex.ToString());
     }
 }
        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 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();
        }
        //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());
            }
        }