//Hiennv
        private void frmUpd_ExtraCostRooms_Load(object sender, EventArgs e)
        {
            try
            {
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                ExtraCosts aExtraCosts = new ExtraCosts();
                aExtraCosts = aExtraCostBO.Select_ByID(this.ID);
                txtSku.EditValue = aExtraCosts.Sku;

                lueCustomerType.Properties.DataSource = CORE.CONSTANTS.ListCustomerTypes;
                lueCustomerType.Properties.DisplayMember = "Name";
                lueCustomerType.Properties.ValueMember = "ID";

               lueCustomerType.EditValue = aExtraCosts.CustomerType;

               cbbPriceType.EditValue = aExtraCosts.PriceType;
               txtNumberPepole.EditValue = aExtraCosts.NumberPeople;
               txtExtraCost.EditValue = aExtraCosts.ExtraValue;

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

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

                decimal? CostRoom = 0;

                CostRoom = aRoomsBO.Select_ByIDBookingRoom(IDBookingRoom).CostRef;

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

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

            }
            else
            {
                return 0;
            }
        }
        //Hiennv
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                ExtraCosts aExtraCosts = new ExtraCosts();
                aExtraCosts.ID = this.ID;
                aExtraCosts.Sku = txtSku.Text;
                aExtraCosts.CustomerType = lueCustomerType.EditValue.ToString();
                aExtraCosts.NumberPeople = Convert.ToInt32(txtNumberPepole.EditValue);
                aExtraCosts.ExtraValue = Convert.ToDecimal(txtExtraCost.EditValue);
                aExtraCosts.PriceType = cbbPriceType.Text;
                aExtraCostBO.Update(aExtraCosts);

                if (this.afrmLst_ExtraCostRooms != null)
                {
                    this.afrmLst_ExtraCostRooms.LoadExtraCostRooms();
                }
                this.Close();
                MessageBox.Show("Thực hiện thành công .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmUpd_ExtraCostRooms.btnSave_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //Hiennv
 public void LoadExtraCostRooms()
 {
     try
     {
         ExtraCostBO aExtraCostBO = new ExtraCostBO();
         dgvExtraCostRooms.DataSource = aExtraCostBO.Select_All();
         dgvExtraCostRooms.RefreshDataSource();
     }
     catch (Exception ex)
     {
         MessageBox.Show("frmLst_ExtraCostRooms.LoadExtraCostRooms\n" + ex.ToString(),"Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        //Hiennv
        private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                DialogResult result = MessageBox.Show("Bạn có muốn xóa ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    int ID = Convert.ToInt32(viewExtraCostRooms.GetFocusedRowCellValue("ID"));
                    aExtraCostBO.Delete(ID);
                    this.LoadExtraCostRooms();
                    MessageBox.Show("Xóa thành công ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmLst_ExtraCostRooms.btnDelete_ButtonClick\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 decimal? CalculateCostRoom(string CodeRoom, string PriceType, int CustomerType, int NumCustomer)
        {
            if (NumCustomer > 0)
            {
                CustomersBO aCustomersBO = new CustomersBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                RoomsBO aRoomsBO = new RoomsBO();
                //List<Customers> aListCustomers = aCustomersBO.SelectListCustomer_ByIDBookingRoom(IDBookingRoom);

                decimal? CostRoom = 0;

                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(CodeRoom, 1);
                CostRoom = aRooms.CostRef;
                string RoomSku = aRooms.Sku;

                decimal ExtraMoneyRoom = Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(RoomSku, PriceType, NumCustomer).ExtraValue);

                return (CostRoom + ExtraMoneyRoom);
            }
            else
            {
                return 0;
            }
        }
        public void CheckOut(int IDBookingRoom)
        {
            try
            {
                RoomsBO aRoomsBO = new RoomsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

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

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

                throw new Exception("AccountancyBO.CheckOut\n" + ex.ToString());
            }
        }