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 Entity_FrameWork
{
    public partial class Search : Form
    {
        public Search()
        {
            InitializeComponent();
        }
        Entity_FrameWorkEntities5 MyModel = new Entity_FrameWorkEntities5();
        bool maxfrosh = false;
        bool Daramad1 = false;
        bool MaxCustomer = false;
        bool SearchKharid = false;
        
        private void superTabControl1_SelectedTabChanged(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
        {

        }

        private void applicationButton1_Click(object sender, EventArgs e)
        {

        }

        private void ribbonTabItemDaramad_Click(object sender, EventArgs e)
        {

        }

       
        

        private void labelX2_Click(object sender, EventArgs e)
        {

        }

      

        private void Daramad_Click(object sender, EventArgs e)
        {
            button_SearchDaramad.Enabled = true;
            Daramad1 = true;
            SearchKharid = false;
           
            MaxCustomer = false;
            maxfrosh = false;
          
            ribbonClientPanel1.Visible = true;
            maskedTextBoxAdv1.Visible = true;
            maskedTextBoxAdv2.Visible = true;
            button_SearchDaramad.Visible = true;
            
            dataGridViewKharid.DataSource = null;

        }

        private void Moshtari_Click(object sender, EventArgs e)
        {
            MaxCustomer = true;
            maxfrosh = false;
            Daramad1 = false;
            maskedTextBoxAdv1.Visible = false;
            maskedTextBoxAdv2.Visible = false;
            button_SearchDaramad.Visible =false;
            labelX1.Visible = false;
            labelX2.Visible = false;

        }

        private void Kharid_Click(object sender, EventArgs e)
        {
            button_SearchDaramad.Visible = true;
            SearchKharid = true;
            Daramad1 = false;
            
            dataGridViewKharid.DataSource = null;
            button_SearchDaramad.Enabled = true;
            labelX1.Enabled = true;
            labelX2.Enabled = true;

            maskedTextBoxAdv1.Visible = true;
            maskedTextBoxAdv2.Visible = true;
          
        }

        private void button_SearchDaramad_Click(object sender, EventArgs e)
        {

            if (maskedTextBoxAdv1.Text == "" && maskedTextBoxAdv2.Text == "")
            {
                FMessegeBox.FarsiMessegeBox.Show("لطفا تاريخ فيلد ها را وارد كنيد ");
            }
            else
            {
                if (Daramad1 == true && SearchKharid == false)
                {
                    dataGridViewKharid.DataSource = MyModel.Sp_SearchTarikh(maskedTextBoxAdv1.Text, maskedTextBoxAdv2.Text);
                    dataGridViewKharid.Columns[0].HeaderText = "كد فاكتور";
                    dataGridViewKharid.Columns[1].HeaderText = "خريدار";
                    dataGridViewKharid.Columns[2].HeaderText = "تاريخ خريد";
                    dataGridViewKharid.Columns[3].HeaderText = "تعداد";
                    dataGridViewKharid.Columns[4].HeaderText = "مبلغ";
                }

                if (SearchKharid == true && Daramad1 == false)
                {
                    dataGridViewKharid.DataSource = MyModel.Sp_SearchKharid(maskedTextBoxAdv1.Text, maskedTextBoxAdv2.Text);
                    dataGridViewKharid.Columns[0].HeaderText = "كد شركت";
                    dataGridViewKharid.Columns[1].HeaderText = "كد خريدار";
                    dataGridViewKharid.Columns[2].HeaderText = "تاريخ خريد";
                    dataGridViewKharid.Columns[3].HeaderText = "مبلغ";

                }

            }
        }

        private void Search_Load(object sender, EventArgs e)
        {
            Daramad.Select();
            Daramad1 = true;
        }

        private void button_MaxKala_Click(object sender, EventArgs e)
        {
            dataGridViewKharid.DataSource = MyModel.Sp_MaxFrosh().ToList();
            dataGridViewKharid.Columns[0].HeaderText = "كد كالا";
            dataGridViewKharid.Columns[1].HeaderText = "نام كالا";
            dataGridViewKharid.Columns[2].HeaderText = "مدل";
            dataGridViewKharid.Columns[3].HeaderText = "رنگ";
            dataGridViewKharid.Columns[4].HeaderText = "تعداد فروش";
            dataGridViewKharid.Columns[5].HeaderText = "مبلغ";
            maxfrosh = true;
            MaxCustomer = false;
            Daramad1 = false;
        }

        private void buttonMaxCustomer_Click(object sender, EventArgs e)
        {
            button_SearchDaramad.Enabled = false;
            dataGridViewKharid.DataSource = MyModel.Sp_MaxCustomer().ToList();
            dataGridViewKharid.Columns[0].HeaderText = "خريدار";
            dataGridViewKharid.Columns[1].HeaderText = "تاريخ خريد";
          
        }

       

        private void buttonPrint_Click(object sender, EventArgs e)
        {

            if (Daramad1== true)
            {
                stiReporDaramad.Load(Application.StartupPath + @"\ReportDaramad.mrt");
                spSearchTarikhResultBindingSource.DataSource = MyModel.Sp_SearchTarikh(maskedTextBoxAdv1.Text, maskedTextBoxAdv2.Text).ToList();
                stiReporDaramad.RegReportDataSources();
                stiReporDaramad.Show();
            }
            if(MaxCustomer==true)
            {
                stiReporMaxCustomer.Load(Application.StartupPath + @"\ReportMaxCustomer.mrt");
                spMaxCustomerResultBindingSource.DataSource = MyModel.Sp_MaxCustomer().ToList();
                stiReporMaxCustomer.RegReportDataSources();
                stiReporMaxCustomer.Show();
            }
            if (maxfrosh == true)
            {
                stiReportMaxFrosh.Load(Application.StartupPath + @"\ReportMaxFrosh.mrt");
                spMaxFroshResultBindingSource.DataSource = MyModel.Sp_MaxFrosh().ToList();
                stiReportMaxFrosh.RegReportDataSources();
                stiReportMaxFrosh.Show();
            }
            if (SearchKharid == true)
            {
                stiReportKharid.Load(Application.StartupPath + @"\ReportKharid.mrt");
                spSearchKharidResultBindingSource.DataSource = MyModel.Sp_SearchKharid(maskedTextBoxAdv1.Text,maskedTextBoxAdv2.Text);
                stiReportKharid.RegReportDataSources();
                stiReportKharid.Show();
            }
        }

        private void buttonItemDaramad_Click(object sender, EventArgs e)
        {
            button_SearchDaramad.Enabled = true;
        }

        private void dataGridViewKharid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Kala_Click(object sender, EventArgs e)
        {
            dataGridViewKharid.DataSource = null; 
            maxfrosh = true;
            MaxCustomer = false;
            Daramad1 = false;
        }

        private void buttonSearchKharid_Click(object sender, EventArgs e)
        {
            SearchKharid = true;

        }

       

      
      

       

        
    }
}
