// Author : Linhting
        public void InitData( int IDBookingH)
        {
            try
            {
                CompaniesBO aCompaniesBO = new CompaniesBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                SystemUsersBO aSystemUsersBO = new SystemUsersBO();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                HallsBO aHallsBO = new HallsBO();
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                FoodsBO aFoodsBO = new FoodsBO();

                BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);

                    // Truyen du lieu cho List BookingRoom cua NewPayment

                    if (aBookingHs != null)
                    {
                         aNewPaymentEN.IDCustomer = aBookingHs.IDCustomer;
                    Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                    if (aCustomers != null)
                    {
                        aNewPaymentEN.NameCustomer = aCustomers.Name;
                    }
                    aNewPaymentEN.IDSystemUser = aBookingHs.IDSystemUser;
                    SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                    if (aSystemUsers != null)
                    {
                        aNewPaymentEN.NameSystemUser = aSystemUsers.Name;
                    }
                    aNewPaymentEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                    CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.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.IDBookingH = aBookingHs.ID;
                        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);

                                List<ServiceUsedEN> aListServiceTemp = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(item.ID);
                                foreach (ServiceUsedEN aTemp in aListServiceTemp)
                                {
                                    aBookingHallUsedEN.aListServiceUsed.Add(aTemp);
                                }
                                aNewPaymentEN.aListBookingHallUsed.Add(aBookingHallUsedEN);
                            }
                        }
                    }

                }

            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PaymentHall.InitData\n" + ex.ToString());
            }
        }
        //hiennv
        public void InitData(PaymentHallsEN aPaymentHallsEN, int IDBookingH)
        {
            try
            {
                HallsBO aHallsBO = new HallsBO();
                BookingHallsBO aBookingHallsBO = new BookingHallsBO();
                FoodsBO aFoodsBO = new FoodsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CompaniesBO aCompaniesBO = new CompaniesBO();
                SystemUsersBO aSystemUsersBO = new SystemUsersBO();

                BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);
                if (aBookingHs != null)
                {
                    aPaymentHallsEN.IDBookingH = aBookingHs.ID;
                    aPaymentHallsEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                    CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.IDCustomerGroup);
                    if (aCustomerGroups != null)
                    {
                        aPaymentHallsEN.NameCustomerGroup = aCustomerGroups.Name;
                        aPaymentHallsEN.IDCompany = aCustomerGroups.IDCompany;
                        Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                        if (aCompanies != null)
                        {
                            aPaymentHallsEN.NameCompany = aCompanies.Name;
                            aPaymentHallsEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        }
                    }
                    aPaymentHallsEN.IDCustomer = aBookingHs.IDCustomer;
                    Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                    if (aCustomers != null)
                    {
                        aPaymentHallsEN.NameCustomer = aCustomers.Name;

                    }
                    aPaymentHallsEN.IDSystemUser = aBookingHs.IDSystemUser;
                    SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                    if (aSystemUsers != null)
                    {
                        aPaymentHallsEN.NameSystemUser = aSystemUsers.Name;
                    }
                    aPaymentHallsEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                    aPaymentHallsEN.CustomerType = aBookingHs.CustomerType;
                    aPaymentHallsEN.BookingType = aBookingHs.BookingType;
                    aPaymentHallsEN.PayMenthod = aBookingHs.PayMenthod;
                    aPaymentHallsEN.StatusPay = aBookingHs.StatusPay;
                    aPaymentHallsEN.Status_BookingH = aBookingHs.Status;
                    aPaymentHallsEN.ExchangeRate = aBookingHs.ExchangeRate;
                    aPaymentHallsEN.Level = aBookingHs.Level;
                    aPaymentHallsEN.BookingMoney = aBookingHs.BookingMoney;
                }

                List<BookingHalls> aListBookingHalls = new List<BookingHalls>();
                aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(IDBookingH);
                InfoDetailPaymentHallsEN aInfoDetailPaymentHallsEN;
                for (int i = 0; i < aListBookingHalls.Count; i++)
                {
                    aInfoDetailPaymentHallsEN = new InfoDetailPaymentHallsEN();
                    Halls aHalls = aHallsBO.Select_ByCodeHall(aListBookingHalls[i].CodeHall, 1);
                    if (aHalls != null)
                    {
                        aInfoDetailPaymentHallsEN.Sku = aHalls.Sku;
                    }
                    else
                    {
                        aInfoDetailPaymentHallsEN.Sku = string.Empty;
                    }
                    aInfoDetailPaymentHallsEN.aBookingHalls = aListBookingHalls[i];
                    aInfoDetailPaymentHallsEN.aMenusEN = aReceptionTaskBO.GetDetailMenu_ByIDBookingHall(aListBookingHalls[i].ID);
                    aInfoDetailPaymentHallsEN.aListServicesHallsEN = aReceptionTaskBO.GetListServicesHallsEN_ByIDBookingHall(aListBookingHalls[i].ID);

                    aPaymentHallsEN.aListInfoDetailPaymentHallsEN.Insert(i, aInfoDetailPaymentHallsEN);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PaymentHall.InitData\n" + ex.ToString());
            }
        }
        // Author : Linhting
        public void LoadCustomerInfo()
        {
            try
            {
                BookingHsBO aBookingHsBO = new BookingHsBO();
                CustomersBO aCustomersBO = new CustomersBO();
                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CompaniesBO aCompaniesBO = new CompaniesBO();
                int IDCustomer = aBookingHsBO.Select_ByID(this.IDBookingH).IDCustomer;
                int IDCustomerGroup = aBookingHsBO.Select_ByID(this.IDBookingH).IDCustomerGroup;

                lblCompany.Text = aCompaniesBO.Select_ByIDCustomerGroup(IDCustomerGroup).Name;
                lblNameCustomerGroup.Text = aCustomerGroupsBO.Select_ByID(IDCustomerGroup).Name;
                lblNameCustomer.Text = aCustomersBO.Select_ByID(IDCustomer).Name;
            }
            catch (Exception ex)
            {

                MessageBox.Show("frmTsk_PaymentHall.LoadCustomerInfo\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public int InsertCustomerIntoCustomerGroup(int IDCustomer, int IDCustomerGroup)
        {
            // Add customer vao group
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = new CustomerGroups();
            aCustomerGroups = aCustomerGroupsBO.Select_ByID(IDCustomerGroup);

            CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO();
            CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers();

            aCustomerGroups_Customers = aCustomerGroups_CustomersBO.Select_ByIDCustomer_ByIDCustomerGroup(IDCustomer, IDCustomerGroup);
            if (aCustomerGroups_Customers == null)
            {
                Customers aCustomers = (new CustomersBO()).Select_ByID(IDCustomer);
                aCustomerGroups_Customers.IDCustomer = IDCustomer;
                aCustomerGroups_Customers.IDCustomerGroup = aCustomerGroups.ID;
                aCustomerGroups_Customers.Name = aCustomerGroups.Name + "_" + aCustomers.Name + "_" + aCustomers.Identifier1 + "_" + DateTime.Now.ToShortDateString();
                return aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers);
            }
            else
                return 0;
        }
        public void InitData(int IDBookingH)
        {
            CompaniesBO aCompaniesBO = new CompaniesBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            HallsBO aHallsBO = new HallsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            FoodsBO aFoodsBO = new FoodsBO();
            List<int> aListIndexTemp = new List<int>();

            BookingHs aBookingHs = aBookingHsBO.Select_ByID(IDBookingH);
            if (aBookingHs != null)
            {
                aNewPaymentHEN.IDCustomer = aBookingHs.IDCustomer;
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingHs.IDCustomer);
                if (aCustomers != null)
                {
                    aNewPaymentHEN.NameCustomer = aCustomers.Name;
                }
                aNewPaymentHEN.IDSystemUser = aBookingHs.IDSystemUser;
                SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingHs.IDSystemUser);
                if (aSystemUsers != null)
                {
                    aNewPaymentHEN.NameSystemUser = aSystemUsers.Name;
                }
                aNewPaymentHEN.IDCustomerGroup = aBookingHs.IDCustomerGroup;
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingHs.IDCustomerGroup);
                if (aCustomerGroups != null)
                {
                    aNewPaymentHEN.NameCustomerGroup = aCustomerGroups.Name;
                    aNewPaymentHEN.IDCompany = aCustomerGroups.IDCompany;
                    Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                    if (aCompanies != null)
                    {
                        aNewPaymentHEN.NameCompany = aCompanies.Name;
                        aNewPaymentHEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        aNewPaymentHEN.AddressCompany = aCompanies.Address;
                    }
                }
                aNewPaymentHEN.Subject = aBookingHs.Subject;
                aNewPaymentHEN.PayMenthodH = aBookingHs.PayMenthod;
                aNewPaymentHEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                aNewPaymentHEN.CustomerType = aBookingHs.CustomerType;
                aNewPaymentHEN.Status_BookingH = aBookingHs.Status;
                aNewPaymentHEN.StatusPay = aBookingHs.StatusPay;
                aNewPaymentHEN.BookingHMoney = aBookingHs.BookingMoney;
                aNewPaymentHEN.AcceptDate = aBookingHs.AcceptDate;
                aNewPaymentHEN.InvoiceDate = aBookingHs.InvoiceDate;
                aNewPaymentHEN.InvoiceNumber = aBookingHs.InvoiceNumber;
                this.aNewPaymentHEN.IDBookingH = aBookingHs.ID;
                this.aNewPaymentHEN.PayMenthodH = aBookingHs.PayMenthod;
                this.aNewPaymentHEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                this.aNewPaymentHEN.CustomerType = aBookingHs.CustomerType;
                this.aNewPaymentHEN.Status_BookingH = aBookingHs.Status;
                this.aNewPaymentHEN.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));
                        }
                        aNewPaymentHEN.aListBookingHallUsed.Add(aBookingHallUsedEN);

                    }
                }
            }
            aNewPaymentHEN.ListIndex = aListIndexTemp.Distinct().ToList();
        }
        private void frmTsk_PendingCheckIn_Step2_Load(object sender, EventArgs e)
        {
            try
            {
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                lblIDBookingR.Text = aBookingRs.ID.ToString();

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

                CompaniesBO aCompaniesBO = new CompaniesBO();
                Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                lblNameCompany.Text = aCompanies.Name;

                CustomersBO aCustomersBO = new CustomersBO();
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                lblNameCustomer.Text = aCustomers.Name;

                RoomsBO aRoomsBO = new RoomsBO();
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(CodeRoom, 1);//1=IDLang
                lblSku.Text = aRooms.Sku;

                dtpTo.DateTime = CheckOutPlan;
                dtpFrom.DateTime = DateTime.Now;
                dtpFrom.Enabled = false;
                dtpFrom.Properties.ReadOnly = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.frmTsk_PendingCheckIn_Step2_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // ===============================================================================
        // 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 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);
            }
        }
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
     int ID = int.Parse(viewAvailableCustomerGroups.GetFocusedRowCellValue("ID").ToString());
     string Name = aCustomerGroupsBO.Select_ByID(ID).Name;
     DialogResult result = MessageBox.Show("Bạn có muốn xóa nhóm khách hàng " + Name + " này không?", "Xóa nhóm khách hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (result == DialogResult.Yes)
     {
         aCustomerGroupsBO.Delete_ByID(ID);
         MessageBox.Show("Xóa thành công");
         this.ReloadData();
     }
 }
        //hiennv
        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.aCheckInRoomBookingEN.aListRoomMembers.Count > 0)
                {
                    BookingRsBO aBookingRsBO = new BookingRsBO();
                    BookingRs aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                    if (aBookingRs !=null)
                    {
                        this.aCheckInRoomBookingEN.IDCustomer = aBookingRs.IDCustomer;
                        this.aCheckInRoomBookingEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                        this.aCheckInRoomBookingEN.Subject = aBookingRs.Subject;
                        this.aCheckInRoomBookingEN.Level = aBookingRs.Level;
                        this.aCheckInRoomBookingEN.Description = aBookingRs.Description;
                        this.aCheckInRoomBookingEN.Note = aBookingRs.Note;

                        CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                        CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                        if (aCustomerGroups !=null)
                        {
                            this.aCheckInRoomBookingEN.IDCompany = aCustomerGroups.IDCompany;
                        }

                    }

                    this.aCheckInRoomBookingEN.IDBookingR = this.IDBookingRs;
                    this.aCheckInRoomBookingEN.CheckInActual = dtpFrom.DateTime;
                    this.aCheckInRoomBookingEN.CheckOutActual = dtpTo.DateTime;
                    this.aCheckInRoomBookingEN.CheckOutPlan = dtpTo.DateTime;

                    frmTsk_CheckInGoverment_ForRoomBooking_Step2 afrmTsk_CheckInGoverment_ForRoomBooking_Step2 = new frmTsk_CheckInGoverment_ForRoomBooking_Step2(this, this.aCheckInRoomBookingEN);
                    afrmTsk_CheckInGoverment_ForRoomBooking_Step2.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn phòng trước khi thực hiện bước tiếp theo !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckInGoverment_ForRoomBooking_Step1.btnNext_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
            }
        }
        private void ResetFormWhenTimeChange()
        {
            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

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

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

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

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

            // Fill All Customer

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

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

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

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

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

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);
        }
        private void InitForm()
        {
            // Kiem tra xem phong dang o che do checkIn hay book phong
            if (this.aBookingRoom.Status < 3)
            {
                dtpCheckIn.Text = aBookingRoom.CheckInPlan.ToString();

                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }
            else if (this.aBookingRoom.Status == 3)  // Phong da checkIn
            {
                dtpCheckIn.Text = DateTime.Now.ToString();
                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }

            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

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

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

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

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

            // Fill All Customer

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

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

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

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

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

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);

            //this.aChangeRoomEn.InsertItemChangeRooms()
        }
        //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;
            }
        }