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

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

        public string ErrorTitle
        {
            get
            {
                return lblErrorTitle.Text;
            }
            set
            {
                lblErrorTitle.Text = value;
            }
        }
        public string ErrorExpl
        {
            get
            {
                return lblErrorExpl.Text;
            }
            set
            {
                lblErrorExpl.Text = value;
            }
        }

        public string LastError
        {
            get
            {
                string answ = "N.A.";
                if (!string.IsNullOrEmpty(memLayer.ML.QSS("aspxerrorpath")))
                {
                    answ = traduci(memLayer.ML.QSS("aspxerrorpath"));
                }
                return answ;
            }
        }
        public string LastErrorCode
        {
            get
            {
                string answ = "N.A.";
                if (!string.IsNullOrEmpty(memLayer.ML.QSS("aspxerrorpath")))
                {
                    answ = memLayer.ML.QSS("aspxerrorpath");
                }
                return answ;
            }
        }

        public string UserName
        {
            get
            {
                return lblUserName.Text;
            }
            set
            {
                lblUserName.Text = value;
            }
        }

        protected void lbtTryReset_Click(object sender, EventArgs e)
        {
            doRedirect();
        }

        private void doRedirect()
        {
            // svuoto session e cache per rileggere i dati da Db
            Session.RemoveAll();
            try
            {
                // aggiorno vocabolario
                DataWrap.DW.resetVocabolario();
                // reset dati in cache x DbConfig...
                memLayer.ML.resetAppConf();
            }
            catch
            { }
            // ulteriore reset sessione
            Session.Clear();
            // attendo...
            Thread.Sleep(500);
            // reload!
            memLayer.ML.setSessionVal("nextPage", "default");
            Response.Redirect("~/default");
        }

        protected int countDown
        {
            get
            {
                int answ = 0;
                int.TryParse(lblCounter.Text, out answ);
                return answ;
            }
            set
            {
                lblCounter.Text = value.ToString();
            }
        }

        public string timeAdv
        {
            get
            {
                return $"width: {(countDown) * 100 / 10}%";
            }
        }

        protected void timerRedirect_Tick(object sender, EventArgs e)
        {
            // decremento contatore
            if (countDown <= 0)
            {
                doRedirect();
            }
            countDown--;
        }
    }
}