//Author : Linhting
        public void Insert(BookingHs bookingHs)
        {
            try
            {
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                aDatabaseDA.BookingHs.Add(bookingHs);
                aDatabaseDA.SaveChanges();
                aBookingHallsBO.AutoChangeStatusBookingHalls(bookingHs.ID);

            }
            catch (Exception ex)
            {
                throw new Exception("BookingHsBO.Insert:" + ex.ToString());
            }
        }
        //Author : Linhting
        public int InsertUnSync(BookingHs bookingHs)
        {
            try
            {
              //  bookingHs.ID = null;

                aDatabaseDA.BookingHs.Add(bookingHs);

                aDatabaseDA.SaveChanges();
                return bookingHs.ID;

            }
            catch (Exception ex)
            {
                throw new Exception("BookingHsBO.InsertUnSync:" + ex.ToString());
            }
        }
 public void SetValue(BookingHs aBookingHs)
 {
     this.ID = aBookingHs.ID;
     this.CreatedDate = aBookingHs.CreatedDate;
     this.CustomerType = aBookingHs.CustomerType;
     this.BookingType = aBookingHs.BookingType;
     this.Note = aBookingHs.Note;
     this.IDGuest = aBookingHs.IDGuest;
     this.PayMenthod = aBookingHs.PayMenthod;
     this.StatusPay = aBookingHs.StatusPay;
     this.BookingMoney = aBookingHs.BookingMoney;
     this.ExchangeRate = aBookingHs.ExchangeRate;
     this.Status = aBookingHs.Status;
     this.Type = aBookingHs.Type;
     this.Disable = aBookingHs.Disable;
     this.Level = aBookingHs.Level;
     this.Subject = aBookingHs.Subject;
     this.Description = aBookingHs.Description;
     this.IDCustomer = aBookingHs.IDCustomer;
     this.IDCustomerGroup = aBookingHs.IDCustomerGroup;
     this.IDSystemUser = aBookingHs.IDSystemUser;
 }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                    //Add du lieu cho BookingH
                    BookingHs aBookingHs = new BookingHs();
                    aBookingHs.ID = IDBookingH;
                    aBookingHs.Subject = txtSubject.Text;
                    aBookingHs.CreatedDate = this.aBookingHs.CreatedDate;
                    aBookingHs.CustomerType = this.aBookingHs.CustomerType;
                    aBookingHs.BookingType = Convert.ToInt16(lueBookingType.EditValue);
                    aBookingHs.Note = txtNote.Text;
                    aBookingHs.IDGuest = Convert.ToInt16(lueGuest.EditValue);
                    if (txtBookingMoney.Text == "")
                    {
                        aBookingHs.BookingMoney = 0;
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(1).ID;
                    }
                    else
                    {
                        aBookingHs.BookingMoney = Convert.ToDecimal(txtBookingMoney.Text);
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(2).ID;
                    }
                    aBookingHs.StatusPay = Convert.ToInt16(lueStatusPay.EditValue);
                    aBookingHs.Status = Convert.ToInt16(lueBookingStatus.EditValue);

                    aBookingHs.PayMenthod = 1;
                    if (cbbType.Text == "Tiệc không thuộc phạm trù nhà bếp")
                    {
                        aBookingHs.Type = 1;
                    }
                    else
                    {
                        aBookingHs.Type = 2;
                    }
                    aBookingHs.Disable = false;
                    aBookingHs.Level = Convert.ToInt16(lueLevel.EditValue);
                    aBookingHs.Description = "";
                    aBookingHs.IDCustomer = Convert.ToInt16(lueCustomer.EditValue);
                    aBookingHs.IDCustomerGroup = Convert.ToInt16(lueCustomerGroup.EditValue);
                    aBookingHs.IDSystemUser = 1;// Để tạm

                    //Add du lieu cho BookingHall
                    List<BookingHalls> aListBookingHall = new List<BookingHalls>();
                    BookingHalls aTemp;
                    for (int i = 0; i < aListSelected.Count; i++)
                    {
                        aTemp = new BookingHalls();
                        aTemp.CodeHall = aListSelected[i].Code;
                        aTemp.Cost = aListSelected[i].Cost;
                        aTemp.PercentTax = 10;
                        aTemp.CostRef_Halls = aListSelected[i].CostRef;
                        aTemp.Date = dtpFrom.DateTime;
                        IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
                        //DateTime Lunardate = DateTime.ParseExact(LunarDateExt.ToLunarDate(dtpFrom.DateTime, 7).ToString(), "dd/MM/yyyy", theCultureInfo);
                        //aTemp.LunarDate = Lunardate;
                        aTemp.BookingStatus = null;
                        aTemp.Unit = aListSelected[i].Unit;
                        aTemp.TableOrPerson = aListSelected[i].TableOrPerson;
                        aTemp.Note = "";
                        aTemp.Status = Convert.ToInt16(lueBookingStatus.EditValue);
                        aTemp.StartTime = !string.IsNullOrEmpty(tedStart.Time.ToString()) ? tedStart.Time.TimeOfDay : TimeSpan.Zero;
                        aTemp.EndTime = !string.IsNullOrEmpty(tedEnd.Time.ToString()) ? tedEnd.Time.TimeOfDay : TimeSpan.Zero;

                        aListBookingHall.Add(aTemp);
                    }
                    aReceptionTaskBO.UpdateCheckIn(aBookingHs, aListBookingHall);
                    if (afrmTsk_ManageBookingHs != null)
                    {
                        afrmTsk_ManageBookingHs.ReloadData();
                    }
                    else if (afrmMain_Halls != null)
                    {
                        afrmMain_Halls.ReloadData();
                    }
                    MessageBox.Show("Đặt hội trường thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_UpdBooking.CheckIn\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadData()
        {
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            HallsEN aTemp;
            aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);
            HallsBO aHallsBO = new HallsBO();
            List<BookingHalls> aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(IDBookingH);
            //Fill data for BookingH
            txtSubject.Text = aBookingHs.Subject;
            txtBookingMoney.Text = String.Format("{0:0,0}", aBookingHs.BookingMoney);
            txtNote.Text = aBookingHs.Note;
            //Fill data for BookingHall
            dtpFrom.DateTime = Convert.ToDateTime(aListBookingHalls[0].Date);
               //tedEnd.Time = DateTime.Parse( aListBookingHalls[0].EndTime.ToString());
            //tedStart.Time = DateTime.Parse(aListBookingHalls[0].StartTime.ToString());

            for (int i = 0; i < aListBookingHalls.Count; i++)
            {
                aTemp = new HallsEN();
                aTemp.IDBookingHall = aListBookingHalls[i].ID;
                aTemp.Code = aListBookingHalls[i].CodeHall;
                aTemp.Sku = aHallsBO.Select_ByCodeHall(aListBookingHalls[i].CodeHall, 1).Sku;
                aTemp.CostRef = aListBookingHalls[i].CostRef_Halls;
                aTemp.Type = aHallsBO.Select_ByCodeHall(aListBookingHalls[i].CodeHall, 1).Type;
                aTemp.TypeDisplay = CORE.CONSTANTS.SelectedHallType(Convert.ToInt32(aTemp.Type)).Name;
                aTemp.Cost = aListBookingHalls[i].Cost;
                aTemp.TableOrPerson = aListBookingHalls[i].TableOrPerson;
                aTemp.Unit = aListBookingHalls[i].Unit;
                aListSelected.Add(aTemp);
            }
            dgvSelectedHalls.DataSource = aListSelected;
            dgvSelectedHalls.RefreshDataSource();
        }
 public bool CreateBookingHs(DateTime createdate, int cusomertype, int bookingtype, string note, int paymethod,
     int statuspay, decimal bookingmoney, int sysuserid, int guestid, int customerid, int groupid, int level, string subject, int status)
 {
     try
     {
         var bhs = new BookingHs
                   {
                       CreatedDate = createdate,
                       CustomerType = cusomertype,
                       BookingType = bookingtype,
                       Note = note,
                       PayMenthod = paymethod,
                       StatusPay = statuspay,
                       BookingMoney = bookingmoney,
                       IDSystemUser = sysuserid,
                       IDGuest = guestid,
                       IDCustomer = customerid,
                       IDCustomerGroup = groupid,
                       Subject = subject,
                       Level = level
                   };
         aDatabaseDA.BookingHs.Add(bhs);
         aDatabaseDA.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         throw new Exception("BookingHallsBO.CreateBookingHs\n" + ex.ToString());
         return false;
     }
 }
        // ===============================================================================
        // 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();
            }
        }
        private void btnCheckIn_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                    //Add du lieu cho BookingH
                    BookingHs aBookingHs = new BookingHs();
                    aBookingHs.Subject = txtSubject.Text;
                    aBookingHs.CreatedDate = DateTime.Now;
                    aBookingHs.CustomerType = 2;
                    aBookingHs.BookingType = Convert.ToInt32(lueBookingType.EditValue);
                    aBookingHs.Note = txtNote.Text;
                    aBookingHs.IDGuest = Convert.ToInt32(lueGuest.EditValue);
                    if (txtBookingMoney.Text == "")
                    {
                        aBookingHs.BookingMoney = 0;
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(1).ID;
                    }
                    else
                    {
                        aBookingHs.BookingMoney = Convert.ToDecimal(txtBookingMoney.Text);
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(2).ID;
                    }
                    aBookingHs.StatusPay = Convert.ToInt32(lueStatusPay.EditValue);
                    aBookingHs.Status = Convert.ToInt32(lueBookingStatus.EditValue);
                    aBookingHs.PayMenthod = 1;
                    if (cbbType.Text == "Tiệc không thuộc phạm trù nhà bếp")
                    {
                        aBookingHs.Type = 1;
                    }
                    else
                    {
                        aBookingHs.Type = 2;
                    }
                    aBookingHs.Disable = false;
                    aBookingHs.Description = "";
                    aBookingHs.IDCustomer = Convert.ToInt32(lueCustomer.EditValue);
                    aBookingHs.IDCustomerGroup = Convert.ToInt32(lueCustomerGroup.EditValue);
                    aBookingHs.IDSystemUser = CORE.CURRENTUSER.SystemUser.ID;

                    //Add du lieu cho BookingHall
                    List<BookingHalls> aListBookingHall = new List<BookingHalls>();
                    BookingHalls aTemp;
                    for (int i = 0; i < aListSelected.Count; i++)
                    {
                        aTemp = new BookingHalls();
                        aTemp.CodeHall = aListSelected[i].Code;
                        aTemp.Cost = aListSelected[i].Cost;
                        aTemp.PercentTax = 10;
                        aTemp.CostRef_Halls = aListSelected[i].CostRef;
                        aTemp.Date = DateTime.Now;
                        IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
                        DateTime Lunardate = DateTime.ParseExact(Convert.ToString(LunarDateExt.ToLunarDate(DateTime.Now, 7)), "d/M/yyyy", theCultureInfo);
                        aTemp.LunarDate = Lunardate;
                        aTemp.BookingStatus = null;
                        aTemp.Unit = aListSelected[i].Unit;
                        aTemp.TableOrPerson = aListSelected[i].TableOrPerson;
                        aTemp.Note = "";
                        aTemp.Status = Convert.ToInt32(lueBookingStatus.EditValue);
                        aTemp.StartTime = !string.IsNullOrEmpty(tedStart.Time.ToString()) ? tedStart.Time.TimeOfDay : TimeSpan.Zero;
                        aTemp.EndTime = !string.IsNullOrEmpty(tedEnd.Time.ToString()) ? tedEnd.Time.TimeOfDay : TimeSpan.Zero;

                        aListBookingHall.Add(aTemp);
                    }
                    this.IDBookingH = aReceptionTaskBO.CheckIn(aBookingHs, aListBookingHall);

                    //Hiennv
                    if (this.IDBookingR > 0)
                    {
                        BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();

                        BookingRs_BookingHs aBookingRs_BookingHs = new BookingRs_BookingHs();
                        aBookingRs_BookingHs.IDBookingR = this.IDBookingR;
                        aBookingRs_BookingHs.IDBookingH = this.IDBookingH;
                        aBookingRs_BookingHs.Type = String.Empty;
                        aBookingRs_BookingHs.Status = String.Empty;
                        aBookingRs_BookingHs.Disable = false;
                        aBookingRs_BookingHs.Extension1 = String.Empty;
                        aBookingRs_BookingHs.Extension2 = String.Empty;
                        aBookingRs_BookingHs.Extension3 = String.Empty;

                        aBookingRs_BookingHsBO.Insert(aBookingRs_BookingHs);

                    }

                    MessageBox.Show("Đặt hội trường thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult result = MessageBox.Show("Bạn có thêm dịch vụ cho hội trường " + aBookingHs.Subject + " này không?", "Thêm dịch vụ hội trường", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        //frmTsk_Payment_Step2 afrmTsk_Payment_Step2 = new frmTsk_Payment_Step2(Convert.ToInt32(this.IDBookingR), Convert.ToInt32(this.IDBookingH));
                        //afrmTsk_Payment_Step2.ShowDialog();
                    }
                    if (afrmMain_Halls != null)
                    {
                        this.afrmMain_Halls.ReloadData();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_BookingHall_Group.CheckIn\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void txtSubject_Leave(object sender, EventArgs e)
        {
            int IDBookingR = Convert.ToInt32(grvPaymentViewAll.GetFocusedRowCellValue("BookingRs_ID"));
            string ObjectType = grvPaymentViewAll.GetFocusedRowCellValue("ObjectType").ToString();
            string Subject = grvPaymentViewAll.GetFocusedRowCellValue("Subject").ToString();

            if (ObjectType == "Phòng")
            {
                BookingRs aItem = new BookingRs();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                aItem = aBookingRsBO.Select_ByID(IDBookingR);
                aItem.Subject = Subject;
                aBookingRsBO.Update(aItem);
                this.LoadData();
            }
            else
            {
                BookingHs aItem = new BookingHs();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
                int IDBookingH = aBookingRs_BookingHsBO.Select_ByIDBookingR(IDBookingR).IDBookingH.GetValueOrDefault(0);

                aItem = aBookingHsBO.Select_ByID(IDBookingH);
                aItem.Subject = Subject;
                aBookingHsBO.Update(aItem);
                this.LoadData();
            }
        }
        //Author : Linhting
        public int UpdateUnSync(BookingHs bookingHs)
        {
            try
            {
                aDatabaseDA.BookingHs.AddOrUpdate(bookingHs);
                return aDatabaseDA.SaveChanges();

            }
            catch (Exception ex)
            {

                throw new Exception("BookingHsBO.UpdateUnSync:" + ex.ToString());
            }
        }
        //Author: Linhting
        public int CheckIn(BookingHs BookingHs, List<BookingHalls> ListBookingHalls)
        {
            try
            {
                BookingHs aBookingHs = new BookingHs();

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

                //add new bookingRs
                BookingHsBO aBookingHsBO = new BookingHsBO();
                int IDBookingH = aBookingHsBO.InsertUnSync(aBookingHs);

                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                BookingHalls aBookingHall;
                for (int i = 0; i < ListBookingHalls.Count; i++)
                {
                    aBookingHall = new BookingHalls();
                    aBookingHall.IDBookingH = IDBookingH;
                    aBookingHall.CodeHall = ListBookingHalls[i].CodeHall;
                    aBookingHall.Cost = ListBookingHalls[i].Cost;
                    aBookingHall.PercentTax = ListBookingHalls[i].PercentTax;
                    aBookingHall.CostRef_Halls = ListBookingHalls[i].CostRef_Halls;
                    aBookingHall.Date = ListBookingHalls[i].Date;
                    aBookingHall.LunarDate = ListBookingHalls[i].LunarDate;
                    aBookingHall.BookingStatus = ListBookingHalls[i].BookingStatus;
                    aBookingHall.Unit = ListBookingHalls[i].Unit;
                    aBookingHall.TableOrPerson = ListBookingHalls[i].TableOrPerson;
                    aBookingHall.Note = ListBookingHalls[i].Note;
                    aBookingHall.Status = ListBookingHalls[i].Status;
                    aBookingHall.StartTime = ListBookingHalls[i].StartTime;
                    aBookingHall.EndTime = ListBookingHalls[i].EndTime;
                    aBookingHall.Location = ListBookingHalls[i].Location;
                    aBookingHall.Color = ListBookingHalls[i].Color;

                    aBookingHallsBO.InsertUnSync(aBookingHall);
                }

                return IDBookingH;

            }
            catch (Exception ex)
            {

                throw new Exception("ReceptionTaskBO.CheckIn\n" + ex.ToString());
            }
        }
        //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());
            }
        }