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

namespace Nano_System
{
    public partial class frmChartKharidForoosh : Form
    {
        public frmChartKharidForoosh()
        {
            InitializeComponent();
        }

        private void UDF_ShowKharid()
        {
            LSC_NanoProjDataContext db = new LSC_NanoProjDataContext();
            var Query = from Row in db.xtblKharidByDates
                        select new
                        {
                            Row.DtOfSodoor,
                            Row.KolleKharid
                        };

            Grd_Kharid.DataSource = Query;

        }

        private void UDF_ShowForoosh()
        {
            LSC_NanoProjDataContext db = new LSC_NanoProjDataContext();
            var Query = from Row in db.xtblForooshByDates
                        select new
                        {
                            Row.DateForoosh,
                            Row.KolleForoosh
                        };

            Grd_Foroosh.DataSource = Query;
        }

        private void frmChartKharidForoosh_Load(object sender, EventArgs e)
        {
            UDF_ShowKharid();
            UDF_ShowForoosh();
        }


        private void Btn_ShowKharid_Click_1(object sender, EventArgs e)
        {
            List<Int32> ListItems = new List<Int32>();
            for (int i = 0; i < Lst_Kharid.Items.Count; i++)
            {
                ListItems.Add(Convert.ToInt32(Lst_Kharid.Items[i].ToString().Trim().Replace("/", "")));
            }

            LSC_NanoProjDataContext db = new LSC_NanoProjDataContext();
            var Query = from Row in db.xtblKharidByDates
                        where ListItems.Contains(Convert.ToInt32(Row.DtOfSodoor.ToString().Trim().Replace("/", "")))
                        select new
                        {
                            Row.DtOfSodoor,
                            Row.KolleKharid

                        };

            reportViewer2.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer2.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer2.ZoomPercent = 25;


            xtblKharidByDateBindingSource.DataSource = Query;
            reportViewer2.RefreshReport();
        }

       
        private void Btn_ShowForoosh_Click_1(object sender, EventArgs e)
        {
            List<Int32> ListItems = new List<Int32>();
            for (int i = 0; i < Lst_Foroosh.Items.Count; i++)
            {
                ListItems.Add(Convert.ToInt32(Lst_Foroosh.Items[i].ToString().Trim().Replace("/", "")));
            }

            LSC_NanoProjDataContext db = new LSC_NanoProjDataContext();
            var Query = from Row in db.xtblForooshByDates
                        where ListItems.Contains(Convert.ToInt32(Row.DateForoosh.ToString().Trim().Replace("/", "")))
                        select new
                        {
                            Row.DateForoosh,
                            Row.KolleForoosh

                        };

            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer1.ZoomPercent = 25;


            xtblForooshByDateBindingSource.DataSource = Query;
            reportViewer1.RefreshReport();
        }

        private void Grd_Foroosh_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            bool bool_ok = false;
            try
            {
                string str_Date = Grd_Foroosh.Rows[e.RowIndex].Cells[0].Value.ToString();

                for (int i = 0; i < Lst_Foroosh.Items.Count; i++)
                {
                    if (Lst_Foroosh.Items[i].ToString() == str_Date)
                    {
                        bool_ok = true;

                    }
                }

                if (bool_ok == false)
                {
                    Lst_Foroosh.Items.Add(str_Date);
                }


            }
            catch
            {
                MessageBox.Show("روی سلول های جدول کلیک کنید");
            }
        }

        private void Grd_Kharid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            bool bool_ok = false;
            try
            {
                string str_Date = Grd_Kharid.Rows[e.RowIndex].Cells[0].Value.ToString();

                for (int i = 0; i < Lst_Kharid.Items.Count; i++)
                {
                    if (Lst_Kharid.Items[i].ToString() == str_Date)
                    {
                        bool_ok = true;

                    }
                }

                if (bool_ok == false)
                {
                    Lst_Kharid.Items.Add(str_Date);
                }


            }
            catch
            {
                MessageBox.Show("روی سلول های جدول کلیک کنید");
            }
        }
    }
}
