public void SetValue(BookingRooms aBookingRooms)
 {
     this.ID = aBookingRooms.ID;
        this.IDBookingR = aBookingRooms.IDBookingR;
        this.CodeRoom = aBookingRooms.CodeRoom;
        this.Cost = aBookingRooms.Cost;
        this.PercentTax = aBookingRooms.PercentTax;
        this.CostRef_Rooms = aBookingRooms.CostRef_Rooms;
        this.Note = aBookingRooms.Note;
        this.CheckInPlan = aBookingRooms.CheckInPlan;
        this.CheckInActual = aBookingRooms.CheckInActual;
        this.CheckOutPlan = aBookingRooms.CheckOutPlan;
        this.CheckOutActual = aBookingRooms.CheckOutActual;
        this.BookingStatus = aBookingRooms.BookingStatus;
        this.Status = aBookingRooms.Status;
        this.StartTime = aBookingRooms.StartTime;
        this.EndTime = aBookingRooms.EndTime;
        this.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
        this.Color = aBookingRooms.Color;
        this.IsRecurring = aBookingRooms.IsRecurring;
        this.IsEditable = aBookingRooms.IsEditable;
        this.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
        this.CostPendingRoom = aBookingRooms.CostPendingRoom;
        this.TimeInUse = aBookingRooms.TimeInUse;
 }
        public void LoadDataBookingRoom()
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListTemp = aBookingRoomsBO.Select_ByDateAndCodeRoomAndStaus(DateTime.Now,this.codeRoom,3); //3 = status = da check In
                BookingRooms aBookingRooms;
                List<BookingRooms> aListBookingRoom = new List<BookingRooms>();
                RoomsBO aRoomsBO = new RoomsBO();

                foreach (BookingRooms item in aListTemp)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.ID = item.ID;
                    aBookingRooms.IDBookingR = item.IDBookingR;
                    aBookingRooms.CodeRoom = item.CodeRoom;
                    aBookingRooms.Cost = item.Cost;
                    aBookingRooms.PercentTax = item.PercentTax;
                    aBookingRooms.CostRef_Rooms = item.CostRef_Rooms;
                    aBookingRooms.Note = item.Note;
                    aBookingRooms.CheckInPlan = item.CheckInPlan;
                    aBookingRooms.CheckInActual = item.CheckInActual;
                    aBookingRooms.CheckOutPlan = item.CheckOutPlan;
                    aBookingRooms.CheckOutActual = item.CheckOutActual;
                    aBookingRooms.BookingStatus = item.BookingStatus;
                    aBookingRooms.Status = item.Status;
                    aBookingRooms.StartTime = item.StartTime;
                    aBookingRooms.EndTime = item.EndTime;
                    aBookingRooms.IsAllDayEvent = item.IsAllDayEvent;
                    aBookingRooms.Color = item.Color;
                    aBookingRooms.IsEditable = item.IsEditable;
                    aBookingRooms.IsRecurring = item.IsRecurring;
                    Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);//1= IDLang

                    //dung tam de hien thi sku
                    aBookingRooms.AdditionalColumn1 = aRooms.Sku;
                    aListBookingRoom.Add(aBookingRooms);

                }

                if (String.IsNullOrEmpty(txtSku.Text) == false)
                {
                    dgvBookingRooms.DataSource = aListBookingRoom.Where(b => b.AdditionalColumn1.Contains(txtSku.Text)).ToList();
                }
                else
                {
                    dgvBookingRooms.DataSource = aListBookingRoom;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingRoom_Step1.LoadDataBookingRoom\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

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

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

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

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

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

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

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadDataBookingRoom(int Status)
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListTemp = aBookingRoomsBO.Select_ByStatus_ByTime(DateTime.Now,Status);
                BookingRooms aBookingRooms;
                List<BookingRooms> aListBookingRoom = new List<BookingRooms>();
                RoomsBO aRoomsBO = new RoomsBO();

                foreach (BookingRooms item in aListTemp)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.ID = item.ID;
                    aBookingRooms.IDBookingR = item.IDBookingR;
                    aBookingRooms.CodeRoom = item.CodeRoom;
                    aBookingRooms.Cost = item.Cost;
                    aBookingRooms.PercentTax = item.PercentTax;
                    aBookingRooms.CostRef_Rooms = item.CostRef_Rooms;

                    //dung tam truong Note de hien thi trang thai phong
                    aBookingRooms.Note = CORE.CONSTANTS.SelectedBookingRoomStatus(item.Status.GetValueOrDefault()).Name;

                    aBookingRooms.CheckInPlan = item.CheckInPlan;
                    aBookingRooms.CheckInActual = item.CheckInActual;
                    aBookingRooms.CheckOutPlan = item.CheckOutPlan;
                    aBookingRooms.CheckOutActual = item.CheckOutActual;
                    aBookingRooms.BookingStatus = item.BookingStatus;
                    aBookingRooms.Status = item.Status;
                    aBookingRooms.StartTime = item.StartTime;
                    aBookingRooms.EndTime = item.EndTime;
                    aBookingRooms.IsAllDayEvent = item.IsAllDayEvent;
                    aBookingRooms.Color = item.Color;
                    aBookingRooms.IsEditable = item.IsEditable;
                    aBookingRooms.IsRecurring = item.IsRecurring;
                    Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);//1= IDLang

                    //dung tam de hien thi sku
                    aBookingRooms.AdditionalColumn1 = aRooms.Sku;
                    aListBookingRoom.Add(aBookingRooms);

                }
                dgvBookingRooms.DataSource = aListBookingRoom;
                dgvBookingRooms.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step1.LoadDataBookingRoom\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public frmTsk_EditBooking(int IDBookingRoom, frmMain afrmMain)
        {
            InitializeComponent();

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

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

            this.afrmMain = afrmMain;
            this.IsReadyInitData = false;
            this.aCurrentCustomerClick = new CustomerInfoEN();
        }
        public bool ChangeStatus(int IDBookingRoom, int ChangeStatusTo)
        {
            BookingRooms aItem = new BookingRooms();
            aItem = this.Select_ByID(IDBookingRoom);

            aItem.Status = ChangeStatusTo;
            int i = this.Update(aItem);
            if (i == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

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

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

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

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

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

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

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv     25/11/2014     Viet lai phuong thuc BookingRoom
        public bool NewBookingRoom(NewBookingEN aNewBookingEN)
        {
            try
            {
                int IDBookingR = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;

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

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

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

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

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

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

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

                    BookingRs aBookingRs = new BookingRs();

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

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

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

                    }
                }
                #endregion

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void ProcessChangeRoom()
        {
            // Vi moi khi check In luon bi tinh mac dinh 1 ngay
            bool IsRootRoomChangeInDay = false;

            ItemChangeRoomEN RootRoom = this.aChangeRoomEn.GetRootItemChangeRoom();
            // Tinh 2 tham so can thiet cho qua trinh chuyen phong
            //===================================================

                if (RootRoom.GetStatusBookingRooms() == 3)
                {
                    if (RootRoom.GetCheckInActual().Date == this.aBookingRoom.CheckInActual.Date)
                    {
                        IsRootRoomChangeInDay = true;
                    }
                    else
                    {
                        IsRootRoomChangeInDay = false;
                    }
                }
                else if (RootRoom.GetStatusBookingRooms() < 3)
                {
                    // phòng ở trạng thái đặt
                    MessageBox.Show("Phòng này đang ở trạng thái đặt. Bạn muốn cho người vào phòng hãy sử dụng chức năng checkin");
                    return;
                }

            ClearRoomHasNotCustomer();
            List<ItemChangeRoomEN> aaa= this.aChangeRoomEn.GetAllItemChangeRoom();
            List<ItemChangeRoomEN> aListItemChangeRooms = new List<ItemChangeRoomEN>();
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            // Doi phong khac ngay
            if (IsRootRoomChangeInDay == false)
            {
                if (ckbCheckOutNow.Checked == true)
                {
                    (new ReceptionTaskBO()).CheckOutFirstRoom(this.aBookingRoom.ID, DateTime.Now);
                }
                else if (ckbCheckOutNow.Checked == false)
                {
                    (new ReceptionTaskBO()).CheckOutFirstRoom(this.aBookingRoom.ID, dtpCheckIn.DateTime);
                }
                aListItemChangeRooms = this.aChangeRoomEn.GetAllItemChangeRoom();
                // Đổi type cua nhung bookingroom sau bookingroom dau tien
                for (int i = 0; i < aListItemChangeRooms.Count; i++)
                {

                    if (aListItemChangeRooms[i].GetTypeBookingRoom() == 2)
                    {
                      aListItemChangeRooms[i].SetTypeBookingRoom(0);
                    }
                    else if (aListItemChangeRooms[i].GetTypeBookingRoom() == 0)
                    {
                        aListItemChangeRooms[i].SetTypeBookingRoom(0);
                    }
                    else if (aListItemChangeRooms[i].GetTypeBookingRoom() == 3)
                    {
                        aListItemChangeRooms[i].SetTypeBookingRoom(1);
                    }
                    else if (aListItemChangeRooms[i].GetTypeBookingRoom() == 1)
                    {
                        aListItemChangeRooms[i].SetTypeBookingRoom(1);
                    }
                    else
                    {
                        aListItemChangeRooms[i].SetTypeBookingRoom(3);
                    }

                    (new ReceptionTaskBO()).CheckInNewRoom(aListItemChangeRooms[i]);
                }

            }
                // Doi phong trong cung 1 ngay, phong cu khong tinh tien
            else
            {

                BookingRooms aItem =  aBookingRoomsBO.Select_ByID(this.aBookingRoom.ID);
                aItem.Cost = 0;
                aItem.CheckOutActual = dtpCheckOut.DateTime;
                aItem.Status = 7;
                aBookingRoomsBO.Update(aItem);

                //va checkIn lai loat moi voi time tu lan checkIn dau tien

                aListItemChangeRooms = this.aChangeRoomEn.GetAllItemChangeRoom();

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

                    aListItemChangeRooms[i].SetCheckInPlan(this.aBookingRoom.CheckInPlan);
                    aListItemChangeRooms[i].SetCheckInActual(this.aBookingRoom.CheckInActual);

                    aListItemChangeRooms[i].SetCheckOutActual(dtpCheckOut.DateTime);
                    aListItemChangeRooms[i].SetCheckOutPlan(dtpCheckOut.DateTime);

                    //Truong hop doi phong trong ngay, thi k tinh tien phong dau ma don het sang phong sau. Vi vay Type cung chuyen sang phong sau
                    aListItemChangeRooms[i].SetTypeBookingRoom(aItem.Type.GetValueOrDefault(3));

                    (new ReceptionTaskBO()).CheckInNewRoom(aListItemChangeRooms[i]);

                }
            }
            //-----------------------------------------------
            aListItemChangeRooms = new List<ItemChangeRoomEN>();
            aListItemChangeRooms = this.aChangeRoomEn.GetAllItemChangeRoom();
            BookingRooms aItem1 = new BookingRooms();
            for (int i = 0; i < aListItemChangeRooms.Count; i++)
            {

                ////---------------------------------------------------
                if (aListItemChangeRooms[i].IsRoomInBookingR == true)
                {
                    aItem1 = new BookingRooms();
                    aItem1 = aBookingRoomsBO.Select_ByID(aListItemChangeRooms[i].GetBookingRooms().ID);
                    if (IsRootRoomChangeInDay == true)
                    {
                        aItem1.Cost = 0;
                    }
                    aItem1.CheckOutActual = dtpCheckIn.DateTime;
                    aItem1.Status = 7;
                    aBookingRoomsBO.Update(aItem1);
                }
            }
            //-----------------------------------------------
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            // Show message box
            DialogResult result = MessageBox.Show("Chuyển phòng thành công","Nhà khách chính phủ", buttons);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                this.afrmMain.RefreshData_auc_StatusRooms(DateTime.Now);
                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);
            }
        }
 public void SetValue(BookingRooms aBookingRooms)
 {
     this.ID = aBookingRooms.ID;
        this.IDBookingR = aBookingRooms.IDBookingR;
        this.CodeRoom = aBookingRooms.CodeRoom;
        this.PercentTax = aBookingRooms.PercentTax;
        this.CostRef_Rooms = aBookingRooms.CostRef_Rooms;
        this.Note = aBookingRooms.Note;
        this.CheckInPlan = aBookingRooms.CheckInPlan;
        this.CheckInActual = aBookingRooms.CheckInActual;
        this.CheckOutPlan = aBookingRooms.CheckOutPlan;
        this.CheckOutActual = aBookingRooms.CheckOutActual;
        this.BookingStatus = aBookingRooms.BookingStatus;
        this.Status = aBookingRooms.Status;
        this.StartTime = aBookingRooms.StartTime;
        this.EndTime = aBookingRooms.EndTime;
        this.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
        this.Color = aBookingRooms.Color;
        this.IsRecurring = aBookingRooms.IsRecurring;
        this.IsEditable = aBookingRooms.IsEditable;
        this.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
        this.CostPendingRoom = aBookingRooms.CostPendingRoom;
        this.PriceType = aBookingRooms.PriceType;
        this.IndexSubPayment = aBookingRooms.IndexSubPayment;
        this.AcceptDate = aBookingRooms.AcceptDate;
        this.InvoiceDate = aBookingRooms.InvoiceDate;
        this.InvoiceNumber = aBookingRooms.InvoiceNumber;
        this.Type = aBookingRooms.Type;
        if (aBookingRooms.Type == 0)
        {
        this.IsCheckInEarly = false;
        this.IsCheckOutLate = false;
        }
        else if (aBookingRooms.Type == 1)
        {
        this.IsCheckInEarly = true;
        this.IsCheckOutLate = false;
        }
        else if (aBookingRooms.Type == 2)
        {
        this.IsCheckInEarly = false;
        this.IsCheckOutLate = true;
        }
        else if (aBookingRooms.Type == 3)
        {
        this.IsCheckInEarly = true;
        this.IsCheckOutLate = true;
        }
 }
        //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;
            }
        }
        //hiennv
        private List<BookingRooms> GetListBookingRooms(List<BookingRooms> aListBookingRooms, List<Rooms> aListRooms)
        {
            try
            {
                List<BookingRooms> aListBookingRoomsTemp = new List<BookingRooms>();
                BookingRooms aBookingRooms;
                foreach (BookingRooms items in aListBookingRooms)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.ID = items.ID;
                    aBookingRooms.IDBookingR = items.IDBookingR;
                    aBookingRooms.CodeRoom = items.CodeRoom;
                    aBookingRooms.Cost = items.Cost;
                    aBookingRooms.PercentTax = items.PercentTax;
                    aBookingRooms.CostRef_Rooms = items.CostRef_Rooms;
                    aBookingRooms.Note = items.Note;
                    aBookingRooms.CheckInPlan = items.CheckInPlan;
                    aBookingRooms.CheckOutPlan = items.CheckOutPlan;
                    aBookingRooms.CheckInActual = items.CheckInActual;
                    aBookingRooms.CheckOutActual = items.CheckOutActual;
                    aBookingRooms.BookingStatus = items.BookingStatus;
                    aBookingRooms.Status = items.Status;
                    aBookingRooms.StartTime = items.StartTime;
                    aBookingRooms.EndTime = items.EndTime;
                    aBookingRooms.IsAllDayEvent = items.IsAllDayEvent;
                    aBookingRooms.Color = items.Color;
                    aBookingRooms.IsRecurring = items.IsRecurring;
                    aBookingRooms.IsEditable = items.IsEditable;

                    //dung tam cot AdditionalColumn1 de hien thi ten phong(Sku)
                    if (aListRooms.Where(r => r.Code == items.CodeRoom).ToList().Count > 0)
                    {
                        aBookingRooms.AdditionalColumn1 = aListRooms.Where(r => r.Code == items.CodeRoom).ToList()[0].Sku;
                    }
                    aBookingRooms.CostPendingRoom = items.CostPendingRoom;
                    aBookingRooms.TimeInUse = items.TimeInUse;
                    aListBookingRoomsTemp.Add(aBookingRooms);
                }
                return aListBookingRoomsTemp;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckOut.GetListBookingRooms\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        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 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;
        }
        //=======================================================
        //Author: Hiennv
        //Function : Booking()
        //=======================================================
        public bool Booking(BookingEN aBookingEN)
        {
            try
            {
                //========================================================

                BookingRs aBookingRs = new BookingRs();

                aBookingRs.CreatedDate = DateTime.Now;
                aBookingRs.CustomerType = aBookingEN.CustomerType;
                aBookingRs.BookingType = aBookingEN.BookingType;
                aBookingRs.Note = aBookingEN.Note;
                aBookingRs.IDCustomerGroup = aBookingEN.IDCustomerGroup;
                aBookingRs.IDCustomer = aBookingEN.IDCustomer;
                aBookingRs.IDSystemUser = aBookingEN.IDSystemUser;
                aBookingRs.PayMenthod = aBookingEN.PayMenthod;
                aBookingRs.StatusPay = aBookingEN.StatusPay;
                aBookingRs.BookingMoney = aBookingEN.BookingMoney;
                aBookingRs.ExchangeRate = aBookingEN.ExchangeRate;
                aBookingRs.Status = aBookingEN.Status;
                aBookingRs.Type = aBookingEN.Type;
                aBookingRs.Disable = aBookingEN.Disable;
                aBookingRs.Level = aBookingEN.Level;
                aBookingRs.Subject = aBookingEN.Subject;
                aBookingRs.Description = aBookingEN.Description;
                aBookingRs.DatePay = aBookingEN.DatePay;
                aBookingRs.DateEdit = aBookingEN.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 < aBookingEN.aListRoomsEN.Count; i++)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.IDBookingR = IDBookingR;
                    aBookingRooms.CodeRoom = aBookingEN.aListRoomsEN[i].Code;
                    aBookingRooms.PercentTax = 10;
                    aBookingRooms.CostRef_Rooms = aBookingEN.aListRoomsEN[i].CostRef;
                    aBookingRooms.Cost = aBookingEN.aListRoomsEN[i].CostRef;
                    aBookingRooms.CheckInPlan = aBookingEN.CheckInActual;
                    aBookingRooms.CheckInActual = aBookingEN.CheckInActual;
                    aBookingRooms.CheckOutPlan = aBookingEN.CheckOutPlan;
                    aBookingRooms.CheckOutActual = aBookingEN.CheckOutActual;
                    aBookingRooms.StartTime = aBookingEN.CheckInActual;
                    aBookingRooms.EndTime = aBookingEN.CheckOutPlan;
                    aBookingRooms.BookingStatus = 1;
                    aBookingRooms.Status = aBookingEN.Status;
                    aBookingRooms.Type = 1;//Tính CheckIn sớm và CheckOut muộn
                    //add new bookingRoom
                    aBookingRoomsBO.Insert(aBookingRooms);
                }
                return true;
            }
            catch (Exception ex)
            {

                throw new Exception("ReceptionTaskBO.Booking\n" + ex.ToString());
            }
        }
        //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());
            }
        }
 //----------------Update BookingRooms -----------------------------
 public int Update(BookingRooms bookingRooms)
 {
     try
     {
         aDatabaseDA.BookingRooms.AddOrUpdate(bookingRooms);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("BookingRoomsBO.Update:" + ex.ToString());
     }
 }
        //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;
            }
        }
        //Hiennv    Tạo mới     26/11/2014
        private void btnUnSelect_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                RoomMemberEN aRoomMemberEN = new RoomMemberEN();
                aRoomMemberEN.IDBookingRooms = 0;
                aRoomMemberEN.RoomCode = viewSelectedRooms.GetFocusedRowCellValue("RoomCode").ToString();
                aRoomMemberEN.RoomSku = viewSelectedRooms.GetFocusedRowCellValue("RoomSku").ToString();
                aRoomMemberEN.RoomTypeDisplay = viewSelectedRooms.GetFocusedRowCellValue("RoomTypeDisplay").ToString();
                aRoomMemberEN.RoomBed1 = Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("RoomBed1"));
                aRoomMemberEN.RoomBed2 = Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("RoomBed2"));
                aRoomMemberEN.RoomCostRef = Convert.ToDecimal(viewSelectedRooms.GetFocusedRowCellValue("RoomCostRef"));

                this.aListAvaiableRooms.Insert(0, aRoomMemberEN);
                dgvAvailableRooms.DataSource = aListAvaiableRooms;
                dgvAvailableRooms.RefreshDataSource();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                aBookingRooms = aBookingRoomsBO.Select_ByIDBookingRsAndIDBookingRoom(this.IDBookingR, Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("IDBookingRooms")));
                if (aBookingRooms != null)
                {
                    this.aListRemoveBookingRooms.Add(aBookingRooms);
                }

                RoomMemberEN Temps = aCheckInEN.IsCodeRoomExistInRoom(viewSelectedRooms.GetFocusedRowCellValue("RoomCode").ToString());
                if(Temps !=null)
                {
                    this.aCheckInEN.RemoveRoom(Temps);
                    dgvSelectedRooms.DataSource = this.aCheckInEN.aListRoomMembers;
                    dgvSelectedRooms.RefreshDataSource();
                }

                if (!String.IsNullOrEmpty(this.aCurrent_CodeRoom))
                {
                    if (this.aCheckInEN.GetListRoomMemberByCodeRoom(this.aCurrent_CodeRoom).Count <= 0)
                    {
                        this.aCurrent_CodeRoom = string.Empty;
                        lblRoomSku.Text = "Phòng số : 000";
                        dgvSelectedCustomer.DataSource = null;
                        dgvSelectedCustomer.RefreshDataSource();
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.btnUnSelect_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv    Tạo mới     26/11/2014   Tim ra toàn bộ danh sách phòng còn trống trong khoảng thời gian tìm kiếm
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.CheckData() == true)
                {
                    DateTime From = dtpFrom.DateTime;
                    DateTime To = dtpTo.DateTime;
                    this.aListAvaiableRooms.Clear();
                    dgvAvailableRooms.DataSource = this.LoadListAvailableRooms(From, To);
                    dgvAvailableRooms.RefreshDataSource();

                    foreach(RoomMemberEN aRoomMemberEN in this.aCheckInEN.aListRoomMembers)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        BookingRooms aBookingRooms = new BookingRooms();
                        aBookingRooms = aBookingRoomsBO.Select_ByIDBookingRsAndIDBookingRoom(this.IDBookingR,aRoomMemberEN.IDBookingRooms);
                        if (aBookingRooms != null)
                        {
                            if (this.aListRemoveBookingRooms.Where(r=>r.ID == aRoomMemberEN.IDBookingRooms).ToList().Count <= 0)
                            {
                                this.aListRemoveBookingRooms.Add(aBookingRooms);
                            }
                        }
                    }

                    this.aCheckInEN.aListRoomMembers.Clear();
                    dgvSelectedRooms.DataSource = this.aCheckInEN.aListRoomMembers;
                    dgvSelectedRooms.RefreshDataSource();

                    this.aCurrent_CodeRoom = string.Empty;
                    lblRoomSku.Text = "Phòng số :000";
                    this.aCheckInEN.ClearAllListCustomer();
                    dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                    dgvSelectedCustomer.RefreshDataSource();
                    this.ResetValueAddNew();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.btnSearch_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void SetBookingRooms(BookingRooms aBookingRooms)
        {
            BookingRooms aItem = new BookingRooms();
            aItem = aBookingRooms;

            this._aBookingRooms.AcceptDate = aItem.AcceptDate;
            this._aBookingRooms.AdditionalColumn1 = aItem.AdditionalColumn1;
            this._aBookingRooms.AddTimeEnd = aItem.AddTimeEnd;
            this._aBookingRooms.AddTimeStart = aItem.AddTimeStart;
            this._aBookingRooms.BookingStatus = aItem.BookingStatus;
            this._aBookingRooms.CheckInActual = aItem.CheckInActual;

            this._aBookingRooms.CheckInPlan = aItem.CheckInPlan;
            this._aBookingRooms.CheckOutActual = aItem.CheckOutActual;
            this._aBookingRooms.CheckOutPlan = aItem.CheckOutPlan;
            this._aBookingRooms.CodeRoom = aItem.CodeRoom;
            this._aBookingRooms.Color = aItem.Color;

            this._aBookingRooms.Cost = null;
            this._aBookingRooms.CostPendingRoom = aItem.CostPendingRoom;
            this._aBookingRooms.CostRef_Rooms = aItem.CostRef_Rooms;
            this._aBookingRooms.Disable = aItem.Disable;
            this._aBookingRooms.EndTime = aItem.EndTime;
            this._aBookingRooms.ID = aItem.ID;

            this._aBookingRooms.IDBookingR = aItem.IDBookingR;
            this._aBookingRooms.IndexSubPayment = aItem.IndexSubPayment;

            this._aBookingRooms.InvoiceDate = aItem.InvoiceDate;
            this._aBookingRooms.InvoiceNumber = aItem.InvoiceNumber;
            this._aBookingRooms.IsAllDayEvent = aItem.IsAllDayEvent;
            this._aBookingRooms.IsEditable = aItem.IsEditable;
            this._aBookingRooms.IsRecurring = aItem.IsRecurring;

            this._aBookingRooms.Note = aItem.Note;
            this._aBookingRooms.PercentTax = aItem.PercentTax;
            this._aBookingRooms.PriceType = aItem.PriceType;
            this._aBookingRooms.StartTime = aItem.StartTime;

            this._aBookingRooms.Status = aItem.Status;
            this._aBookingRooms.TimeInUse = aItem.TimeInUse;
            this._aBookingRooms.Type = aItem.Type;
        }
        //-----------------Add New ---------------------------------
        public int Insert(BookingRooms bookingRooms)
        {
            try
            {

                aDatabaseDA.BookingRooms.Add(bookingRooms);
                aDatabaseDA.SaveChanges();
                return bookingRooms.ID;
            }
            catch (Exception ex)
            {
                throw new Exception("BookingRoomsBO.Insert:" + ex.ToString());
            }
        }
        //=======================================================
        //Author: LinhTing
        //Function : Chon Company bang ID CustomerGroup
        //=======================================================
        public Companies Select_ByIDBookingRoom(int IDBookingRoom)
        {
            try
               {
               BookingRooms aItem = new BookingRooms();
               aItem = aBookingRoomsBO.Select_ByID(IDBookingRoom);
               int IDBookingR = 0 ;

               if (aItem != null)
               {
                   IDBookingR = aItem.IDBookingR;
               }
               int IDCustomerGroup = aBookingRsBO.Select_ByID(IDBookingR).IDCustomerGroup;
               Companies aCompanies = this.Select_ByIDCustomerGroup(IDCustomerGroup);
               return aCompanies;
               }
               catch (Exception ex)
               {
               throw new Exception(string.Format("CompaniesBO.Select_ByIDCustomerGroup :"+ ex.Message.ToString()));
               }
        }