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 FCM0000.Inventory
{
    public partial class fInventoryJagoPlace : FCOMMON.fBase
    {
        public fInventoryJagoPlace(int itemIndex,string itemname)
        {
            
            InitializeComponent();
            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            this.tbPumIDX.Text = itemIndex.ToString();
            this.tbPumName.Text = itemname;
            this.tbPumName.Tag = itemname;
            this.tbPumName.KeyDown += (s1, e1) => { if (e1.KeyCode == Keys.Enter) Lov_Item(tbPumName.Text, false); };
        }
      
        private void fInventoryJagoPlace_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.Show();
            Application.DoEvents();
            button1.PerformClick();
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Lov_Item("", true);
        }
        void Lov_Item(string search, Boolean allowAll)
        {
            if (search == "" && allowAll == false)
            {
                FCOMMON.Util.MsgE("품명은 필수 값 입니다");
                tbPumName.Focus();
                return;
            }
            else if (search.ToLower() != tbPumName.Tag.ToString().ToLower() || tbPumIDX.Text == "-1" || tbPumIDX.Text == "") //값이 바뀌엇다면 검색을 해준다.
            {
                var f = new FCM0000.fLovItem(search);
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //인덱스값이 다르면 모델 및 가격을 업데이트 한다.
                    tbPumName.Text = f.itemName;
                    tbPumName.Tag = f.itemName;

                    this.tbPumIDX.Text = f.item.ToString();
                    //this.tbPumModel.Text = f.itemmodel;
                    //this.tbPumPrice.Text = f.itemprice.ToString();
                    //this.tbSID.Text = f.SID;
                    //this.tbSID.Tag = f.SID;
                    //this.tbPumModel.Enabled = false;
                    //if (tbSID.Text != "") tbSID.Enabled = false;
                    //else tbSID.Enabled = true;
                }
            }
        }
        void refreshData()
        {
            var itmidx = 0;
            if(!int.TryParse(tbPumIDX.Text,out itmidx))
            {
                FCOMMON.Util.MsgE("품목을 먼저 선택하세요");
                return;
            }
            this.ta.FillByItemIdx(this.dSReport.jagosummaryPlace, FCOMMON.info.Login.gcode, DateTime.Now.ToString("yyyy-MM-dd"), itmidx);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            refreshData();
        }
    }
}
