using AppData;
using System;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_stackNextloading : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        private void checkVisibility()
        {
            // mostra button x collezionare Redo SOLO SE ci sono fogli da rilavorare...
            int numRedo = 0;
            var stList = DLMan.taSTL.getByBatch(BatchId);
            foreach (var item in stList)
            {
                numRedo += item.NumSheetsToRedo;
            }
            lbtCollectRedo.Visible = numRedo > 0;
            lbtCollectRedoOnEnd.Visible = numRedo > 0;
        }

        public int BatchId
        {
            set
            {
                hfBatchID.Value = value.ToString();
                doUpdate();
            }
            get
            {
                int answ = 0;
                int.TryParse(hfBatchID.Value, out answ);
                return answ;
            }
        }

        public void doUpdate()
        {
            grViewCurrent.DataBind();
            frmViewNext.DataBind();
            checkVisibility();
        }

        public int StackIdReq
        {
            get
            {
                int answ = 0;
                if (frmViewNext.SelectedValue != null)
                {
                    int.TryParse(frmViewNext.SelectedValue.ToString(), out answ);
                }
                return answ;
            }
        }
        /// <summary>
        /// Effettua steps x gestire Redo Sheets PRIMA POSSIBILE
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtCollectRedo_Click(object sender, EventArgs e)
        {
            // chiamo stored x sistemare
            DLMan.taBL.fixRedoSheet(BatchId);
            doUpdate();
        }

        /// <summary>
        /// Effettua steps x gestire Redo Sheets ALLA FINE
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtCollectRedoOnEnd_Click(object sender, EventArgs e)
        {
            // chiamo stored x sistemare
            DLMan.taBL.fixRedoSheetOnEnd(BatchId);
            doUpdate();
        }


    }
}