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 Customer : Form
    {
        public Customer()
        {
            InitializeComponent();
            this.MinimumSize = new System.Drawing.Size(808, 637);
        }

        Entity_FrameWorkEntities5 MyModel = new Entity_FrameWorkEntities5();
       
        private void Customer_Load(object sender, EventArgs e)
        {


            dataGridViewCustomer.DataSource = MyModel.Sp_SelectCustomer().ToList();
       dataGridViewCustomer.Columns[0].HeaderText = "كد فاكتور";
      dataGridViewCustomer.Columns[1].HeaderText = "خريدار";
      dataGridViewCustomer.Columns[2].HeaderText = "تاريخ خريد";
       
     
       textBox_DateBuy.Text = myfunction.convertDate(DateTime.Now.ToShortDateString(), myfunction.dataConvertMode.toPersian);

          

        }

        private void button_Insert_Click(object sender, EventArgs e)
        {

            MyModel.Sp_InsertCustomer(textBox_Buyer.Text, textBox_DateBuy.Text);
            FMessegeBox.FarsiMessegeBox.Show("ثبت شد");
            dataGridViewCustomer.DataSource = MyModel.Sp_SelectCustomer();





        }

        private void button_Update_Click(object sender, EventArgs e)
        {
        // MyModel.Sp_UpdateCustomer(
            FMessegeBox.FarsiMessegeBox.Show("ثبت شد");
            dataGridViewCustomer.DataSource = MyModel.Sp_SelectCustomer();
        }

        private void dataGridViewCustomer_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            Factor factor = new Factor(Convert.ToInt32(dataGridViewCustomer.CurrentRow.Cells[0].Value.ToString()));
            factor.ShowDialog();
       
        }

        private void button_Delete_Click(object sender, EventArgs e)
        {
            MyModel.Sp_DeleteCustomer(Convert.ToInt32(dataGridViewCustomer.CurrentRow.Cells[0].Value.ToString()));
            FMessegeBox.FarsiMessegeBox.Show("حذف شد");
            dataGridViewCustomer.DataSource = MyModel.Sp_SelectCustomer();
        }

        private void button_Search_Click(object sender, EventArgs e)
        {

            dataGridViewCustomer.DataSource = MyModel.Sp_SearchCustomer(textBox_Search.Text);
        }

        private void textBox_Search_TextChanged(object sender, EventArgs e)
        {
            if (radioButton_FactorCod.Checked == true)
            {

                dataGridViewCustomer.DataSource = MyModel.Sp_SearchFactor(textBox_Search.Text);
            }
            if (radioButton_Buyer.Checked == true)
            {
                dataGridViewCustomer.DataSource = MyModel.Sp_SearchCustomer(textBox_Search.Text);
            }
            if (radioButton_Date.Checked == true)
            {
                dataGridViewCustomer.DataSource = MyModel.Sp_SearchDate(textBox_Search.Text);
            }
        }

        private void button_Date_Click(object sender, EventArgs e)
        {
        
        }

        private void richTextBox_Comment_TextChanged(object sender, EventArgs e)
        {

        }

        private void button_ShowKala_Click(object sender, EventArgs e)
        {

            Kala kala = new Kala(Convert.ToInt32(dataGridViewCustomer.CurrentRow.Cells[0].Value.ToString()));
            kala.ShowDialog();
          
        }

        private void Customer_FormClosing(object sender, FormClosingEventArgs e)
        {
           
        }

        private void Customer_FormClosed(object sender, FormClosedEventArgs e)
        {
           
        }

        private void button_Report_Click(object sender, EventArgs e)
        {
            PrintCustomer Print = new PrintCustomer();
            Print.ShowDialog();
        }

        private void button_PrintStimul_Click(object sender, EventArgs e)
        {
            try
            {
                stiReportCustomer.Load(Application.StartupPath + @"\ReportCustomer.mrt");
                spSelectCustomerResultBindingSource.DataSource = MyModel.Sp_SelectCustomer().ToList();
                stiReportCustomer.RegReportDataSources();
                stiReportCustomer.Show();
            }
            catch
            {
            }
          
        }

        private void dataGridViewCustomer_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            textBox_Buyer.Text = dataGridViewCustomer.CurrentRow.Cells[1].Value.ToString();
            textBox_DateBuy.Text = dataGridViewCustomer.CurrentRow.Cells[2].Value.ToString();
        }

        private void radioButton_FactorCod_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void dataGridViewCustomer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dataGridViewCustomer_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            
        }

        private void dataGridViewCustomer_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
        {
            
        }
    }
}