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 frmRptServiceDef : Form
    {
        public frmRptServiceDef()
        {
            InitializeComponent();
        }
        private void UDF_FilterDefService()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            try
            {
                var Query = from Row in db.tblServicesDefs
                            where int.Parse(Cmb_FilterDefServise.SelectedValue.ToString()) == Row.ServiceID
                            select Row;
                XtblServiceDefBindingSource.DataSource = Query;
            }
            catch
            {
                MessageBox.Show("لطفا فیلدی برای فیلتر کردن انتخاب نمایید");
            }
        }
        /// <summary>
        ///  تابع پر کردن کامو باکس سرویس
        /// </summary>
        private void UDF_FillComServiceCol()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblServicesDefs
                        orderby row.ServiceID descending
                        select new
                        {
                            row.ServiceID,
                            row.ServiceDescript,
                            row.ServiceDate
                        };
            Cmb_FilterDefServise.DisplayMember = "ServiceDescript";
            Cmb_FilterDefServise.ValueMember = "ServiceID";
            Cmb_FilterDefServise.DataSource = Query;
        }
        /// <summary>
        /// تابع پر کردن کامو باکس سرویس های بسته شده
        /// </summary>
        private void UDF_FillComServiceBasteShode()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblServicesDefs
                        where row.ExpireBit == bool.Parse("false")
                        orderby row.ServiceID descending
                        select new
                        {
                            row.ServiceID,
                            row.ServiceDescript,
                            row.ServiceDate
                        };
            Cmb_FilterDefServise.DisplayMember = "ServiceDescript";
            Cmb_FilterDefServise.ValueMember = "ServiceID";
            Cmb_FilterDefServise.DataSource = Query;
        }
        /// <summary>
        /// تابع پرکردن کاموباکس سرویس های پر نشده
        /// </summary>
        private void UDF_FillComServiceJustifyOpenService()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblServicesDefs
                        where row.ExpireBit == bool.Parse("true")
                        orderby row.ServiceID descending
                        select new
                        {
                            row.ServiceID,
                            row.ServiceDescript,
                            row.ServiceDate
                        };
            Cmb_FilterDefServise.DisplayMember = "ServiceDescript";
            Cmb_FilterDefServise.ValueMember = "ServiceID";
            Cmb_FilterDefServise.DataSource = Query;
        }
        /// <summary>
        /// تابع به روز رسانی سرویس جدید 
        /// </summary>
        private void UDf_RefreshServiceDef()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblServicesDefs
                        orderby row.ServiceID descending
                        select new
                        {
                            row.ServiceID,
                            row.ServiceDescript,
                            row.ServiceDate,
                            row.Quantity,
                            row.Str_ServiceDescript,
                            row.DefPrice,
                            row.ExpireBit
                        };
            XtblServiceDefBindingSource.DataSource = Query;
        }
        private void frmRptServiceDef_Load(object sender, EventArgs e)
        {
            LSC_TADataContext db = new LSC_TADataContext();
                   var Query = from row in db.tblServicesDefs
                        orderby row.ServiceID descending
                        select new
                        { 
                            row.ServiceID,
                            row.ServiceDescript,
                            row.Quantity,
                            row.ServiceDate,
                            row.tblServiceType.ServiceDesCript,
                            row.DefPrice
                        };
            XtblServiceDefBindingSource.DataSource = Query;
            this.reportViewer1.RefreshReport();        
        }
        private void Btn__FilterDefServise_Click(object sender, EventArgs e)
        {
            UDF_FilterDefService();
            this.reportViewer1.RefreshReport();
        }
        private void Btn__RefreshDefServise_Click(object sender, EventArgs e)
        {
            try
            {
                UDf_RefreshServiceDef();
                this.reportViewer1.RefreshReport();
            }
            catch
            {
                MessageBox.Show("لطفا خطای به وجود آمده را برطرف نمایید");
            }
        }
        private void Cmb_FilterDefServise_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
        private void Cmb_FilterDefServise_Click(object sender, EventArgs e)
        {
            if (Chk_ServiceDefBaste.Checked == true && Chk_ServiceDefCol.Checked == true)
            {
                UDF_FillComServiceJustifyOpenService();
            }
            else if (Chk_ServiceDefBaste.Checked == true && Chk_ServiceDefCol.Checked == false)
            {
                UDF_FillComServiceBasteShode();
            }
            else if (Chk_ServiceDefBaste.Checked == false && Chk_ServiceDefCol.Checked == true)
            {
                UDF_FillComServiceCol();
            }
            else if (Chk_ServiceDefBaste.Checked == false && Chk_ServiceDefCol.Checked == false)
            {
                LSC_TADataContext db = new LSC_TADataContext();
                var Query = from row in db.tblServicesDefs
                            where row.Quantity > 2121212
                            orderby row.ServiceID descending
                            select new
                            {
                                row.ServiceID,
                                row.ServiceDescript,
                                row.ServiceDate
                            };
                Cmb_FilterDefServise.DisplayMember = "ServiceDescript";
                Cmb_FilterDefServise.ValueMember = "ServiceID";
                Cmb_FilterDefServise.DataSource = Query;
            }

            
        }
    }
}
