//public decimal? CalculateCostRoom(NewPaymentEN aNewPaymentEN, int IDBookingRoom, string PriceType)
        //{
        //    if (aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == IDBookingRoom).ToList().Count > 0)
        //    {
        //        CustomersBO aCustomersBO = new CustomersBO();
        //        ExtraCostBO aExtraCostBO = new ExtraCostBO();
        //        RoomsBO aRoomsBO = new RoomsBO();
        //        BookingRoomUsedEN aTemp = aNewPaymentEN.aListBookingRoomUsed.Where(a => a.ID == IDBookingRoom).ToList()[0];
        //        List<Customers> aListCustomers = aCustomersBO.SelectListCustomer_ByIDBookingRoom(IDBookingRoom);
        //        if (aListCustomers.Count >0 )
        //        {
        //        int CustomerType = Convert.ToInt32(aNewPaymentEN.CustomerType);
        //        decimal? CostRoom = 0;
        //        //if (aTemp.Cost != 0)
        //        //{
        //        //    CostRoom = aTemp.Cost - Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aTemp.RoomSku, aTemp.PriceType, aTemp.ListCustomer.Count).ExtraValue);
        //        //}
        //        //else
        //        //{
        //        CostRoom = aRoomsBO.Select_ByIDBookingRoom(IDBookingRoom).CostRef;
        //        //}
        //        string RoomSku = aTemp.RoomSku;
        //        decimal ExtraMoneyRoom = Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(RoomSku, PriceType, aListCustomers.Count).ExtraValue);
        //        return (CostRoom + ExtraMoneyRoom);
        //        }
        //        else  // Neu phong k co ai thi tien  =0
        //        {
        //            return 0;
        //        }
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        //}
        public decimal? CalculateCostRoom( int IDBookingRoom, string PriceType , int CustomerType, int NumCustomer )
        {
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();

            if (aBookingRoomsBO.Select_ByID(IDBookingRoom) != null)
            {
                CustomersBO aCustomersBO = new CustomersBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                RoomsBO aRoomsBO = new RoomsBO();
                //List<Customers> aListCustomers = aCustomersBO.SelectListCustomer_ByIDBookingRoom(IDBookingRoom);

                decimal? CostRoom = 0;

                CostRoom = aRoomsBO.Select_ByIDBookingRoom(IDBookingRoom).CostRef;

                string RoomSku = aRoomsBO.Select_ByIDBookingRoom(IDBookingRoom).Sku;

                try
                {
                    decimal? ExtraMoneyRoom = aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(RoomSku, PriceType, NumCustomer).ExtraValue;
                    return (CostRoom + ExtraMoneyRoom);
                }
                catch(Exception w)
                {
                    MessageBox.Show("Trong dữ liệu giá bảng giá " + PriceType + " của phòng " + RoomSku + " chưa có giá dành cho " + NumCustomer + " người ");
                    return 0;
                }

            }
            else
            {
                return 0;
            }
        }
        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();
        }
        // tqtrung
        public List<BookingRoomsEN> LoadListRoomsCheckOutInDayAndH(DateTime CheckOutPlan, int Status)
        {
            try
            {

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                return aBookingRoomsBO.GetListRoomsCheckOutPlanInDayAndH(CheckOutPlan, Status);
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckOutExpire.GetListRoomsCheckOutPlanInDayAndH\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        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);
            }
        }
        public void Reload()
        {
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            RoomsBO aRoomsBO = new RoomsBO();

            BookingRoomsEN aBookingRoomsEN = new BookingRoomsEN();
            BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
            aBookingRoomsEN.SetValue(aBookingRooms);
            aBookingRoomsEN.ID = aBookingRooms.ID;
            aBookingRoomsEN.RoomSku = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).Sku;
            this.lbCurrentRoom.Text = "Phòng số : " + aBookingRoomsEN.RoomSku;

            aListBookingRoom.Add(aBookingRoomsEN);
            dgvRooms.DataSource = aListBookingRoom;
            dgvRooms.RefreshDataSource();

            ServicesBO aServicesBO = new ServicesBO();
            aListService = aServicesBO.Select_ByType(2);
            dgvServices.DataSource = aListService;
            dgvServices.RefreshDataSource();
        }
 public Rooms Select_ByIDBookingRoom(int IDBookingRoom)
 {
     try
     {
         BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
         BookingRooms aTemp = aBookingRoomsBO.Select_ByID(IDBookingRoom);
         Rooms aRooms = this.Select_ByCodeRoom(aTemp.CodeRoom, 1);
         return aRooms;
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("RoomBO.Select_ByIDBookingRoom :" + ex.Message.ToString()));
     }
 }
        public frmRpt_PersonalPayment(List<RptPaymentStyle1_ForPrint> aListData, string CompanyName, string Address, string NameCustomerGroup, string InvoiceNumber
            , DateTime FirstDate, DateTime LastDate, decimal? BookingHMoney, decimal? BookingRMoney,int IDBookingR)
        {
            InitializeComponent();
            //Load dữ liệu
             BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
                        CustomersBO aCustomersBO = new CustomersBO();
            RoomsBO aRoomsBO = new RoomsBO();

            string RoomSku = "";
            string CustomerNames = "";
              List<BookingRooms> aListBookingRooms = aBookingRoomBO.Select_ByIDBookingRs(IDBookingR);
              if (aListBookingRooms.Count > 0)
              {
                  BookingRoomUsedEN aBookingRoomUsedEN;

                  foreach (BookingRooms item in aListBookingRooms)
                  {
                      aBookingRoomUsedEN = new BookingRoomUsedEN();
                      aBookingRoomUsedEN.SetValue(item);
                      aBookingRoomUsedEN.ListCustomer = aCustomersBO.SelectListCustomer_ByIDBookingRoom(item.ID);
                      Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);
                      if (aRooms != null)
                      {
                          aBookingRoomUsedEN.RoomSku = aRooms.Sku;
                      }
                      else
                      {
                          aBookingRoomUsedEN.RoomSku = string.Empty;
                      }
                      if (RoomSku == "")
                      {
                          RoomSku = aBookingRoomUsedEN.RoomSku;
                      }
                      else
                      {
                          RoomSku = RoomSku + " + " + aBookingRoomUsedEN.RoomSku;
                      }
                      foreach (Customers aItem in aBookingRoomUsedEN.ListCustomer)
                      {
                          if (CustomerNames == "")
                          {
                              CustomerNames = aItem.Name;
                          }
                          else
                          {
                              CustomerNames = CustomerNames + " + " + aItem.Name;
                          }
                      }
                  }

              }
              decimal MealCharge = 0;
              decimal DrinkCharge = 0;
              decimal    RoomCharge= 0;
               decimal   RoomServiceCharge= 0;
               decimal   Tel= 0;
              decimal Laundry = 0;
              decimal    OtherServiceCharge = 0;
              decimal TotalServiceMoney = 0;
              decimal TotalMoneyBeforeTax = 0;
              foreach (RptPaymentStyle1_ForPrint aItem in aListData)
              {
                  MealCharge = MealCharge + aItem.ServiceGroup8_Fee;
                  DrinkCharge = DrinkCharge + aItem.ServiceGroup7_Fee;
                  RoomCharge = RoomCharge + aItem.Room_Fee;
                  RoomServiceCharge = RoomServiceCharge + aItem.ServiceGroup5_Fee;
                  Tel = Tel + aItem.ServiceGroup2_Fee;
                  Laundry = Laundry + aItem.ServiceGroup3_Fee;
                  OtherServiceCharge = OtherServiceCharge + aItem.ServiceGroup4_Fee + aItem.ServiceGroup5_Fee + aItem.ServiceGroup9_Fee;
                  TotalServiceMoney = TotalServiceMoney + aItem.TotalServiceMoney;
                  TotalMoneyBeforeTax = TotalMoneyBeforeTax + aItem.TotalMoney;
              }

            //Hiển thị dữ liệu
              BookingRs aBookingRs = new BookingRs();
              aBookingRs = (new BookingRsBO()).Select_ByID(IDBookingR);

              lblIDBookingR.Text = IDBookingR.ToString();
              lblInvoiceNumber.Text = aBookingRs.InvoiceNumber;
              lblInvoiceDate.Text = aBookingRs.InvoiceDate.GetValueOrDefault().Date.ToShortDateString();
              lbAcceptDate.Text = aBookingRs.AcceptDate.GetValueOrDefault().Date.ToShortDateString();

              lblCheckIn.Text = FirstDate.ToString("dd/MM/yyyy");
              lblCheckOut.Text = LastDate.ToString("dd/MM/yyyy");
              lblCustomerName.Text = CustomerNames;
              lblRoomSku.Text = RoomSku;

              lblMealChargeVN.Text = MealCharge.ToString("0,0");
              lblDrinkChargeVN.Text = DrinkCharge.ToString("0,0");
              lblRoomChargeVN.Text = RoomCharge.ToString("0,0");
              lblRoomServiceVN.Text = RoomServiceCharge.ToString("0,0");
              lblTelVN.Text = Tel.ToString("0,0");
              lblLaundryVN.Text = Laundry.ToString("0,0");
              lblOtherServiceVN.Text = OtherServiceCharge.ToString("0,0");

              lblServiceChargeVN.Text = TotalServiceMoney.ToString("0,0");
              lblTotalBTVN.Text = TotalMoneyBeforeTax.ToString("0,0");
              lblTaxVN.Text = (TotalMoneyBeforeTax * 10 / 100).ToString("0,0");
              lblMoneyAfterTaxVN.Text = (TotalMoneyBeforeTax * 110 / 100).ToString("0,0");
              lblBookingMoneyVN.Text = Convert.ToDecimal(BookingHMoney + BookingHMoney).ToString("0,0");
              lblTotalMoneyVN.Text = ((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney + BookingHMoney)).ToString("0,0");
              string TotalMoney_String = UppercaseFirst(StringUtility.ConvertDecimalToString((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney + BookingHMoney)));
              lblConvertToString.Text = TotalMoney_String;

              int day = DateTime.Now.Day;
              int month = DateTime.Now.Month;
              int year = DateTime.Now.Year;
              lblDayMonthYear.Text = "Hà nội , ngày " + day.ToString() + " tháng " + month.ToString() + " năm " + year.ToString();
        }
 private void btnCancel_2_Click(object sender, EventArgs e)
 {
     try
     {
         BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
         int count = aBookingRoomsBO.Delete(this.Datasource.BookingRooms_ID);
         if (count > 0)
         {
             this.afrmMain.ReloadData();
             MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Đã có lỗi xẩy ra trong quá trình thực hiện vui lòng liên hệ với người quản trị.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         this.Parent.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show("uc_Tooltip_StatusRoom_2.btnCancel_2_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private List<CustomerInfoEN> GetDataForSelectCustomerGridview(string CodeRoom)
        {
            BookingRsBO aBookingRsBO = new BookingRsBO();
            List<Rooms> aListRoom = aBookingRsBO.SelectListRooms_ByIDBookingR(this.aBookingRoom.IDBookingR, 1);

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

                        aListRet.Add(aItem);
                    }
                    return aListRet;
                }
                // nếu thông tin phong đã có trong khối aChangeRoom thì lấy danh sách người ở trong khối đó ra
                else
                {
                    return this.aChangeRoomEn.GetItemChangeRooms(CodeRoom).GetAllCustomers();
                }
            }
            else
            {
                if (this.aChangeRoomEn.IsExitRoom(CodeRoom) == false)
                {
                    return new List<CustomerInfoEN>();
                }
                // nếu thông tin phong đã có trong khối aChangeRoom thì lấy danh sách người ở trong khối đó ra
                else
                {
                    return this.aChangeRoomEn.GetItemChangeRooms(CodeRoom).GetAllCustomers();
                }
            }
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ValidateData() == true)
                {
                    BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                    BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRooms);
                    aBookingRooms.CodeRoom = this.NewCodeRoom;
                    aBookingRooms.Cost = this.NewCostRoom;
                    aBookingRooms.CostRef_Rooms = this.NewCostRoom;
                    aBookingRoomsBO.Update(aBookingRooms);

                    MessageBox.Show("Chuyển phòng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (afrmMain != null)
                    {
                        this.afrmMain.ReloadData();
                    }
                    this.Close();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_ChangeRoom.btnUpdate_Click\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btnPrintListCus_Click(object sender, EventArgs e)
 {
     BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
     List<vw__BookingRInfo__BookingRooms_Room_Customers_CustomerGroups> aListCustomerInGroup = aBookingRoomsBO.SelectListInfoCustomer_ByIDBookingR(this.IDBookingR);
     frmRpt_ListCustomersInGroup afrmRpt_ListCustomersInGroup = new frmRpt_ListCustomersInGroup(aListCustomerInGroup, this.aNewPaymentEN.NameCompany, this.aNewPaymentEN.NameCustomerGroup);
     ReportPrintTool tool = new ReportPrintTool(afrmRpt_ListCustomersInGroup);
     tool.ShowPreview();
 }
        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 btnCancel_1_Click(object sender, EventArgs e)
 {
     BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
        bool i = aBookingRoomsBO.ChangeStatus( this.Datasource.BookingRooms_ID, 6); // 6: Cancel
        if (i == true)
        {
        MessageBox.Show("Đã chuyển trạng thái phòng");
        }
        else {
        MessageBox.Show("Chưa chuyển trạng thái phòng");
        }
 }
        //=======================================================
        //Author: Hien
        //Function : ReportPaymentBookingR
        //=======================================================
        public List<InfoDetailPaymentEN> ReportPaymentBookingR(int IDBookingR)
        {
            PaymentEN aPaymentEN = new PaymentEN();
            BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
            List<BookingRooms> aListBookingRoom = new List<BookingRooms>();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();

            aListBookingRoom = aBookingRoomBO.Select_ByIDBookingRs(IDBookingR);
            InfoDetailPaymentEN aInfoDetailPaymentEn;
            for (int i = 0; i < aListBookingRoom.Count; i++)
            {
                aInfoDetailPaymentEn = new InfoDetailPaymentEN();
                aInfoDetailPaymentEn.aBookingRooms = aListBookingRoom[i];
                aInfoDetailPaymentEn.aListService = aReceptionTaskBO.GetListService_ByIDBookingRoom(aListBookingRoom[i].ID);
                //aInfoDetailPaymentEn.DateInUse = aReceptionTaskBO.CaculateBooking(aListBookingRoom[i].ID,aListBookingRoom[i].CheckInActual, aListBookingRoom[i].CheckOutActual);
                aPaymentEN.aListInfoDetailPaymentEN.Add(aInfoDetailPaymentEn);
            }

            return aPaymentEN.aListInfoDetailPaymentEN;
        }
        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());
            }
        }
        private void btnDelBooking_Click(object sender, EventArgs e)
        {
            int BookingRs_ID = Convert.ToInt32(grvOvertimeBooking.GetFocusedRowCellValue("BookingRs_ID").ToString());
            DialogResult aRet = MessageBox.Show("Có chắc bạn muốn xóa đặt phòng này không ?", "Cảnh báo", MessageBoxButtons.YesNo);
            if (aRet == System.Windows.Forms.DialogResult.Yes)
            {

                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRooms =  aBookingRoomsBO.Select_ByIDBookingRs(BookingRs_ID);

                int ret1 = aBookingRoomsBO.Delete(aListBookingRooms);
                int ret2 = aBookingRsBO.Delete(BookingRs_ID);
                if (ret2 > 0 && ret1 >0)
                {
                    MessageBox.Show("Xóa thành công");
                    LoadDataForOverTimeBooking();
                }
                else
                {
                    MessageBox.Show("Xóa không thành công");
                }

            }
        }
        private void LoadDataForOverTimeCheckIn()
        {
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            List<RoomExtStatusEN> aList = new List<RoomExtStatusEN>();

            RoomsBO aRoomsBO = new RoomsBO();

            List<int> aListStatus = new List<int>();
            aListStatus.Add(3);

            aList = aRoomsBO.GetStatusRoom_ByListStatus(aListStatus).Where(p => p.CheckOutPlan.Date <= DateTime.Now.Date).ToList();

            dgvBookingRooms.DataSource = aList;
            dgvBookingRooms.RefreshDataSource();
        }
        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);
            }
        }
        //Hiennv     26/11/2014       ham dung de load toan bo du lieu theo IDBookingR
        public CheckInEN InitData(int IDBookingR)
        {
            try
            {
                CheckInEN aCheckInEN = new CheckInEN();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                if(aBookingRs != null)
                {
                    aCheckInEN.IDBookingR = aBookingRs.ID;
                    aCheckInEN.CustomerType = aBookingRs.CustomerType.GetValueOrDefault();
                    aCheckInEN.BookingType = aBookingRs.BookingType.GetValueOrDefault();
                    aCheckInEN.Note = aBookingRs.Note;
                    aCheckInEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                    aCheckInEN.IDCustomer = aBookingRs.IDCustomer;
                    aCheckInEN.IDSystemUser = aBookingRs.IDSystemUser;
                    aCheckInEN.PayMenthod = aBookingRs.PayMenthod.GetValueOrDefault();
                    aCheckInEN.StatusPay = aBookingRs.StatusPay.GetValueOrDefault();
                    aCheckInEN.BookingMoney = aBookingRs.BookingMoney.GetValueOrDefault();
                    aCheckInEN.ExchangeRate = aBookingRs.ExchangeRate.GetValueOrDefault();
                    aCheckInEN.Status = aBookingRs.Status.GetValueOrDefault();
                    aCheckInEN.Type = aBookingRs.Type.GetValueOrDefault();
                    aCheckInEN.Disable = aBookingRs.Disable.GetValueOrDefault();
                    aCheckInEN.Level = aBookingRs.Level;
                    aCheckInEN.Subject = aBookingRs.Subject;
                    aCheckInEN.Description = aBookingRs.Description;
                    aCheckInEN.DatePay = aBookingRs.DatePay;
                    aCheckInEN.DateEdit = aBookingRs.DateEdit;
                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    CustomerGroups aCustomerGroups = new CustomerGroups();
                    aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                    if(aCustomerGroups !=null)
                    {
                        aCheckInEN.IDCompany = aCustomerGroups.IDCompany;
                    }

                }
                RoomsBO aRoomsBO = new RoomsBO();
                List<Rooms> aListRooms = new List<Rooms>();
                aListRooms = aRoomsBO.Select_All();

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListBookingRooms = new List<BookingRooms>();
                aListBookingRooms = aBookingRoomsBO.Select_ByIDBookingRs(IDBookingR);
                for (int i = 0; i < aListBookingRooms.Count; i++ )
                {
                    RoomMemberEN aRoomMemberEN = new RoomMemberEN();
                    aRoomMemberEN.IDBookingRooms = aListBookingRooms[i].ID;
                    aRoomMemberEN.RoomCode = aListBookingRooms[i].CodeRoom;
                    aRoomMemberEN.RoomSku = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Sku;
                    aRoomMemberEN.RoomType = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault();
                    aRoomMemberEN.RoomTypeDisplay = CORE.CONSTANTS.SelectedRoomsType(aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Type.GetValueOrDefault()).Name;
                    aRoomMemberEN.RoomBed1 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed1.GetValueOrDefault();
                    aRoomMemberEN.RoomBed2 = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).Bed2.GetValueOrDefault();
                    aRoomMemberEN.RoomCostRef = aCheckInEN.GetInfoRooms(aListRooms, aListBookingRooms[i].CodeRoom).CostRef.GetValueOrDefault();
                    aRoomMemberEN.RoomCost = aListBookingRooms[i].Cost.GetValueOrDefault();
                    aCheckInEN.InsertRoom(aRoomMemberEN);
                }
                return aCheckInEN;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInForRoomBooking.InitData()\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        // ===============================================================================
        // Khoi tao doi tuong Payment
        private void InitData(int IDBookingR, int IDBookingH)
        {
            CompaniesBO aCompaniesBO = new CompaniesBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingRsBO aBookingRsBO = new BookingRsBO();
            BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
            CustomersBO aCustomersBO = new CustomersBO();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            RoomsBO aRoomsBO = new RoomsBO();
            HallsBO aHallsBO = new HallsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            FoodsBO aFoodsBO = new FoodsBO();
            ExtraCostBO aExtraCostBO = new ExtraCostBO();
            List<int> aListIndexTemp = new List<int>();
            BookingHs aBookingHs = new BookingHs();
            BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
            if (this.IDBookingH > 0)
            {
                aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
            }
            else
            {
                BookingRs_BookingHs aItem = (new BookingRs_BookingHsBO()).Select_ByIDBookingR(this.IDBookingR);
                if (aItem != null)
                {
                    this.IDBookingH = aItem.IDBookingH.GetValueOrDefault(0);
                    aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
                }

            }

            // Truyen du lieu chung cua NewPayment
            if (aBookingRs != null)
            {
                aNewPaymentEN.IDBookingR = aBookingRs.ID;
                aNewPaymentEN.IDCustomer = aBookingRs.IDCustomer;
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                if (aCustomers != null)
                {
                    aNewPaymentEN.NameCustomer = aCustomers.Name;
                }
                aNewPaymentEN.IDSystemUser = aBookingRs.IDSystemUser;
                SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingRs.IDSystemUser);
                if (aSystemUsers != null)
                {
                    aNewPaymentEN.NameSystemUser = aSystemUsers.Name;
                }
                aNewPaymentEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                if (aCustomerGroups != null)
                {
                    aNewPaymentEN.NameCustomerGroup = aCustomerGroups.Name;
                    aNewPaymentEN.IDCompany = aCustomerGroups.IDCompany;
                    Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                    if (aCompanies != null)
                    {
                        aNewPaymentEN.NameCompany = aCompanies.Name;
                        aNewPaymentEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        aNewPaymentEN.AddressCompany = aCompanies.Address;
                    }
                }
                aNewPaymentEN.PayMenthodR = aBookingRs.PayMenthod;
                aNewPaymentEN.CreatedDate_BookingR = aBookingRs.CreatedDate;
                aNewPaymentEN.CustomerType = aBookingRs.CustomerType;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.StatusPay = aBookingRs.StatusPay;
                aNewPaymentEN.BookingRMoney = aBookingRs.BookingMoney;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.AcceptDate = aBookingRs.AcceptDate;
                aNewPaymentEN.InvoiceDate = aBookingRs.InvoiceDate;
                aNewPaymentEN.InvoiceNumber = aBookingRs.InvoiceNumber;

                // Truyen du lieu cho List BookingRoom cua NewPayment
                List<BookingRooms> aListBookingRooms = aBookingRoomBO.Select_ByIDBookingRs(this.IDBookingR);
                if (aListBookingRooms.Count > 0)
                {
                    BookingRoomUsedEN aBookingRoomUsedEN;

                    foreach (BookingRooms item in aListBookingRooms)
                    {
                        aBookingRoomUsedEN = new BookingRoomUsedEN();
                        aBookingRoomUsedEN.SetValue(item);
                        aBookingRoomUsedEN.ListCustomer = aCustomersBO.SelectListCustomer_ByIDBookingRoom(item.ID);
                        Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);
                        if (aRooms != null)
                        {
                            aBookingRoomUsedEN.RoomSku = aRooms.Sku;
                        }
                        else
                        {
                            aBookingRoomUsedEN.RoomSku = string.Empty;
                        }
                        if (item.Status == 8 || item.Status == 7)
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutActual));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutActual) * 24 * 60);
                        }
                        else
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutPlan));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutPlan) * 24 * 60);

                        }
                        decimal? cost = 0;
                        if (item.Cost == null)
                        {
                            cost = item.CostRef_Rooms;
                            aBookingRoomUsedEN.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRoomUsedEN.PriceType, aBookingRoomUsedEN.ListCustomer.Count).ExtraValue);
                        }
                        else
                        {
                            cost = item.Cost;
                            aBookingRoomUsedEN.Cost = cost;
                        }
                        List<ServiceUsedEN> aListServiceRTemp = aReceptionTaskBO.GetListServiceUsedInRoom_ByIDBookingRoom(item.ID);
                        foreach (ServiceUsedEN aTemp in aListServiceRTemp)
                        {
                            aBookingRoomUsedEN.ListServiceUsed.Add(aTemp);
                            aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                        }
                        aListIndexTemp.Add(Convert.ToInt32(aBookingRoomUsedEN.IndexSubPayment));
                        aNewPaymentEN.aListBookingRoomUsed.Add(aBookingRoomUsedEN);
                    }
                }

                //====================================================================================================
                //====================================================================================================
                //====================================================================================================
                // Brucelee Thanh sửa ngày 04/06/2015
                //
                //---------------
                // Lỗi sai điều kiện câu lệnh if khiến aBookingHs truyền dữ liệu CustomerType sai cho NewPaymentEN
                //---------------
                // Ban đầu : if (aBookingHs != null)
                //-------------------------------------
                if (aBookingHs.ID > 0)
                {
                    aNewPaymentEN.IDBookingH = aBookingHs.ID;
                    aNewPaymentEN.PayMenthodH = aBookingHs.PayMenthod;
                    aNewPaymentEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                    aNewPaymentEN.CustomerType = aBookingHs.CustomerType;
                    aNewPaymentEN.Status_BookingH = aBookingHs.Status;
                    aNewPaymentEN.BookingHMoney = aBookingHs.BookingMoney;
                    // Truyen du lieu cho List BookingHall cua NewPayment
                    List<BookingHalls> aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(this.IDBookingH);
                    if (aListBookingHalls != null)
                    {
                        BookingHallUsedEN aBookingHallUsedEN;
                        foreach (BookingHalls item in aListBookingHalls)
                        {
                            aBookingHallUsedEN = new BookingHallUsedEN();
                            aBookingHallUsedEN.SetValue(item);
                            Halls aHalls = aHallsBO.Select_ByCodeHall(item.CodeHall, 1);
                            if (aHalls != null)
                            {
                                aBookingHallUsedEN.HallSku = aHalls.Sku;
                            }
                            else
                            {
                                aBookingHallUsedEN.HallSku = string.Empty;
                            }
                            aBookingHallUsedEN.CustomerType = aBookingHs.CustomerType;
                            aBookingHallUsedEN.BookingTypeBookingH = aBookingHs.BookingType;
                            aBookingHallUsedEN.StatusPayBookingH = aBookingHs.StatusPay;
                            aBookingHallUsedEN.LevelBookingH = aBookingHs.Level;
                            aBookingHallUsedEN.aListMenuEN = aReceptionTaskBO.GetListMenus_ByIDBookingHall(item.ID);

                            aListIndexTemp.Add(Convert.ToInt32(aBookingHallUsedEN.IndexSubPayment));
                            List<ServiceUsedEN> aListServiceTemp = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(item.ID);
                            foreach (ServiceUsedEN aTemp in aListServiceTemp)
                            {
                                aBookingHallUsedEN.aListServiceUsed.Add(aTemp);
                                aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                            }
                            aNewPaymentEN.aListBookingHallUsed.Add(aBookingHallUsedEN);
                        }
                    }
                }
                aNewPaymentEN.ListIndex = aListIndexTemp.Distinct().ToList();
            }
        }
        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 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");
            }
        }
        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;
        }
        //hiennv
        private void btnRemoveSelectedRooms_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            try
            {
                RoomsEN aRoomEN = new RoomsEN();

                aRoomEN.Code = viewSelectedRooms.GetFocusedRowCellValue("RoomCode").ToString();
                aRoomEN.Sku = viewSelectedRooms.GetFocusedRowCellValue("RoomSku").ToString();
                aRoomEN.TypeDisplay = viewSelectedRooms.GetFocusedRowCellValue("RoomTypeDisplay").ToString();
                aRoomEN.Bed1 = Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("RoomBed1"));
                aRoomEN.Bed2 = Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("RoomBed2"));
                aRoomEN.CostRef = Convert.ToDecimal(viewSelectedRooms.GetFocusedRowCellValue("RoomCostRef"));

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

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                int ID = Convert.ToInt32(viewSelectedRooms.GetFocusedRowCellValue("IDBookingRooms"));
                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(ID);
                if (aBookingRooms != null)
                {
                   aBookingRoomsBO.Delete(aBookingRooms.ID);
                }

                RoomMemberEN Temps = aCheckInRoomBookingEN.aListRoomMembers.Where(p => p.RoomSku == viewSelectedRooms.GetFocusedRowCellValue("RoomSku").ToString()).ToList()[0];
                this.aCheckInRoomBookingEN.aListRoomMembers.Remove(Temps);
                dgvSelectedRooms.DataSource = aCheckInRoomBookingEN.aListRoomMembers;
                dgvSelectedRooms.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInGoverment_ForRoomBooking_Step1.btnRemoveSelectedRooms_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //hiennv
        private void btnUnFill_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                RoomsEN aRoomEN = new RoomsEN();

                aRoomEN.Sku = grvSelectedRooms.GetFocusedRowCellValue("RoomSku").ToString();
                aRoomEN.Code = grvSelectedRooms.GetFocusedRowCellValue("RoomCode").ToString();
                aRoomEN.TypeDisplay = Convert.ToString(grvSelectedRooms.GetFocusedRowCellValue("RoomTypeDisplay"));
                aRoomEN.Bed1 = Convert.ToInt32(grvSelectedRooms.GetFocusedRowCellValue("RoomBed1"));
                aRoomEN.Bed2 = Convert.ToInt32(grvSelectedRooms.GetFocusedRowCellValue("RoomBed2"));
                aRoomEN.CostRef = Convert.ToDecimal(grvSelectedRooms.GetFocusedRowCellValue("RoomCostRef"));

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

                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                int ID = Convert.ToInt32(grvSelectedRooms.GetFocusedRowCellValue("IDBookingRooms"));
                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(ID);
                if (aBookingRooms != null)
                {
                    aBookingRoomsBO.Delete(aBookingRooms.ID);
                }

                RoomMemberEN aRoomMemberEN = this.aCheckInRoomBookingEN.aListRoomMembers.Where(p => p.RoomSku == grvSelectedRooms.GetFocusedRowCellValue("RoomSku").ToString()).ToList()[0];
                this.aCheckInRoomBookingEN.aListRoomMembers.Remove(aRoomMemberEN);
                dgvSelectedRooms.DataSource = this.aCheckInRoomBookingEN.aListRoomMembers;
                dgvSelectedRooms.RefreshDataSource();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Check In Step 1 - Khách lẻ - Bỏ chọn " + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //-----------------Select by list idbookingroom-------------------------------
        public List<BookingRs> Select_ByListIDBookingRoom(List<int> ListIDBookingRoom)
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                List<BookingRooms> aListItem = new List<BookingRooms>();
                aListItem = aBookingRoomsBO.Select_ByListID(ListIDBookingRoom);
                List<int> aListIDBookingRs = new List<int>();
                int aIDBookingRs;
                for (int i = 0; i < aListItem.Count; i++)
                {
                    aIDBookingRs = new int();
                    aIDBookingRs = aListItem[i].IDBookingR;
                    aListIDBookingRs.Add(aIDBookingRs);
                }
                List<BookingRs> aListBookingRs = aBookingRsBO.Select_ByListID(aListIDBookingRs);
                return aListBookingRs;
            }
            catch (Exception ex)
            {

                throw new Exception("BookingRsBO.Select_ByListIDBookingRoom:" + ex.ToString());
            }
        }
        //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);
            }
        }