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

namespace GMW
{
    public partial class PostFin_DT : System.Web.UI.Page
    {
        /// <summary>
        /// caricamento pagina!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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("IdxPosizioneFiniti");
            }

            // update vari...
            doUpdate();
            mod_storicoAzioniOperatore1.eh_stampa += new EventHandler(mod_storicoAzioniOperatore1_eh_stampa);
            mod_PostFin_DT.doUpdate();
            mod_PostFin_DT.eh_ucev += Mod_PostFin_DT_eh_ucev;
            mod_selLineaNtDt1.eh_lineSelected += mod_selLineaNtDt1_eh_doRefresh;
            mod_selLineaNtDt1.eh_showHideStorico += mod_selLineaNtDt1_eh_showHideStorico;
        }

        private void Mod_PostFin_DT_eh_ucev(object sender, EventArgs e)
        {
            ucEvent evento = (ucEvent)e;
            switch (evento.tipoEvento)
            {
                case ucEvType.Delete:
                    break;
                case ucEvType.Edit:
                    break;
                case ucEvType.New:
                    break;
                case ucEvType.Reset:
                    break;
                case ucEvType.ReqUpdateParent:
                    doUpdate();
                    break;
                case ucEvType.Selected:
                    break;
                default:
                    break;
            }
        }

        /// <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_PostFin_DT.doUpdate();
        }
        /// <summary>
        /// richiesta update del controllo SAO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mod_PostRX_DT1_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_PostFin_DT.ristampa();
        }
        /// <summary>
        /// sistemo visualizzazione pannelli
        /// </summary>
        private void fixPanels()
        {
            // default: moduli NON visibili SE non ho linea indicata..
            bool enableBtn = false;
            if (Postazione.currCodCella != "") enableBtn = true;
            mod_PostFin_DT.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();
            // 2015.04.20 modifica vers 2.9 x gesitone multi Dmtx: imposto formato Dmtx su selezione... 
            mod_selLineaNtDt1.formatoDmtx = Postazione.formatoDmtx;
            // mostro warning se postazione non configurata...
            if (Postazione.printer == "n.d.")
            {
                lblWarning.Text = traduci("lblWarnPostNonConf");
            }
        }
    }
}