public void DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(int IDBookingRs)
 {
     CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
     CustomerGroups aCustomerGroups = new CustomerGroups();
     aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);
     List<CustomerGroups_Customers> aCustomerGroups_Customers = this.Select_ByIDCustomerGroup(aCustomerGroups.ID);
     foreach (CustomerGroups_Customers item in aCustomerGroups_Customers)
     {
         this.Delete(item);
     }
 }
        public void ReloadData()
        {
            try
            {
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                List<CustomerGroups> aListCustomerGroup = new List<CustomerGroups>();
                dgvAvailableCustomerGroups.DataSource = null;

             if (afrmIns_CustomerGroups_Customers_Old != null)
                {
                    aListCustomerGroup = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
                    btnAdd.Visible = false;
                }
             else if (afrmTsk_BookingHall_Goverment_Old != null)
                {
                 aListCustomerGroup = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
                 btnAdd.Visible = false;
                }
             else if (this.afrmTsk_BookingHall_Group != null)
             {
                 aListCustomerGroup = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
                 btnAdd.Visible = false;
             }
             else if (this.afrmTsk_UpdBooking != null)
             {
                 aListCustomerGroup = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
                 btnAdd.Visible = false;
             }
                else
                {
                    aListCustomerGroup = aCustomerGroupsBO.Select_All();
                    btnAdd.Visible = true;
                    colFill.Visible = false;
                }
                dgvAvailableCustomerGroups.DataSource = aListCustomerGroup;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmLst_CustomerGroups.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
            }
        }
        public int InsertCustomerIntoCustomerGroup(int IDCustomer, int IDCustomerGroup)
        {
            // Add customer vao group
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByID(IDCustomerGroup);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();

            aCustomerGroups_Customers = aCustomerGroups_CustomersBO.Select_ByIDCustomer_ByIDCustomerGroup(IDCustomer, IDCustomerGroup);
            if (aCustomerGroups_Customers == null)
            {
                Customers aCustomers = (new CustomersBO()).Select_ByID(IDCustomer);
                aCustomerGroups_Customers.IDCustomer = IDCustomer;
                aCustomerGroups_Customers.IDCustomerGroup = aCustomerGroups.ID;
                aCustomerGroups_Customers.Name = aCustomerGroups.Name + "_" + aCustomers.Name + "_" + aCustomers.Identifier1 + "_" + DateTime.Now.ToShortDateString();
                return aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
            }
            else
                return 0;
        }
        private void lueIDCompanies_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (lueIDCompanies.EditValue == null)
                {
                    MessageBox.Show("Vui lòng chọn tên công ty.");
                    lueIDCompanies.Focus();
                    return;
                }
                BookingRsBO abookingRsBO = new BookingRsBO();
                BookingRs abookingRs = new BookingRs();
                List<PaymentExt_GetAllDataEN> aListPaymentExt_GetAllDataEN = new List<PaymentExt_GetAllDataEN>();
                int IDCompany = Convert.ToInt32(lueIDCompanies.EditValue.ToString());

                CustomerGroupsBO aCustomerGroupBO = new CustomerGroupsBO();
                List<int> aListIDCustomerGroup = aCustomerGroupBO.Select_All().Where(x => x.IDCompany == IDCompany).Select(p => p.ID).ToList();

                List<int> ListIDBookingR = abookingRsBO.Select_ByListCustomerGroup(aListIDCustomerGroup).Select(p => p.ID).ToList();

                PaymentBO aPaymentBO = new PaymentBO();
                List<sp_PaymentExt_GetAllData_Result> aListTemp = aPaymentBO.Search_ServicesStatus_ObjectStatus_BillRPaymentStatusByCompany(ListIDBookingR);
                PaymentExt_GetAllDataEN aPaymentExt_GetAllDataEN;

                foreach (sp_PaymentExt_GetAllData_Result item in aListTemp)
                {
                    BookingRooms aBookingRoom = aBookingRoomBO.Select_ByIDBookingR(item.BookingRs_ID);

                    decimal? cost = aBookingRoom.Cost;
                    if (cost == null)
                    {
                        cost = 0;
                    }
                    double? addTimeStart = aBookingRoom.AddTimeStart;
                    if (addTimeStart == null)
                    {
                        addTimeStart = 0;
                    }
                    double? addTimeEnd = aBookingRoom.AddTimeEnd;
                    if (addTimeEnd == null)
                    {
                        addTimeEnd = 0;
                    }

                    decimal? timeUser = aBookingRoom.TimeInUse;
                    if (timeUser == null)
                    {
                        timeUser = 0;
                    }
                    double? costPendingRoom = aBookingRoom.CostPendingRoom;
                    if (costPendingRoom == null)
                    {
                        costPendingRoom = 0;
                    }
                    double? tax = aBookingRoom.PercentTax;
                    if (tax == null)
                    {
                        tax = 0;
                    }
                    decimal? sum = CalculatorMoneyRoom(cost, addTimeStart, addTimeEnd, timeUser);

                    // Tinh pending
                    aPaymentExt_GetAllDataEN = new PaymentExt_GetAllDataEN();
                    aPaymentExt_GetAllDataEN.SetValue(item);
                    if (item.IDService == null)
                    {
                        aPaymentExt_GetAllDataEN.DisplayService_PaymentStatus = "";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayService_PaymentStatus = "Đã thanh toán";
                    }
                    if (item.BillR_PaymentStatus == 8)
                    {
                        aPaymentExt_GetAllDataEN.DisplayBillR_PaymentStatus = "Đã thanh toán";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayBillR_PaymentStatus = "Chưa thanh toán";
                    }
                    if (item.Object_PaymentStatus == 8)
                    {
                        aPaymentExt_GetAllDataEN.DisplayObject_PaymentStatus = "Đã thanh toán";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayObject_PaymentStatus = "Chưa thanh toán";

                    }

                    aPaymentExt_GetAllDataEN.DisplayMoneySumRoom = sum;
                    aListPaymentExt_GetAllDataEN.Add(aPaymentExt_GetAllDataEN);
                }
                dgvPaymentViewUnPay.DataSource = aListPaymentExt_GetAllDataEN;
                dgvPaymentViewUnPay.RefreshDataSource();

            }
            catch (Exception ex)
            {
                throw new Exception("frmTsk_UnPay " + ex.ToString());
            }
        }
        // ===============================================================================
        // 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();
            }
        }
        // Author : Linhting
        public void LoadCustomerInfo()
        {
            try
            {
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CompaniesBO aCompaniesBO = new CompaniesBO();
                int IDCustomer = aBookingHsBO.Select_ByID(this.IDBookingH).IDCustomer;
                int IDCustomerGroup = aBookingHsBO.Select_ByID(this.IDBookingH).IDCustomerGroup;

                lblCompany.Text = aCompaniesBO.Select_ByIDCustomerGroup(IDCustomerGroup).Name;
                lblNameCustomerGroup.Text = aCustomerGroupsBO.Select_ByID(IDCustomerGroup).Name;
                lblNameCustomer.Text = aCustomersBO.Select_ByID(IDCustomer).Name;
            }
            catch (Exception ex)
            {

                MessageBox.Show("frmTsk_PaymentHall.LoadCustomerInfo\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // Author : Linhting
        public void InitData( int IDBookingH)
        {
            try
            {
                CompaniesBO aCompaniesBO = new CompaniesBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                SystemUsersBO aSystemUsersBO = new SystemUsersBO();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                HallsBO aHallsBO = new HallsBO();
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                FoodsBO aFoodsBO = new FoodsBO();

                BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);

                    // Truyen du lieu cho List BookingRoom cua NewPayment

                    if (aBookingHs != null)
                    {
                         aNewPaymentEN.IDCustomer = aBookingHs.IDCustomer;
                    Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                    if (aCustomers != null)
                    {
                        aNewPaymentEN.NameCustomer = aCustomers.Name;
                    }
                    aNewPaymentEN.IDSystemUser = aBookingHs.IDSystemUser;
                    SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                    if (aSystemUsers != null)
                    {
                        aNewPaymentEN.NameSystemUser = aSystemUsers.Name;
                    }
                    aNewPaymentEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                    CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.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.IDBookingH = aBookingHs.ID;
                        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);

                                List<ServiceUsedEN> aListServiceTemp = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(item.ID);
                                foreach (ServiceUsedEN aTemp in aListServiceTemp)
                                {
                                    aBookingHallUsedEN.aListServiceUsed.Add(aTemp);
                                }
                                aNewPaymentEN.aListBookingHallUsed.Add(aBookingHallUsedEN);
                            }
                        }
                    }

                }

            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PaymentHall.InitData\n" + ex.ToString());
            }
        }
        public int DeleteCustomerFromCustomerGroup_ByIDBookingRs(int IDCustomer, int IDBookingRs)
        {
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();

            return aCustomerGroups_CustomersBO.Delete(IDCustomer, aCustomerGroups.ID);
        }
        //Hiennv     26/11/2014     Viet lai phuong thuc checkInForRoomBooking
        public bool NewCheckInForRoomBooking(CheckInEN aCheckInEN)
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                List<Customers> aListCustomersTemp = aCustomersBO.Select_All();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRoomTemp = aBookingRoomsBO.Select_All();

                int IDBookingRooms = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;
                int Result = 0;

                string customerType = string.Empty;

                if (aCheckInEN.CustomerType == 0)
                {
                    customerType = "Tất cả loại khác";
                }
                else if (aCheckInEN.CustomerType == 1)
                {
                    customerType = "Khách nhà nước";
                }
                else if (aCheckInEN.CustomerType == 2)
                {
                    customerType = "Khách đoàn";
                }
                else if (aCheckInEN.CustomerType == 3)
                {
                    customerType = "Khách lẻ";
                }
                else if (aCheckInEN.CustomerType == 4)
                {
                    customerType = "Khách vãng lai";
                }
                else if (aCheckInEN.CustomerType == 5)
                {
                    customerType = "Khách bộ ngoại giao";
                }
                else
                {
                    customerType = string.Empty;
                }

                #region Them moi cong ty khi cong ty chua co
                if (aCheckInEN.IDCompany > 0)
                {
                    IDCompany = aCheckInEN.IDCompany;
                }
                else
                {
                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    Companies aCompanies = new Companies();
                    if (aCheckInEN.NameCompany.Length > 250)
                    {
                        aCompanies.Name = aCheckInEN.NameCompany.Substring(0, 250);
                    }
                    else
                    {
                        aCompanies.Name = aCheckInEN.NameCompany;
                    }

                    aCompanies.TaxNumberCode = string.Empty;
                    aCompanies.Address = string.Empty;
                    aCompanies.Type = aCheckInEN.CustomerType;
                    aCompanies.Status = 1;
                    aCompanies.Disable = false;
                    IDCompany = aCompaniesBO.Insert(aCompanies);
                }
                #endregion

                #region Them moi nhom vao trong cong ty
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomerGroups aCustomerGroups;
                aCustomerGroups = aCustomerGroupsBO.Select_ByIDCompanyAndIDCustomerGroup(IDCompany, aCheckInEN.IDCustomerGroup);

                if (aCustomerGroups == null)
                {

                    aCustomerGroups = new CustomerGroups();

                    string nameGroup = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]";
                    aCustomerGroups.IDCompany = IDCompany;
                    if (nameGroup.Length > 250)
                    {
                        aCustomerGroups.Name = nameGroup.Substring(0, 250);
                    }
                    else
                    {
                        aCustomerGroups.Name = nameGroup;
                    }

                    aCustomerGroups.Type = 1;
                    aCustomerGroups.Status = 1;
                    aCustomerGroups.Disable = false;
                    IDCustomerGroup = aCustomerGroupsBO.Insert(aCustomerGroups);
                }
                else
                {
                    IDCustomerGroup = aCheckInEN.IDCustomerGroup;
                }
                #endregion

                string subject = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]";

                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                if (aBookingRs != null)
                {
                    aBookingRs.CreatedDate = DateTime.Now;
                    aBookingRs.CustomerType = aCheckInEN.CustomerType;
                    aBookingRs.BookingType = aCheckInEN.BookingType;
                    if (subject.Length > 250)
                    {
                        aBookingRs.Subject = subject.Substring(0, 250);
                    }
                    else
                    {
                        aBookingRs.Subject = subject;
                    }

                    aBookingRs.IDCustomerGroup = IDCustomerGroup;
                    aBookingRs.IDCustomer = aCheckInEN.IDCustomer;
                    aBookingRs.IDSystemUser = aCheckInEN.IDSystemUser;
                    aBookingRs.PayMenthod = aCheckInEN.PayMenthod;
                    aBookingRs.StatusPay = aCheckInEN.StatusPay;
                    aBookingRs.BookingMoney = aCheckInEN.BookingMoney;
                    aBookingRs.ExchangeRate = aCheckInEN.ExchangeRate;
                    aBookingRs.Level = 0;// de mac dinh hien tai chua dung den
                    aBookingRs.Note = string.Empty;
                    aBookingRs.Description = string.Empty;
                    aBookingRs.DatePay = aCheckInEN.CheckOutPlan;
                    aBookingRs.DateEdit = aCheckInEN.CheckInActual;
                    aBookingRs.Status = aCheckInEN.Status;
                    aBookingRs.Type = aCheckInEN.Type;
                    aBookingRs.Disable = aCheckInEN.Disable;
                    aBookingRsBO.Update(aBookingRs);
                }

                //==========================================================
                BookingRooms aBookingRooms;
                BookingRoomsMembers aBookingRoomsMembers;

                for (int i = 0; i < aCheckInEN.aListRoomMembers.Count; i++)
                {

                    List<BookingRooms> aListBookingRoom = aListBookingRoomTemp.Where(r => r.ID == aCheckInEN.aListRoomMembers[i].IDBookingRooms).ToList();
                    if (aListBookingRoom.Count > 0)
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms = aListBookingRoom[0];
                        aBookingRooms.IDBookingR = aCheckInEN.IDBookingR;
                        aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckInActual = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual;
                        aBookingRooms.StartTime = aCheckInEN.CheckInActual;
                        aBookingRooms.EndTime = aCheckInEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aCheckInEN.Status;
                        aBookingRooms.PriceType = "G1";
                        aBookingRoomsBO.Update(aBookingRooms);

                        IDBookingRooms = aCheckInEN.aListRoomMembers[i].IDBookingRooms;
                    }
                    else
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms.IDBookingR = aCheckInEN.IDBookingR;
                        aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckInActual = aCheckInEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual;
                        aBookingRooms.StartTime = aCheckInEN.CheckInActual;
                        aBookingRooms.EndTime = aCheckInEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aCheckInEN.Status;
                        aBookingRooms.PriceType = "G1";
                        //add new bookingRoom
                        IDBookingRooms = aBookingRoomsBO.Insert(aBookingRooms);
                    }

                    //-----------------------------------------------------------
                    aBookingRoomsMembers = new BookingRoomsMembers();
                    aBookingRoomsMembers.IDBookingRoom = IDBookingRooms;

                    BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                    for (int ii = 0; ii < aCheckInEN.aListRoomMembers[i].ListCustomer.Count; ii++)
                    {
                        Customers aCustomers;
                        List<Customers> aListCustomers = aListCustomersTemp.Where(c => c.ID == aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID).ToList();
                        if (aListCustomers.Count > 0)
                        {
                            IDCustomer = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID;
                            aCustomers = aListCustomers[0];
                            aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name;
                            aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1;
                            aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday;
                            aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender;
                            aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel;
                            aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality;
                            aCustomersBO.Update(aCustomers);
                        }
                        else
                        {
                            aCustomers = new Customers();
                            aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name;
                            aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1;
                            aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday;
                            aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender;
                            aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel;
                            aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality;

                            //Them moi khach hang
                            IDCustomer = aCustomersBO.Insert(aCustomers);
                        }
                        aBookingRoomsMembers.IDCustomer = IDCustomer;
                        aBookingRoomsMembers.PurposeComeVietnam = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PurposeComeVietnam;
                        aBookingRoomsMembers.DateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].DateEnterCountry;
                        aBookingRoomsMembers.EnterGate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].EnterGate;
                        aBookingRoomsMembers.TemporaryResidenceDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].TemporaryResidenceDate;
                        aBookingRoomsMembers.LimitDateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LimitDateEnterCountry;
                        aBookingRoomsMembers.Organization = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Organization;
                        aBookingRoomsMembers.LeaveDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LeaveDate;

                        //add new bookingRoomMember
                        aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);

                        #region  them nguoi vao trong customergroup_customer

                        string nameCustomerGroup_customer = "[" + customerType + "][" + aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name + "]";

                        CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                        CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();
                        if (nameCustomerGroup_customer.Length > 150)
                        {
                            aCustomerGroups_Customers.Name = nameCustomerGroup_customer.Substring(0, 150);
                        }
                        else
                        {
                            aCustomerGroups_Customers.Name = nameCustomerGroup_customer;
                        }

                        aCustomerGroups_Customers.Type = 1;
                        aCustomerGroups_Customers.Status = 1;
                        aCustomerGroups_Customers.Disable = false;
                        aCustomerGroups_Customers.FromDate = DateTime.Now;
                        aCustomerGroups_Customers.ToDate = DateTime.Now;
                        aCustomerGroups_Customers.IDCustomer = IDCustomer;
                        aCustomerGroups_Customers.IDCustomerGroup = IDCustomerGroup;
                        aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
                        #endregion

                        // dung de cap nhap lai nguoi dai dien khi dat phong
                        if (aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PepoleRepresentative == true)
                        {
                            aBookingRsBO = new BookingRsBO();
                            aBookingRs = new BookingRs();
                            aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                            if (aBookingRs != null)
                            {
                                aBookingRs.IDCustomer = IDCustomer;
                                Result = aBookingRsBO.Update(aBookingRs);
                            }

                        }
                        else
                        {
                            if (ii == (aCheckInEN.aListRoomMembers[i].ListCustomer.Count - 1))
                            {
                                if (Result == 0)
                                {
                                    aBookingRsBO = new BookingRsBO();
                                    aBookingRs = new BookingRs();
                                    aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR);
                                    if (aBookingRs != null)
                                    {
                                        aBookingRs.IDCustomer = IDCustomer;
                                        aBookingRsBO.Update(aBookingRs);
                                    }
                                }
                            }
                        }

                    }
                }
                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    aCustomerGroups.IDCompany = Convert.ToInt32(lueCompany.EditValue);
                    aCustomerGroups.Name = txtName.Text;
                    aCustomerGroups.Type = cboType.SelectedIndex + 1;
                    aCustomerGroups.Status = cboStatus.SelectedIndex + 1;
                    aCustomerGroups.Disable = bool.Parse(cboDisable.Text);
                    aCustomerGroupsBO.Insert(aCustomerGroups);

                    if (this.afrmLst_CustomerGroups_Old != null)
                    {
                        afrmLst_CustomerGroups_Old.ReloadData();
                    }
                    else if (afrmIns_CustomerGroups_Customers_Old != null)
                    {
                        afrmIns_CustomerGroups_Customers_Old.Reload();
                    }
                    else if (afrmTsk_BookingHall_Goverment_Old != null)
                    {
                        afrmTsk_BookingHall_Goverment_Old.ReloadData();
                    }
                    else if (afrmTsk_BookingHall_Group != null)
                    {
                        this.afrmTsk_BookingHall_Group.ReloadData();
                    }
                    else if (afrmTsk_BookingHall_Customer != null)
                    {
                        this.afrmTsk_BookingHall_Customer.ReloadData();
                    }
                    else if (afrmTsk_UpdBooking != null)
                    {
                        this.afrmTsk_UpdBooking.ReloadData();
                    }
                    this.Close();
                    MessageBox.Show("Thêm mới thành công .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_CustomerGroups.btnAddNew_Click\n" + ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

                aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRooms);
                if (aBookingRooms != null)
                {
                    lblCheckIn.Text = aBookingRooms.CheckInActual.ToString("dd/MM/yyyy HH:mm");
                    lblCheckOut.Text = aBookingRooms.CheckOutPlan.ToString("dd/MM/yyyy HH:mm");
                    lblRoomSku.Text = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom,1).Sku;
                }
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                if (aBookingRs != null)
                {
                    lblCustomerType.Text = CORE.CONSTANTS.SelectedCustomerType(Convert.ToInt32(aBookingRs.CustomerType)).Name;

                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    lblCompany.Text = aCompaniesBO.Select_ByIDBookingRoom(this.IDBookingRooms).Name;

                    lblCustomer.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Name;

                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    lblGroup.Text = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup).Name;

                    lblTel.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Tel;

                    this.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                }
                dgvAvaiableRooms.DataSource = this.LoadListAvailableRooms(aBookingRooms.CheckInActual, aBookingRooms.CheckOutPlan);
                dgvAvaiableRooms.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ResetFormWhenTimeChange()
        {
            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

            CustomersBO aCustomersBO = new CustomersBO();
            CustomerInfoEN aCustomers = new CustomerInfoEN();
            aCustomers = new CustomerInfoEN (aCustomersBO.Select_ByID(aBookingRs.IDCustomer));

            lblCustomer.Text = aCustomers.Name;
            lblTel.Text = aCustomers.Tel;

            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
            lblGroup.Text = aCustomerGroups.Name;

            CompaniesBO aCompaniesBO = new CompaniesBO();
            lblCompany.Text = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany).Name;

            // Fill All Customer

            dgvAvailableCustomers.DataSource = ConvertListCustomer ((new CustomersBO()).Select_All());

            lueRooms.Properties.DataSource = this.GetAvaiableRoom();
            lueRooms.Properties.ValueMember = "Code";
            lueRooms.Properties.DisplayMember = "Sku";

            RoomsBO aRoomsBO = new RoomsBO();
            Rooms aRooms = new Rooms();
            aRooms = aRoomsBO.Select_ByCodeRoom(this.aBookingRoom.CodeRoom, 1);

            lueRooms.Properties.NullText = aRooms.Sku;
            lueRooms.SelectedText = aRooms.Sku;
            lueRooms.EditValue = aRooms.Code;

            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom (this.aBookingRoom.ID);

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);
        }
        private void InitForm()
        {
            // Kiem tra xem phong dang o che do checkIn hay book phong
            if (this.aBookingRoom.Status < 3)
            {
                dtpCheckIn.Text = aBookingRoom.CheckInPlan.ToString();

                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }
            else if (this.aBookingRoom.Status == 3)  // Phong da checkIn
            {
                dtpCheckIn.Text = DateTime.Now.ToString();
                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }

            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

            CustomersBO aCustomersBO = new CustomersBO();
            CustomerInfoEN aCustomers = new CustomerInfoEN();
            aCustomers = new CustomerInfoEN (aCustomersBO.Select_ByID(aBookingRs.IDCustomer));

            lblCustomer.Text = aCustomers.Name;
            lblTel.Text = aCustomers.Tel;

            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
            lblGroup.Text = aCustomerGroups.Name;

            CompaniesBO aCompaniesBO = new CompaniesBO();
            lblCompany.Text = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany).Name;

            // Fill All Customer

            dgvAvailableCustomers.DataSource = ConvertListCustomer ((new CustomersBO()).Select_All());

            lueRooms.Properties.DataSource = this.GetAvaiableRoom();
            lueRooms.Properties.ValueMember = "Code";
            lueRooms.Properties.DisplayMember = "Sku";

            RoomsBO aRoomsBO = new RoomsBO();
            Rooms aRooms = new Rooms();
            aRooms = aRoomsBO.Select_ByCodeRoom(this.aBookingRoom.CodeRoom, 1);

            lueRooms.Properties.NullText = aRooms.Sku;
            lueRooms.SelectedText = aRooms.Sku;
            lueRooms.EditValue = aRooms.Code;

            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom (this.aBookingRoom.ID);

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);

            //this.aChangeRoomEn.InsertItemChangeRooms()
        }
        //Hiennv     26/11/2014       ham dung de load toan bo du lieu theo IDBookingR
        public CheckInEN InitData(int IDBookingR)
        {
            try
            {
                CheckInEN aCheckInEN = new CheckInEN();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                if(aBookingRs != null)
                {
                    aCheckInEN.IDBookingR = aBookingRs.ID;
                    aCheckInEN.CustomerType = aBookingRs.CustomerType.GetValueOrDefault();
                    aCheckInEN.BookingType = aBookingRs.BookingType.GetValueOrDefault();
                    aCheckInEN.Note = aBookingRs.Note;
                    aCheckInEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                    aCheckInEN.IDCustomer = aBookingRs.IDCustomer;
                    aCheckInEN.IDSystemUser = aBookingRs.IDSystemUser;
                    aCheckInEN.PayMenthod = aBookingRs.PayMenthod.GetValueOrDefault();
                    aCheckInEN.StatusPay = aBookingRs.StatusPay.GetValueOrDefault();
                    aCheckInEN.BookingMoney = aBookingRs.BookingMoney.GetValueOrDefault();
                    aCheckInEN.ExchangeRate = aBookingRs.ExchangeRate.GetValueOrDefault();
                    aCheckInEN.Status = aBookingRs.Status.GetValueOrDefault();
                    aCheckInEN.Type = aBookingRs.Type.GetValueOrDefault();
                    aCheckInEN.Disable = aBookingRs.Disable.GetValueOrDefault();
                    aCheckInEN.Level = aBookingRs.Level;
                    aCheckInEN.Subject = aBookingRs.Subject;
                    aCheckInEN.Description = aBookingRs.Description;
                    aCheckInEN.DatePay = aBookingRs.DatePay;
                    aCheckInEN.DateEdit = aBookingRs.DateEdit;
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                    if(aCustomerGroups !=null)
                    {
                        aCheckInEN.IDCompany = aCustomerGroups.IDCompany;
                    }

                }
                RoomsBO aRoomsBO = new RoomsBO();
                List<Rooms> aListRooms = new List<Rooms>();
                aListRooms = aRoomsBO.Select_All();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRooms = new List<BookingRooms>();
                aListBookingRooms = aBookingRoomsBO.Select_ByIDBookingRs(IDBookingR);
                for (int i = 0; i < aListBookingRooms.Count; i++ )
                {
                    RoomMemberEN aRoomMemberEN = new RoomMemberEN();
                    aRoomMemberEN.IDBookingRooms = aListBookingRooms[i].ID;
                    aRoomMemberEN.RoomCode = aListBookingRooms[i].CodeRoom;
                    aRoomMemberEN.RoomSku = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Sku;
                    aRoomMemberEN.RoomType = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault();
                    aRoomMemberEN.RoomTypeDisplay = CORE.CONSTANTS.SelectedRoomsType(aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault()).Name;
                    aRoomMemberEN.RoomBed1 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed1.GetValueOrDefault();
                    aRoomMemberEN.RoomBed2 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed2.GetValueOrDefault();
                    aRoomMemberEN.RoomCostRef = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).CostRef.GetValueOrDefault();
                    aRoomMemberEN.RoomCost = aListBookingRooms[i].Cost.GetValueOrDefault();
                    aCheckInEN.InsertRoom(aRoomMemberEN);
                }
                return aCheckInEN;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.InitData()\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        // Ngoc
        public int InsertCustomerIntoCustomerGroup_ByIDBookingRs(int IDCustomer, int IDBookingRs)
        {
            // Add customer vao group
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByIDBookingR(IDBookingRs);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            //Kiem tra xe khach do da co trong custome group chua
            CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();
            aCustomerGroups_Customers = aCustomerGroups_CustomersBO.Select_ByIDCustomer_ByIDCustomerGroup(IDCustomer, aCustomerGroups.ID);
            if (aCustomerGroups_Customers == null)
            {
                aCustomerGroups_Customers = new CustomerGroups_Customers();
                Customers aCustomers = (new CustomersBO()).Select_ByID(IDCustomer);
                aCustomerGroups_Customers.IDCustomer = IDCustomer;
                aCustomerGroups_Customers.IDCustomerGroup = aCustomerGroups.ID;
                aCustomerGroups_Customers.Name = aCustomerGroups.Name + "_" + aCustomers.Name + "_" + aCustomers.Identifier1 + "_" + DateTime.Now.ToShortDateString();
                return aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
            }
            else
            {
                return 0;
            }
        }
        public void InitData(int IDBookingH)
        {
            CompaniesBO aCompaniesBO = new CompaniesBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            HallsBO aHallsBO = new HallsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            FoodsBO aFoodsBO = new FoodsBO();
            List<int> aListIndexTemp = new List<int>();

            BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);
            if (aBookingHs != null)
            {
                aNewPaymentHEN.IDCustomer = aBookingHs.IDCustomer;
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                if (aCustomers != null)
                {
                    aNewPaymentHEN.NameCustomer = aCustomers.Name;
                }
                aNewPaymentHEN.IDSystemUser = aBookingHs.IDSystemUser;
                SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                if (aSystemUsers != null)
                {
                    aNewPaymentHEN.NameSystemUser = aSystemUsers.Name;
                }
                aNewPaymentHEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.IDCustomerGroup);
                if (aCustomerGroups != null)
                {
                    aNewPaymentHEN.NameCustomerGroup = aCustomerGroups.Name;
                    aNewPaymentHEN.IDCompany = aCustomerGroups.IDCompany;
                    Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                    if (aCompanies != null)
                    {
                        aNewPaymentHEN.NameCompany = aCompanies.Name;
                        aNewPaymentHEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        aNewPaymentHEN.AddressCompany = aCompanies.Address;
                    }
                }
                aNewPaymentHEN.Subject = aBookingHs.Subject;
                aNewPaymentHEN.PayMenthodH = aBookingHs.PayMenthod;
                aNewPaymentHEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                aNewPaymentHEN.CustomerType = aBookingHs.CustomerType;
                aNewPaymentHEN.Status_BookingH = aBookingHs.Status;
                aNewPaymentHEN.StatusPay = aBookingHs.StatusPay;
                aNewPaymentHEN.BookingHMoney = aBookingHs.BookingMoney;
                aNewPaymentHEN.AcceptDate = aBookingHs.AcceptDate;
                aNewPaymentHEN.InvoiceDate = aBookingHs.InvoiceDate;
                aNewPaymentHEN.InvoiceNumber = aBookingHs.InvoiceNumber;
                this.aNewPaymentHEN.IDBookingH = aBookingHs.ID;
                this.aNewPaymentHEN.PayMenthodH = aBookingHs.PayMenthod;
                this.aNewPaymentHEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                this.aNewPaymentHEN.CustomerType = aBookingHs.CustomerType;
                this.aNewPaymentHEN.Status_BookingH = aBookingHs.Status;
                this.aNewPaymentHEN.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));
                        }
                        aNewPaymentHEN.aListBookingHallUsed.Add(aBookingHallUsedEN);

                    }
                }
            }
            aNewPaymentHEN.ListIndex = aListIndexTemp.Distinct().ToList();
        }
        //hiennv
        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.aCheckInRoomBookingEN.aListRoomMembers.Count > 0)
                {
                    BookingRsBO aBookingRsBO = new BookingRsBO();
                    BookingRs aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                    if (aBookingRs !=null)
                    {
                        this.aCheckInRoomBookingEN.IDCustomer = aBookingRs.IDCustomer;
                        this.aCheckInRoomBookingEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                        this.aCheckInRoomBookingEN.Subject = aBookingRs.Subject;
                        this.aCheckInRoomBookingEN.Level = aBookingRs.Level;
                        this.aCheckInRoomBookingEN.Description = aBookingRs.Description;
                        this.aCheckInRoomBookingEN.Note = aBookingRs.Note;

                        CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                        CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                        if (aCustomerGroups !=null)
                        {
                            this.aCheckInRoomBookingEN.IDCompany = aCustomerGroups.IDCompany;
                        }

                    }

                    this.aCheckInRoomBookingEN.IDBookingR = this.IDBookingRs;
                    this.aCheckInRoomBookingEN.CheckInActual = dtpFrom.DateTime;
                    this.aCheckInRoomBookingEN.CheckOutActual = dtpTo.DateTime;
                    this.aCheckInRoomBookingEN.CheckOutPlan = dtpTo.DateTime;

                    frmTsk_CheckInGoverment_ForRoomBooking_Step2 afrmTsk_CheckInGoverment_ForRoomBooking_Step2 = new frmTsk_CheckInGoverment_ForRoomBooking_Step2(this, this.aCheckInRoomBookingEN);
                    afrmTsk_CheckInGoverment_ForRoomBooking_Step2.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn phòng trước khi thực hiện bước tiếp theo !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInGoverment_ForRoomBooking_Step1.btnNext_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv     25/11/2014     Viet lai phuong thuc BookingRoom
        public bool NewBookingRoom(NewBookingEN aNewBookingEN)
        {
            try
            {
                int IDBookingR = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;

                string customerType = string.Empty;
                if (aNewBookingEN.CustomerType == 0)
                {
                    customerType = "Tất cả loại khác";
                }
                else if (aNewBookingEN.CustomerType == 1)
                {
                    customerType = "Khách nhà nước";
                }
                else if (aNewBookingEN.CustomerType == 2)
                {
                    customerType = "Khách đoàn";
                }
                else if (aNewBookingEN.CustomerType == 3)
                {
                    customerType = "Khách lẻ";
                }
                else if (aNewBookingEN.CustomerType == 4)
                {
                    customerType = "Khách vãng lai";
                }
                else if (aNewBookingEN.CustomerType == 5)
                {
                    customerType = "Khách bộ ngoại giao";
                }
                else
                {
                    customerType = string.Empty;
                }

                #region Them moi khach hang khi khach hang chua co
                if (aNewBookingEN.IDCustomer > 0)
                {
                    IDCustomer = aNewBookingEN.IDCustomer;
                }
                else
                {
                    CustomersBO aCustomersBO = new CustomersBO();
                    Customers aCustomers = new Customers();
                    if (aNewBookingEN.NameCustomer.Length > 50)
                    {
                        aCustomers.Name = aNewBookingEN.NameCustomer.Substring(0, 50);
                    }
                    else
                    {
                        aCustomers.Name = aNewBookingEN.NameCustomer;
                    }
                    IDCustomer = aCustomersBO.Insert(aCustomers);
                }
                #endregion

                #region Them moi cong ty khi cong ty chua co
                if (aNewBookingEN.IDCompany > 0)
                {
                    IDCompany = aNewBookingEN.IDCompany;
                }
                else
                {
                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    Companies aCompanies = new Companies();
                    if (aNewBookingEN.NameCompany.Length > 250)
                    {
                        aCompanies.Name = aNewBookingEN.NameCompany.Substring(0, 250);
                    }
                    else
                    {
                        aCompanies.Name = aNewBookingEN.NameCompany;
                    }

                    aCompanies.TaxNumberCode = string.Empty;
                    aCompanies.Address = string.Empty;
                    aCompanies.Type = aNewBookingEN.CustomerType;
                    aCompanies.Status = 1;
                    aCompanies.Disable = false;
                    IDCompany = aCompaniesBO.Insert(aCompanies);
                }
                #endregion

                #region Them moi nhom vao trong cong ty
                if (IDCompany > 0)
                {
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    string nameGroup;
                    if (string.IsNullOrEmpty(aNewBookingEN.Subject))
                    {
                        nameGroup = "[" + customerType + "][" + aNewBookingEN.NameCompany + "][" + DateTime.Now.ToString() + "]";
                    }
                    else
                    {
                        nameGroup = aNewBookingEN.Subject;
                    }
                    aCustomerGroups.IDCompany = IDCompany;
                    if (nameGroup.Length > 250)
                    {
                        aCustomerGroups.Name = nameGroup.Substring(0, 250);
                    }
                    else
                    {
                        aCustomerGroups.Name = nameGroup;
                    }

                    aCustomerGroups.Type = 1;
                    aCustomerGroups.Status = 1;
                    aCustomerGroups.Disable = false;
                    IDCustomerGroup = aCustomerGroupsBO.Insert(aCustomerGroups);
                }
                #endregion

                #region Them moi bookingRs
                if (IDCustomer > 0 && IDCustomerGroup > 0)
                {
                    string subject = "[" + customerType + "][" + aNewBookingEN.NameCompany + "][" + DateTime.Now.ToString() + "]";

                    BookingRs aBookingRs = new BookingRs();

                    aBookingRs.CreatedDate = DateTime.Now;
                    aBookingRs.CustomerType = aNewBookingEN.CustomerType;
                    aBookingRs.BookingType = aNewBookingEN.BookingType;
                    if (subject.Length > 250)
                    {
                        aBookingRs.Subject = subject.Substring(0, 250);
                    }
                    else
                    {
                        aBookingRs.Subject = subject;
                    }
                    aBookingRs.IDCustomerGroup = IDCustomerGroup;
                    aBookingRs.IDCustomer = IDCustomer;
                    aBookingRs.IDSystemUser = aNewBookingEN.IDSystemUser;
                    aBookingRs.PayMenthod = aNewBookingEN.PayMenthod;
                    aBookingRs.StatusPay = aNewBookingEN.StatusPay;
                    aBookingRs.BookingMoney = aNewBookingEN.BookingMoney;
                    aBookingRs.ExchangeRate = aNewBookingEN.ExchangeRate;
                    aBookingRs.Level = 0;// de mac dinh hien tai chua dung den
                    aBookingRs.Note = string.Empty;
                    aBookingRs.Description = string.Empty;
                    aBookingRs.DatePay = aNewBookingEN.CheckOutPlan;
                    aBookingRs.DateEdit = aNewBookingEN.CheckInActual;
                    aBookingRs.Status = aNewBookingEN.Status;
                    aBookingRs.Type = aNewBookingEN.Type;
                    aBookingRs.Disable = aNewBookingEN.Disable;

                    //add new bookingRs
                    BookingRsBO aBookingRsBO = new BookingRsBO();
                    IDBookingR = aBookingRsBO.Insert(aBookingRs);
                }
                #endregion

                #region them moi bookingRoom
                if (IDBookingR > 0)
                {
                    BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                    BookingRooms aBookingRooms;
                    for (int i = 0; i < aNewBookingEN.aListNewRoomMembers.Count; i++)
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms.IDBookingR = IDBookingR;
                        aBookingRooms.CodeRoom = aNewBookingEN.aListNewRoomMembers[i].RoomCode;
                        aBookingRooms.PercentTax = 10;
                        aBookingRooms.CostRef_Rooms = aNewBookingEN.aListNewRoomMembers[i].RoomCostRef;
                        aBookingRooms.Cost = aNewBookingEN.aListNewRoomMembers[i].RoomCostRef;
                        aBookingRooms.CheckInPlan = aNewBookingEN.CheckInActual;
                        aBookingRooms.CheckInActual = aNewBookingEN.CheckInActual;
                        aBookingRooms.CheckOutPlan = aNewBookingEN.CheckOutPlan;
                        aBookingRooms.CheckOutActual = aNewBookingEN.CheckOutActual;
                        aBookingRooms.StartTime = aNewBookingEN.CheckInActual;
                        aBookingRooms.EndTime = aNewBookingEN.CheckOutPlan;
                        aBookingRooms.BookingStatus = 1;
                        aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn
                        aBookingRooms.Status = aNewBookingEN.Status;
                        aBookingRooms.PriceType = "G1";
                        //add new bookingRoom
                        aBookingRoomsBO.Insert(aBookingRooms);

                    }
                }
                #endregion

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public List<Customers> SelectListCustomer_ByIDBookingH(int IDBookingH)
        {
            try
            {

                List<int> aList = aDatabaseDA.BookingHs.Where(p => p.ID == IDBookingH).Select(p => p.IDCustomerGroup).ToList();
                if (aList.Count > 0)
                {
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    return this.SelectListCustomer_ByIDCustomerGroups(aList[0]).ToList();
                }
                else
                {
                    return new List<Customers>();
                }
            }
            catch (Exception ex)
            {

                throw new Exception("CustomersBO.SelectListCustomer_ByIDBookingRoom\n" + ex.ToString());
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

                // Load các thông tin chung về phòng
                aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRooms);
                if (aBookingRooms != null)
                {
                    lblCheckIn.Text = aBookingRooms.CheckInActual.ToString("dd/MM/yyyy HH:mm");
                    lblCheckOut.Text = aBookingRooms.CheckOutPlan.ToString("dd/MM/yyyy HH:mm");
                    lblRoomSku.Text = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).Sku;
                }
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                if (aBookingRs != null)
                {
                    lblCustomerType.Text = CORE.CONSTANTS.SelectedCustomerType(Convert.ToInt32(aBookingRs.CustomerType)).Name;

                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    lblCompany.Text = aCompaniesBO.Select_ByIDBookingRoom(this.IDBookingRooms).Name;

                    lblCustomer.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Name;

                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    lblGroup.Text = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup).Name;

                    lblTel.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Tel;

                    this.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                }
                //Load danh sách phòng còn trống
                lueRooms.Properties.DataSource = this.LoadListAvailableRooms(aBookingRooms.CheckInActual, aBookingRooms.CheckOutPlan);
                lueRooms.Properties.ValueMember = "RoomCode";
                lueRooms.EditValue = this.IDBookingRooms;
                //Load danh sách khách trong phòng
                this.aListCustomersInRoom = aCustomersBO.SelectListCustomer_ByIDBookingRoom(this.IDBookingRooms);
                dgvAvailableCustomers.DataSource = this.aListCustomersInRoom;
                dgvAvailableCustomers.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //hiennv
        public void InitData(PaymentHallsEN aPaymentHallsEN, int IDBookingH)
        {
            try
            {
                HallsBO aHallsBO = new HallsBO();
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                FoodsBO aFoodsBO = new FoodsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CompaniesBO aCompaniesBO = new CompaniesBO();
                SystemUsersBO aSystemUsersBO = new SystemUsersBO();

                BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);
                if (aBookingHs != null)
                {
                    aPaymentHallsEN.IDBookingH = aBookingHs.ID;
                    aPaymentHallsEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                    CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.IDCustomerGroup);
                    if (aCustomerGroups != null)
                    {
                        aPaymentHallsEN.NameCustomerGroup = aCustomerGroups.Name;
                        aPaymentHallsEN.IDCompany = aCustomerGroups.IDCompany;
                        Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                        if (aCompanies != null)
                        {
                            aPaymentHallsEN.NameCompany = aCompanies.Name;
                            aPaymentHallsEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        }
                    }
                    aPaymentHallsEN.IDCustomer = aBookingHs.IDCustomer;
                    Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                    if (aCustomers != null)
                    {
                        aPaymentHallsEN.NameCustomer = aCustomers.Name;

                    }
                    aPaymentHallsEN.IDSystemUser = aBookingHs.IDSystemUser;
                    SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                    if (aSystemUsers != null)
                    {
                        aPaymentHallsEN.NameSystemUser = aSystemUsers.Name;
                    }
                    aPaymentHallsEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                    aPaymentHallsEN.CustomerType = aBookingHs.CustomerType;
                    aPaymentHallsEN.BookingType = aBookingHs.BookingType;
                    aPaymentHallsEN.PayMenthod = aBookingHs.PayMenthod;
                    aPaymentHallsEN.StatusPay = aBookingHs.StatusPay;
                    aPaymentHallsEN.Status_BookingH = aBookingHs.Status;
                    aPaymentHallsEN.ExchangeRate = aBookingHs.ExchangeRate;
                    aPaymentHallsEN.Level = aBookingHs.Level;
                    aPaymentHallsEN.BookingMoney = aBookingHs.BookingMoney;
                }

                List<BookingHalls> aListBookingHalls = new List<BookingHalls>();
                aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(IDBookingH);
                InfoDetailPaymentHallsEN aInfoDetailPaymentHallsEN;
                for (int i = 0; i < aListBookingHalls.Count; i++)
                {
                    aInfoDetailPaymentHallsEN = new InfoDetailPaymentHallsEN();
                    Halls aHalls = aHallsBO.Select_ByCodeHall(aListBookingHalls[i].CodeHall, 1);
                    if (aHalls != null)
                    {
                        aInfoDetailPaymentHallsEN.Sku = aHalls.Sku;
                    }
                    else
                    {
                        aInfoDetailPaymentHallsEN.Sku = string.Empty;
                    }
                    aInfoDetailPaymentHallsEN.aBookingHalls = aListBookingHalls[i];
                    aInfoDetailPaymentHallsEN.aMenusEN = aReceptionTaskBO.GetDetailMenu_ByIDBookingHall(aListBookingHalls[i].ID);
                    aInfoDetailPaymentHallsEN.aListServicesHallsEN = aReceptionTaskBO.GetListServicesHallsEN_ByIDBookingHall(aListBookingHalls[i].ID);

                    aPaymentHallsEN.aListInfoDetailPaymentHallsEN.Insert(i, aInfoDetailPaymentHallsEN);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PaymentHall.InitData\n" + ex.ToString());
            }
        }
        private void lueIDCompanies_EditValueChanged(object sender, EventArgs e)
        {
            if (lueIDCompanies.EditValue == null)
            {
                MessageBox.Show("Vui lòng chọn tên công ty.");
                lueIDCompanies.Focus();

            }
            BookingRsBO aBookingRsBO = new BookingRsBO();
            BookingRs aBookingRs = new BookingRs();
            List<PaymentExt_GetAllDataEN> aListPaymentExt_GetAllDataEN = new List<PaymentExt_GetAllDataEN>();
            int IDCompany = Convert.ToInt32(lueIDCompanies.EditValue.ToString());

            CustomerGroupsBO aCustomerGroupBO = new CustomerGroupsBO();
            List<int> aListIDCustomerGroup = aCustomerGroupBO.Select_All().Where(x => x.IDCompany == IDCompany).Select(p => p.ID).ToList();

            CompaniesBO aCompaniesBO = new CompaniesBO();
            List<int> ListIDBookingR = aBookingRsBO.Select_ByIDCompany(int.Parse(lueIDCompanies.EditValue.ToString())).Select(p=>p.ID).ToList();
            dgvPaymentViewAll.DataSource = this.aListPaymentExt_GetAllDataEN.Where(p => ListIDBookingR.Contains(p.BookingRs_ID));
        }
        public void LoadCustomerGroup()
        {
            try
            {
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();

                int IDCompany = Convert.ToInt32(lueIDCompany.EditValue.ToString());
                List<CustomerGroups> aListCustomerGroups = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
                lueIDCustomerGroup.Properties.DataSource = aListCustomerGroups;
                lueIDCustomerGroup.Properties.DisplayMember = "Name";
                lueIDCustomerGroup.Properties.ValueMember = "ID";

                if (aListCustomerGroups.Count > 0)
                {
                    lueIDCustomerGroup.EditValue = aListCustomerGroups.ToList()[0].ID;
                    //if (aListCustomerGroups.Where(a => a.Name == lueIDCompany.Text + " " + DateTime.Now.ToShortDateString() + "" + txtSubject.Text).ToList().Count > 0)
                    //{
                    //    lueIDCustomerGroup.EditValue = aListCustomerGroups.Where(a => a.Name == lueIDCompany.Text + "" + DateTime.Now.ToShortDateString() + "" + txtSubject.Text).ToList()[0].ID;
                    //}
                    //else
                    //{
                    //    CustomerGroups aTemp = new CustomerGroups();
                    //    aTemp.IDCompany = IDCompany;
                    //    aTemp.Name = lueIDCompany.Text + "" + DateTime.Now.ToShortDateString() + "" + txtSubject.Text;
                    //    aTemp.Status = 1;
                    //    aTemp.Type = 1;
                    //    aTemp.Disable = false;
                    //    int IDaTemp= aCustomerGroupsBO.Insert(aTemp);
                    //    lueIDCustomerGroup.EditValue = IDaTemp;
                    //}
                }
                else
                {
                    lueIDCustomerGroup.EditValue = 0;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmAddNewBookingRs_Goverment.LoadCustomerGroup\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
     int ID = int.Parse(viewAvailableCustomerGroups.GetFocusedRowCellValue("ID").ToString());
     string Name = aCustomerGroupsBO.Select_ByID(ID).Name;
     DialogResult result = MessageBox.Show("Bạn có muốn xóa nhóm khách hàng " + Name + " này không?", "Xóa nhóm khách hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (result == DialogResult.Yes)
     {
         aCustomerGroupsBO.Delete_ByID(ID);
         MessageBox.Show("Xóa thành công");
         this.ReloadData();
     }
 }
 public void LoadIDCustomerGroups()
 {
     try
     {
         CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
         int IDCompany = Convert.ToInt32(lueCompany.EditValue.ToString());
         List<CustomerGroups> aListCustomerGroups = aCustomerGroupsBO.Select_ByIDCompany(IDCompany);
         lueCustomerGroup.Properties.DataSource = aListCustomerGroups;
         lueCustomerGroup.Properties.DisplayMember = "Name";
         lueCustomerGroup.Properties.ValueMember = "ID";
         if (aListCustomerGroups.Count > 0)
         {
             lueCustomerGroup.EditValue = aListCustomerGroups.ToList()[0].ID;
         }
         else
         {
             lueCustomerGroup.EditValue = 0;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmTsk_UpdBooking.LoadIDCustomerGroups\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void frmTsk_PendingCheckIn_Step2_Load(object sender, EventArgs e)
        {
            try
            {
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                lblIDBookingR.Text = aBookingRs.ID.ToString();

                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                lblNameCustomerGroup.Text = aCustomerGroups.Name;

                CompaniesBO aCompaniesBO = new CompaniesBO();
                Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                lblNameCompany.Text = aCompanies.Name;

                CustomersBO aCustomersBO = new CustomersBO();
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                lblNameCustomer.Text = aCustomers.Name;

                RoomsBO aRoomsBO = new RoomsBO();
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(CodeRoom, 1);//1=IDLang
                lblSku.Text = aRooms.Sku;

                dtpTo.DateTime = CheckOutPlan;
                dtpFrom.DateTime = DateTime.Now;
                dtpFrom.Enabled = false;
                dtpFrom.Properties.ReadOnly = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.frmTsk_PendingCheckIn_Step2_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }