// chuyen nguoi vao phong
        public List<CustomerInfoEN> AddCustomer(CustomerInfoEN cust)
        {
            try
            {
                CustomerInfoEN temp = new CustomerInfoEN();
                temp.Address = cust.Address;
                temp.Birthday = cust.Birthday;
                temp.Citizen = cust.Citizen;

                temp.Description = cust.Description;
                temp.Disable = cust.Disable;
                temp.Email = cust.Email;
                temp.Gender = cust.Gender;

                temp.ID = cust.ID;
                temp.Identifier1 = cust.Identifier1;
                temp.Identifier1CreatedDate = cust.Identifier1CreatedDate;
                temp.Identifier2 = cust.Identifier2;
                temp.Identifier2CreatedDate = cust.Identifier2CreatedDate;

                temp.Identifier3 = cust.Identifier3;
                temp.Identifier3CreatedDate = cust.Identifier3CreatedDate;
                temp.Info = cust.Info;
                temp.Name = cust.Name;
                temp.Nationality = cust.Nationality;

                temp.Note = cust.Note;
                temp.PlaceOfIssue1 = cust.PlaceOfIssue1;
                temp.PlaceOfIssue2 = cust.PlaceOfIssue2;
                temp.PlaceOfIssue3 = cust.PlaceOfIssue3;

                temp.AgencyOfIssue1 = cust.AgencyOfIssue1;
                temp.AgencyOfIssue2 = cust.AgencyOfIssue2;
                temp.AgencyOfIssue3 = cust.AgencyOfIssue3;
                temp.Status = cust.Status;

                temp.Tel = cust.Tel;
                temp.Type = cust.Type;

                temp.EnterGate = cust.EnterGate;
                temp.PepoleRepresentative = cust.PepoleRepresentative;
                temp.PurposeComeVietnam = cust.PurposeComeVietnam;
                temp.DateEnterCountry = cust.DateEnterCountry;
                temp.EnterGate = cust.EnterGate;
                temp.TemporaryResidenceDate = cust.TemporaryResidenceDate;
                temp.LeaveDate = cust.LeaveDate;
                temp.Organization = cust.Organization;
                temp.LimitDateEnterCountry = cust.LimitDateEnterCountry;

                _alistCustomer.Add(temp);
                return _alistCustomer;
            }
            catch(Exception p)
            {
                throw new Exception("ItemChangeRoomEn_AddCustomer "+ p.ToString());
            }
        }
 //============== FORM 3 =========
 public void AddCustomerToRoom(string CodeRoom, CustomerInfoEN aCustomerInfo)
 {
     for (int i = 0; i < aListRoomMembers.Count; i++)
     {
         if (aListRoomMembers[i].RoomCode == CodeRoom)
         {
             aListRoomMembers[i].ListCustomer.Add(aCustomerInfo);
         }
     }
 }
        public frmTsk_EditBooking(int IDBookingRoom, frmMain afrmMain)
        {
            InitializeComponent();

            BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
            this.aBookingRoom = aBookingRoomBO.Select_ByID(IDBookingRoom);

            BookingRsBO aBookingRsBO = new BookingRsBO();
            this.aBookingRs = aBookingRsBO.Select_ByID(this.aBookingRoom.IDBookingR);

            this.afrmMain = afrmMain;
            this.IsReadyInitData = false;
            this.aCurrentCustomerClick = new CustomerInfoEN();
        }
 public void UpdateCustomerToRoom(string CodeRoom, CustomerInfoEN aCustomerInfo)
 {
     this.RemoveCustomerToRoom(aCustomerInfo.ID);
     this.AddCustomerToRoom(CodeRoom, aCustomerInfo);
 }
        //Hiennv    Tạo mới     18/11/2014
        private void btnSelectPepoleToRoom_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(this.aCurrent_CodeRoom))
                {
                    dgvSelectedRooms.Focus();
                    MessageBox.Show("Vui lòng chọn phòng cần thêm người vào trước.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    int countCustomerInRoom = 0;
                    if(this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom) != null) {
                        countCustomerInRoom = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom).Count();
                    }
                    if(countCustomerInRoom < 3) {
                        DateTime? dateTime = null;
                        CustomerInfoEN aCustomerInfoEN = new CustomerInfoEN();
                        int IDCustomer = Convert.ToInt32(grvAvailableCustomer.GetFocusedRowCellValue("ID"));
                        aCustomerInfoEN.ID = IDCustomer;
                        aCustomerInfoEN.RoomCode = this.aCurrent_CodeRoom;
                        aCustomerInfoEN.Name = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Name"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Name"));
                        aCustomerInfoEN.Identifier1 = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Identifier1"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Identifier1"));
                        aCustomerInfoEN.Identifier1CreatedDate = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Identifier1CreatedDate"))) == true ? dateTime : Convert.ToDateTime(grvAvailableCustomer.GetFocusedRowCellValue("Identifier1CreatedDate"));
                        aCustomerInfoEN.PlaceOfIssue1 = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("PlaceOfIssue1"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("PlaceOfIssue1"));
                        aCustomerInfoEN.AgencyOfIssue1 = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("AgencyOfIssue1"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("AgencyOfIssue1"));
                        aCustomerInfoEN.Address = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Address"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Address"));
                        aCustomerInfoEN.Birthday = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Birthday"))) == true ? dateTime : Convert.ToDateTime(grvAvailableCustomer.GetFocusedRowCellValue("Birthday"));
                        aCustomerInfoEN.Tel = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Tel"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Tel"));
                        aCustomerInfoEN.Gender = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Gender"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Gender"));
                        aCustomerInfoEN.Nationality = String.IsNullOrEmpty(Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Nationality"))) == true ? String.Empty : Convert.ToString(grvAvailableCustomer.GetFocusedRowCellValue("Nationality"));
                        aCustomerInfoEN.PepoleRepresentative = false;

                        if(this.aCheckInEN.IsCustomerExistInRoom(this.aCurrent_CodeRoom, IDCustomer) == true) {
                            MessageBox.Show("Khách đã có ở trong phòng vui lòng chọn người khác.", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else {
                            if(!String.IsNullOrEmpty(this.aCurrent_CodeRoom)) {
                                this.aCheckInEN.AddCustomerToRoom(this.aCurrent_CodeRoom, aCustomerInfoEN);
                                dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                                dgvSelectedCustomer.RefreshDataSource();
                            }
                        }

                        List<Customers> aListTemps = aListAvailableCustomers.Where(c => c.ID == Convert.ToInt32(grvAvailableCustomer.GetFocusedRowCellValue("ID"))).ToList();
                        if(aListTemps.Count > 0) {
                            this.aListAvailableCustomers.Remove(aListTemps[0]);
                        }
                        dgvAvailableCustomer.DataSource = this.aListAvailableCustomers;
                        dgvAvailableCustomer.RefreshDataSource();
                    }
                    else {
                        MessageBox.Show("Một phòng chỉ được nhập tối đa 3 người", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.btnSelectPepoleToRoom_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv     Tạo mới   21/11/2014  luu tam thong tin khach hang
        public void SaveCustomer()
        {
            try
            {
                if (this.CheckDataBeforeSaveCustomer() == true)
                {

                    DateTime? dateTime = null;
                    int IDCustomer = 0;

                    if (this.aCurrent_IDCustomer != 0)
                    {
                        this.aCheckInEN.RemoveCustomerToRoom(this.aCurrent_IDCustomer);
                        List<Customers> aListTemps = aListAvailableCustomers.Where(c => c.ID == this.aCurrent_IDCustomer).ToList();
                        if (aListTemps.Count > 0)
                        {
                            this.aListAvailableCustomers.Remove(aListTemps[0]);
                        }
                    }

                    if (String.IsNullOrEmpty(this.aCurrent_CodeRoom))
                    {
                        MessageBox.Show("Vui lòng chọn phòng trước khi thêm người vào phòng.", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        CustomerInfoEN aCustomerInfoEN = new CustomerInfoEN();

                        if (this.aCurrent_IDCustomer == 0)
                        {
                            IDCustomer = StringUtility.AutoCreateCode();
                        }
                        else
                        {
                            IDCustomer = this.aCurrent_IDCustomer;
                        }

                        aCustomerInfoEN.ID = IDCustomer;
                        aCustomerInfoEN.RoomCode = this.aCurrent_CodeRoom;
                        aCustomerInfoEN.Name = txtNames.Text;
                        aCustomerInfoEN.Identifier1 = txtIdentifier1.Text;
                        aCustomerInfoEN.Identifier1CreatedDate = String.IsNullOrEmpty(dtpIdentifier1CreatedDate.Text) ? dateTime : dtpIdentifier1CreatedDate.DateTime;
                        aCustomerInfoEN.PlaceOfIssue1 = txtPlaceOfIssue1.Text;
                        aCustomerInfoEN.AgencyOfIssue1 = txtAgencyOfIssue.Text;
                        aCustomerInfoEN.Address = txtAddress.Text;
                        aCustomerInfoEN.Birthday = String.IsNullOrEmpty(dtpBirthday.Text) ? dateTime : dtpBirthday.DateTime;
                        aCustomerInfoEN.Citizen = Convert.ToInt32(lueCitizen.EditValue);
                        aCustomerInfoEN.Gender = Convert.ToString(lueGender.EditValue);
                        aCustomerInfoEN.Tel = txtTel.Text;
                        aCustomerInfoEN.Nationality = Convert.ToString(lueNationality.EditValue);
                        aCustomerInfoEN.PurposeComeVietnam = txtPurposeComeVietnam.Text;
                        aCustomerInfoEN.DateEnterCountry = String.IsNullOrEmpty(dtpDateEnterCountry.Text) ? dateTime : dtpDateEnterCountry.DateTime;
                        aCustomerInfoEN.EnterGate = txtEnterGate.Text;
                        aCustomerInfoEN.TemporaryResidenceDate = String.IsNullOrEmpty(dtpTemporaryResidenceDate.Text) ? dateTime : dtpTemporaryResidenceDate.DateTime;
                        aCustomerInfoEN.LeaveDate = String.IsNullOrEmpty(dtpLeaveDate.Text) ? dateTime : dtpLeaveDate.DateTime;
                        aCustomerInfoEN.Organization = txtOrganization.Text;
                        aCustomerInfoEN.LimitDateEnterCountry = String.IsNullOrEmpty(dtpLimitDateEnterCountry.Text) ? dateTime : dtpLimitDateEnterCountry.DateTime;
                        aCustomerInfoEN.PepoleRepresentative = false;
                        this.aCheckInEN.AddCustomerToRoom(this.aCurrent_CodeRoom, aCustomerInfoEN);

                        dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                        dgvSelectedCustomer.RefreshDataSource();

                        //Customers aCustomers = new Customers();

                        //aCustomers.ID = IDCustomer;
                        //aCustomers.Name = txtNames.Text;
                        //aCustomers.Identifier1 = txtIdentifier1.Text;
                        //aCustomers.Birthday = String.IsNullOrEmpty(dtpBirthday.Text) ? dateTime : dtpBirthday.DateTime;
                        //aCustomers.Gender = Convert.ToString(lueGender.EditValue);
                        //aCustomers.Tel = txtTel.Text;
                        //aCustomers.Nationality = Convert.ToString(lueNationality.EditValue);
                        //this.aListAvailableCustomers.Insert(0, aCustomers);

                        //dgvAvailableCustomer.DataSource = this.aListAvailableCustomers;
                        //dgvAvailableCustomer.RefreshDataSource();

                    }
                    this.ResetValueAddNew();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.SaveCustomer()\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void viewSelectCustomers_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            int aCurrent_IDCustomer;
            try
            {
                this.ClearControl();

                aCurrent_IDCustomer = Convert.ToInt32(viewSelectCustomers.GetFocusedRowCellValue("ID"));
                List<CustomerInfoEN> aList = this.aCurrentRoomInfo.GetAllCustomers().Where(p => p.ID == aCurrent_IDCustomer).ToList();

                if (aList.Count == 1)
                {
                    CustomerInfoEN aCurrentCustomer = aList[0];

                    this.aCurrentCustomerClick = aCurrentCustomer;
                    lblSelectedCustomer.Text = aCurrentCustomer.Name;
                    txtPurposeComeVietnam.EditValue = aCurrentCustomer.PurposeComeVietnam;
                    dtpDateEnterCountry.EditValue = aCurrentCustomer.DateEnterCountry;
                    txtEnterGate.EditValue = aCurrentCustomer.EnterGate;
                    dtpTemporaryResidenceDate.EditValue = aCurrentCustomer.TemporaryResidenceDate;
                    dtpLeaveDate.EditValue = aCurrentCustomer.LeaveDate;
                    txtOrganization.EditValue = aCurrentCustomer.Organization;
                    dtpLimitDateEnterCountry.EditValue = aCurrentCustomer.LimitDateEnterCountry;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.viewSelectedCustomer_RowCellClick\n" + ex.ToString(), "Error ", 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);
        }
        // this function overwrite list customer in this._alistCustomer.
        public List<CustomerInfoEN> UpdateCustomer(List<CustomerInfoEN> aListCustomers)
        {
            try
            {
                this._alistCustomer = new List<CustomerInfoEN>();
                List<CustomerInfoEN> aList = new List<CustomerInfoEN>();
                CustomerInfoEN temp = new CustomerInfoEN();
                for (int i = 0; i < aListCustomers.Count; i++)
                {

                        temp = new CustomerInfoEN();
                        temp.Address = aListCustomers[i].Address;
                        temp.Birthday = aListCustomers[i].Birthday;
                        temp.Citizen = aListCustomers[i].Citizen;

                        temp.Description = aListCustomers[i].Description;
                        temp.Disable = aListCustomers[i].Disable;
                        temp.Email = aListCustomers[i].Email;
                        temp.Gender = aListCustomers[i].Gender;

                        temp.ID = aListCustomers[i].ID;
                        temp.Identifier1 = aListCustomers[i].Identifier1;
                        temp.Identifier1CreatedDate = aListCustomers[i].Identifier1CreatedDate;
                        temp.Identifier2 = aListCustomers[i].Identifier2;
                        temp.Identifier2CreatedDate = aListCustomers[i].Identifier2CreatedDate;

                        temp.Identifier3 = aListCustomers[i].Identifier3;
                        temp.Identifier3CreatedDate = aListCustomers[i].Identifier3CreatedDate;
                        temp.Info = aListCustomers[i].Info;
                        temp.Name = aListCustomers[i].Name;
                        temp.Nationality = aListCustomers[i].Nationality;

                        temp.Note = aListCustomers[i].Note;
                        temp.PlaceOfIssue1 = aListCustomers[i].PlaceOfIssue1;
                        temp.PlaceOfIssue2 = aListCustomers[i].PlaceOfIssue2;
                        temp.PlaceOfIssue3 = aListCustomers[i].PlaceOfIssue3;
                        temp.Status = aListCustomers[i].Status;

                        temp.Tel = aListCustomers[i].Tel;
                        temp.Type = aListCustomers[i].Type;

                        temp.EnterGate = aListCustomers[i].EnterGate;
                        temp.PepoleRepresentative = aListCustomers[i].PepoleRepresentative;
                        temp.PurposeComeVietnam = aListCustomers[i].PurposeComeVietnam;
                        temp.DateEnterCountry = aListCustomers[i].DateEnterCountry;
                        temp.EnterGate = aListCustomers[i].EnterGate;
                        temp.TemporaryResidenceDate = aListCustomers[i].TemporaryResidenceDate;
                        temp.LeaveDate = aListCustomers[i].LeaveDate;
                        temp.Organization = aListCustomers[i].Organization;
                        temp.LimitDateEnterCountry = aListCustomers[i].LimitDateEnterCountry;

                        aList.Add(temp);

                }
                _alistCustomer.AddRange(aList);
                return _alistCustomer;
            }
            catch (Exception p)
            {
                throw new Exception("ItemChangeRoomEn_UpdateCustomer " + p.ToString());
            }
        }
        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()
        }
        private List<CustomerInfoEN> GetDataForSelectCustomerGridview(string CodeRoom)
        {
            BookingRsBO aBookingRsBO = new BookingRsBO();
            List<Rooms> aListRoom = aBookingRsBO.SelectListRooms_ByIDBookingR(this.aBookingRoom.IDBookingR, 1);

            bool IsRoomInBookingR = false;
            if (aListRoom.Where(p=>p.Code == CodeRoom).Where(p=>p.Status <7).ToList().Count == 1)
            {
                IsRoomInBookingR = true;
            }
            // Kiem tra xem phong co phai cung hoa don tong khong (cung BookingR)
            if (IsRoomInBookingR == true)
            {
                // Kiem tra xem da co thong tin cap nhat trong aChangeRoom chua, neu chua thi lay danh sachs khach trong database
                if (this.aChangeRoomEn.IsExitRoom(CodeRoom) == false)
                {
                    BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                    int CurrentIDBookingRooms = aBookingRoomsBO.Select_ByIDBookingRsAndCodeRoom(this.aBookingRoom.IDBookingR, CodeRoom).Max(p=>p.ID);
                    CustomersBO aCustomersBO = new CustomersBO();
                    List<Customers> aList = aCustomersBO.SelectListCustomer_ByIDBookingRoom(CurrentIDBookingRooms);
                    List<CustomerInfoEN> aListRet = new List<CustomerInfoEN>();
                    for (int i = 0; i < aList.Count; i++)
                    {
                        CustomerInfoEN aItem = new CustomerInfoEN(aList[i]);

                        aListRet.Add(aItem);
                    }
                    return aListRet;
                }
                // nếu thông tin phong đã có trong khối aChangeRoom thì lấy danh sách người ở trong khối đó ra
                else
                {
                    return this.aChangeRoomEn.GetItemChangeRooms(CodeRoom).GetAllCustomers();
                }
            }
            else
            {
                if (this.aChangeRoomEn.IsExitRoom(CodeRoom) == false)
                {
                    return new List<CustomerInfoEN>();
                }
                // nếu thông tin phong đã có trong khối aChangeRoom thì lấy danh sách người ở trong khối đó ra
                else
                {
                    return this.aChangeRoomEn.GetItemChangeRooms(CodeRoom).GetAllCustomers();
                }
            }
        }
        //#####################################################################
        private List<CustomerInfoEN> GetCustomers(List<BookingRoomsMembers> aList)
        {
            List<CustomerInfoEN> ret = new List<CustomerInfoEN>();
            CustomersBO aCustomersBO = new CustomersBO();
            for (int i = 0; i < aList.Count(); i++)
            {
                CustomerInfoEN aTemp = new CustomerInfoEN(aCustomersBO.Select_ByID(aList[i].IDCustomer));
                aTemp.DateEnterCountry = aList[i].DateEnterCountry;
                aTemp.EnterGate = aList[i].EnterGate;
                aTemp.LimitDateEnterCountry = aList[i].LimitDateEnterCountry;
                aTemp.Organization = aList[i].Organization;

                aTemp.PurposeComeVietnam = aList[i].PurposeComeVietnam;
                aTemp.TemporaryResidenceDate = aList[i].TemporaryResidenceDate;
                ret.Add(aTemp);
            }
            return ret;
        }
        private List<CustomerInfoEN> ConvertListCustomer(List<Customers> aList)
        {
            List<CustomerInfoEN> ret = new List<CustomerInfoEN>();
            for (int i = 0; i < aList.Count; i++)
            {
                CustomerInfoEN aTemp = new CustomerInfoEN(aList[i]);
                ret.Add(aTemp);

            }
            return ret ;
        }
        private void btnApplyBookingRoomMember_Click(object sender, EventArgs e)
        {
            if (this.aCurrentCustomerClick != null)
            {
                this.aCurrentCustomerClick.PurposeComeVietnam = txtPurposeComeVietnam.Text.ToString();

                if (dtpDateEnterCountry.EditValue != null)
                {
                    this.aCurrentCustomerClick.DateEnterCountry = (DateTime)dtpDateEnterCountry.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.TemporaryResidenceDate = DateTime.Parse("01/01/1900");
                }

                this.aCurrentCustomerClick.EnterGate = txtEnterGate.Text;
                if (dtpTemporaryResidenceDate.EditValue != null)
                {
                    this.aCurrentCustomerClick.TemporaryResidenceDate = (DateTime)dtpTemporaryResidenceDate.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.TemporaryResidenceDate = DateTime.Parse("01/01/1900");
                }

                if (dtpLeaveDate.EditValue != null)
                {
                    this.aCurrentCustomerClick.LeaveDate = (DateTime)dtpLeaveDate.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.LeaveDate = DateTime.Parse("01/01/1900");
                }

                this.aCurrentCustomerClick.Organization = txtOrganization.Text;

                if (dtpLimitDateEnterCountry.EditValue != null)
                {
                    this.aCurrentCustomerClick.LimitDateEnterCountry = (DateTime)dtpLimitDateEnterCountry.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.LimitDateEnterCountry = DateTime.Parse("01/01/1900");
                }

                this.aCurrentRoomInfo.UpdateCustomer(this.aCurrentCustomerClick);
            }
            else
            {
                this.aCurrentCustomerClick = new CustomerInfoEN();
                this.aCurrentCustomerClick.PurposeComeVietnam = txtPurposeComeVietnam.Text.ToString();

                if (dtpDateEnterCountry.EditValue != null)
                {this.aCurrentCustomerClick.DateEnterCountry = (DateTime)dtpDateEnterCountry.EditValue;}
                else{this.aCurrentCustomerClick.TemporaryResidenceDate = DateTime.Parse("01/01/1900");}

                this.aCurrentCustomerClick.EnterGate = txtEnterGate.Text;
                if (dtpTemporaryResidenceDate.EditValue != null)
                {
                    this.aCurrentCustomerClick.TemporaryResidenceDate = (DateTime)dtpTemporaryResidenceDate.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.TemporaryResidenceDate = DateTime.Parse("01/01/1900");
                }

                if (dtpLeaveDate.EditValue != null)
                {
                    this.aCurrentCustomerClick.LeaveDate = (DateTime)dtpLeaveDate.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.LeaveDate = DateTime.Parse("01/01/1900");
                }

                this.aCurrentCustomerClick.Organization = txtOrganization.Text;

                if (dtpLimitDateEnterCountry.EditValue != null)
                {
                    this.aCurrentCustomerClick.LimitDateEnterCountry = (DateTime)dtpLimitDateEnterCountry.EditValue;
                }
                else
                {
                    this.aCurrentCustomerClick.LimitDateEnterCountry = DateTime.Parse("01/01/1900");
                }

                this.aCurrentRoomInfo.AddCustomer(this.aCurrentCustomerClick);

                this.aChangeRoomEn.UpdateItemChangeRooms(this.aCurrentRoomInfo);
            }
        }
        public List<CustomerInfoEN> UpdateCustomer(CustomerInfoEN aCustomers)
        {
            try
               {

                for (int i = 0; i < this._alistCustomer.Count; i++)
                {
                    if (this._alistCustomer[i].ID == aCustomers.ID)
                    {

                        this._alistCustomer[i].Address = aCustomers.Address;
                        this._alistCustomer[i].Birthday = aCustomers.Birthday;
                        this._alistCustomer[i].Citizen = aCustomers.Citizen;

                        this._alistCustomer[i].Description = aCustomers.Description;
                        this._alistCustomer[i].Disable = aCustomers.Disable;
                        this._alistCustomer[i].Email = aCustomers.Email;
                        this._alistCustomer[i].Gender = aCustomers.Gender;

                        this._alistCustomer[i].ID = aCustomers.ID;
                        this._alistCustomer[i].Identifier1 = aCustomers.Identifier1;
                        this._alistCustomer[i].Identifier1CreatedDate = aCustomers.Identifier1CreatedDate;
                        this._alistCustomer[i].Identifier2 = aCustomers.Identifier2;
                        this._alistCustomer[i].Identifier2CreatedDate = aCustomers.Identifier2CreatedDate;

                        this._alistCustomer[i].Identifier3 = aCustomers.Identifier3;
                        this._alistCustomer[i].Identifier3CreatedDate = aCustomers.Identifier3CreatedDate;
                        this._alistCustomer[i].Info = aCustomers.Info;
                        this._alistCustomer[i].Name = aCustomers.Name;
                        this._alistCustomer[i].Nationality = aCustomers.Nationality;

                        this._alistCustomer[i].Note = aCustomers.Note;
                        this._alistCustomer[i].PlaceOfIssue1 = aCustomers.PlaceOfIssue1;
                        this._alistCustomer[i].PlaceOfIssue2 = aCustomers.PlaceOfIssue2;
                        this._alistCustomer[i].PlaceOfIssue3 = aCustomers.PlaceOfIssue3;
                        this._alistCustomer[i].Status = aCustomers.Status;

                        this._alistCustomer[i].Tel = aCustomers.Tel;
                        this._alistCustomer[i].Type = aCustomers.Type;

                        this._alistCustomer[i].EnterGate = aCustomers.EnterGate;
                        this._alistCustomer[i].PepoleRepresentative = aCustomers.PepoleRepresentative;
                        this._alistCustomer[i].PurposeComeVietnam = aCustomers.PurposeComeVietnam;
                        this._alistCustomer[i].DateEnterCountry = aCustomers.DateEnterCountry;
                        this._alistCustomer[i].EnterGate = aCustomers.EnterGate;
                        this._alistCustomer[i].TemporaryResidenceDate = aCustomers.TemporaryResidenceDate;
                        this._alistCustomer[i].LeaveDate = aCustomers.LeaveDate;
                        this._alistCustomer[i].Organization = aCustomers.Organization;
                        this._alistCustomer[i].LimitDateEnterCountry = aCustomers.LimitDateEnterCountry;
                    }
                }

               return this._alistCustomer;
               }
               catch (Exception p)
               {
               throw new Exception("ItemChangeRoomEn_UpdateCustomer " + p.ToString());
               }
        }
        //Hiennv         tao moi        10/12/2014            them 1 customer vao phong
        public void InsertCustomerInfoInRoom(CustomerInfoEN aCustomerInfoEN)
        {
            try
            {
                  this.aListCustomersInRoom.Insert(0,aCustomerInfoEN);
            }
            catch (Exception ex)
            {

            }
        }
        private void btnSelectCustomer_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                CustomerInfoEN aCustomersInfo = new CustomerInfoEN();
                aCustomersInfo.ID = Convert.ToInt32(Convert.ToString(viewAvailableCustomer.GetFocusedRowCellValue("ID")));
                aCustomersInfo.Name = Convert.ToString(viewAvailableCustomer.GetFocusedRowCellValue("Name"));
                aCustomersInfo.Identifier1 = Convert.ToString(viewAvailableCustomer.GetFocusedRowCellValue("Identifier1"));

                if(aCustomersInfo.Birthday !=null)
                {
                    aCustomersInfo.Birthday = Convert.ToDateTime(viewAvailableCustomer.GetFocusedRowCellValue("Birthday"));
                }

                RoomMemberEN aItem = aCheckInEN.aListRoomMembers.Where(p => p.RoomCode == lueIDRooms.EditValue.ToString()).ToList()[0];
                int Index = aCheckInEN.aListRoomMembers.IndexOf(aItem);
                aCheckInEN.aListRoomMembers[Index].ListCustomer.Add(aCustomersInfo);
                dgvSelectCustomer.DataSource = aCheckInEN.aListRoomMembers[Index].ListCustomer;
                dgvSelectCustomer.RefreshDataSource();

                Customers Temps = aListCustomers.Where(c => c.ID == Convert.ToInt32(viewAvailableCustomer.GetFocusedRowCellValue("ID"))).ToList()[0];
                aListCustomers.Remove(Temps);
                dgvAvailableCustomer.DataSource = this.aListCustomers;
                dgvAvailableCustomer.RefreshDataSource();

                txtPurposeComeVietnam.Text = null;
                txtEnterGate.Text = null;
                txtOrganization.Text =null;
                dtpDateEnterCountry.EditValue = null;
                dtpLeaveDate.EditValue = null;
                dtpLimitDateEnterCountry.EditValue = null;
                dtpTemporaryResidenceDate.EditValue = null;

                this.ReloadExtendInfoBookingRoomMembers(aCustomersInfo.ID);

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn_Goverment_Step3.btnSelectCustomer_ButtonClick\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void MoveCustomerRightToLeft()
        {
            DateTime? dateTime = null;
            CustomerInfoEN aCustomers = new CustomerInfoEN();
            aCustomers.ID = Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"));
            aCustomers.Name = String.IsNullOrEmpty(Convert.ToString(viewAvailableCustomers.GetFocusedRowCellValue("Name"))) == true ? String.Empty : Convert.ToString(viewAvailableCustomers.GetFocusedRowCellValue("Name"));
            aCustomers.Identifier1 = String.IsNullOrEmpty(Convert.ToString(viewAvailableCustomers.GetFocusedRowCellValue("Identifier1"))) == true ? String.Empty : Convert.ToString(viewAvailableCustomers.GetFocusedRowCellValue("Identifier1"));
            aCustomers.Birthday = String.IsNullOrEmpty(Convert.ToString(viewAvailableCustomers.GetFocusedRowCellValue("Birthday"))) == true ? dateTime : Convert.ToDateTime(viewAvailableCustomers.GetFocusedRowCellValue("Birthday"));

            List<CustomerInfoEN> ListAvailableCustomers = (List<CustomerInfoEN>)dgvAvailableCustomers.DataSource;
            CustomerInfoEN aRemoveCustomer = ListAvailableCustomers.Where(p => p.ID == aCustomers.ID).ToList()[0];
            ListAvailableCustomers.Remove(aRemoveCustomer);

            dgvAvailableCustomers.DataSource = null;
            dgvAvailableCustomers.DataSource = ListAvailableCustomers;
            dgvAvailableCustomers.RefreshDataSource();

            List<CustomerInfoEN> ListSelectCustomers = (List<CustomerInfoEN>)dgvSelectCustomers.DataSource;

            ListSelectCustomers.Insert(0, aRemoveCustomer);

            dgvSelectCustomers.DataSource = null;
            dgvSelectCustomers.DataSource = ListSelectCustomers;
            dgvSelectCustomers.RefreshDataSource();

            this.aCurrentRoomInfo.SetAddTimeStart(null);
            this.aCurrentRoomInfo.SetAddTimeEnd(null);
            this.aCurrentRoomInfo.SetTimeInUsed(null);

            this.aCurrentRoomInfo.SetCheckInActual(dtpCheckIn.DateTime);
            this.aCurrentRoomInfo.SetCheckInPlan(dtpCheckIn.DateTime);
            this.aCurrentRoomInfo.SetCheckOutActual(dtpCheckOut.DateTime);
            this.aCurrentRoomInfo.SetCheckOutPlan(dtpCheckOut.DateTime);

            this.aCurrentRoomInfo.UpdateCustomer(ListSelectCustomers);
            this.aCurrentRoomInfo.SetCost((new AccountancyBO()).CalculateCostRoom(this.aCurrentRoomInfo.GetCodeRoom(), this.aCurrentRoomInfo.GetPriceType(), this.aBookingRs.CustomerType.GetValueOrDefault(0), this.aCurrentRoomInfo.GetAllCustomers().Count));

            this.aChangeRoomEn.UpdateItemChangeRooms(this.aCurrentRoomInfo);

            this.ClearControl();
        }