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);
            }
        }
        //-----------------Add New ---------------------------------
        public int Insert(BookingRs bookingRs)
        {
            try
            {
                aDatabaseDA.BookingRs.Add(bookingRs);
                aDatabaseDA.SaveChanges();
                return bookingRs.ID;

            }
            catch (Exception ex)
            {
                throw new Exception("BookingRsBO.Insert:" + ex.ToString());
            }
        }
        public frmTsk_EditBooking(int IDBookingRoom, frmMain afrmMain)
        {
            InitializeComponent();

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

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

            this.afrmMain = afrmMain;
            this.IsReadyInitData = false;
            this.aCurrentCustomerClick = new CustomerInfoEN();
        }
        public void 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 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();
        }
        public frmRpt_GroupPayment_Rs(List<RptPaymentStyle1_ForPrint> aListData,string CompanyName, string Address, string NameCustomerGroup,string InvoiceNumber
            , DateTime FirstDate, DateTime LastDate, decimal? BookingHMoney, decimal? BookingRMoney, int IDBookingR)
        {
            InitializeComponent();

            this.aListData = aListData;
            foreach (RptPaymentStyle1_ForPrint aItem in aListData)
            {
                TotalServiceMoney = TotalServiceMoney + aItem.TotalServiceMoney;
                TotalMoneyBeforeTax = TotalMoneyBeforeTax + aItem.TotalMoney;
                aItem.Room_Fee = aItem.Room_Fee + aItem.Hall_Fee;  // Gộp 2 cột
            }
            //Truyền dữ liệu cho Detail
            lblCompanyName.Text = CompanyName;
            lblAddress.Text = Address;
            lblCustomerGroupName.Text = NameCustomerGroup;

            lblCheckIn.Text = FirstDate.ToString("dd-MM-yyyy");
            lblCheckOut.Text = LastDate.ToString("dd-MM-yyyy");

            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();

            this.DetailReport.DataSource = this.aListData;
            colDate.DataBindings.Add("Text", this.DetailReport.DataSource, "Date", "{0:dd-MM}");
            colDescription.DataBindings.Add("Text", this.DetailReport.DataSource, "Note");
            colNumberCus.DataBindings.Add("Text", this.DetailReport.DataSource, "CountCustomerInGroup");
            colMoneyRoom.DataBindings.Add("Text", this.DetailReport.DataSource, "Room_Fee", "{0:0,0}");
            colTotalARoom.DataBindings.Add("Text", this.DetailReport.DataSource, "TotalMoney", "{0:0,0}");
               // colHallMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "Hall_Fee", "{0:0,0}");
            colMealMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "MealMoney", "{0:0,0}");
            colDrinkMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "DrinkMoney", "{0:0,0}");
            colRoomServiceMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "RoomServiceMoney", "{0:0,0}");
            colOtherMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "OtherMoney", "{0:0,0}");

            colMoneyService.Text = TotalServiceMoney.ToString("0,0");
            colMoneyBeforeTax.Text = TotalMoneyBeforeTax.ToString("0,0");
            colMoneyTax.Text = (TotalMoneyBeforeTax * 10 / 100).ToString("0,0");
            colMoneyAfterTax.Text = (TotalMoneyBeforeTax * 110 / 100).ToString("0,0");
            colBookingMoney.Text = Convert.ToDecimal(BookingHMoney + BookingHMoney).ToString("0,0");
            colTotalMoneyPay.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();

            //--------------Tính tổng---------------------------------
            XRSummary aXRSummaryMoney = new XRSummary();
            aXRSummaryMoney.Func = SummaryFunc.Sum;
            aXRSummaryMoney.Running = SummaryRunning.Group;
            aXRSummaryMoney.IgnoreNullValues = true;
            aXRSummaryMoney.FormatString = "{0:0,0}";
            XRBinding aXRBindingMoney = new XRBinding("Text", this.DetailReport.DataSource, "TotalMoney", "{0:0,0}");
            XRBinding[] listXRBindingMoney = new XRBinding[] { aXRBindingMoney };
            colSumTotalMoney.DataBindings.AddRange(listXRBindingMoney);
            colSumTotalMoney.Summary = aXRSummaryMoney;

            XRSummary aXRSumDrinkMoney = new XRSummary();
            aXRSumDrinkMoney.Func = SummaryFunc.Sum;
            aXRSumDrinkMoney.Running = SummaryRunning.Group;
            aXRSumDrinkMoney.IgnoreNullValues = true;
            aXRSumDrinkMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding = new XRBinding("Text", this.DetailReport.DataSource, "DrinkMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding = new XRBinding[] { aXRBinding };
            colSumDrinkMoney.DataBindings.AddRange(aList_aXRBinding);
            colSumDrinkMoney.Summary = aXRSumDrinkMoney;

            //XRSummary aXRSumHallMoney = new XRSummary();
            //aXRSumHallMoney.Func = SummaryFunc.Sum;
            //aXRSumHallMoney.Running = SummaryRunning.Group;
            //aXRSumHallMoney.IgnoreNullValues = true;
            //aXRSumHallMoney.FormatString = "{0:0,0}";
            //XRBinding aXRBinding1 = new XRBinding("Text", this.DetailReport.DataSource, "Hall_Fee", "{0:0,0}");
            //XRBinding[] aList_aXRBinding1 = new XRBinding[] { aXRBinding1 };
            //colSumHallMoney.DataBindings.AddRange(aList_aXRBinding1);
            //colSumHallMoney.Summary = aXRSumHallMoney;

            XRSummary aXRSumMealMoney = new XRSummary();
            aXRSumMealMoney.Func = SummaryFunc.Sum;
            aXRSumMealMoney.Running = SummaryRunning.Group;
            aXRSumMealMoney.IgnoreNullValues = true;
            aXRSumMealMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding2 = new XRBinding("Text", this.DetailReport.DataSource, "MealMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding2 = new XRBinding[] { aXRBinding2 };
            colSumMealMoney.DataBindings.AddRange(aList_aXRBinding2);
            colSumMealMoney.Summary = aXRSumMealMoney;

            XRSummary aXRSumMoneyRoom = new XRSummary();
            aXRSumMoneyRoom.Func = SummaryFunc.Sum;
            aXRSumMoneyRoom.Running = SummaryRunning.Group;
            aXRSumMoneyRoom.IgnoreNullValues = true;
            aXRSumMoneyRoom.FormatString = "{0:0,0}";
            XRBinding aXRBinding3 = new XRBinding("Text", this.DetailReport.DataSource, "Room_Fee", "{0:0,0}");
            XRBinding[] aList_aXRBinding3 = new XRBinding[] { aXRBinding3 };
            colSumMoneyRoom.DataBindings.AddRange(aList_aXRBinding3);
            colSumMoneyRoom.Summary = aXRSumMoneyRoom;

            XRSummary aXRSumOtherMoney = new XRSummary();
            aXRSumOtherMoney.Func = SummaryFunc.Sum;
            aXRSumOtherMoney.Running = SummaryRunning.Group;
            aXRSumOtherMoney.IgnoreNullValues = true;
            aXRSumOtherMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding4 = new XRBinding("Text", this.DetailReport.DataSource, "OtherMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding4 = new XRBinding[] { aXRBinding4 };
            colSumOtherMoney.DataBindings.AddRange(aList_aXRBinding4);
            colSumOtherMoney.Summary = aXRSumOtherMoney;

            XRSummary aXRSumRoomServiceMoney = new XRSummary();
            aXRSumRoomServiceMoney.Func = SummaryFunc.Sum;
            aXRSumRoomServiceMoney.Running = SummaryRunning.Group;
            aXRSumRoomServiceMoney.IgnoreNullValues = true;
            aXRSumRoomServiceMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding5 = new XRBinding("Text", this.DetailReport.DataSource, "RoomServiceMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding5 = new XRBinding[] { aXRBinding5 };
            colSumRoomServiceMoney.DataBindings.AddRange(aList_aXRBinding5);
            colSumRoomServiceMoney.Summary = aXRSumRoomServiceMoney;
        }
        private void txtSubject_Leave(object sender, EventArgs e)
        {
            int IDBookingR = Convert.ToInt32(grvPaymentViewAll.GetFocusedRowCellValue("BookingRs_ID"));
            string ObjectType = grvPaymentViewAll.GetFocusedRowCellValue("ObjectType").ToString();
            string Subject = grvPaymentViewAll.GetFocusedRowCellValue("Subject").ToString();

            if (ObjectType == "Phòng")
            {
                BookingRs aItem = new BookingRs();
                BookingRsBO aBookingRsBO = new BookingRsBO();
                aItem = aBookingRsBO.Select_ByID(IDBookingR);
                aItem.Subject = Subject;
                aBookingRsBO.Update(aItem);
                this.LoadData();
            }
            else
            {
                BookingHs aItem = new BookingHs();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
                int IDBookingH = aBookingRs_BookingHsBO.Select_ByIDBookingR(IDBookingR).IDBookingH.GetValueOrDefault(0);

                aItem = aBookingHsBO.Select_ByID(IDBookingH);
                aItem.Subject = Subject;
                aBookingHsBO.Update(aItem);
                this.LoadData();
            }
        }
        private void lueIDCompanies_EditValueChanged(object sender, EventArgs e)
        {
            if (lueIDCompanies.EditValue == null)
            {
                MessageBox.Show("Vui lòng chọn tên công ty.");
                lueIDCompanies.Focus();

            }
            BookingRsBO aBookingRsBO = new BookingRsBO();
            BookingRs aBookingRs = new BookingRs();
            List<PaymentExt_GetAllDataEN> aListPaymentExt_GetAllDataEN = new List<PaymentExt_GetAllDataEN>();
            int IDCompany = Convert.ToInt32(lueIDCompanies.EditValue.ToString());

            CustomerGroupsBO aCustomerGroupBO = new CustomerGroupsBO();
            List<int> aListIDCustomerGroup = aCustomerGroupBO.Select_All().Where(x => x.IDCompany == IDCompany).Select(p => p.ID).ToList();

            CompaniesBO aCompaniesBO = new CompaniesBO();
            List<int> ListIDBookingR = aBookingRsBO.Select_ByIDCompany(int.Parse(lueIDCompanies.EditValue.ToString())).Select(p=>p.ID).ToList();
            dgvPaymentViewAll.DataSource = this.aListPaymentExt_GetAllDataEN.Where(p => ListIDBookingR.Contains(p.BookingRs_ID));
        }
        //=======================================================
        //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());
            }
        }
        //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;
            }
        }
        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());
            }
        }
        //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     25/11/2014     Viet lai phuong thuc BookingRoom
        public bool NewBookingRoom(NewBookingEN aNewBookingEN)
        {
            try
            {
                int IDBookingR = 0;
                int IDCompany = 0;
                int IDCustomerGroup = 0;
                int IDCustomer = 0;

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

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

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

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

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

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

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

                    BookingRs aBookingRs = new BookingRs();

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

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

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

                    }
                }
                #endregion

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private void btnBook_Click(object sender, EventArgs e)
        {
            try
            {
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                if (this.ValidateData() == true)
                {
                    //Truyền dữ liệu BookingH
                    this.aNewBookingHEN.Subject = txtSubject.Text;
                    this.aNewBookingHEN.CreatedDate = dtpFrom.DateTime;
                    this.aNewBookingHEN.CustomerType = this.CustomerType;
                    this.aNewBookingHEN.BookingType = 3;//3 : Đặt trực tiếp
                    if (txtBookingMoney.Text == "")
                    {
                        this.aNewBookingHEN.BookingMoney = 0;
                        this.aNewBookingHEN.StatusPay = 1;//1 : Trạng thái chưa thanh toán
                    }
                    else
                    {
                        this.aNewBookingHEN.BookingMoney = this.aNewBookingHEN.BookingMoney = Convert.ToDecimal(txtBookingMoney.Text);
                        this.aNewBookingHEN.StatusPay = 2;//2 : Trạng thái tạm ứng
                    }

                    this.aNewBookingHEN.Status = 2;//2: Trạng thái đã xác thực

                    this.aNewBookingHEN.PayMenthod = 1;
                    if (cbbType.EditValue.ToString().ToUpper() == "NGOÀI NẤU")
                    {
                        this.aNewBookingHEN.Type = 1;//1: Tiệc KHÔNG thuộc phạm trù bếp
                    }
                    else if (cbbType.EditValue.ToString().ToUpper() == "BẾP NẤU")
                    {
                        this.aNewBookingHEN.Type = 2;//2: Tiệc thuộc phạm trù bếp
                    }

                    this.aNewBookingHEN.Disable = false;
                    this.aNewBookingHEN.Description = "";
                    string CustomerGroupName;
                    if (Convert.ToInt32(lueCompany.EditValue) == 0)
                    {

                        this.IDCompany = this.aCompaniesBO.AutoInsertCompany(txtCompanyName.Text, 3);// 3 : Loại khách lẻ
                        if (lueCustomer.Text == "")
                        {
                            if (txtSubject.Text == "")
                            {
                                CustomerGroupName = "[" + txtCompanyName.Text + "][" + DateTime.Now.ToShortDateString() + "]" + "[" + txtCustomerName.Text + "]";
                            }
                            else
                            {
                                CustomerGroupName = txtSubject.Text;
                            }
                        }
                        else
                        {
                            if (txtSubject.Text == "")
                            {
                                CustomerGroupName = "[" + txtCompanyName.Text + "][" + DateTime.Now.ToShortDateString() + "]" + "[" + lueCustomer.Text + "]";
                            }
                            else
                            {
                                CustomerGroupName = txtSubject.Text;
                            }
                        }
                        this.IDCustomerGroup = this.aCustomerGroupsBO.AutoInsertCustomerGroup(CustomerGroupName, IDCompany);
                    }
                    else
                    {
                        this.IDCompany = Convert.ToInt32(lueCompany.EditValue);
                        if (lueCustomer.Text == "")
                        {
                            if (txtSubject.Text == "")
                            {
                                CustomerGroupName = "[" + txtCompanyName.Text + "][" + DateTime.Now.ToShortDateString() + "]" + "[" + txtCustomerName.Text + "]";
                            }
                            else
                            {
                                CustomerGroupName = txtSubject.Text;
                            }
                        }
                        else
                        {
                            if (txtSubject.Text == "")
                            {
                                CustomerGroupName = "[" + txtCompanyName.Text + "][" + DateTime.Now.ToShortDateString() + "]" + "[" + lueCustomer.Text + "]";
                            }
                            else
                            {
                                CustomerGroupName = txtSubject.Text;
                            }
                        }
                        this.IDCustomerGroup = this.aCustomerGroupsBO.AutoInsertCustomerGroup(CustomerGroupName, Convert.ToInt32(lueCompany.EditValue));
                    }
                    if (Convert.ToInt32(lueCustomer.EditValue) == 0)
                    {
                        this.IDCustomer = this.aCustomersBO.AutoInsertCustomer(txtCustomerName.Text, this.IDCustomerGroup, txtPhoneNumber.Text, DateTime.Now);
                    }
                    else
                    {
                        CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
                        this.IDCustomer = Convert.ToInt32(lueCustomer.EditValue);
                        aCustomerGroups_CustomersBO.AutoInsertCustomerToGroup(IDCustomer, this.IDCustomerGroup, dtpFrom.DateTime);
                    }
                    this.aNewBookingHEN.Disable = false;
                    this.aNewBookingHEN.IDCustomer = this.IDCustomer;
                    this.aNewBookingHEN.IDSystemUser = CORE.CURRENTUSER.SystemUser.ID;
                    this.aNewBookingHEN.IDCustomerGroup = this.IDCustomerGroup;
                    //===============================================================================
                    // Ngoc edit. All BookingR and BookingH join together
                    // Tao them 1 bookingR neu chua co
                    //===============================================================================
                    if (this.IDBookingR == 0)
                    {
                        BookingRsBO aBookingRsBO = new BookingRsBO();
                        BookingRs aBookingRs = new BookingRs();
                        aBookingRs.CreatedDate = this.aNewBookingHEN.CreatedDate;
                        aBookingRs.ID = 0;
                        aBookingRs.CustomerType = this.aNewBookingHEN.CustomerType;
                        aBookingRs.IDCustomer = this.aNewBookingHEN.IDCustomer;
                        aBookingRs.IDCustomerGroup = this.aNewBookingHEN.IDCustomerGroup;
                        aBookingRs.DatePay = Convert.ToDateTime("01/01/1900");
                        aBookingRs.DateEdit = Convert.ToDateTime("01/01/1900");
                        aBookingRs.IDSystemUser = this.aNewBookingHEN.IDSystemUser;
                        aBookingRs.Type = 0;
                        aBookingRs.Status = 0;
                        aBookingRs.Disable = true;
                        aBookingRs.Level = -1;

                        this.IDBookingR = aBookingRsBO.Insert(aBookingRs);
                    }
                    //===============================================================================
                    this.IDBookingH = aReceptionTaskBO.NewBookHall(this.aNewBookingHEN);
                    if (this.IDBookingR != 0)
                    {
                        BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();

                        BookingRs_BookingHs aBookingRs_BookingHs = new BookingRs_BookingHs();
                        aBookingRs_BookingHs.IDBookingR = this.IDBookingR;
                        aBookingRs_BookingHs.IDBookingH = this.IDBookingH;
                        aBookingRs_BookingHs.Type = String.Empty;
                        aBookingRs_BookingHs.Status = String.Empty;
                        aBookingRs_BookingHs.Disable = false;
                        aBookingRs_BookingHs.Extension1 = String.Empty;
                        aBookingRs_BookingHs.Extension2 = String.Empty;
                        aBookingRs_BookingHs.Extension3 = String.Empty;

                        aBookingRs_BookingHsBO.Insert(aBookingRs_BookingHs);
                    }
                    MessageBox.Show("Đặt hội trường thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (afrmMain_Halls != null)
                    {
                        this.afrmMain_Halls.Reload();
                    }
                    if (afrmTsk_Payment_Step2 != null)
                    {
                        this.afrmTsk_Payment_Step2.Reload();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_BookingHall_Customer_New.btnBook_Click\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //----------------Update Customers -----------------------------
        public int Update(BookingRs bookingRs)
        {
            try
            {
                aDatabaseDA.BookingRs.AddOrUpdate(bookingRs);
                return aDatabaseDA.SaveChanges();

            }
            catch (Exception ex)
            {
                return 0;
                throw new Exception("BookingRsBO.Update:" + ex.ToString());

            }
        }
        public frmRpt_GroupPayment_Rs(List<RptPaymentStyle1_ForPrint> aListData,string CompanyName, string Address, string NameCustomerGroup,string InvoiceNumber
            , DateTime FirstDate, DateTime LastDate, decimal? BookingHMoney, decimal? BookingRMoney, int IDBookingR, int Div)
        {
            InitializeComponent();

            this.aListData = aListData;

            if (string.IsNullOrEmpty(Div.ToString()) || Div == 1)
            {
                Div = 1;
                lblTitle.Text = "PHIẾU BÁO THANH TOÁN";
            }
            else
            {
                lblTitle.Text = "PHIẾU BÁO THANH TOÁN (CHIA " + Div + ")";
            }

            for (int i = 0; i < this.aListData.Count; i++)
            {
                this.aListData[i].DrinkMoney = this.aListData[i].DrinkMoney / Div;
                this.aListData[i].Hall_Fee = this.aListData[i].Hall_Fee / Div;
                this.aListData[i].MealMoney = this.aListData[i].MealMoney / Div;
                this.aListData[i].OtherMoney = this.aListData[i].OtherMoney / Div;
                this.aListData[i].Room_Fee = this.aListData[i].Room_Fee / Div;
                this.aListData[i].RoomServiceMoney = this.aListData[i].RoomServiceMoney / Div;

                this.aListData[i].ServiceGroup10_Fee = this.aListData[i].ServiceGroup10_Fee / Div;
                this.aListData[i].ServiceGroup11_Fee = this.aListData[i].ServiceGroup11_Fee / Div;
                this.aListData[i].ServiceGroup12_Fee = this.aListData[i].ServiceGroup12_Fee / Div;
                this.aListData[i].ServiceGroup13_Fee = this.aListData[i].ServiceGroup13_Fee / Div;
                this.aListData[i].ServiceGroup14_Fee = this.aListData[i].ServiceGroup14_Fee / Div;
                this.aListData[i].ServiceGroup15_Fee = this.aListData[i].ServiceGroup15_Fee / Div;
                this.aListData[i].ServiceGroup2_Fee = this.aListData[i].ServiceGroup2_Fee / Div;
                this.aListData[i].ServiceGroup3_Fee = this.aListData[i].ServiceGroup3_Fee / Div;

                this.aListData[i].ServiceGroup4_Fee = this.aListData[i].ServiceGroup4_Fee / Div;
                this.aListData[i].ServiceGroup5_Fee = this.aListData[i].ServiceGroup5_Fee / Div;
                this.aListData[i].ServiceGroup6_Fee = this.aListData[i].ServiceGroup6_Fee / Div;
                this.aListData[i].ServiceGroup7_Fee = this.aListData[i].ServiceGroup7_Fee / Div;
                this.aListData[i].ServiceGroup8_Fee = this.aListData[i].ServiceGroup8_Fee / Div;
                this.aListData[i].ServiceGroup9_Fee = this.aListData[i].ServiceGroup9_Fee / Div;
                this.aListData[i].TotalMoney = this.aListData[i].TotalMoney / Div;
                this.aListData[i].TotalServiceMoney = this.aListData[i].TotalServiceMoney / Div;

                //----------------------------------------------------------------------
                TotalServiceMoney = TotalServiceMoney + this.aListData[i].TotalServiceMoney;
                TotalMoneyBeforeTax = TotalMoneyBeforeTax + this.aListData[i].TotalMoney;
                this.aListData[i].Room_Fee = this.aListData[i].Room_Fee + this.aListData[i].Hall_Fee;
            }

            //Truyền dữ liệu cho Detail
            lblCompanyName.Text = CompanyName;
            lblAddress.Text = Address;
            lblCustomerGroupName.Text = NameCustomerGroup;

            lblCheckIn.Text = FirstDate.ToString("dd-MM-yyyy");
            lblCheckOut.Text = LastDate.ToString("dd-MM-yyyy");

            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();

            this.DetailReport.DataSource = this.aListData;
            colDate.DataBindings.Add("Text", this.DetailReport.DataSource, "Date", "{0:dd-MM}");
            colDescription.DataBindings.Add("Text", this.DetailReport.DataSource, "Note");
            colNumberCus.DataBindings.Add("Text", this.DetailReport.DataSource, "CountCustomerInGroup");
            colMoneyRoom.DataBindings.Add("Text", this.DetailReport.DataSource, "Room_Fee", "{0:0,0}");
            colTotalARoom.DataBindings.Add("Text", this.DetailReport.DataSource, "TotalMoney", "{0:0,0}");
               // colHallMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "Hall_Fee", "{0:0,0}");
            colMealMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "MealMoney", "{0:0,0}");
            colDrinkMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "DrinkMoney", "{0:0,0}");
            colRoomServiceMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "RoomServiceMoney", "{0:0,0}");
            colOtherMoney.DataBindings.Add("Text", this.DetailReport.DataSource, "OtherMoney", "{0:0,0}");

            colMoneyService.Text = TotalServiceMoney.ToString("0,0");
            colMoneyBeforeTax.Text = TotalMoneyBeforeTax.ToString("0,0");
            colMoneyTax.Text = (TotalMoneyBeforeTax * 10 / 100).ToString("0,0");
            colMoneyAfterTax.Text = (TotalMoneyBeforeTax * 110 / 100).ToString("0,0");
            colBookingMoney.Text = Convert.ToDecimal(BookingHMoney.GetValueOrDefault(0) + BookingRMoney.GetValueOrDefault(0)).ToString("0,0");
            colTotalMoneyPay.Text = ((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney.GetValueOrDefault(0) + BookingRMoney.GetValueOrDefault(0))).ToString("0,0");
            string TotalMoney_String = UppercaseFirst(StringUtility.ConvertDecimalToString((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney.GetValueOrDefault(0) + BookingRMoney.GetValueOrDefault(0))));
            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();

            //--------------Tính tổng---------------------------------
            XRSummary aXRSummaryMoney = new XRSummary();
            aXRSummaryMoney.Func = SummaryFunc.Sum;
            aXRSummaryMoney.Running = SummaryRunning.Group;
            aXRSummaryMoney.IgnoreNullValues = true;
            aXRSummaryMoney.FormatString = "{0:0,0}";
            XRBinding aXRBindingMoney = new XRBinding("Text", this.DetailReport.DataSource, "TotalMoney", "{0:0,0}");
            XRBinding[] listXRBindingMoney = new XRBinding[] { aXRBindingMoney };
            colSumTotalMoney.DataBindings.AddRange(listXRBindingMoney);
            colSumTotalMoney.Summary = aXRSummaryMoney;

            XRSummary aXRSumDrinkMoney = new XRSummary();
            aXRSumDrinkMoney.Func = SummaryFunc.Sum;
            aXRSumDrinkMoney.Running = SummaryRunning.Group;
            aXRSumDrinkMoney.IgnoreNullValues = true;
            aXRSumDrinkMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding = new XRBinding("Text", this.DetailReport.DataSource, "DrinkMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding = new XRBinding[] { aXRBinding };
            colSumDrinkMoney.DataBindings.AddRange(aList_aXRBinding);
            colSumDrinkMoney.Summary = aXRSumDrinkMoney;

            //XRSummary aXRSumHallMoney = new XRSummary();
            //aXRSumHallMoney.Func = SummaryFunc.Sum;
            //aXRSumHallMoney.Running = SummaryRunning.Group;
            //aXRSumHallMoney.IgnoreNullValues = true;
            //aXRSumHallMoney.FormatString = "{0:0,0}";
            //XRBinding aXRBinding1 = new XRBinding("Text", this.DetailReport.DataSource, "Hall_Fee", "{0:0,0}");
            //XRBinding[] aList_aXRBinding1 = new XRBinding[] { aXRBinding1 };
            //colSumHallMoney.DataBindings.AddRange(aList_aXRBinding1);
            //colSumHallMoney.Summary = aXRSumHallMoney;

            XRSummary aXRSumMealMoney = new XRSummary();
            aXRSumMealMoney.Func = SummaryFunc.Sum;
            aXRSumMealMoney.Running = SummaryRunning.Group;
            aXRSumMealMoney.IgnoreNullValues = true;
            aXRSumMealMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding2 = new XRBinding("Text", this.DetailReport.DataSource, "MealMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding2 = new XRBinding[] { aXRBinding2 };
            colSumMealMoney.DataBindings.AddRange(aList_aXRBinding2);
            colSumMealMoney.Summary = aXRSumMealMoney;

            XRSummary aXRSumMoneyRoom = new XRSummary();
            aXRSumMoneyRoom.Func = SummaryFunc.Sum;
            aXRSumMoneyRoom.Running = SummaryRunning.Group;
            aXRSumMoneyRoom.IgnoreNullValues = true;
            aXRSumMoneyRoom.FormatString = "{0:0,0}";
            XRBinding aXRBinding3 = new XRBinding("Text", this.DetailReport.DataSource, "Room_Fee", "{0:0,0}");
            XRBinding[] aList_aXRBinding3 = new XRBinding[] { aXRBinding3 };
            colSumMoneyRoom.DataBindings.AddRange(aList_aXRBinding3);
            colSumMoneyRoom.Summary = aXRSumMoneyRoom;

            XRSummary aXRSumOtherMoney = new XRSummary();
            aXRSumOtherMoney.Func = SummaryFunc.Sum;
            aXRSumOtherMoney.Running = SummaryRunning.Group;
            aXRSumOtherMoney.IgnoreNullValues = true;
            aXRSumOtherMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding4 = new XRBinding("Text", this.DetailReport.DataSource, "OtherMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding4 = new XRBinding[] { aXRBinding4 };
            colSumOtherMoney.DataBindings.AddRange(aList_aXRBinding4);
            colSumOtherMoney.Summary = aXRSumOtherMoney;

            XRSummary aXRSumRoomServiceMoney = new XRSummary();
            aXRSumRoomServiceMoney.Func = SummaryFunc.Sum;
            aXRSumRoomServiceMoney.Running = SummaryRunning.Group;
            aXRSumRoomServiceMoney.IgnoreNullValues = true;
            aXRSumRoomServiceMoney.FormatString = "{0:0,0}";
            XRBinding aXRBinding5 = new XRBinding("Text", this.DetailReport.DataSource, "RoomServiceMoney", "{0:0,0}");
            XRBinding[] aList_aXRBinding5 = new XRBinding[] { aXRBinding5 };
            colSumRoomServiceMoney.DataBindings.AddRange(aList_aXRBinding5);
            colSumRoomServiceMoney.Summary = aXRSumRoomServiceMoney;
        }
        private void lueIDCompanies_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (lueIDCompanies.EditValue == null)
                {
                    MessageBox.Show("Vui lòng chọn tên công ty.");
                    lueIDCompanies.Focus();
                    return;
                }
                BookingRsBO abookingRsBO = new BookingRsBO();
                BookingRs abookingRs = new BookingRs();
                List<PaymentExt_GetAllDataEN> aListPaymentExt_GetAllDataEN = new List<PaymentExt_GetAllDataEN>();
                int IDCompany = Convert.ToInt32(lueIDCompanies.EditValue.ToString());

                CustomerGroupsBO aCustomerGroupBO = new CustomerGroupsBO();
                List<int> aListIDCustomerGroup = aCustomerGroupBO.Select_All().Where(x => x.IDCompany == IDCompany).Select(p => p.ID).ToList();

                List<int> ListIDBookingR = abookingRsBO.Select_ByListCustomerGroup(aListIDCustomerGroup).Select(p => p.ID).ToList();

                PaymentBO aPaymentBO = new PaymentBO();
                List<sp_PaymentExt_GetAllData_Result> aListTemp = aPaymentBO.Search_ServicesStatus_ObjectStatus_BillRPaymentStatusByCompany(ListIDBookingR);
                PaymentExt_GetAllDataEN aPaymentExt_GetAllDataEN;

                foreach (sp_PaymentExt_GetAllData_Result item in aListTemp)
                {
                    BookingRooms aBookingRoom = aBookingRoomBO.Select_ByIDBookingR(item.BookingRs_ID);

                    decimal? cost = aBookingRoom.Cost;
                    if (cost == null)
                    {
                        cost = 0;
                    }
                    double? addTimeStart = aBookingRoom.AddTimeStart;
                    if (addTimeStart == null)
                    {
                        addTimeStart = 0;
                    }
                    double? addTimeEnd = aBookingRoom.AddTimeEnd;
                    if (addTimeEnd == null)
                    {
                        addTimeEnd = 0;
                    }

                    decimal? timeUser = aBookingRoom.TimeInUse;
                    if (timeUser == null)
                    {
                        timeUser = 0;
                    }
                    double? costPendingRoom = aBookingRoom.CostPendingRoom;
                    if (costPendingRoom == null)
                    {
                        costPendingRoom = 0;
                    }
                    double? tax = aBookingRoom.PercentTax;
                    if (tax == null)
                    {
                        tax = 0;
                    }
                    decimal? sum = CalculatorMoneyRoom(cost, addTimeStart, addTimeEnd, timeUser);

                    // Tinh pending
                    aPaymentExt_GetAllDataEN = new PaymentExt_GetAllDataEN();
                    aPaymentExt_GetAllDataEN.SetValue(item);
                    if (item.IDService == null)
                    {
                        aPaymentExt_GetAllDataEN.DisplayService_PaymentStatus = "";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayService_PaymentStatus = "Đã thanh toán";
                    }
                    if (item.BillR_PaymentStatus == 8)
                    {
                        aPaymentExt_GetAllDataEN.DisplayBillR_PaymentStatus = "Đã thanh toán";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayBillR_PaymentStatus = "Chưa thanh toán";
                    }
                    if (item.Object_PaymentStatus == 8)
                    {
                        aPaymentExt_GetAllDataEN.DisplayObject_PaymentStatus = "Đã thanh toán";
                    }
                    else
                    {
                        aPaymentExt_GetAllDataEN.DisplayObject_PaymentStatus = "Chưa thanh toán";

                    }

                    aPaymentExt_GetAllDataEN.DisplayMoneySumRoom = sum;
                    aListPaymentExt_GetAllDataEN.Add(aPaymentExt_GetAllDataEN);
                }
                dgvPaymentViewUnPay.DataSource = aListPaymentExt_GetAllDataEN;
                dgvPaymentViewUnPay.RefreshDataSource();

            }
            catch (Exception ex)
            {
                throw new Exception("frmTsk_UnPay " + ex.ToString());
            }
        }