using System;
using System.Web.UI.WebControls;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_kitReqRunning : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                fixVisibility();
            }
        }

        private void fixVisibility()
        {
            cmp_KR_cart.Visible = (grView.SelectedIndex >= 0);
            divHeader.Visible = showTitle;
        }

        internal void doUpdate()
        {
            grView.DataBind();
            fixVisibility();
            cmp_KR_cart.doUpdate();
        }

        public bool showTitle
        {
            get
            {
                bool answ = false;
                bool.TryParse(hfShowTitle.Value, out answ);
                return answ;
            }
            set
            {
                hfShowTitle.Value = value.ToString();
                fixVisibility();
            }
        }
        public bool showFull
        {
            get
            {
                bool answ = false;
                bool.TryParse(hfShowFull.Value, out answ);
                return answ;
            }
            set
            {
                hfShowFull.Value = value.ToString();
                grView.DataBind();
            }
        }
        public bool enableSuspend
        {
            get
            {
                bool answ = false;
                bool.TryParse(hfEnableSuspend.Value, out answ);
                return answ;
            }
            set
            {
                hfEnableSuspend.Value = value.ToString();
                grView.DataBind();
            }
        }
        protected void grView_SelectedIndexChanged(object sender, EventArgs e)
        {
            int PackListId = 0;
            int.TryParse(grView.SelectedValue.ToString(), out PackListId);
            // mostra dettaglio CART
            cmp_KR_cart.PackListID = PackListId;
            cmp_KR_cart.Visible = true;
        }
        /// <summary>
        /// comando reset
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtReset_Click(object sender, EventArgs e)
        {
            grView.SelectedIndex = -1;
            doUpdate();
        }

        protected void lbtSuspendJob_Click(object sender, EventArgs e)
        {
            int PackListId = 0;
            LinkButton lbtBtn = (LinkButton)sender;
            if (lbtBtn != null)
            {
                int.TryParse(lbtBtn.CommandArgument, out PackListId);
                // SOSPENDO il job selezionato e indico status approvato
                DLMan.taPL.updateStatus(PackListId, 2);
                DLMan.taPL.updateSchedPrior(PackListId, 0);
                DLMan.taPL.fixSched();
                // resetto CART e BIN che al KIT siano NON completati...
                DLMan.taCR.resetKitIncomplete();
                DLMan.taBN.resetKitIncomplete();
                // fix grafico!
                grView.SelectedIndex = -1;
                doUpdate();
                raiseEvent();
            }
        }
    }
}