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 WareHouse
{
    public partial class frmRepPurched : Form
    {
        public frmRepPurched()
        {
            InitializeComponent();
        }

        private void frmRepPurched_Load(object sender, EventArgs e)
        {
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;
            // TODO: This line of code loads data into the 'dtsForRepAnbar.tblPurched' table. You can move, or remove it, as needed.
            this.tblPurchedTableAdapter.Fill(this.dtsForRepAnbar.tblPurched);
            tblPurchedBindingSource.DataSource = this.dtsForRepAnbar.tblPurched;
            this.reportViewer1.RefreshReport();

            String Str_Sql = String.Empty;

            ////////////////////////////////////////////////////////////////////////////

            Str_Sql = "SELECT UnitID, UnitName FROM Units";
            dbconnClass1 comBo102 = new dbconnClass1();
            comBo102.dbCon1(Str_Sql);
            comBo102.dt.Rows.Add(new Object[] { 0, "نمایش همه رکوردها . . ." });
            comBo102.dt.Rows.Add(new Object[] { -1, "لطفا انتخاب فرمائید . . ." });
            cmbUnitename.DataSource = comBo102.dt;
            cmbUnitename.ValueMember = "UnitID";
            cmbUnitename.DisplayMember = "UnitName";
            cmbUnitename.SelectedValue = -1;
        }

        private void Btn_ViewReport_Click(object sender, EventArgs e)
        {
            if (int.Parse(cmbUnitename.SelectedValue.ToString()) == -1)
            { }
            else if (int.Parse(cmbUnitename.SelectedValue.ToString()) == 0)
            {
                ShowAll();
            }
            else
            {
                ShowByUnitID(int.Parse(cmbUnitename.SelectedValue.ToString()));
            }

        }

        private void ShowAll()
        {
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;
            // TODO: This line of code loads data into the 'dtsForRepAnbar.tblPurched' table. You can move, or remove it, as needed.
            this.tblPurchedTableAdapter.Fill(this.dtsForRepAnbar.tblPurched);
            tblPurchedBindingSource.DataSource = this.dtsForRepAnbar.tblPurched;
            this.reportViewer1.RefreshReport();
        }

        private void ShowByUnitID(int int_UnitID)
        {
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;
            // TODO: This line of code loads data into the 'dtsForRepAnbar.tblPurched' table. You can move, or remove it, as needed.
            this.tblPurchedTableAdapter.FillByUnitID(this.dtsForRepAnbar.tblPurched, int_UnitID);
            tblPurchedBindingSource.DataSource = this.dtsForRepAnbar.tblPurched;
            this.reportViewer1.RefreshReport();
        }
    }
}
