public void SetValue(Customers aCustomers)
 {
     this.ID = aCustomers.ID;
     this.Name = aCustomers.Name;
     this.Identifier1 = aCustomers.Identifier1;
     this.Identifier1CreatedDate = aCustomers.Identifier1CreatedDate;
     this.Identifier2 = aCustomers.Identifier2;
     this.Identifier2CreatedDate = aCustomers.Identifier2CreatedDate;
     this.Identifier3 = aCustomers.Identifier3;
     this.Identifier3CreatedDate = aCustomers.Identifier3CreatedDate;
     this.Nationality = aCustomers.Nationality;
     this.Birthday = aCustomers.Birthday;
     this.Tel = aCustomers.Tel;
     this.Address = aCustomers.Address;
     this.Email = aCustomers.Email;
     this.Info = aCustomers.Info;
     this.Note = aCustomers.Note;
     this.Description = aCustomers.Description;
     this.Status = aCustomers.Status;
     this.Type = aCustomers.Type;
     this.Disable = aCustomers.Disable;
     this.Gender = aCustomers.Gender;
     this.Citizen = aCustomers.Citizen;
     this.PlaceOfIssue1 = aCustomers.PlaceOfIssue1;
     this.PlaceOfIssue2 = aCustomers.PlaceOfIssue2;
     this.PlaceOfIssue3 = aCustomers.PlaceOfIssue3;
 }
        public CustomerInfoEN()
        {
            Customers aItem = new Customers();

            this.Address = aItem.Address;
            this.Birthday = aItem.Birthday;
            this.Citizen = aItem.Citizen;

            this.Description = aItem.Description;
            this.Disable = aItem.Disable;
            this.Email = aItem.Email;
            this.Gender = aItem.Gender;
            this.ID = aItem.ID;
            this.Identifier1 = aItem.Identifier1;
            this.Identifier2 = aItem.Identifier2;
            this.Identifier3 = aItem.Identifier3;
            this.Identifier1CreatedDate = aItem.Identifier1CreatedDate;
            this.Identifier2CreatedDate = aItem.Identifier2CreatedDate;
            this.Identifier3CreatedDate = aItem.Identifier3CreatedDate;

            this.Info = aItem.Info;
            this.Name = aItem.Name;
            this.Nationality = aItem.Nationality;
            this.Note = aItem.Note;

            this.PlaceOfIssue1 = aItem.PlaceOfIssue1;
            this.PlaceOfIssue2 = aItem.PlaceOfIssue2;
            this.PlaceOfIssue3 = aItem.PlaceOfIssue3;

            this.Status = aItem.Status;
            this.Tel = aItem.Tel;
            this.Type = aItem.Type;
        }
        private void btnPrintByCustomer_Click(object sender, EventArgs e)
        {
            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomer = new Customers();
            aCustomer = aCustomersBO.Select_ByID(int.Parse(loeListCustomer.EditValue.ToString()));
            this.aNewPaymentEN = this.aNewPaymentEN.SlipPaymentByCustomer(aCustomer);

            try
            {
                if (this.aNewPaymentEN.Status_BookingR == 8 || this.aNewPaymentEN.Status_BookingR == 7)
                {

                    frmRpt_Payment_BookingRs afrmRpt_Payment_BookingRs = new frmRpt_Payment_BookingRs(this.aNewPaymentEN);
                    ReportPrintTool tool = new ReportPrintTool(afrmRpt_Payment_BookingRs);
                    tool.ShowPreview();
                }
                else
                {
                    frmRpt_Payment_BookingRsUnPay afrmRpt_Payment_BookingRs = new frmRpt_Payment_BookingRsUnPay(this.aNewPaymentEN);
                    ReportPrintTool tool = new ReportPrintTool(afrmRpt_Payment_BookingRs);
                    tool.ShowPreview();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_ChoosePrintType.btnPrint_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //hiennv
        private void btCreateNew_Click(object sender, EventArgs e)
        {
            try
            {

                if (this.CheckDataBeforeCreateNew() == true)
                {
                    DateTime? NullDateTime = null;

                    CustomersBO acustomersBo = new CustomersBO();
                    Customers aCustomers = new Customers();

                    aCustomers.Name = txtNames.Text;
                    aCustomers.Identifier1 = txtIdentifier1.Text;
                    aCustomers.Identifier2 = txtIdentifier2.Text;
                    aCustomers.Identifier3 = txtIdentifier3.Text;
                    aCustomers.Identifier1CreatedDate = String.IsNullOrEmpty(dtpIdentifier1CreatedDate.Text) == true ? NullDateTime : dtpIdentifier1CreatedDate.DateTime;
                    aCustomers.PlaceOfIssue1 = txtPlaceOfIssue1.Text;
                    aCustomers.AgencyOfIssue1 = txtAgencyOfIssue1.Text;
                    aCustomers.Birthday = String.IsNullOrEmpty(dtpBirthday.Text) == true ? NullDateTime : dtpBirthday.DateTime;
                    aCustomers.Gender = Convert.ToString(lueGender.EditValue);
                    aCustomers.Address = txtAddress.Text;
                    aCustomers.Nationality = Convert.ToString(lueNationality.EditValue);
                    aCustomers.Tel = txtTel.Text;
                    aCustomers.Email = txtEmail.Text;
                    aCustomers.Info = txaInfo.Text;
                    aCustomers.Note = txaNote.Text;
                    aCustomers.Description = txaDescription.Text;
                    aCustomers.Status = Convert.ToInt32(lueStatus.EditValue);
                    aCustomers.Type = cbbCustomerType.SelectedIndex + 1;
                    aCustomers.Citizen = Convert.ToInt32(lueCitizen.EditValue);
                    aCustomers.Disable = bool.Parse(cboDisable.Text);

                    int count = acustomersBo.Insert(aCustomers);

                    if (count > 0)
                    {
                        MessageBox.Show("Bạn đã thêm mới khách hàng thành công !", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (this.afrmIns_CustomerGroups_Customers != null)
                        {
                            this.afrmIns_CustomerGroups_Customers.LoadDataAvailableCustomers();
                        }
                        else if (this.afrmLst_Customers != null)
                        {
                            this.afrmLst_Customers.ReloadData();
                        }
                        else if (this.afrmTsk_EditBooking != null)
                        {
                            this.afrmTsk_EditBooking.ReloadCustomers();
                        }
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmAddNewCustomers.btCreateNew_Click\n" + ex.ToString(), "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //add new customer
 public int Insert(Customers customer)
 {
     try
     {
         aDatabaseDA.Customers.Add(customer);
         aDatabaseDA.SaveChanges();
         return customer.ID;
     }
     catch (Exception ex)
     {
         throw new Exception("CustomersBO.Insert:" + ex.ToString());
     }
 }
        //Lingting - Tự động thêm khách hàng và đưa vào nhóm
        public int AutoInsertCustomer(string Name, int IDCustomerGroup, string Tel,DateTime FromDate)
        {
            try
            {
                Customers aCustomer = new Customers();
                aCustomer.Name = Name;
                aCustomer.Tel = Tel;
                aCustomer.Disable = false;
                this.Insert(aCustomer);

                CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                aCustomerGroups_CustomersBO.AutoInsertCustomerToGroup(aCustomer.ID, IDCustomerGroup, FromDate);
                return aCustomer.ID;
            }
            catch (Exception ex)
            {
                return 0;
                throw new Exception("CustomersBO.AutoInsertCustomer:" + ex.ToString());
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DateTime? dateTime = null;

            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomers = new Customers();

            //Update
            if (this.IDCustomer > 0)
            {
                aCustomers = aCustomersBO.Select_ByID(IDCustomer);
            }
            else
            {
                aCustomers = new Customers();
            }
            aCustomers.Address = txtAddress.Text;
            aCustomers.Birthday = String.IsNullOrEmpty(dtpBirthday.Text) ? dateTime : dtpBirthday.DateTime;
            aCustomers.Citizen = Convert.ToInt32(lueCitizen.EditValue);

            aCustomers.Email = txtEmail.Text;
            aCustomers.Gender = lueGender.EditValue.ToString();
            aCustomers.Identifier1 = txtIdentifier1.Text;
            aCustomers.Identifier2 = txtIdentifier2.Text;
            aCustomers.Identifier3 = txtIdentifier3.Text;

            aCustomers.Name = txtNames.Text;
            aCustomers.Nationality = lueNationality.EditValue.ToString();
            aCustomers.Tel = txtTel.Text;

            if (this.IDCustomer > 0)
            {
                aCustomersBO.Update(aCustomers);
            }
            else
            {
                this.IDCustomer = aCustomersBO.Insert(aCustomers);
            }
            MessageBox.Show("Thêm mới khách thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public bool NewOrEditBookingRoomByType(BookingRoomByTypeEN aBookingRoomByTypeEN)
        {
            try{
                BookingRoomByType aNewBooking = new BookingRoomByType();
                int IDCustomer = 0;

                #region Them moi khach hang khi khach hang chua co
                if (aBookingRoomByTypeEN.IDCustomer > 0) {
                    IDCustomer = aBookingRoomByTypeEN.IDCustomer;
                }
                else {
                    CustomersBO aCustomersBO = new CustomersBO();
                    Customers aCustomers = new Customers();
                    if (aBookingRoomByTypeEN.CustomerName.Length > 50) {
                        aCustomers.Name = aBookingRoomByTypeEN.CustomerName.Substring(0, 50);
                    }
                    else {
                        aCustomers.Name = aBookingRoomByTypeEN.CustomerName;
                    }
                    IDCustomer = aCustomersBO.Insert(aCustomers);
                }
                #endregion
                aNewBooking.ID = aBookingRoomByTypeEN.ID;
                aNewBooking.IDCustomer = IDCustomer;
                aNewBooking.FromDate = aBookingRoomByTypeEN.FromDate;
                aNewBooking.ToDate = aBookingRoomByTypeEN.ToDate;
                aNewBooking.Suite = aBookingRoomByTypeEN.Suite;
                aNewBooking.Superior = aBookingRoomByTypeEN.Superior;
                aNewBooking.Standard = aBookingRoomByTypeEN.Standard;
                aNewBooking.BookingStatus = aBookingRoomByTypeEN.BookingStatus;

                aDatabaseDA.BookingRoomByType.AddOrUpdate(aNewBooking);
                aDatabaseDA.SaveChanges();
                return true;
            }
            catch(Exception ex){
                return false;
                throw new Exception("BookingRoomByTypeBO.NewBookingRoomByType"+ex.ToString());
            }
        }
        private void btCreateNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    CustomersBO acustomersBo = new CustomersBO();
                    Customers aCustomers = new Customers();
                    aCustomers.Name = txtNames.Text;
                    aCustomers.Identifier1 = txtIdentifier1.Text;
                    aCustomers.Birthday = dtpBirthday.DateTime;
                    aCustomers.Address = txtAddress.Text;
                    aCustomers.Tel = txtTel.Text;
                    aCustomers.Email = txtEmail.Text;
                    aCustomers.Info = txtInfo.Text;
                    aCustomers.Status = Convert.ToInt32(lueStatus.EditValue);
                    aCustomers.Type = Convert.ToInt32(cbbCustomerType.Text);
                    aCustomers.Disable = bool.Parse(cboDisable.Text);

                    acustomersBo.Insert(aCustomers);

                    if (this.afrmIns_CustomerGroups_Customers != null)
                    {
                        this.afrmIns_CustomerGroups_Customers.LoadDataAvailableCustomers();
                    }
                    else if (this.afrmLst_Customers != null)
                    {
                        this.afrmLst_Customers.ReloadData();
                    }

                    MessageBox.Show("Bạn đã thêm mới khách hàng thành công !", "Success ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmAddNewCustomers.btCreateNew_Click\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void loeListCustomer_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {
            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomer = new Customers();

            if (loeListCustomer.OldEditValue != null || int.Parse(e.NewValue.ToString()) != 0 )  // Để khi fill dữ liệu vào lần đầu không xóa mất aNewPaymentEN
            {
                if (int.Parse(e.OldValue.ToString()) == 0)
                {
                    this.aNewPaymentEN_Backup.Clone(this.aNewPaymentEN);
                    aCustomer = aCustomersBO.Select_ByID(int.Parse(e.NewValue.ToString()));
                    this.aNewPaymentEN = this.aNewPaymentEN.SlipPaymentByCustomer(aCustomer);
                    if (this.aNewPaymentEN.aListBookingRoomUsed.Count > 0)
                    {
                        this.CurrentIDBookingRoom = this.aNewPaymentEN.aListBookingRoomUsed[0].ID;
                    }
                    else
                    {
                        MessageBox.Show("Có thể có lỗi dữ liệu vì người dùng này đang không tồn tại trong phòng nào");
                    }

                    this.LoadDataCurrentHallForControl();
                    this.LoadDataCurrentRoomForControl();
                }
                else if (int.Parse(e.OldValue.ToString()) != 0)
                {

                    if (int.Parse(e.NewValue.ToString()) != 0) // Khi chọn hiển thị dữ liệu cho một người khác
                    {
                        this.aNewPaymentEN.Clone(this.aNewPaymentEN_Backup);

                        aCustomer = aCustomersBO.Select_ByID(int.Parse(e.NewValue.ToString()));
                        this.aNewPaymentEN = this.aNewPaymentEN.SlipPaymentByCustomer(aCustomer);

                        if (this.aNewPaymentEN.aListBookingRoomUsed.Count > 0)
                        {
                            this.CurrentIDBookingRoom = this.aNewPaymentEN.aListBookingRoomUsed[0].ID;
                        }
                        else
                        {
                            MessageBox.Show("Có thể có lỗi dữ liệu vì người dùng này đang không tồn tại trong phòng nào");
                        }

                        this.LoadDataCurrentHallForControl();
                        this.LoadDataCurrentRoomForControl();
                    }
                    else //khi chọn hiển thị dữ liệu cho tất cả
                    {
                        this.aNewPaymentEN.Clone(this.aNewPaymentEN_Backup);
                        if (this.aNewPaymentEN.aListBookingRoomUsed.Count > 0)
                        {
                            this.CurrentIDBookingRoom = this.aNewPaymentEN.aListBookingRoomUsed[0].ID;
                        }
                        else
                        {
                            MessageBox.Show("Có thể có lỗi dữ liệu vì người dùng này đang không tồn tại trong phòng nào");
                        }

                        this.LoadDataCurrentHallForControl();
                        this.LoadDataCurrentRoomForControl();
                    }
                }
            }
        }
        public void frmTsk_Payment_Step2_Load(object sender, EventArgs e)
        {
            try
            {

                // Load du lieu vao khoi Payment
                this.InitData(this.IDBookingR, this.IDBookingH);
                // Set trang thai lock/unlock cac control tuy theo trang thai hoa don da dc thanh toan hay chua
                this.CheckPaymentStatus();

                this.LoadDataCurrentRoomForControl();
                this.LoadDataCurrentHallForControl();

                Customers aDefaultCustomer = new Customers();
                aDefaultCustomer.Name = "[Hiển thị tất cả]";
                aDefaultCustomer.ID = 0;
                List<Customers> aListCustomer = new List<Customers>();
                aListCustomer = this.aNewPaymentEN.GetListAllCustomer();
                aListCustomer.Add(aDefaultCustomer);
                loeListCustomer.Properties.DataSource = aListCustomer;
                loeListCustomer.Properties.NullText = "[Hiển thị tất cả]";
                loeListCustomer.EditValue = 0;

            }
            catch (Exception ex)
            {

                MessageBox.Show("frmTsk_PaymentStep2.frmTsk_Payment_Step2_Load\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            BookingRoomsMembers aBookingRoomsMembers = new BookingRoomsMembers();

            DateTime? dateTime = null;

            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomers = new Customers();

            //Update
            if (this.IDCustomer > 0)
            {
                aCustomers = aCustomersBO.Select_ByID(IDCustomer);
            }
            else
            {
                aCustomers = new Customers();
            }
            aCustomers.Address = txtAddress.Text;
            aCustomers.Birthday = String.IsNullOrEmpty(dtpBirthday.Text) ? dateTime : dtpBirthday.DateTime;
            aCustomers.Citizen = Convert.ToInt32(lueCitizen.EditValue);

            aCustomers.Email = txtEmail.Text;
            aCustomers.Gender = lueGender.EditValue.ToString();
            aCustomers.Identifier1 = txtIdentifier1.Text;
            aCustomers.Identifier2 = txtIdentifier2.Text;
            aCustomers.Identifier3 = txtIdentifier3.Text;

            aCustomers.Name = txtNames.Text;
            aCustomers.Nationality = lueNationality.EditValue.ToString();
            aCustomers.Tel = txtTel.Text;

            if (this.IDCustomer > 0)
            {
                aCustomersBO.Update(aCustomers);
            }
            else
            {
                this.IDCustomer = aCustomersBO.Insert(aCustomers);
            }
            /*Insert nguoi moi vao group*/
            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            aCustomerGroups_CustomersBO.InsertCustomerIntoCustomerGroup_ByIDBookingRs(this.IDCustomer, (new BookingRsBO()).Select_ByIDBookingRoom(this.IDBookingRoom).ID);
            /*--------------------------*/

            aBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom_ByIDCustomer(this.IDBookingRoom, this.IDCustomer);
            if (aBookingRoomsMembers == null)
            {
                aBookingRoomsMembers = new BookingRoomsMembers();
                aBookingRoomsMembers.IDBookingRoom = this.IDBookingRoom;
                aBookingRoomsMembers.IDCustomer = this.IDCustomer;
            }

            aBookingRoomsMembers.DateEnterCountry = String.IsNullOrEmpty(dtpDateEnterCountry.Text) ? dateTime : dtpDateEnterCountry.DateTime;
            aBookingRoomsMembers.EnterGate = txtEnterGate.Text;

            aBookingRoomsMembers.LeaveDate = String.IsNullOrEmpty(dtpLeaveDate.Text) ? dateTime : dtpLeaveDate.DateTime;
            aBookingRoomsMembers.LimitDateEnterCountry = String.IsNullOrEmpty(dtpLimitDateEnterCountry.Text) ? dateTime : dtpLimitDateEnterCountry.DateTime;
            aBookingRoomsMembers.Organization = txtOrganization.Text;
            aBookingRoomsMembers.PurposeComeVietnam = txtPurposeComeVietnam.Text;
            aBookingRoomsMembers.TemporaryResidenceDate = String.IsNullOrEmpty(dtpTemporaryResidenceDate.Text) ? dateTime : dtpTemporaryResidenceDate.DateTime;

            if (aBookingRoomsMembers.ID > 0)
            {
                aBookingRoomsMembersBO.Update(aBookingRoomsMembers);
            }
            else
            {
                aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);
            }
            MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.afrmTsk_Payment_Step2.Reload();
              //  this.afrmTsk_Payment_Step2.ReloadMoneyRoom();
            this.Close();
        }
        private void btnRemoveAvaiableCustomers_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            this.IDCustomer = Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"));
            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomers = new Customers();

            aCustomers = aCustomersBO.Select_ByID(this.IDCustomer);
            txtAddress.Text = aCustomers.Address;
            dtpBirthday.EditValue = aCustomers.Birthday;
            lueCitizen.EditValue = aCustomers.Citizen;

            txtEmail.Text = aCustomers.Email;

            if (String.IsNullOrEmpty(aCustomers.Gender) == false)
            {
                lueGender.EditValue = Convert.ToInt32(aCustomers.Gender);
            }

            txtIdentifier1.Text = aCustomers.Identifier1;
            txtIdentifier2.Text = aCustomers.Identifier2;
            txtIdentifier3.Text = aCustomers.Identifier3;

            txtNames.Text = aCustomers.Name;
            lueNationality.EditValue = aCustomers.Nationality;
            txtTel.Text = aCustomers.Tel;
        }
        //=======================================================
        //Author: LinhTing
        //Function : Tìm danh sách khách qua đêm
        //=======================================================
        //public List<OverNightCustomerEN> GetOverNightCustomer(DateTime CheckPoint, int Status)
        //{
        //    List<BookingRooms> aListBookingRooms = aBookingRoomsBO.Select_ByStatus_ByTime(CheckPoint, Status);
        //    List<BookingRoomsMembers> aListBookingRoomsMembers = new List<BookingRoomsMembers>();
        //    List<OverNightCustomerEN> aListOverNightCustomer = new List<OverNightCustomerEN>();
        //    OverNightCustomerEN aOverNightCustomer = new OverNightCustomerEN();
        //    Customers aCustomers;
        //    string a = DateTime.Now.Ticks.ToString();
        //    for (int i = 0; i < aListBookingRooms.Count; i++)
        //    {
        //        aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom(aListBookingRooms[i].ID);
        //        for (int y = 0; y < aListBookingRoomsMembers.Count; y++)
        //        {
        //            aOverNightCustomer = new OverNightCustomerEN();
        //            aCustomers = new Customers();
        //            int IDCustomer = aListBookingRoomsMembers[y].IDCustomer;
        //            aCustomers = aCustomersBO.Select_ByID(IDCustomer);
        //            if (aCompaniesBO.Select_ByIDBookingRoom(aListBookingRooms[i].ID) != null)
        //            {
        //                aOverNightCustomer.CompanyName = aCompaniesBO.Select_ByIDBookingRoom(aListBookingRooms[i].ID).Name;
        //            }
        //            aOverNightCustomer.PurposeComeVietnam = aListBookingRoomsMembers[y].PurposeComeVietnam;
        //            aOverNightCustomer.IDBookingRoom = aListBookingRooms[i].ID;
        //            if (aRoomsBO.Select_ByCodeRoom(aListBookingRooms[i].CodeRoom, 1) != null)
        //            {
        //                aOverNightCustomer.Sku = aRoomsBO.Select_ByCodeRoom(aListBookingRooms[i].CodeRoom, 1).Sku;
        //            }
        //            if (aBookingRsBO.Select_ByID(aListBookingRooms[i].IDBookingR) != null)
        //            {
        //                aOverNightCustomer.CustomerType = aBookingRsBO.Select_ByID(aListBookingRooms[i].IDBookingR).CustomerType;
        //            }
        //            aOverNightCustomer.CheckInActual = aListBookingRooms[i].CheckInActual;
        //            aOverNightCustomer.CheckOutPlan = aListBookingRooms[i].CheckOutPlan;
        //            aOverNightCustomer.Name = aCustomers.Name;
        //            aOverNightCustomer.IDCustomer = aCustomers.ID;
        //            aOverNightCustomer.Identifier1 = aCustomers.Identifier1;
        //            aOverNightCustomer.Identifier2 = aCustomers.Identifier2;
        //            aOverNightCustomer.Identifier3 = aCustomers.Identifier3;
        //            aOverNightCustomer.Nationality = aCustomers.Nationality;
        //            aOverNightCustomer.Birthday = aCustomers.Birthday;
        //            aOverNightCustomer.Tel = aCustomers.Tel;
        //            aOverNightCustomer.Address = aCustomers.Address;
        //            aOverNightCustomer.Email = aCustomers.Email;
        //            aOverNightCustomer.Info = aCustomers.Info;
        //            aOverNightCustomer.Gender = aCustomers.Gender;
        //            aOverNightCustomer.Citizen = aCustomers.Citizen;
        //            aOverNightCustomer.Identifier1CreatedDate = aCustomers.Identifier1CreatedDate;
        //            aOverNightCustomer.Identifier2CreatedDate = aCustomers.Identifier2CreatedDate;
        //            aOverNightCustomer.Identifier3CreatedDate = aCustomers.Identifier3CreatedDate;
        //            aOverNightCustomer.PlaceOfIssue1 = aCustomers.PlaceOfIssue1;
        //            aOverNightCustomer.PlaceOfIssue2 = aCustomers.PlaceOfIssue2;
        //            aOverNightCustomer.PlaceOfIssue3 = aCustomers.PlaceOfIssue3;
        //            aListOverNightCustomer.Add(aOverNightCustomer);
        //        }
        //    }
        //    a = a + "---" + DateTime.Now.Ticks.ToString();
        //    return aListOverNightCustomer;
        //}
        // Author : LinhTing
        // Select list khách qua đêm mới
        public List<OverNightCustomerEN> GetNewOverNightCustomer(DateTime CheckPoint, int Status)
        {
            List<BookingRooms> aListNewBookingRooms = aBookingRoomsBO.Select_ByStatus_ByTime(CheckPoint, CheckPoint.AddDays(-1), Status);
            List<BookingRoomsMembers> aListNewBookingRoomsMembers = new List<BookingRoomsMembers>();
            List<OverNightCustomerEN> aListNewOverNightCustomer = new List<OverNightCustomerEN>();
            OverNightCustomerEN aNewOverNightCustomer = new OverNightCustomerEN();
            Customers aCustomers;

            for (int i = 0; i < aListNewBookingRooms.Count; i++)
            {
                aListNewBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom(aListNewBookingRooms[i].ID);

                for (int y = 0; y < aListNewBookingRoomsMembers.Count; y++)
                {
                    aNewOverNightCustomer = new OverNightCustomerEN();

                    aCustomers = new Customers();
                    int IDCustomer = aListNewBookingRoomsMembers[y].IDCustomer;
                    aCustomers = aCustomersBO.Select_ByID(IDCustomer);

                    aNewOverNightCustomer.CompanyName = aCompaniesBO.Select_ByIDBookingRoom(aListNewBookingRooms[i].ID).Name;

                    aNewOverNightCustomer.PurposeComeVietnam = aListNewBookingRoomsMembers[y].PurposeComeVietnam;
                    aNewOverNightCustomer.IDBookingRoom = aListNewBookingRooms[i].ID;

                    aNewOverNightCustomer.Sku = aRoomsBO.Select_ByCodeRoom(aListNewBookingRooms[i].CodeRoom, 1).Sku;

                    aNewOverNightCustomer.CustomerType = aBookingRsBO.Select_ByID(aListNewBookingRooms[i].IDBookingR).CustomerType;

                    aNewOverNightCustomer.CheckInActual = aListNewBookingRooms[i].CheckInActual;
                    aNewOverNightCustomer.CheckOutPlan = aListNewBookingRooms[i].CheckOutPlan;
                    aNewOverNightCustomer.Name = aCustomers.Name;
                    aNewOverNightCustomer.IDCustomer = aCustomers.ID;
                    aNewOverNightCustomer.Identifier1 = aCustomers.Identifier1;
                    aNewOverNightCustomer.Identifier2 = aCustomers.Identifier2;
                    aNewOverNightCustomer.Identifier3 = aCustomers.Identifier3;
                    aNewOverNightCustomer.Nationality = aCustomers.Nationality;
                    aNewOverNightCustomer.Birthday = String.Format("{0:MM-dd-yyyy}", aCustomers.Birthday);

                    aNewOverNightCustomer.Tel = aCustomers.Tel;
                    aNewOverNightCustomer.Address = aCustomers.Address;
                    aNewOverNightCustomer.Email = aCustomers.Email;
                    aNewOverNightCustomer.Info = aCustomers.Info;
                    aNewOverNightCustomer.Gender = aCustomers.Gender;
                    aNewOverNightCustomer.Citizen = aCustomers.Citizen;
                    aNewOverNightCustomer.Identifier1CreatedDate = aCustomers.Identifier1CreatedDate;
                    aNewOverNightCustomer.Identifier2CreatedDate = aCustomers.Identifier2CreatedDate;
                    aNewOverNightCustomer.Identifier3CreatedDate = aCustomers.Identifier3CreatedDate;
                    aNewOverNightCustomer.PlaceOfIssue1 = aCustomers.PlaceOfIssue1;
                    aNewOverNightCustomer.PlaceOfIssue2 = aCustomers.PlaceOfIssue2;
                    aNewOverNightCustomer.PlaceOfIssue3 = aCustomers.PlaceOfIssue3;
                    aNewOverNightCustomer.AgencyOfIssue1 = aCustomers.AgencyOfIssue1;
                    aNewOverNightCustomer.AgencyOfIssue2 = aCustomers.AgencyOfIssue2;
                    aNewOverNightCustomer.AgencyOfIssue3 = aCustomers.AgencyOfIssue3;

                    aListNewOverNightCustomer.Add(aNewOverNightCustomer);
                }
            }
            return aListNewOverNightCustomer;
        }
        //update customers
        public int Update(Customers customer)
        {
            try
            {
                aDatabaseDA.Customers.AddOrUpdate(customer);
                return aDatabaseDA.SaveChanges();

            }
            catch (Exception ex)
            {

                throw new Exception("CustomersBO.Update:" + ex.ToString());
            }
        }
        public NewPaymentEN SlipPaymentByCustomer(Customers aCustomers)
        {
            NewPaymentEN aNewPaymentEN = new NewPaymentEN();
               aNewPaymentEN = this;

               List<BookingRoomUsedEN> aList = new List<BookingRoomUsedEN>();
               for (int a = 0; a < this.aListBookingRoomUsed.Count; a++)
               {

               int Count  = this.aListBookingRoomUsed[a].ListCustomer.Where(p=>p.ID == aCustomers.ID).ToList().Count;
               if (Count > 0)
               {
                   aList.Add(this.aListBookingRoomUsed[a]);
               }
               }

               int NumberCustomerInRoom = 0;
               List<ServiceUsedEN> aListService = new List<ServiceUsedEN>();
               for (int i = 0; i < aList.Count; i++)
               {
               NumberCustomerInRoom = aList[i].ListCustomer.Count ;
               aList[i].Cost = aList[i].Cost / NumberCustomerInRoom;
               aList[i].CostPendingRoom = aList[i].CostPendingRoom / NumberCustomerInRoom;
               aList[i].CostRef_Rooms = aList[i].CostRef_Rooms / NumberCustomerInRoom;
               aListService = new List<ServiceUsedEN>();
               aListService = aList[i].ListServiceUsed.Where(p => p.Tag != aCustomers.ID.ToString()).ToList();
               for (int ii = 0; ii < aListService.Count; ii++)
               {
                   aList[i].ListServiceUsed.Remove(aListService[ii]);
               }

               }
               aNewPaymentEN.aListBookingRoomUsed.Clear();
               aNewPaymentEN.aListBookingRoomUsed.AddRange (aList);
               return aNewPaymentEN;
        }
        public void LoadData()
        {
            //Load dữ liệu công ty
            if (this.CustomerType == 1)
            {
                this.Text = "Đặt tiệc cho khách nhà nước";
                Companies aDefault = new Companies();
                List<Companies> aList = new List<Companies>();
                aDefault.Name = "[Tạo mới cty]";
                aDefault.ID = 0;

                aList = aCompaniesBO.Select_ByType(1);// [Company] Type = 1 : khách nhà nước
                aList.Add(aDefault);
                lueCompany.Properties.DataSource = aList;
                lueCompany.Properties.DisplayMember = "Name";
                lueCompany.Properties.ValueMember = "ID";

                if (this.IDCompany > 0)
                {
                    lueCompany.EditValue = this.IDCompany;
                }
                else
                {
                    lueCompany.EditValue = 0;
                }
            }
            if (this.CustomerType == 2)
            {
                this.Text = "Đặt tiệc cho khách đoàn";

                Companies aDefault = new Companies();
                List<Companies> aList = new List<Companies>();
                aDefault.Name = "[Tạo mới cty]";
                aDefault.ID = 0;

                aList = aCompaniesBO.Select_ByType(2);// [Company] Type = 2 : khách đoàn
                aList.Add(aDefault);
                lueCompany.Properties.DataSource = aList;
                lueCompany.Properties.DisplayMember = "Name";
                lueCompany.Properties.ValueMember = "ID";

                if (this.IDCompany > 0)
                {
                    lueCompany.EditValue = this.IDCompany;
                }
                else
                {
                    lueCompany.EditValue = 0;
                }
            }
            if (this.CustomerType == 3)
            {
                this.Text = "Đặt tiệc cho khách lẻ";

                Companies aDefault = new Companies();
                List<Companies> aList = new List<Companies>();
                aDefault.Name = "[Tạo mới cty]";
                aDefault.ID = 0;

                aList = aCompaniesBO.Select_ByType(3);// [Company] Type = 3 : khách lẻ
                aList.Add(aDefault);
                lueCompany.Properties.DataSource = aList;
                lueCompany.Properties.DisplayMember = "Name";
                lueCompany.Properties.ValueMember = "ID";
                if (this.IDCompany > 0)
                {
                    lueCompany.EditValue = this.IDCompany;
                }
                else
                {
                    lueCompany.EditValue = 0;
                }
            }

            //Load dữ liệu khách
            Customers aDefaultCustomers = new Customers();
            List<Customers> aListCustomers = new List<Customers>();
            aDefaultCustomers.Name = "[Tạo mới người đại diện]";
            aDefaultCustomers.ID = 0;

            aListCustomers = aCustomersBO.Select_All();// [Company] Type = 3 : khách lẻ
            aListCustomers.Add(aDefaultCustomers);

            lueCustomer.Properties.DataSource = aListCustomers;
            lueCustomer.Properties.DisplayMember = "Name";
            lueCustomer.Properties.ValueMember = "ID";

            if (this.IDCustomer > 0)
            {
                lueCustomer.EditValue = this.IDCustomer;

            }
            else
            {
                lueCustomer.EditValue = 0;
            }

            // Load khách mời
            GuestsBO aGuestsBO = new GuestsBO();
            lueGuest.Properties.DataSource = aGuestsBO.Select_All();
            lueGuest.Properties.DisplayMember = "Name";
            lueGuest.Properties.ValueMember = "ID";
            //LoadDataListFoods();

            if (this.IsEditForm == true)
            {
                BookingHsBO aBookingHsBO = new BookingHsBO();
                aBookingHsBO.Select_ByID(this.IDBookingH);
            }
        }
        //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;
            }
        }
        private void btnRemoveAvaiableCustomers_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            this.IDCustomer = Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"));
            CustomersBO aCustomersBO = new CustomersBO();
            Customers aCustomers = new Customers();

            aCustomers = aCustomersBO.Select_ByID(this.IDCustomer);
            txtAddress.Text = aCustomers.Address;
            dtpBirthday.EditValue = aCustomers.Birthday;
            lueCitizen.EditValue = aCustomers.Citizen;

            txtEmail.Text = aCustomers.Email;

            if (String.IsNullOrEmpty(aCustomers.Gender) == false)
            {
                lueGender.EditValue = Convert.ToInt32(aCustomers.Gender);
            }

            txtIdentifier1.Text = aCustomers.Identifier1;
            txtIdentifier2.Text = aCustomers.Identifier2;
            txtIdentifier3.Text = aCustomers.Identifier3;

            txtNames.Text = aCustomers.Name;
            lueNationality.EditValue = aCustomers.Nationality;
            txtTel.Text = aCustomers.Tel;
            //--------------------
            txtNames.EditValue = aCustomers.Name;
            txtIdentifier1.EditValue = aCustomers.Identifier1;
            txtIdentifier2.EditValue = aCustomers.Identifier2;
            txtIdentifier3.EditValue = aCustomers.Identifier3;
            if (aCustomers.Birthday != null)
            {
                dtpBirthday.EditValue = aCustomers.Birthday;
            }
            if (String.IsNullOrEmpty(aCustomers.Gender) == false)
            {
                lueGender.EditValue = Convert.ToInt32(aCustomers.Gender);
            }

            txtAddress.EditValue = aCustomers.Address;

            if (String.IsNullOrEmpty(aCustomers.Nationality) == false)
            {
                lueNationality.EditValue = aCustomers.Nationality;
            }
            if (lueNationality.EditValue == null)
            {
                lueNationality.EditValue = CORE.CONSTANTS.SelectedCountry(704).Code;
            }
            if (aCustomers.Citizen > 0)
            {
                lueCitizen.EditValue = aCustomers.Citizen;
            }
            else
            {
                lueCitizen.EditValue = CORE.CONSTANTS.SelectedCitizen(2).ID;
            }
            //----------------------------------------------------------------
            if (aCustomers.Gender != null)
            {
                lueGender.EditValue = aCustomers.Citizen;
            }
            else
            {
                lueGender.EditValue = CORE.CONSTANTS.SelectedGender(1).ID;
            }

            txtTel.EditValue = aCustomers.Tel;
            txtEmail.EditValue = aCustomers.Email;
        }
        public List<OverNightCustomerEN> GetOverNightCustomer(DateTime CheckPoint, int Status)
        {
            List<BookingRooms> aListBookingRooms = aBookingRoomsBO.Select_ByStatus_ByTime(CheckPoint, Status);
            List<BookingRoomsMembers> aListBookingRoomsMembers = new List<BookingRoomsMembers>();
            List<OverNightCustomerEN> aListOverNightCustomer = new List<OverNightCustomerEN>();
            OverNightCustomerEN aOverNightCustomer = new OverNightCustomerEN();
            Customers aCustomers;

            // get tất cả dữ liệu
            List<int> aListIDBookingRoom = new List<int>();
            int aTemp;
            for (int i = 0; i < aListBookingRooms.Count; i++)
            {
                aTemp = new int();
                aTemp = aListBookingRooms[i].ID;
                aListIDBookingRoom.Add(aTemp);
            }
            List<string> aListCodeRoom = new List<string>();

            for (int i = 0; i < aListBookingRooms.Count; i++)
            {
                string aCode;
                aCode = aListBookingRooms[i].CodeRoom;
                aListCodeRoom.Add(aCode);
            }

            List<BookingRoomsMembers> aListAllBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByListIDBookingRoom(aListIDBookingRoom);
            List<Companies> aListCompanies = aCompaniesBO.Select_ByListIDBookingRoom(aListIDBookingRoom);
            List<CustomerGroups> aListCustomerGroups = aCustomerGroupsBO.Select_ByListIDBookingRoom(aListIDBookingRoom);
            List<Rooms> aListRooms = aRoomsBO.Select_ByListCodeRoom(aListCodeRoom, 1);
            List<Customers> aListCustomers = aCustomersBO.SelectListCustomer_ByListIDBookingRoom(aListIDBookingRoom);
            List<BookingRs> aListBookingRs = aBookingRsBO.Select_ByListIDBookingRoom(aListIDBookingRoom);

            for (int i = 0; i < aListBookingRooms.Count; i++)
            {
                aListBookingRoomsMembers = aListAllBookingRoomsMembers.Where(p => p.IDBookingRoom == aListBookingRooms[i].ID).ToList();

                for (int y = 0; y < aListBookingRoomsMembers.Count; y++)
                {
                    aOverNightCustomer = new OverNightCustomerEN();

                    aCustomers = new Customers();
                    int IDCustomer = aListBookingRoomsMembers[y].IDCustomer;
                    aCustomers = aListCustomers.Where(p => p.ID == IDCustomer).ToList()[0];

                    int IDCustomerGroup = aListBookingRs.Where(p => p.ID == aListBookingRooms[i].IDBookingR).ToList()[0].IDCustomerGroup;
                    int IDCompany = aListCustomerGroups.Where(p => p.ID == IDCustomerGroup).ToList()[0].IDCompany;
                    if (IDCompany != null)
                    {
                        aOverNightCustomer.CompanyName = aListCompanies.Where(p => p.ID == IDCompany).ToList()[0].Name;
                    }

                    aOverNightCustomer.PurposeComeVietnam = aListBookingRoomsMembers[y].PurposeComeVietnam;
                    aOverNightCustomer.DateEnterCountry = aListBookingRoomsMembers[y].DateEnterCountry;
                    aOverNightCustomer.EnterGate = aListBookingRoomsMembers[y].EnterGate;
                    aOverNightCustomer.TemporaryResidenceDate = aListBookingRoomsMembers[y].TemporaryResidenceDate;
                    aOverNightCustomer.LeaveDate = aListBookingRoomsMembers[y].LeaveDate;
                    aOverNightCustomer.Organization = aListBookingRoomsMembers[y].Organization;
                    aOverNightCustomer.LimitDateEnterCountry = aListBookingRoomsMembers[y].LimitDateEnterCountry;

                    aOverNightCustomer.IDBookingRoom = aListBookingRooms[i].ID;

                    if (aListRooms.Where(p => p.Code == aListBookingRooms[i].CodeRoom).ToList()[0] != null)
                    {
                        aOverNightCustomer.Sku = aListRooms.Where(p => p.Code == aListBookingRooms[i].CodeRoom).ToList()[0].Sku;
                    }

                    if (aListBookingRs.Where(p => p.ID == aListBookingRooms[i].IDBookingR).ToList()[0] != null)
                    {
                        aOverNightCustomer.CustomerType = aListBookingRs.Where(p => p.ID == aListBookingRooms[i].IDBookingR).ToList()[0].CustomerType;
                    }
                    aOverNightCustomer.CheckInActual = aListBookingRooms[i].CheckInActual;
                    aOverNightCustomer.CheckOutPlan = aListBookingRooms[i].CheckOutPlan;
                    aOverNightCustomer.Name = aCustomers.Name;
                    aOverNightCustomer.IDCustomer = aCustomers.ID;
                    aOverNightCustomer.Identifier1 = aCustomers.Identifier1;
                    aOverNightCustomer.Identifier2 = aCustomers.Identifier2;
                    aOverNightCustomer.Identifier3 = aCustomers.Identifier3;
                    aOverNightCustomer.Nationality = aCustomers.Nationality;
                    aOverNightCustomer.Birthday = String.Format("{0:MM-dd-yyyy}", aCustomers.Birthday);
                    aOverNightCustomer.Tel = aCustomers.Tel;
                    aOverNightCustomer.Address = aCustomers.Address;
                    aOverNightCustomer.Email = aCustomers.Email;
                    aOverNightCustomer.Info = aCustomers.Info;
                    aOverNightCustomer.Gender = aCustomers.Gender;
                    aOverNightCustomer.Citizen = aCustomers.Citizen;
                    aOverNightCustomer.Identifier1CreatedDate = aCustomers.Identifier1CreatedDate;
                    aOverNightCustomer.Identifier2CreatedDate = aCustomers.Identifier2CreatedDate;
                    aOverNightCustomer.Identifier3CreatedDate = aCustomers.Identifier3CreatedDate;
                    aOverNightCustomer.PlaceOfIssue1 = aCustomers.PlaceOfIssue1;
                    aOverNightCustomer.PlaceOfIssue2 = aCustomers.PlaceOfIssue2;
                    aOverNightCustomer.PlaceOfIssue3 = aCustomers.PlaceOfIssue3;
                    aOverNightCustomer.AgencyOfIssue1 = aCustomers.AgencyOfIssue1;
                    aOverNightCustomer.AgencyOfIssue2 = aCustomers.AgencyOfIssue2;
                    aOverNightCustomer.AgencyOfIssue3 = aCustomers.AgencyOfIssue3;
                    aOverNightCustomer.CAN_BO_NM = "NVNK";
                    aOverNightCustomer.IsVietNam = "N";
                    aOverNightCustomer.Quan = "HK";
                    aOverNightCustomer.DIACHI_TT = "2 Lê Thạch";
                    aOverNightCustomer.NgayTruyen = DateTime.Now.Date.ToShortDateString();

                    aListOverNightCustomer.Add(aOverNightCustomer);
                }
            }

            return aListOverNightCustomer;
        }
        //SelectCustomer_ByIDCustomerGroups
        public List<Customers> SelectListCustomer_ByIDCustomerGroups(int IDCustomerGroup)
        {
            List<vw__SearchCustomer__Companies_CustomerGroups_Customers> aListTemp = new List<vw__SearchCustomer__Companies_CustomerGroups_Customers>();
            aListTemp = aDatabaseDA.vw__SearchCustomer__Companies_CustomerGroups_Customers.Where(c => c.CustomerGroups_ID == IDCustomerGroup).Distinct().ToList();
            List<Customers> aListReturn = new List<Customers>();
            Customers aCustomers;
            foreach (var items in aListTemp)
            {
                aCustomers = new Customers();
                aCustomers.ID = items.Customers_ID;
                aCustomers.Name = items.Customers_Name;
                aCustomers.Identifier1 = items.Customers_Identifier1;
                aCustomers.Identifier2 = items.Customers_Identifier2;
                aCustomers.Identifier3 = items.Customers_Identifier3;
                aCustomers.Nationality = items.Customers_Nationality;
                aCustomers.Birthday = items.Customers_Birthday;
                aCustomers.Tel = items.Customers_Tel;
                aCustomers.Address = items.Customers_Address;
                aCustomers.Email = items.Customers_Email;
                aCustomers.Status = items.Customers_Status;
                aCustomers.Type = items.Customers_Type;
                aCustomers.Disable = items.Customers_Disable;
                aCustomers.Gender = items.Customers_Gender;
                aCustomers.Citizen = items.Customers_Citizen;
                aCustomers.Identifier1CreatedDate = items.Customers_Identifier1CreatedDate;
                aCustomers.Identifier2CreatedDate = items.Customers_Identifier2CreatedDate;
                aCustomers.Identifier3CreatedDate = items.Customers_Identifier3CreatedDate;
                aCustomers.PlaceOfIssue1 = items.Customers_PlaceOfIssue1;
                aCustomers.PlaceOfIssue2 = items.Customers_PlaceOfIssue2;
                aCustomers.PlaceOfIssue3 = items.Customers_PlaceOfIssue3;
                aCustomers.AgencyOfIssue1 = items.Customers_AgencyOfIssue1;
                aCustomers.AgencyOfIssue2 = items.Customers_AgencyOfIssue2;
                aCustomers.AgencyOfIssue3 = items.Customers_AgencyOfIssue3;

                aListReturn.Add(aCustomers);
            }
            return aListReturn;
        }
        private void btnRemoveSelectCustomers_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                DateTime? dateTime = null;
                Customers aCustomers = new Customers();

                aCustomers.ID = Convert.ToInt32(viewSelectCustomers.GetFocusedRowCellValue("ID"));
                aCustomers.Name = String.IsNullOrEmpty(Convert.ToString(viewSelectCustomers.GetFocusedRowCellValue("Name"))) == true ? String.Empty : Convert.ToString(viewSelectCustomers.GetFocusedRowCellValue("Name"));
                aCustomers.Identifier1 = String.IsNullOrEmpty(Convert.ToString(viewSelectCustomers.GetFocusedRowCellValue("Identifier1"))) == true ? String.Empty : Convert.ToString(viewSelectCustomers.GetFocusedRowCellValue("Identifier1"));
                aCustomers.Birthday = String.IsNullOrEmpty(Convert.ToString(viewSelectCustomers.GetFocusedRowCellValue("Birthday"))) == true ? dateTime : Convert.ToDateTime(viewSelectCustomers.GetFocusedRowCellValue("Birthday"));

                aListAvailableCustomers.Insert(0, aCustomers);
                aListRemove.Add(aCustomers);
                dgvAvailableCustomers.DataSource = aListAvailableCustomers;
                dgvAvailableCustomers.RefreshDataSource();

                Customers Temps = aListSelectCustomers.Where(c => c.ID == Convert.ToInt32(viewSelectCustomers.GetFocusedRowCellValue("ID").ToString())).ToList()[0];
                aListSelectCustomers.Remove(Temps);
                dgvSelectCustomers.DataSource = aListSelectCustomers;
                dgvSelectCustomers.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmAddListCustomerToCustomerGroups.btnRemoveSelectCustomers_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSelectCustomers_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                DateTime? dateTime = null;

                Customers aCustomers = new Customers();
                int ID = Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"));
                aCustomers.ID = 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<Customers> aList = aListSelectCustomers.Where(c => c.ID == ID).ToList();
                if (aList.Count > 0)
                {
                    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
                {
                    aListSelectCustomers.Insert(0, aCustomers);
                    aListAdd.Add(aCustomers);
                    dgvSelectCustomers.DataSource = aListSelectCustomers;
                    dgvSelectCustomers.RefreshDataSource();
                }
                List<Customers> aListTemps = aListAvailableCustomers.Where(c => c.ID == Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"))).ToList();
                if (aListTemps.Count > 0)
                {
                    Customers Temps = aListAvailableCustomers.Where(c => c.ID == Convert.ToInt32(viewAvailableCustomers.GetFocusedRowCellValue("ID"))).ToList()[0];
                    aListAvailableCustomers.Remove(Temps);
                }
                dgvAvailableCustomers.DataSource = aListAvailableCustomers;
                dgvAvailableCustomers.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmAddListCustomerToCustomerGroups.btnSelectCustomers_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv     Tạo mới    18/11/2014
        private void btnDeletePepoleOutRoom_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                DateTime? dateTime = null;
                Customers aCustomers = new Customers();

                aCustomers.ID = Convert.ToInt32(viewSelectedCustomer.GetFocusedRowCellValue("ID"));
                aCustomers.Name = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Name"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Name"));
                aCustomers.Identifier1 = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Identifier1"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Identifier1"));
                aCustomers.Identifier1CreatedDate = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Identifier1CreatedDate"))) == true ? dateTime : Convert.ToDateTime(viewSelectedCustomer.GetFocusedRowCellValue("Identifier1CreatedDate"));
                aCustomers.PlaceOfIssue1 = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("PlaceOfIssue1"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("PlaceOfIssue1"));
                aCustomers.AgencyOfIssue1 = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("AgencyOfIssue1"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("AgencyOfIssue1"));
                aCustomers.Address = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Address"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Address"));
                aCustomers.Birthday = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Birthday"))) == true ? dateTime : Convert.ToDateTime(viewSelectedCustomer.GetFocusedRowCellValue("Birthday"));
                aCustomers.Tel = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Tel"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Tel"));
                aCustomers.Gender = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Gender"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Gender"));
                aCustomers.Nationality = String.IsNullOrEmpty(Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Nationality"))) == true ? String.Empty : Convert.ToString(viewSelectedCustomer.GetFocusedRowCellValue("Nationality"));

                this.aListAvailableCustomers.Insert(0, aCustomers);
                dgvSelectedCustomer.DataSource = aListAvailableCustomers;
                dgvSelectedCustomer.RefreshDataSource();

                this.aCheckInEN.RemoveCustomerToRoom(Convert.ToInt32(viewSelectedCustomer.GetFocusedRowCellValue("ID").ToString()));
                dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                dgvSelectedCustomer.RefreshDataSource();

                if (this.aCheckInEN.IsCustomerExistInRoom(this.aCurrent_CodeRoom, this.aCurrent_IDCustomer) == false)
                {
                    this.ResetValueAddNew();

                    this.aCurrent_IDCustomer = 0;
                }
                if (this.aCheckInEN.IsCustomerExistInRoom(this.aCurrent_CodeRoom, Convert.ToInt32(viewSelectedCustomer.GetFocusedRowCellValue("ID"))) == false)
                {
                    this.aCheckInEN.SetValuePepoleRepresentative(Convert.ToInt32(viewSelectedCustomer.GetFocusedRowCellValue("ID")));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.btnRemoveSelectCustomers_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //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 btnRemoveCustomer_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                Customers aCustomers = new Customers();
                aCustomers.ID = Convert.ToInt32(Convert.ToString(viewSelectCustomer.GetFocusedRowCellValue("ID")));
                aCustomers.Name = Convert.ToString(viewSelectCustomer.GetFocusedRowCellValue("Name"));
                aCustomers.Identifier1 = Convert.ToString(viewSelectCustomer.GetFocusedRowCellValue("Identifier1"));
                if(aCustomers.Birthday !=null)
                {
                    aCustomers.Birthday = Convert.ToDateTime(viewSelectCustomer.GetFocusedRowCellValue("Birthday"));
                }

                aListCustomers.Insert(0, aCustomers);
                dgvAvailableCustomer.DataSource = aListCustomers;
                dgvAvailableCustomer.RefreshDataSource();

                RoomMemberEN aItem = aCheckInEN.aListRoomMembers.Where(p => p.RoomCode == lueIDRooms.EditValue.ToString()).ToList()[0];
                int Index = aCheckInEN.aListRoomMembers.IndexOf(aItem);

                CustomerInfoEN Temps = aCheckInEN.aListRoomMembers[Index].ListCustomer.Where(c => c.ID == Convert.ToInt32(viewSelectCustomer.GetFocusedRowCellValue("ID"))).ToList()[0];
                aCheckInEN.aListRoomMembers[Index].ListCustomer.Remove(Temps);
                dgvSelectCustomer.DataSource = aCheckInEN.aListRoomMembers[Index].ListCustomer;
                dgvSelectCustomer.RefreshDataSource();
                this.LoadLueIDRooms();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn_Goverment_Step3.btnRemoveCustomer_ButtonClick\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void lueListCustomerInRoom_Case1_EditValueChanged(object sender, EventArgs e)
        {
            if (this.ListCustomerInRoomBeforeChange_Case1.Count > 0)
            {
                this.CustomerRemove_Case1 = this.ListCustomerInRoomBeforeChange_Case1.Where(p => p.ID == int.Parse(lueListCustomerInRoom_Case1.EditValue.ToString())).ToList()[0];

            }
            else
            {
                MessageBox.Show("Phòng không có dữ liệu người ở");
            }
        }