using GMW_data;
using SteamWare;
using System;
using System.Web.UI;

namespace GMW_Term.WebUserControls
{
    public partial class mod_delibLog : System.Web.UI.UserControl
    {
        /// <summary>
        /// azioni setup a creazione controllo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                divDetailDelib.Visible = false;
                divDetailUdc.Visible = false;
                btnReset.Visible = false;
                btnDelibera.Visible = false;
            }
            btnReset.Text = traduci("btnResetCtrl");
            lblReset.Text = traduci("btnResetCtrl");
            btnDelibera.Text = traduci("btnDelibera");
            lblDelibera.Text = traduci("btnDelibera");
        }
        /// <summary>
        /// wrapper traduzione termini
        /// </summary>
        /// <param name="lemma"></param>
        /// <returns></returns>
        public string traduci(string lemma)
        {
            return user_std.UtSn.Traduci(lemma);
        }
        /// <summary>
        /// mostro i dettagli dell'udc indicato
        /// </summary>
        public void showUdcDetail(string UDC)
        {
            UDC_sel = UDC;
            memLayer.ML.setSessionVal("UDC4det_sel", UDC);
            memLayer.ML.setSessionVal("CodCS", memLayer.ML.confReadString("CodCS"));
            divDetailUdc.Visible = true;
            btnReset.Visible = true;
            // calcolo se devo fare delibera...
            bool showNC = false;
            try
            {
                showNC = MagClass.magazzino.taCartellini.getSenzaDC(UDC).Rows.Count > 0;
            }
            catch
            { }
            bool showDL = false;
            try
            {
                showDL = MagClass.magazzino.taCartellini.getSenzaDeliberaPM(UDC).Rows.Count > 0;
            }
            catch
            { }
            // se ho da deliberare mostro pannello
            if (showNC || showDL)
            {
                // verifico se ho da deliberare PM o NC
                divDetailDelib.Visible = true;
                btnDelibera.Visible = true;
                mod_detail_NC1.Visible = showNC;
                mod_detail_DL1.Visible = showDL;
            }
            lblDeliberato.Visible = !showDL;
            divDatiDelibera.Visible = !showDL;
        }
        /// <summary>
        /// ricarica pagina corrente
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnResetCtrl_Click(object sender, EventArgs e)
        {
            memLayer.ML.emptySessionVal("UDC4det_sel");
            Response.Redirect("~/delibLog.aspx");
        }
        /// <summary>
        /// delibera UDC corrente PM/NC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelibera_Click(object sender, EventArgs e)
        {
            if (UDC_sel != "")
            {
                MagClass.magazzino.taCartellini.setDL_DC_FORCED(UDC_sel, MagClass.magazzino.CodSoggCurrUser);
            }
            showUdcDetail(UDC_sel);
            memLayer.ML.emptySessionVal("UDC4det_sel");
            Response.Redirect("~/delibLog.aspx");
        }
        /// <summary>
        /// UDC impostato
        /// </summary>
        public string UDC_sel
        {
            get
            {
                return hfUdc.Value;
            }
            set
            {
                hfUdc.Value = value;
                mod_detail_NC1.UDC_sel = value;
            }
        }
    }
}