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;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;

namespace FEQ0000
{
    public partial class fEquipmentSummary : Form
    {



        public fEquipmentSummary()
        {
            InitializeComponent();


            this.FormClosed += fEquipment_FormClosed;
        }

        void fEquipment_FormClosed(object sender, FormClosedEventArgs e)
        {
            var form = this as Form;
            // FCOMMON.Util.SetFormStatus(ref form, this.Name + this.tableName, false);
        }

        void RefreshDate()
        {
            //등록된 날짜 목록을 가져온다.
            var taDateList = new dsEQTableAdapters.EqDateListTableAdapter();
            
            DataTable dtListF = taDateList.GetDateListF();
            DataTable dtListB = taDateList.GetDateListB();
            DataTable dtListM = taDateList.GetDateListME();
            DataTable dtListO = taDateList.GetDateListOther();

            this.cmbDateF.Items.Clear();
            this.cmbDateB.Items.Clear();
            this.cmbDateM.Items.Clear();
            this.cmbDateO.Items.Clear();

            if (dtListF != null)
                foreach (DataRow dr in dtListF.Rows)
                    this.cmbDateF.Items.Add(dr["pdate"].ToString());

            if (dtListB != null)
                foreach (DataRow dr in dtListB.Rows)
                    this.cmbDateB.Items.Add(dr["pdate"].ToString());

            if (dtListM != null)
                foreach (DataRow dr in dtListM.Rows)
                    this.cmbDateM.Items.Add(dr["pdate"].ToString());

            if (dtListO != null)
                foreach (DataRow dr in dtListO.Rows)
                    this.cmbDateO.Items.Add(dr["pdate"].ToString());

            if (this.cmbDateF.Items.Count > 0) this.cmbDateF.SelectedIndex = 0;
            if (this.cmbDateB.Items.Count > 0) this.cmbDateB.SelectedIndex = 0;
            if (this.cmbDateM.Items.Count > 0) this.cmbDateM.SelectedIndex = 0;
            if (this.cmbDateO.Items.Count > 0) this.cmbDateO.SelectedIndex = 0;
        }

        private void __Load(object sender, EventArgs e)
        {
            this.Text = string.Format("Equipment Summary");
            var form = this as Form;
            //FCOMMON.Util.SetFormStatus(ref form, this.Name + this.tableName, true);
            this.Show();
            Application.DoEvents();

            RefreshDate();

            //목록을 가져온다.


        }




        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string key = tbFilter.Text.Trim();
                string filter = "";
                if (!key.isEmpty())
                {
                    filter = "asset like @ or type like @ or manu like @ or model like @ or linecode like @  or serial like @";
                    filter = filter.Replace("@", "'%" + key.Replace("'", "''") + "%'");
                }
                try
                {
                    this.bsB.Filter = filter;

                    if (key.isEmpty()) this.tbFilter.BackColor = Color.White;
                    else this.tbFilter.BackColor = Color.Lime;
                }
                catch (Exception ex)
                {
                    tbFilter.BackColor = Color.HotPink;
                    FCOMMON.Util.MsgE("filter error\n" + ex.Message);
                }
                tbFilter.Focus();
                tbFilter.SelectAll();
            }
            catch (Exception ex)
            {
                FCOMMON.Util.MsgE(ex.Message);
            }

        }


        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            var f = new rpt_equipmentSum(
                cmbDateF.Text,
                cmbDateB.Text,
                cmbDateM.Text,
                cmbDateO.Text);
            f.Show();
        }



        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            if (cmbDateF.SelectedIndex < 0)
            {
                FCOMMON.Util.MsgE("No Date");
                return;
            }


            this.ta.Fill(this.dsEQ.vEquStockSummary,
                cmbDateB.Text, 
                cmbDateF.Text, 
                cmbDateM.Text,
                cmbDateO.Text);
        }


        private void autosizeColumnsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.dv.AutoResizeColumns();
        }


        private void tbFilter_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) btFind.PerformClick();
        }

    }
}

