// Tạm thanh toán ( Update lại BookingRMoney)
 private void btnDownPayment_Click(object sender, EventArgs e)
 {
     try
     {
         BookingRsBO aBookingRsBO = new BookingRsBO();
         BookingRs aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingR);
         aBookingRs.BookingMoney = this.aNewPaymentEN.BookingRMoney;
         aBookingRs.StatusPay = 2;// Tạm ứng
         int count = aBookingRsBO.Update(aBookingRs);
         if (this.afrmTsk_Payment_Step1 != null)
         {
             this.afrmTsk_Payment_Step1.LoadListBookingR();
         }
         //this.LoadData();
         MessageBox.Show("Thực hiện thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmTsk_PaymentStep2.btnDownPayment_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void txtSubject_Leave(object sender, EventArgs e)
        {
            int IDBookingR = Convert.ToInt32(grvPaymentViewAll.GetFocusedRowCellValue("BookingRs_ID"));
            string ObjectType = grvPaymentViewAll.GetFocusedRowCellValue("ObjectType").ToString();
            string Subject = grvPaymentViewAll.GetFocusedRowCellValue("Subject").ToString();

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

                aItem = aBookingHsBO.Select_ByID(IDBookingH);
                aItem.Subject = Subject;
                aBookingHsBO.Update(aItem);
                this.LoadData();
            }
        }
        //Author :Hiennv
        public bool CheckInForRoomAlreadyBooking(CheckInRoomBookingEN aCheckInRoomBookingEN)
        {
            try
            {
                //========================================================

                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(aCheckInRoomBookingEN.IDBookingR);
                if (aBookingRs != null)
                {
                    aBookingRs.Subject = aCheckInRoomBookingEN.Subject;
                    aBookingRs.Level = aCheckInRoomBookingEN.Level;
                    aBookingRs.Description = aCheckInRoomBookingEN.Description;
                    aBookingRs.Note = aCheckInRoomBookingEN.Note;
                    aBookingRs.IDCustomerGroup = aCheckInRoomBookingEN.IDCustomerGroup;
                    aBookingRs.IDCustomer = aCheckInRoomBookingEN.IDCustomer;
                    aBookingRs.BookingMoney = aCheckInRoomBookingEN.BookingMoney;
                    aBookingRs.IDSystemUser = aCheckInRoomBookingEN.IDSystemUser;
                    aBookingRs.BookingType = aCheckInRoomBookingEN.BookingType;
                    aBookingRs.Status = aCheckInRoomBookingEN.Status;
                    aBookingRs.StatusPay = aCheckInRoomBookingEN.StatusPay;
                    aBookingRs.DateEdit = DateTime.Now;

                    //cap nhat lai bang BookingRs
                    aBookingRsBO.Update(aBookingRs);

                    BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                    BookingRooms aBookingRooms;
                    BookingRoomsMembers aBookingRoomsMembers;
                    foreach (RoomMemberEN aRoomMemberEN in aCheckInRoomBookingEN.aListRoomMembers)
                    {
                        aBookingRooms = new BookingRooms();
                        aBookingRooms = aBookingRoomsBO.Select_ByID(aRoomMemberEN.IDBookingRooms);
                        if (aBookingRooms != null)
                        {
                            aBookingRooms.CheckInActual = aCheckInRoomBookingEN.CheckInActual;
                            aBookingRooms.CheckOutActual = aCheckInRoomBookingEN.CheckOutActual;
                            aBookingRooms.CheckOutPlan = aCheckInRoomBookingEN.CheckOutPlan;
                            aBookingRooms.Status = aCheckInRoomBookingEN.Status;
                            aBookingRoomsBO.Update(aBookingRooms);
                        }
                        else
                        {
                            aBookingRooms = new BookingRooms();
                            aBookingRooms.IDBookingR = aCheckInRoomBookingEN.IDBookingR;
                            aBookingRooms.CodeRoom = aRoomMemberEN.RoomCode;
                            aBookingRooms.PercentTax = 10;
                            aBookingRooms.CostRef_Rooms = aRoomMemberEN.RoomCostRef;
                            aBookingRooms.Cost = aRoomMemberEN.RoomCostRef;
                            aBookingRooms.CheckInPlan = aCheckInRoomBookingEN.CheckInActual;
                            aBookingRooms.CheckInActual = aCheckInRoomBookingEN.CheckInActual;
                            aBookingRooms.CheckOutPlan = aCheckInRoomBookingEN.CheckOutPlan;
                            aBookingRooms.CheckOutActual = aCheckInRoomBookingEN.CheckOutActual;
                            aBookingRooms.StartTime = aCheckInRoomBookingEN.CheckInActual;
                            aBookingRooms.EndTime = aCheckInRoomBookingEN.CheckOutPlan;
                            aBookingRooms.BookingStatus = 1;
                            aBookingRooms.Status = aCheckInRoomBookingEN.Status;
                            aBookingRooms.Status = 1;//Tính CheckIn sớm và CheckOut muộn
                            //add new bookingRoom
                            aBookingRoomsBO.Insert(aBookingRooms);
                            aRoomMemberEN.IDBookingRooms = aBookingRooms.ID;
                        }

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

                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                        foreach (CustomerInfoEN aCustomerInfoEN in aRoomMemberEN.ListCustomer)
                        {
                            aBookingRoomsMembers.IDCustomer = aCustomerInfoEN.ID;
                            aBookingRoomsMembers.PurposeComeVietnam = aCustomerInfoEN.PurposeComeVietnam;
                            aBookingRoomsMembers.DateEnterCountry = aCustomerInfoEN.DateEnterCountry;
                            aBookingRoomsMembers.EnterGate = aCustomerInfoEN.EnterGate;
                            aBookingRoomsMembers.TemporaryResidenceDate = aCustomerInfoEN.TemporaryResidenceDate;
                            aBookingRoomsMembers.LimitDateEnterCountry = aCustomerInfoEN.LimitDateEnterCountry;
                            aBookingRoomsMembers.Organization = aCustomerInfoEN.Organization;
                            aBookingRoomsMembers.LeaveDate = aCustomerInfoEN.LeaveDate;
                            //add new bookingRoomMember
                            aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.CheckInForRoomAlreadyBooking\n" + ex.ToString());
            }
        }
        //Hiennv        31/08/2014           Thanh toan le cho phong
        public void SplitPaymentForBookingR(NewPaymentEN aNewPaymentEN, List<BookingRoomUsedEN> aListRooms, List<ServiceUsedEN> aListServicesR)
        {
            try
            {

                foreach (ServiceUsedEN aServicesEN in aListServicesR)
                {

                    aServicesEN.StatusPay = 8;
                    aServicesEN.Save(1);
                }
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                foreach (BookingRoomUsedEN aBookingRoomUsedEN in aListRooms)
                {

                    aBookingRoomUsedEN.Status = 8;//da thanh toan
                    aBookingRoomUsedEN.CheckOutActual = DateTime.Now;
                    aBookingRoomUsedEN.Save();
                }
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(Convert.ToInt32(aNewPaymentEN.IDBookingR));
                List<BookingRooms> aListBookingRooms = aBookingRoomsBO.Select_ByIDBookingR_ByStatus(Convert.ToInt32(aNewPaymentEN.IDBookingR), 8);
                if (aListBookingRooms.Count < 1)
                {
                    aBookingRs.ID = Convert.ToInt32(aNewPaymentEN.IDBookingR);
                    aBookingRs.PayMenthod = aNewPaymentEN.PayMenthodR;
                    aBookingRs.StatusPay = 3;
                    aBookingRs.Status = 8;
                    aBookingRs.DatePay = DateTime.Now;
                }
                aBookingRs.BookingMoney = aNewPaymentEN.BookingRMoney;
                aBookingRsBO.Update(aBookingRs);
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.SplitPaymentForBookingR \n" + ex.ToString());
            }
        }
        //hiennv
        public bool PaymentRoom(PaymentEN aPaymentEN)
        {
            try
            {
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(aPaymentEN.IDBookingR);
                if (aBookingRs != null)
                {
                    aBookingRs.ID = aPaymentEN.IDBookingR;
                    aBookingRs.PayMenthod = aPaymentEN.PayMenthod;
                    aBookingRs.StatusPay = 3;
                    aBookingRs.Status = 8;
                    aBookingRs.DatePay = DateTime.Now;
                    aBookingRs.BookingMoney = 0;

                    aBookingRsBO.Update(aBookingRs);
                }

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

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

                            aBookingRoomsBO.Update(aBookingRooms);
                        }

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

                                    aBookingRooms_ServicesBO.Update(aBookingRooms_Services);
                                }
                            }

                        }

                    }

                }
                return true;

            }
            catch (Exception ex)
            {
                return false;
                throw new Exception(string.Format("ReceptionTaskBO.PaymentRoom\n" + ex.Message));
            }
        }
        //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;
            }
        }