private void btnCheckIn_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (ValidateData() == true)
                {
                    ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                    //Add du lieu cho BookingH
                    BookingHs aBookingHs = new BookingHs();
                    aBookingHs.Subject = txtSubject.Text;
                    aBookingHs.CreatedDate = DateTime.Now;
                    aBookingHs.CustomerType = 2;
                    aBookingHs.BookingType = Convert.ToInt32(lueBookingType.EditValue);
                    aBookingHs.Note = txtNote.Text;
                    aBookingHs.IDGuest = Convert.ToInt32(lueGuest.EditValue);
                    if (txtBookingMoney.Text == "")
                    {
                        aBookingHs.BookingMoney = 0;
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(1).ID;
                    }
                    else
                    {
                        aBookingHs.BookingMoney = Convert.ToDecimal(txtBookingMoney.Text);
                        lueStatusPay.EditValue = CORE.CONSTANTS.SelectedStatusPay(2).ID;
                    }
                    aBookingHs.StatusPay = Convert.ToInt32(lueStatusPay.EditValue);
                    aBookingHs.Status = Convert.ToInt32(lueBookingStatus.EditValue);
                    aBookingHs.PayMenthod = 1;
                    if (cbbType.Text == "Tiệc không thuộc phạm trù nhà bếp")
                    {
                        aBookingHs.Type = 1;
                    }
                    else
                    {
                        aBookingHs.Type = 2;
                    }
                    aBookingHs.Disable = false;
                    aBookingHs.Description = "";
                    aBookingHs.IDCustomer = Convert.ToInt32(lueCustomer.EditValue);
                    aBookingHs.IDCustomerGroup = Convert.ToInt32(lueCustomerGroup.EditValue);
                    aBookingHs.IDSystemUser = CORE.CURRENTUSER.SystemUser.ID;

                    //Add du lieu cho BookingHall
                    List<BookingHalls> aListBookingHall = new List<BookingHalls>();
                    BookingHalls aTemp;
                    for (int i = 0; i < aListSelected.Count; i++)
                    {
                        aTemp = new BookingHalls();
                        aTemp.CodeHall = aListSelected[i].Code;
                        aTemp.Cost = aListSelected[i].Cost;
                        aTemp.PercentTax = 10;
                        aTemp.CostRef_Halls = aListSelected[i].CostRef;
                        aTemp.Date = DateTime.Now;
                        IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
                        DateTime Lunardate = DateTime.ParseExact(Convert.ToString(LunarDateExt.ToLunarDate(DateTime.Now, 7)), "d/M/yyyy", theCultureInfo);
                        aTemp.LunarDate = Lunardate;
                        aTemp.BookingStatus = null;
                        aTemp.Unit = aListSelected[i].Unit;
                        aTemp.TableOrPerson = aListSelected[i].TableOrPerson;
                        aTemp.Note = "";
                        aTemp.Status = Convert.ToInt32(lueBookingStatus.EditValue);
                        aTemp.StartTime = !string.IsNullOrEmpty(tedStart.Time.ToString()) ? tedStart.Time.TimeOfDay : TimeSpan.Zero;
                        aTemp.EndTime = !string.IsNullOrEmpty(tedEnd.Time.ToString()) ? tedEnd.Time.TimeOfDay : TimeSpan.Zero;

                        aListBookingHall.Add(aTemp);
                    }
                    this.IDBookingH = aReceptionTaskBO.CheckIn(aBookingHs, aListBookingHall);

                    //Hiennv
                    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);
                    DialogResult result = MessageBox.Show("Bạn có thêm dịch vụ cho hội trường " + aBookingHs.Subject + " này không?", "Thêm dịch vụ hội trường", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        //frmTsk_Payment_Step2 afrmTsk_Payment_Step2 = new frmTsk_Payment_Step2(Convert.ToInt32(this.IDBookingR), Convert.ToInt32(this.IDBookingH));
                        //afrmTsk_Payment_Step2.ShowDialog();
                    }
                    if (afrmMain_Halls != null)
                    {
                        this.afrmMain_Halls.ReloadData();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_BookingHall_Group.CheckIn\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
            }
        }
        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 btnPaymentInfo_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            int IDBookingR = Convert.ToInt32(grvPaymentViewAll.GetFocusedRowCellValue("BookingRs_ID"));
            string ObjectType = grvPaymentViewAll.GetFocusedRowCellValue("ObjectType").ToString();
            bool IsFocusTab1 = true;
            if (ObjectType == "Phòng")
            {
                IsFocusTab1 = true;
            }
            else
            {
                IsFocusTab1 = false;
            }

            BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
            int IDBookingH = 0;
            if (aBookingRs_BookingHsBO.Select_ByIDBookingR(IDBookingR) == null)
            {
                IDBookingH = 0;
            }
            else
            {
                IDBookingH = Convert.ToInt32(aBookingRs_BookingHsBO.Select_ByIDBookingR(IDBookingR).IDBookingH);
            }

            List<int?> ListStatus = aListPaymentExt_GetAllDataEN.Where(p => p.BookingRs_ID == IDBookingR).Select(p => p.BillR_PaymentStatus).ToList();

            frmTsk_Payment_Step2 afrmTsk_Payment_Step2 = new frmTsk_Payment_Step2(this, IDBookingR, IDBookingH, ListStatus[0].GetValueOrDefault(0), IsFocusTab1);
            afrmTsk_Payment_Step2.ShowDialog();
        }
        private void btnDetailRooms_Click(object sender, EventArgs e)
        {
            try
            {
                BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
                BookingRs_BookingHs aBookingRs_BookingHs = aBookingRs_BookingHsBO.Select_ByIDBookingR(Convert.ToInt32(this.Datasource.BookingRs_ID));
                int IDBookingH = 0;
                if(aBookingRs_BookingHs !=null)
                {
                    IDBookingH = Convert.ToInt32(aBookingRs_BookingHs.IDBookingH);
                }
                frmTsk_Payment_Step2 afrmTsk_Payment_Step2 = new frmTsk_Payment_Step2(this.afrmMain,Convert.ToInt32(this.Datasource.BookingRs_ID),IDBookingH,3,true);
                afrmTsk_Payment_Step2.ShowDialog();
                this.Parent.Dispose();

            }
            catch (Exception ex)
            {
                MessageBox.Show("uc_Tooltip_StatusRoom_3.btnDetailRooms_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDetailBooking_Click(object sender, EventArgs e)
        {
            int BookingRs_ID = Convert.ToInt32(grvBookingRoom.GetFocusedRowCellValue("BookingRs_ID").ToString());

            BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
            BookingRs_BookingHs aBookingRs_BookingHs = aBookingRs_BookingHsBO.Select_ByIDBookingR(Convert.ToInt32(BookingRs_ID));
            int IDBookingH = 0;

            if (aBookingRs_BookingHs != null)
            {
                IDBookingH = Convert.ToInt32(aBookingRs_BookingHs.IDBookingH);
            }
            frmTsk_Payment_Step2 afrmTsk_Payment_Step2 = new frmTsk_Payment_Step2(this, Convert.ToInt32(BookingRs_ID), IDBookingH, 3, true);
            afrmTsk_Payment_Step2.ShowDialog();
        }
        public void LoadServiceInBookingHall(int IDBookingHall)
        {
            try
            {
                ServicesBO aServicesBO = new ServicesBO();
                BookingHalls_ServicesBO aBookingHalls_ServicesBO = new BookingHalls_ServicesBO();
                List<BookingHalls_Services> aListTemp = aBookingHalls_ServicesBO.Select_ByIDBookingHall(IDBookingHall);
                BookingHall_ServiceEN aBookingHall_ServiceEN;
                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aBookingHall_ServiceEN = new BookingHall_ServiceEN();
                    aBookingHall_ServiceEN.ID = aListTemp[i].ID;
                    aBookingHall_ServiceEN.Info = aListTemp[i].Info;
                    aBookingHall_ServiceEN.Type = aListTemp[i].Type;
                    aBookingHall_ServiceEN.Status = aListTemp[i].Status;
                    aBookingHall_ServiceEN.Disable = aListTemp[i].Disable;
                    aBookingHall_ServiceEN.IDBookingHall = aListTemp[i].IDBookingHall;
                    aBookingHall_ServiceEN.IDService = aListTemp[i].IDService;
                    aBookingHall_ServiceEN.Service_Name = aServicesBO.Select_ByID(aListTemp[i].IDService).Name;
                    aBookingHall_ServiceEN.Service_Unit = aServicesBO.Select_ByID(aListTemp[i].IDService).Unit;

                    aBookingHall_ServiceEN.Cost = aListTemp[i].Cost == null ? aListTemp[i].CostRef_Services : aListTemp[i].Cost;
                    aBookingHall_ServiceEN.CostRef_Services = aListTemp[i].CostRef_Services;
                    aBookingHall_ServiceEN.Date = aListTemp[i].Date;
                    aBookingHall_ServiceEN.PercentTax = aListTemp[i].PercentTax;
                    aBookingHall_ServiceEN.Quantity = aListTemp[i].Quantity;

                    aBookingHall_ServiceEN.Tag = aListTemp[i].Tag;

                    aListSelected.Add(aBookingHall_ServiceEN);
                }
                dgvServiceInHall.DataSource = aListSelected;
                dgvServiceInHall.RefreshDataSource();

                CustomersBO aCustomersBO = new CustomersBO();
                BookingRs_BookingHsBO aBookingRs_BookingHsBO = new BookingRs_BookingHsBO();
                List<Customers> aListCustomerRoom = new List<Customers>();
                List<Customers> aListCustomerHall = aCustomersBO.SelectListCustomer_ByIDBookingH(this.IDBookingHall);
                if (this.aNewPayment != null)
                {
                    if (this.aNewPayment.IDBookingR > 0)
                    {
                       aListCustomerRoom = aCustomersBO.SelectListCustomer_ByIDBookingR(this.aNewPayment.IDBookingR.GetValueOrDefault(0));
                    }
                }
                aListCustomerHall.AddRange(aListCustomerRoom);
                lueUserInHall.DataSource = aListCustomerHall;
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_BookingHalls_Services.grvHalls_RowClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }