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 TaxiTelphoni
{
    public partial class frmChartDaramadAja : Form
    {
        public frmChartDaramadAja()
        {
            InitializeComponent();
        }
        private void UDF_Grd_Fill()
        {
            LSC_TaxiTelfoniDataContext db = new LSC_TaxiTelfoniDataContext();

            var Query = from Row in db.xtblDaramadAjanses
                        where Row.TasviehBit == true
                        select new
                        {
                            Row.ServDate1,
                            Row.DarsadeAjanse
                        };
            Grd_Daramad.DataSource = Query;
        }
        private void UDF_ShowDaramadByDate()
        {
            LSC_TaxiTelfoniDataContext db = new LSC_TaxiTelfoniDataContext();
            var Query1 = from Row in db.xtblDaramadAjanses
                         where Row.TasviehBit == true
                         select new
                        {
                            Row.ServDate1,
                            Row.DarsadeAjanse
                        };
            try
            {
                Int64 int_StartDate = Convert.ToInt64(MTxt_StartDate.Text.Trim().Replace("/", ""));
                Int64 int_EndDate = Convert.ToInt64(MTxt_EndDate.Text.Trim().Replace("/", ""));
                var Query2 = from Row in Query1
                             where ((Convert.ToInt64(Row.ServDate1.Trim().Replace("/", "")) >= int_StartDate) && (Convert.ToInt64(Row.ServDate1.Trim().Replace("/", "")) <= int_EndDate))
                             select new
                             {
                                 Row.ServDate1,
                                 Row.DarsadeAjanse
                             };

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

                xtblDaramadAjanseBindingSource.DataSource = Query2;
                reportViewer1.RefreshReport();
            }
            catch
            {
                MessageBox.Show("تاریخ ها را وارد کنید");
            }
        }

        private void frmChartDaramadAja_Load(object sender, EventArgs e)
        {
            UDF_Grd_Fill();
        }
        private void Btn_ShowChart_Click(object sender, EventArgs e)
        {
            List<Int32> ListItems = new List<Int32>();
            for (int i = 0; i < Lst_Date.Items.Count; i++)
            {
                ListItems.Add(Convert.ToInt32(Lst_Date.Items[i].ToString().Trim().Replace("/", "")));
            }
            LSC_TaxiTelfoniDataContext db = new LSC_TaxiTelfoniDataContext();
            var Query = from Row in db.xtblDaramadAjanses
                        where ListItems.Contains(Convert.ToInt32(Row.ServDate1.ToString().Trim().Replace("/", ""))) && Row.TasviehBit == true
                        select new
                        {
                            Row.ServDate1,
                            Row.DarsadeAjanse

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

            xtblDaramadAjanseBindingSource.DataSource = Query;
            reportViewer1.RefreshReport();
        }
        private void Btn_Delete_Click(object sender, EventArgs e)
        {
            try
            {
                Lst_Date.Items.RemoveAt(Lst_Date.SelectedIndex);
            }
            catch
            {
                MessageBox.Show("یک تاریخ از لیست انتخاب شود");
            }
        }
        private void Grd_Foroosh_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            bool bool_ok = false;
            try
            {
                string str_Date = Grd_Daramad.Rows[e.RowIndex].Cells[0].Value.ToString();
                for (int i = 0; i < Lst_Date.Items.Count; i++)
                {
                    if (Lst_Date.Items[i].ToString() == str_Date)
                    {
                        bool_ok = true;

                    }
                }
                if (bool_ok == false)
                {
                    Lst_Date.Items.Add(str_Date);
                }
            }
            catch
            {
                MessageBox.Show("روی سلول های جدول کلیک کنید");
            }
        }
        private void Btn_Show_Click(object sender, EventArgs e)
        {
            UDF_ShowDaramadByDate();
        }
    }
}
