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

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

        }
        /// <summary>
        /// comando reset
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtReset_Click(object sender, EventArgs e)
        {
            resetSelezione();
        }

        protected string task
        {
            get
            {
                return hfTask.Value;
            }
            set
            {
                hfTask.Value = value;
            }
        }

        private void resetSelezione()
        {
            grView.SelectedIndex = -1;
            grView.DataBind();
        }

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

        protected void grView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // se selezionato --> passo da status 1 a 2...

            int packListId = 0;
            int.TryParse(grView.SelectedValue.ToString(), out packListId);
            if (packListId > 0)
            {
                // verifico richiesta...
                switch (task)
                {
                    case "Appr":
                        DLMan.taPL.updateStatus(packListId, 2);
                        break;
                    case "Remove":
                        DLMan.taPL.updateStatus(packListId, 5);
                        break;
                    default:
                        break;
                }
                // refresh!
                resetSelezione();
            }
        }

        protected void lbtCheck_Click(object sender, EventArgs e)
        {
            LinkButton lbt = (LinkButton)sender;
            if (!string.IsNullOrEmpty(lbt.CommandArgument))
            {
                // salvo richiesta...
                task = lbt.CommandArgument;
            }
        }

        protected void lbtRemove_Click(object sender, EventArgs e)
        {
            LinkButton lbt = (LinkButton)sender;
            if (!string.IsNullOrEmpty(lbt.CommandArgument))
            {
                // salvo richiesta...
                task = lbt.CommandArgument;
            }
        }
        

        protected void grView_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            doUpdate();
        }
    }
}