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 frmRptStaffs : Form
    {
        public frmRptStaffs()
        {
            InitializeComponent();
        }

        private void frmRptStaffs_Load(object sender, EventArgs e)
        {
            LSC_TADataContext db = new LSC_TADataContext();
            UDF_FillComOperator();
            var Query = from row in db.tblStaffsTables
                        orderby row.StaffID descending
                        select row;
            XtblStaffBindingSource.DataSource = Query;
            this.reportViewer1.RefreshReport();
        }
        /// <summary>
        /// تابع پر کردن کامو باکس اپراتور
        /// </summary>
        private void UDF_FillComOperator()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from Row in db.tblStaffsTables
                        orderby Row.StaffID descending
                        select new
                        {
                            Row.StaffID,
                            Row.NameSname
                        };
            Cmb_FilterStaffs.DisplayMember = "NameSname";
            Cmb_FilterStaffs.ValueMember = "StaffID";
            Cmb_FilterStaffs.DataSource = Query;
        }
        /// <summary>
        ///  تابع مربوط به فیلتر کردن آیتم های مشتریان
        /// </summary>
        private void UDF_FilterStaff()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            try
            {
                var Query = from Row in db.tblStaffsTables
                            where int.Parse(Cmb_FilterStaffs.SelectedValue.ToString()) == Row.StaffID
                            select Row;

                XtblStaffBindingSource.DataSource = Query;
            }
            catch
            {
                MessageBox.Show("لطفا فیلدی برای فیلتر کردن انتخاب نمایید");
            }
        }
        /// <summary>
        /// تابع به روز رسانی رزرو بلیط
        /// </summary>
        private void UDf_RefreshStaffs()
        {
            LSC_TADataContext db = new LSC_TADataContext();
            var Query = from row in db.tblStaffsTables
                        orderby row.StaffID descending
                        select new
                        {   
                            row.StaffID,
                            row.NameSname,
                            row.PhoneNum,
                            row.FaxNum,
                            row.Notes
                        };
            XtblStaffBindingSource.DataSource = Query;
            this.reportViewer1.RefreshReport();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            UDF_FilterStaff();
            this.reportViewer1.RefreshReport();
        }

        private void Btn__RefreshStaffs_Click(object sender, EventArgs e)
        {
            try
            {
                UDf_RefreshStaffs();
            }
            catch
            {
                MessageBox.Show("لطفا خطای به وجود آمده را برطرف نمایید");
            }
        }

        private void Cmb_FilterStaffs_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
    }
}
