private void btnDeleteBookingR_Click(object sender, EventArgs e)
        {
            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            BookingRsBO aBookingRsBO = new BookingRsBO();
            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            MenusBO aMenusBO = new MenusBO();
            Menus_FoodsBO aMenus_FoodsBO = new Menus_FoodsBO();
            try
            {
                MessageBox.Show("Chức năng này sẽ xóa tất cả các phòng và hóa đơn đặt phòng đã đặt!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (this.IDBookingH == 0)
                {
                    DialogResult result = MessageBox.Show("Xóa tất cả các phòng đã đặt. Tiếp tục?", "Xóa phòng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        foreach (BookingRoomUsedEN item in this.aNewPaymentEN.aListBookingRoomUsed)
                        {
                            aBookingRooms_ServicesBO.DeleteListServiceUsed(item.ID);
                            aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(item.ID);
                            aBookingRoomsBO.Delete(item.ID);
                        }
                        aCustomerGroups_CustomersBO.DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(this.IDBookingR);
                        aCustomerGroupsBO.Delete_ByID(Convert.ToInt32(this.aNewPaymentEN.IDCustomerGroup));
                        int ret =  aBookingRsBO.Delete(this.IDBookingR);

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

                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa tất cả các phòng và hội trường đã đặt. Tiếp tục?", "Xóa hóa đơn", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {

                        foreach (BookingRoomUsedEN item in this.aNewPaymentEN.aListBookingRoomUsed)
                        {
                            aBookingRooms_ServicesBO.DeleteListServiceUsed(item.ID);
                            aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(item.ID);
                            aBookingRoomsBO.Delete(item.ID);
                        }
                        aCustomerGroups_CustomersBO.DeleteAllCustomersFromCustomerGroup_ByIDBookingRs(this.IDBookingR);
                        aCustomerGroupsBO.Delete_ByID(Convert.ToInt32(this.aNewPaymentEN.IDCustomerGroup));
                        aBookingRsBO.Delete(this.IDBookingR);
                        foreach (BookingHallUsedEN item1 in this.aNewPaymentEN.aListBookingHallUsed)
                        {
                            aBookingHalls_ServicesBO.DeleteListServiceUsed(item1.ID);
                            aBookingHallsBO.Delete(item1.ID);
                            foreach (MenusEN aMenu in item1.aListMenuEN)
                            {
                                aMenusBO.Delete(aMenu.ID);
                                aMenus_FoodsBO.Delete_ByIDMenu(aMenu.ID);
                            }
                        }
                        int ret = aBookingHsBO.Delete(this.IDBookingH);
                        if (ret > 0)
                        {
                            MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

                this.Close();
                if (this.afrmMain != null)
                {
                    this.afrmMain.ReloadData();
                }
                else if (this.afrmMain_Halls != null)
                {
                    this.afrmMain_Halls.ReloadData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_UpdBookingHall.btnDeleteBookingRs\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDeleteCus_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.IsLockForm == false)
            {
                if (this.aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == this.CurrentIDBookingRoom).ToList()[0].ListCustomer.Count == 1)
                {
                    MessageBox.Show("Không thể xóa", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa khách khỏi phòng. Tiếp tục?", "Xóa khách", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                        int IDCustomer = Convert.ToInt32(viewCustomers.GetFocusedRowCellValue("ID"));
                        aBookingRoomsMembersBO.Delete(this.CurrentIDBookingRoom, IDCustomer);
                        MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Reload();
                        txtBookingRoomsCost.Text = aAccountancyBO.CalculateCostRoom(this.CurrentIDBookingRoom, cbbPriceType.Text, this.aNewPaymentEN.CustomerType.GetValueOrDefault(0), aNewPaymentEN.GetNumberCustomerInRoom(this.CurrentIDBookingRoom)).GetValueOrDefault(0).ToString();
                        CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                        aCustomerGroups_CustomersBO.DeleteCustomerFromCustomerGroup_ByIDBookingRs(IDCustomer, this.IDBookingR);

                    }
                }
            }
            else
            {
                MessageBox.Show("Không thực hiện được chức năng này do form đang chế độ khóa");
            }
        }
        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 btnCheckIn_Click(object sender, EventArgs e)
        {
            try
            {
                if (dtpFrom.DateTime < dtpTo.DateTime)
                {
                    if (this.Status == 2)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        //cap nhat bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);

                        //aBookingRooms.CheckInPlan = DateTime.Now;
                        //aBookingRooms.CheckInActual = DateTime.Now;

                        aBookingRooms.CheckInPlan = dtpFrom.DateTime;
                        aBookingRooms.CheckInActual = dtpFrom.DateTime;

                        aBookingRooms.CheckOutPlan = dtpTo.DateTime;
                        aBookingRooms.CheckOutActual = dtpTo.DateTime;
                        //aBookingRooms.PriceType = "G1";
                        aBookingRooms.Status = 3;// 3= Da check in

                        aBookingRoomsBO.Update(aBookingRooms);

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(this.Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.Close();

                    }
                    else if (this.Status == 5)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        RoomsBO aRoomsBO = new RoomsBO();
                        AccountancyBO aAccountancyBO = new AccountancyBO();
                        //Check out giai doan pending
                        aAccountancyBO.CheckOut(this.IDBookingRoom, dtpFrom.DateTime);

                        //them moi mot bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);
                        BookingRooms aBookingRoomsAddNew = new BookingRooms();
                        aBookingRoomsAddNew.IDBookingR = IDBookingR;
                        aBookingRoomsAddNew.CodeRoom = CodeRoom;

                        aBookingRoomsAddNew.PercentTax = aBookingRooms.PercentTax;
                        aBookingRoomsAddNew.CostRef_Rooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).CostRef;
                        aBookingRoomsAddNew.Note = aBookingRooms.Note;

                        aBookingRoomsAddNew.CheckInPlan = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckInActual = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckOutPlan = dtpTo.DateTime;
                        aBookingRoomsAddNew.CheckOutActual = dtpTo.DateTime;
                        aBookingRoomsAddNew.PriceType = aBookingRooms.PriceType;
                        aBookingRoomsAddNew.Type = 1;

                        aBookingRoomsAddNew.BookingStatus = aBookingRooms.BookingStatus;

                        aBookingRoomsAddNew.Status = 3;// 3 = Da CheckIn

                        aBookingRoomsAddNew.StartTime = aBookingRooms.StartTime;
                        aBookingRoomsAddNew.EndTime = aBookingRooms.EndTime;
                        aBookingRoomsAddNew.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
                        aBookingRoomsAddNew.Color = aBookingRooms.Color;
                        aBookingRoomsAddNew.IsRecurring = aBookingRooms.IsRecurring;
                        aBookingRoomsAddNew.IsEditable = aBookingRooms.IsEditable;
                        aBookingRoomsAddNew.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
                        int ID = aBookingRoomsBO.Insert(aBookingRoomsAddNew);

                        if (ID > 0)
                        {
                            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom(this.IDBookingRoom);
                            BookingRoomsMembers aBookingRoomsMembers;
                            foreach (BookingRoomsMembers item1 in aListBookingRoomsMembers)
                            {
                                aBookingRoomsMembers = new BookingRoomsMembers();
                                aBookingRoomsMembers.IDBookingRoom = ID;
                                aBookingRoomsMembers.IDCustomer = item1.IDCustomer;
                                aBookingRoomsMembers.PurposeComeVietnam = item1.PurposeComeVietnam;
                                aBookingRoomsMembers.DateEnterCountry = item1.DateEnterCountry;
                                aBookingRoomsMembers.EnterGate = item1.EnterGate;
                                aBookingRoomsMembers.TemporaryResidenceDate = item1.TemporaryResidenceDate;
                                aBookingRoomsMembers.LimitDateEnterCountry = item1.LimitDateEnterCountry;
                                aBookingRoomsMembers.Organization = item1.Organization;
                                aBookingRoomsMembers.LeaveDate = item1.LeaveDate;

                                aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);

                            }
                        }

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                    }
                }
                else
                {
                    MessageBox.Show("Ngày giờ không hợp lệ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.btnCheckIn_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private bool ChangeRoom_Case1()
        {
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            BookingRooms aBookingRooms = new BookingRooms();
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();

               // Neu phong chi co 1 nguoi, va nguoi do chuyen di mat thi coi nhu checkout luon
            if (this.ListCustomerInRoomBeforeChange_Case1.Count == 1)
            {
                aReceptionTaskBO.CheckOut(this.IDBookingRoom_Case1, dtpFrom_Case1.DateTime);
            }
            else if (this.ListCustomerInRoomBeforeChange_Case1.Count > 1)
            {

                aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom_Case1);

                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                List<BookingRoomsMembers> aListCustomer = aBookingRoomsMembersBO.Select_ByIDBookingRoom(this.IDBookingRoom_Case1);
                BookingRoomsMembers aBookingRoomsMembers = aListCustomer.Where(p => p.IDCustomer == int.Parse(lueListCustomerInRoom_Case1.EditValue.ToString())).ToList()[0];
                aListCustomer.Remove(aBookingRoomsMembers);

                aReceptionTaskBO.CheckOutFirstRoom(this.IDBookingRoom_Case1, dtpFrom_Case1.DateTime);

                aBookingRooms.CheckInActual = dtpFrom_Case1.DateTime;
                aBookingRooms.CheckInPlan = dtpFrom_Case1.DateTime;
                aBookingRooms.AddTimeEnd = null;
                aBookingRooms.AddTimeStart = null;
                aBookingRooms.TimeInUse = null;

                //BookingRooms Item = new BookingRooms();
                //Item.AcceptDate = aBookingRooms.AcceptDate;
                //Item.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
                //Item.AddTimeEnd = aBookingRooms.AddTimeEnd;

                //Item.AddTimeStart = aBookingRooms.AddTimeStart;
                //Item.BookingStatus = aBookingRooms.BookingStatus;
                //Item.CheckInActual = aBookingRooms.CheckInActual;

                //Item.CheckInPlan = aBookingRooms.CheckInPlan;
                //Item.CheckOutActual = aBookingRooms.CheckOutActual;
                //Item.CheckOutPlan = aBookingRooms.CheckOutPlan;

                //Item.CodeRoom = aBookingRooms.CodeRoom;
                //Item.Color = aBookingRooms.Color;
                //Item.Cost = aBookingRooms.Cost;

                //Item.CostPendingRoom = aBookingRooms.CostPendingRoom;
                //Item.CostRef_Rooms = aBookingRooms.CostRef_Rooms;
                //Item.Disable = aBookingRooms.Disable;

                //Item.EndTime = aBookingRooms.EndTime;

                //Item.IDBookingR = aBookingRooms.IDBookingR;

                //Item.IndexSubPayment = aBookingRooms.IndexSubPayment;
                //Item.InvoiceDate = aBookingRooms.InvoiceDate;
                //Item.InvoiceNumber = aBookingRooms.InvoiceNumber;

                //Item.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
                //Item.IsEditable = aBookingRooms.IsEditable;
                //Item.IsRecurring = aBookingRooms.IsRecurring;

                //Item.Note = aBookingRooms.Note;
                //Item.PercentTax = aBookingRooms.PercentTax;
                //Item.PriceType = aBookingRooms.PriceType;

                //Item.StartTime = aBookingRooms.StartTime;
                //Item.Status = aBookingRooms.Status;
                //Item.TimeInUse = aBookingRooms.TimeInUse;
                //Item.Type = aBookingRooms.Type;

                int NewIDBookingRoom = aBookingRoomsBO.Insert(aBookingRooms);
                for (int i = 0; i < aListCustomer.Count; i++)
                {
                    aListCustomer[i].IDBookingRoom = NewIDBookingRoom;
                    aBookingRoomsMembersBO.Insert(aListCustomer[i]);
                }

            }
            return true;
        }
 public int CountMemberInRoom(int IDBookingRoom)
 {
     BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
     return aBookingRoomsMembersBO.Select_ByIDBookingRoom(IDBookingRoom).Count();
 }
        //public frmUpd_Customers_2(frmIns_CustomerGroups_Customers afrmIns_CustomerGroups_Customers, int IDCustomer)
        //{
        //    InitializeComponent();
        //    this.afrmIns_CustomerGroups_Customers = afrmIns_CustomerGroups_Customers;
        //    this.IDCustomer = IDCustomer;
        //}
        //public frmUpd_Customers_2(frmLst_Customers afrmLst_Customers, int aIDCustomer)
        //{
        //    InitializeComponent();
        //    this.afrmLst_Customers = afrmLst_Customers;
        //    this.IDCustomer = aIDCustomer;
        //}
        //public frmUpd_Customers_2(frmTsk_EditBooking afrmTsk_EditBooking, int aIDCustomer)
        //{
        //    InitializeComponent();
        //    this.afrmTsk_EditBooking = afrmTsk_EditBooking;
        //    this.IDCustomer = aIDCustomer;
        //}
        //public frmUpd_Customers_2(frmTsk_Payment_Step2 afrmTsk_Payment_Step2, int aIDCustomer)
        //{
        //    InitializeComponent();
        //    this.afrmTsk_Payment_Step2 = afrmTsk_Payment_Step2;
        //    this.IDCustomer = aIDCustomer;
        //}
        private void frmUpdateCustomers_Load(object sender, EventArgs e)
        {
            try
            {
                dgvAvailableCustomers.DataSource = (new CustomersBO()).Select_All();
                btnAdd.Enabled = false;

                lueNationality.Properties.DataSource = CORE.CONSTANTS.ListCountries;//Load Country
                lueNationality.Properties.DisplayMember = "Name";
                lueNationality.Properties.ValueMember = "Code";

                lueCitizen.Properties.DataSource = CORE.CONSTANTS.ListCitizens;//Load Citizen
                lueCitizen.Properties.DisplayMember = "Name";
                lueCitizen.Properties.ValueMember = "ID";

                lueGender.Properties.DataSource = CORE.CONSTANTS.ListGenders;//Load Gioi tinh
                lueGender.Properties.DisplayMember = "Name";
                lueGender.Properties.ValueMember = "ID";

                CustomersBO aCustomersBO = new CustomersBO();
                // lấy IDCustomer này từ FormCustomers
                if (this.IDCustomer > 0)
                {
                    Customers aCustomer = aCustomersBO.Select_ByID(IDCustomer);
                    if (aCustomer != null)
                    {
                        txtNames.EditValue = aCustomer.Name;
                        txtIdentifier1.EditValue = aCustomer.Identifier1;
                        txtIdentifier2.EditValue = aCustomer.Identifier2;
                        txtIdentifier3.EditValue = aCustomer.Identifier3;
                        if (aCustomer.Birthday != null)
                        {
                            dtpBirthday.EditValue = aCustomer.Birthday;
                        }
                        if (aCustomer.Gender != null)
                        {
                            lueGender.EditValue = int.Parse(aCustomer.Gender.ToString());
                        }
                        else
                        {
                            lueGender.EditValue = CORE.CONSTANTS.SelectedGender(1).ID;
                        }

                        txtAddress.EditValue = aCustomer.Address;

                        if (String.IsNullOrEmpty(aCustomer.Nationality) == false)
                        {
                            lueNationality.EditValue = aCustomer.Nationality;
                        }
                        if (lueNationality.EditValue == null)
                        {
                            lueNationality.EditValue = CORE.CONSTANTS.SelectedCountry(704).Code;
                        }
                        if (aCustomer.Citizen > 0)
                        {
                            lueCitizen.EditValue = aCustomer.Citizen;
                        }
                        else
                        {
                            lueCitizen.EditValue = CORE.CONSTANTS.SelectedCitizen(2).ID;
                        }
                        //----------------------------------------------------------------
                        txtTel.EditValue = aCustomer.Tel;
                        txtEmail.EditValue = aCustomer.Email;
                        //----------------------------------------------------------------
                        CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                        aCustomerGroups_CustomersBO.InsertCustomerIntoCustomerGroup_ByIDBookingRs(this.IDCustomer, (new BookingRsBO()).Select_ByIDBookingRoom(this.IDBookingRoom).ID);
                        /*--------------------------*/
                        BookingRoomsMembers aBookingRoomsMembers = new BookingRoomsMembers();
                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                        aBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom_ByIDCustomer(this.IDBookingRoom, this.IDCustomer);
                        if (aBookingRoomsMembers != null)
                        {
                            dtpDateEnterCountry.DateTime = aBookingRoomsMembers.DateEnterCountry.GetValueOrDefault() ;
                            txtEnterGate.Text = aBookingRoomsMembers.EnterGate;
                            dtpLeaveDate.DateTime = aBookingRoomsMembers.LeaveDate.GetValueOrDefault();
                            dtpLimitDateEnterCountry.DateTime = aBookingRoomsMembers.LimitDateEnterCountry.GetValueOrDefault();
                            txtOrganization.Text = aBookingRoomsMembers.Organization ;
                            txtPurposeComeVietnam.Text = aBookingRoomsMembers.PurposeComeVietnam ;
                            aBookingRoomsMembers.TemporaryResidenceDate = dtpTemporaryResidenceDate.DateTime ;
                        }

                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmUpdateCustomers.frmUpdateCustomers_Load\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool CheckIn(CheckInEN aCheckInEN)
        {
            try
            {
                //========================================================

                BookingRs aBookingRs = new BookingRs();

                aBookingRs.CreatedDate = DateTime.Now;
                aBookingRs.CustomerType = aCheckInEN.CustomerType;
                aBookingRs.BookingType = aCheckInEN.BookingType;
                aBookingRs.Note = aCheckInEN.Note;
                aBookingRs.IDCustomerGroup = aCheckInEN.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.Status = aCheckInEN.Status;
                aBookingRs.Type = aCheckInEN.Type;
                aBookingRs.Disable = aCheckInEN.Disable;
                aBookingRs.Level = aCheckInEN.Level;
                aBookingRs.Subject = aCheckInEN.Subject;
                aBookingRs.Description = aCheckInEN.Description;
                aBookingRs.DatePay = aCheckInEN.DatePay;
                aBookingRs.DateEdit = aCheckInEN.DateEdit;

                //add new bookingRs
                BookingRsBO aBookingRsBO = new BookingRsBO();
                aBookingRsBO.Insert(aBookingRs);

                int IDBookingR = aBookingRs.ID;
                //==========================================================
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms;
                BookingRoomsMembers aBookingRoomsMembers;

                for (int i = 0; i < aCheckInEN.aListRoomMembers.Count; i++)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.IDBookingR = 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
                    aBookingRoomsBO.Insert(aBookingRooms);

                    int IDBookingRooms = aBookingRooms.ID;

                    aCheckInEN.aListRoomMembers[i].IDBookingRooms = IDBookingRooms;
                    //-----------------------------------------------------------
                    aBookingRoomsMembers = new BookingRoomsMembers();
                    aBookingRoomsMembers.IDBookingRoom = aCheckInEN.aListRoomMembers[i].IDBookingRooms;

                    BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                    for (int ii = 0; ii < aCheckInEN.aListRoomMembers[i].ListCustomer.Count; ii++)
                    {
                        aBookingRoomsMembers.IDCustomer = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID;
                        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);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {

                throw new Exception("ReceptionTaskBO.CheckInGoverment\n" + ex.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 void ResetFormWhenTimeChange()
        {
            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

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

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

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

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

            // Fill All Customer

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

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

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

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

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

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);
        }
        private void InitData()
        {
            ItemChangeRoomEN aItemChangeRoomEN = new ItemChangeRoomEN();
            aItemChangeRoomEN.SetBookingRooms(this.aBookingRoom);

            if (aItemChangeRoomEN.GetStatusBookingRooms() < 3)
            {
                // Phong trang thai dat
            }
            else if (aItemChangeRoomEN.GetStatusBookingRooms() == 3) // Phong dang co nguoi o
            {
                // Thay doi thoi gian de check in
                //aItemChangeRoomEN.SetCheckInActual(dtpCheckIn.DateTime);
            }
            aItemChangeRoomEN.IsRootRoom = true;

            List<CustomerInfoEN> aListCustomer = (List<CustomerInfoEN>)this.dgvSelectCustomers.DataSource;
            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            BookingRoomsMembers aBookingRoomsMembers = new BookingRoomsMembers();
            for (int i = 0; i < aListCustomer.Count; i++)
            {
                aBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom_ByIDCustomer(this.aBookingRoom.ID, aListCustomer[i].ID);
                aListCustomer[i].LeaveDate = aBookingRoomsMembers.LeaveDate;
                aListCustomer[i].LimitDateEnterCountry = aBookingRoomsMembers.LimitDateEnterCountry;

                aListCustomer[i].PurposeComeVietnam = aBookingRoomsMembers.PurposeComeVietnam;
                aListCustomer[i].TemporaryResidenceDate = aBookingRoomsMembers.TemporaryResidenceDate;
                aListCustomer[i].DateEnterCountry = aBookingRoomsMembers.DateEnterCountry;
                aListCustomer[i].EnterGate = aBookingRoomsMembers.EnterGate;

            }
            aItemChangeRoomEN.AddCustomer(aListCustomer);

            AccountancyBO aAccountancyBO = new AccountancyBO();

            //aItemChangeRoomEN.SetCost(aAccountancyBO.CalculateCostRoom(lueRooms.EditValue.ToString(), this.aBookingRoom.PriceType, aBookingRs.CustomerType.GetValueOrDefault(0), aItemChangeRoomEN.GetAllCustomers().Count).GetValueOrDefault(0));

            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.aChangeRoomEn.InsertItemChangeRooms(aItemChangeRoomEN);
            this.aCurrentRoomInfo = aItemChangeRoomEN;
        }
        //NgocBM 24/12/2014
        public bool CheckInNewRoom(ItemChangeRoomEN aItem)
        {
            try
            {
                BookingRooms aBookingRooms = new BookingRooms();
                aBookingRooms = aItem.GetBookingRooms();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();

                int IDBookingRoom = aBookingRoomsBO.Insert(aBookingRooms);

                //-----------------------------------------------------------
                // Cao nhatj danh sach nguoi trong phong
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                List<CustomerInfoEN> aList = new List<CustomerInfoEN>();
                aList = aItem.GetAllCustomers();
                for (int i = 0; i < aList.Count; i++)
                {
                    BookingRoomsMembers aBookingRoomsMembers = new BookingRoomsMembers();
                    aBookingRoomsMembers.DateEnterCountry = aList[i].DateEnterCountry;
                    aBookingRoomsMembers.EnterGate = aList[i].EnterGate;
                    aBookingRoomsMembers.LeaveDate = aList[i].LeaveDate;
                    aBookingRoomsMembers.LimitDateEnterCountry = aList[i].LimitDateEnterCountry;
                    aBookingRoomsMembers.Organization = aList[i].Organization;

                    aBookingRoomsMembers.PurposeComeVietnam = aList[i].PurposeComeVietnam;
                    aBookingRoomsMembers.TemporaryResidenceDate = aList[i].TemporaryResidenceDate;

                    aBookingRoomsMembers.IDBookingRoom = IDBookingRoom;

                    aBookingRoomsMembers.IDCustomer = aList[i].ID;

                    aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);
                }
                return true;
            }
            catch (Exception ee)
            {
                return false;
            }
        }
        //Author :Hiennv
        public bool CheckInForRoomAlreadyBooking(CheckInRoomBookingEN aCheckInRoomBookingEN)
        {
            try
            {
                //========================================================

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

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

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

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

                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                        foreach (CustomerInfoEN aCustomerInfoEN in aRoomMemberEN.ListCustomer)
                        {
                            aBookingRoomsMembers.IDCustomer = aCustomerInfoEN.ID;
                            aBookingRoomsMembers.PurposeComeVietnam = aCustomerInfoEN.PurposeComeVietnam;
                            aBookingRoomsMembers.DateEnterCountry = aCustomerInfoEN.DateEnterCountry;
                            aBookingRoomsMembers.EnterGate = aCustomerInfoEN.EnterGate;
                            aBookingRoomsMembers.TemporaryResidenceDate = aCustomerInfoEN.TemporaryResidenceDate;
                            aBookingRoomsMembers.LimitDateEnterCountry = aCustomerInfoEN.LimitDateEnterCountry;
                            aBookingRoomsMembers.Organization = aCustomerInfoEN.Organization;
                            aBookingRoomsMembers.LeaveDate = aCustomerInfoEN.LeaveDate;
                            //add new bookingRoomMember
                            aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.CheckInForRoomAlreadyBooking\n" + ex.ToString());
            }
        }
        private void btnDeleteRoom_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.IsLockForm == false)
            {
                if (this.aNewPaymentEN.aListBookingRoomUsed.Count == 1)
                {
                    MessageBox.Show("Không thể xóa", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Xóa phòng. Tiếp tục?", "Xóa phòng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                        BookingRooms_ServicesBO aBookingRooms_ServicesBO = new BookingRooms_ServicesBO();
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        int IDDeletedBookingRoom = Convert.ToInt32(viewRooms.GetFocusedRowCellValue("ID"));
                        aBookingRooms_ServicesBO.DeleteListServiceUsed(IDDeletedBookingRoom);
                        aBookingRoomsMembersBO.DeleteListBookingRoomsMembers(IDDeletedBookingRoom);
                        aBookingRoomsBO.Delete(IDDeletedBookingRoom);
                        MessageBox.Show("Thực hiện thành công!", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Reload();

                    }
                }
            }
            else
            {
                MessageBox.Show("Không thực hiện được chức năng này do form đang chế độ khóa");
            }
        }
        public void CheckOut(int IDBookingRoom)
        {
            try
            {
                RoomsBO aRoomsBO = new RoomsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
                List<BookingRoomsMembers> aListCus = aBookingRoomsMembersBO.Select_ByIDBookingRoom(IDBookingRoom);
                aBookingRooms.CheckOutActual = DateTime.Now;
                aBookingRooms.Status = 7;
                aBookingRooms.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckInActual));
                aBookingRooms.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckOutActual));
                aBookingRooms.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(aBookingRooms.CheckInActual, aBookingRooms.CheckOutActual) * 24 * 60);
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1);
                if (aRooms != null)
                {
                    if (aBookingRooms.Cost == null)
                    {
                        decimal? cost = 0;
                        cost = aBookingRooms.CostRef_Rooms;
                        aBookingRooms.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRooms.PriceType, aListCus.Count).ExtraValue);
                    }
                }

                aBookingRoomsBO.Update(aBookingRooms);
            }
            catch (Exception ex)
            {

                throw new Exception("AccountancyBO.CheckOut\n" + ex.ToString());
            }
        }
        //SelectListCustomer_ByCustomerName
        //public List<Customers> SelectListCustomer_ByCustomerName(string NameCustomer)
        //{
        //    List<vw__SearchCustomer__Companies_CustomerGroups_Customers> aListTemp = new List<vw__SearchCustomer__Companies_CustomerGroups_Customers>();
        //    aListTemp = aDatabaseDA.vw__SearchCustomer__Companies_CustomerGroups_Customers.Where(c => c.Customers_Name.Contains(NameCustomer)).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;
        //        aListReturn.Insert(0, aCustomers);
        //    }
        //    return aListReturn;
        //}
        //SelectListCustomer_ByCustomerName_ByIDCustomerGroups
        //public List<Customers> SelectListCustomer_ByCustomerName_ByIDCustomerGroups(string NameCustomer,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.Customers_Name.Contains(NameCustomer)).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;
        //        aListReturn.Insert(0, aCustomers);
        //    }
        //    return aListReturn;
        //}
        public List<Customers> SelectListCustomer_ByListIDBookingRoom(List<int> ListIDBookingRoom)
        {
            try
            {
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                List<int> aListIDCustomer = aBookingRoomsMembersBO.Select_ByListIDBookingRoom(ListIDBookingRoom).Select(b => b.IDCustomer).Distinct().ToList();
                return this.SelectListCustomer_ByListIDCustomer(aListIDCustomer);
            }
            catch (Exception ex)
            {

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