using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_searchBin : BaseUserControl
    {
        #region Protected Properties

        protected bool binOk
        {
            get
            {
                return BinID > 0;
            }
        }

        #endregion Protected Properties

        #region Public Properties

        /// <summary>
        /// Bin selezionato
        /// </summary>
        public int BinID
        {
            get
            {
                int answ = 0;
                int.TryParse(hfBinID.Value, out answ);
                return answ;
            }
            set
            {
                hfBinID.Value = value.ToString();
            }
        }

        /// <summary>
        /// INdica se sia stato chaimato in modalità painted
        /// </summary>
        public bool isPainted
        {
            get
            {
                bool answ = false;
                bool.TryParse(hfIsPainted.Value, out answ);
                return answ;
            }
            set
            {
                hfIsPainted.Value = value.ToString();
            }
        }

        #endregion Public Properties

        #region Protected Methods

        protected void lbtReorderParts_Click(object sender, EventArgs e)
        {
            LinkButton lbt = null;
            int BinID = 0;
            int ItemId = 0;
            try
            {
                lbt = (LinkButton)sender;
            }
            catch
            { }
            if (lbt != null)
            {
                int.TryParse(lbt.CommandArgument, out BinID);
                // cerco primo da riordinare x quel BIN
                var tabIL = DLMan.taIL.getLastToProduceByBin(BinID);
                if (tabIL != null && tabIL.Rows.Count > 0)
                {
                    ItemId = tabIL[0].ItemID;
                    // riordino item ID corrente... status 990....
                    if (ItemId > 0)
                    {
                        // resetto item selezionato...
                        DLMan.taIL.updateStatus(ItemId, 990, PlaceCod);
                        lgInfo($"cmp_searchBin | SCRAP | Status --> 990 | itemIdSelected: {BinID} | PlaceCod: {PlaceCod}");
                        raiseEvent();
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            PlaceCod = "ND";
        }

        #endregion Protected Methods

        #region Public Methods

        public void doUpdate()
        {
            frmView.DataBind();
        }

        #endregion Public Methods
    }
}