using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.SqlClient;
using System.Text;
using System.Windows.Forms;

namespace RezerveBeliteHavaPeimaCS
{
    public partial class frmRptReserves : Form
    {
        public frmRptReserves()
        {
            InitializeComponent();
        }
        /// <summary>
        /// تابع مربوط به فیلتر فرم رزرو
        /// </summary>    
        private void Btn__FilterRezerve_Click(object sender, EventArgs e)
        {
            UDF_FilterStaff();
            this.reportViewer1.RefreshReport();
        }
        /// <summary>
        /// نابع مربوط به فیلتر لیست رزروی
        /// </summary>
        private void UDF_FilterStaff()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            try
            {
                var Query = from Row in db.tblRezerveTickets
                            where int.Parse(Cmb_FilterRezerve.SelectedValue.ToString()) == Row.RezerveID
                            select new
                            {
                                Row.RezerveID,
                                Row.RezerveDate,
                                Row.QuanTity,
                                Row.tblCustumer.NameSname,
                                Row.tblServicesDef.ServiceDescript,
                                Row.BianehPardakhti,
                                Row.Mandeh
                            };

                XtblReservBindingSource.DataSource = Query;
            }
            catch
            {
                MessageBox.Show("لطفا فیلدی برای فیلتر کردن انتخاب نمایید");
            }
        }
        /// <summary>
        /// تابع مربوط به به روزرسانی لیست رزروی
        /// </summary>
        private void UDf_RefreshRezerve()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblRezerveTickets
                        orderby row.RezerveID descending
                        select new
                        {
                            row.RezerveID,
                            row.RezerveDate,
                            row.QuanTity,
                            row.tblCustumer.NameSname,
                            row.tblServicesDef.ServiceDescript,
                            row.BianehPardakhti,
                            row.Mandeh
                        };
            XtblReservBindingSource.DataSource = Query;
            this.reportViewer1.RefreshReport();
        }
        /// <summary>
        /// تابع پر کردن کاموباکس تاریخ
        /// </summary>
        private void UDF_FillComDate()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from Row in db.tblRezerveTickets
                        orderby Row.RezerveID descending
                        select new
                        {
                            Row.RezerveDate,
                            Row.RezerveID
                        };
            Cmb_FilterRezerve.DisplayMember = "RezerveDate";
            Cmb_FilterRezerve.ValueMember = "RezerveID";
            Cmb_FilterRezerve.DataSource = Query;
        }
        private void frmRptReserves_Load(object sender, EventArgs e)
        {
            LSC_TADataContext db = new LSC_TADataContext();
            UDF_FillComDate();
            var Query = from row in db.tblRezerveTickets
                        orderby row.RezerveID descending
                        select new
                        {
                            row.RezerveID,
                            row.RezerveDate,
                            row.QuanTity,
                            row.tblCustumer.NameSname,
                            row.tblServicesDef.ServiceDescript,
                            row.BianehPardakhti,
                            row.Mandeh
                        };
            XtblReservBindingSource.DataSource = Query;
            this.reportViewer1.RefreshReport();     
        }
        private void Btn__RefreshRezerve_Click(object sender, EventArgs e)
        {
            try
            {
                UDf_RefreshRezerve();
                this.reportViewer1.RefreshReport();
            }
            catch
            {
                MessageBox.Show("لطفا خطای به وجود آمده را برطرف نمایید");
            }
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {

        }
    }
}
