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 Kharid : Form
    {
        int CodCompany;
        public Kharid(int _CodCompany)
        {
           
            InitializeComponent();
            CodCompany = _CodCompany;
            this.MinimumSize = new System.Drawing.Size(815, 406);
        }
        Entity_FrameWorkEntities5 MyModel = new Entity_FrameWorkEntities5();
        private void Kharid_Load(object sender, EventArgs e)
        {
            dataGridViewKharid.DataSource = MyModel.Sp_SelectKharid(CodCompany).ToList();
            dataGridViewKharid.Columns[1].HeaderText = "كد شركت";
            dataGridViewKharid.Columns[2].HeaderText = "كد خريد";
            dataGridViewKharid.Columns[3].HeaderText = "تاريخ خريد";
            dataGridViewKharid.Columns[4].HeaderText = "ميلغ كلي خريد";
          
            
        }

        private void buttonInsert_Click(object sender, EventArgs e)
        {
            MyModel.Sp_InsertKharid(maskedTexDateBuy.Text, Convert.ToInt32(textBoxMoney.Text));
            FMessegeBox.FarsiMessegeBox.Show("ثبت شد");
            dataGridViewKharid.DataSource = MyModel.Sp_SelectKharid(CodCompany).ToList();



        }

        private void dataGridViewKharid_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataBuy databuy = new DataBuy(Convert.ToInt32(dataGridViewKharid.CurrentRow.Cells[2].Value.ToString()));
            databuy.ShowDialog();
        }

        private void dataGridViewKharid_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                maskedTexDateBuy.Text = dataGridViewKharid.CurrentRow.Cells[3].Value.ToString();
                textBoxMoney.Text = dataGridViewKharid.CurrentRow.Cells[4].Value.ToString();
            }
            catch
            { }
            

        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            MyModel.Sp_UpdateKharid(Convert.ToInt32(dataGridViewKharid.CurrentRow.Cells[2].Value.ToString()),maskedTexDateBuy.Text,Convert.ToInt32(textBoxMoney.Text));
            FMessegeBox.FarsiMessegeBox.Show("ويرايش شد");
            dataGridViewKharid.DataSource = MyModel.Sp_SelectKharid(CodCompany).ToList();

        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            MyModel.Sp_DeleteKharid(Convert.ToInt32(dataGridViewKharid.CurrentRow.Cells[2].Value.ToString()));
            FMessegeBox.FarsiMessegeBox.Show("حذف شد");
            dataGridViewKharid.DataSource = MyModel.Sp_SelectKharid(CodCompany).ToList();

        }

        private void button_Kharid_Click(object sender, EventArgs e)
        {
            stiReportKharid.Load(Application.StartupPath + @"\ReportKharid.mrt");
            spSelectKharidResultBindingSource.DataSource = MyModel.Sp_SelectKharid(CodCompany).ToList();
            stiReportKharid.RegReportDataSources();
            stiReportKharid.Show();
        }

        private void button_Search_Click(object sender, EventArgs e)
        {
           dataGridViewKharid.DataSource= MyModel.Sp_SearchKharidCompany(maskedTextBoxSearch.Text,CodCompany);
        }

        private void buttonKoli_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridViewKharid.Rows)
            {

                if (Convert.ToBoolean(row.Cells[Check.Name].Value) == true)
                {
                    stiReportKoli.Load(Application.StartupPath + @"\ReportKharidFroshgah.mrt");
                    spListKharidKoliResultBindingSource.DataSource = MyModel.Sp_ListKharidKoli(Convert.ToInt32(dataGridViewKharid.CurrentRow.Cells[2].Value.ToString()));
                    stiReportKoli.RegReportDataSources();
                    stiReportKoli.Show();
                }
            }
        }

        private void dataGridViewKharid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        

    }
}
