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

namespace GMW
{
    public partial class fusiTK : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                updatePrinterPostazione();
                // fix css...
                Postazione.CssClass = "stileAttesa";
                // imposto pos abilitata x cancellazione
                mod_storicoAzioniOperatore1.IdxPosizione2del = memLayer.ML.cdvi("IdxPosizioneFusi");
                // pulisco dir temp dai file dei cartellini stampati
                reportPrinter.obj.pulisciDir();
            }
            // update vari...
            doUpdate();
            mod_storicoAzioniOperatore1.eh_stampa += new EventHandler(mod_storicoAzioniOperatore1_eh_stampa);
            mod_fusiTK1.doUpdate();
            mod_fusiTK1.eh_reqUpdate += mod_PostRX_NT1_eh_reqUpdate; 
            mod_selLineaNtDt1.eh_lineSelected += mod_selLineaNtDt1_eh_doRefresh;
            mod_selLineaNtDt1.eh_showHideStorico += mod_selLineaNtDt1_eh_showHideStorico;
        }
        /// <summary>
        /// Handles the showHideStorico event of the mod_selLineaNtDt1_eh control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void mod_selLineaNtDt1_eh_showHideStorico(object sender, EventArgs e)
        {
            fixStorico();
        }
        /// <summary>
        /// Handles the doRefresh event of the mod_selLineaNtDt1_eh control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void mod_selLineaNtDt1_eh_doRefresh(object sender, EventArgs e)
        {
            doUpdate();
            mod_fusiTK1.doUpdate(); 
        }
        /// <summary>
        /// richiesta update del controllo SAO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mod_PostRX_NT1_eh_reqUpdate(object sender, EventArgs e)
        {
            doUpdate();
        }
        /// <summary>
        /// aggiorna messaggi e css
        /// </summary>
        private void updateMessCss()
        {
            lblWarning.Text = Postazione.warningText;
            lblMessaggi.Text = Postazione.messaggiText;
            pnlAll.CssClass = Postazione.CssClass;
        }
        /// <summary>
        /// richiesta (ri)stampa UDC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mod_storicoAzioniOperatore1_eh_stampa(object sender, EventArgs e)
        {
            mod_fusiTK1.ristampa(); 
        }
        /// <summary>
        /// sistemo visualizzazione pannelli
        /// </summary>
        private void fixPanels()
        {
            // default: moduli visibili (non serve linea)..
            bool enableBtn = true;
            mod_fusiTK1.Visible = enableBtn;
            fixStorico();
        }
        /// <summary>
        /// wrapper traduzione
        /// </summary>
        /// <param name="lemma"></param>
        /// <returns></returns>
        public string traduci(object lemma)
        {
            return user_std.UtSn.Traduci(lemma.ToString());
        }
        /// <summary>
        /// toggle controllo storico
        /// </summary>
        private void fixStorico()
        {
            pnlSAO.Visible = Postazione.showStorico;
        }
        /// <summary>
        /// update generale controlli
        /// </summary>
        private void doUpdate()
        {
            updateMessCss();
            fixPanels();
            mod_storicoAzioniOperatore1.doUpdate();
        }
        /// <summary>
        /// calcola postazione corrente (ip, name, printer)
        /// </summary>
        private void updatePrinterPostazione()
        {
            Postazione.IP = Request.UserHostName;
            Postazione.setupPrinter();
            // mostro warning se postazione non configurata...
            if (Postazione.printer == "n.d.")
            {
                lblWarning.Text = traduci("lblWarnPostNonConf");
            }
        }
    }
}