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


namespace GMW.WebUserControls
{
    public partial class mod_detailParticolari : SteamWare.ApplicationUserControl
    {
        #region area da NON modificare

        #region area protected

        protected string _idxGridView;
        protected string _idxGridViewExt;
        protected string _tabCache;

        /// <summary>
        /// aggiorna controlli datagrid e numero righe in pagina
        /// </summary>
        protected override void aggiornaControlliDataGL()
        {
            base.aggiornaControlliDataGL();
            grView.PageSize = _righeDataGridMed;
        }
        /// <summary>
        /// traduce gli header delle colonne
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grView_DataBound(object sender, EventArgs e)
        {
            if (grView.Rows.Count > 0)
            {
                LinkButton lb;
                // aggiorno gli headers        
                foreach (TableCell cella in grView.HeaderRow.Cells)
                {
                    try
                    {
                        lb = (LinkButton)cella.Controls[0];
                        lb.Text = traduci(lb.Text);
                    }
                    catch
                    { }
                }
                int totRecord = grView.Rows.Count + grView.PageSize * (grView.PageCount - 1);
                lblNumRec.Text = string.Format("{0} records of ~ {1}", grView.Rows.Count, totRecord);
            }
            else
            {
                lblNumRec.Text = "";
            }
        }
        /// <summary>
        /// reset della selezione
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReset_Click(object sender, EventArgs e)
        {
            resetSelezione();
        }


        /// <summary>
        /// collega i controlli
        /// </summary>
        protected override void bindControlli()
        {
            base.bindControlli();
            caricaTabelle();
        }

        #endregion

        #region gestione eventi

        public event EventHandler eh_resetSelezione;
        //public event EventHandler eh_nuovoValore;
        public event EventHandler eh_selValore;

        #endregion

        #region public

        /// <summary>
        /// effettua update del modulo
        /// </summary>
        public void doUpdate()
        {
            resetSelezione();
        }


        #endregion

        #endregion

        #region area codice variabile

        /// <summary>
        /// carico le tabelle
        /// </summary>
        private void caricaTabelle()
        {
        }
        /// <summary>
        /// elenco colonne del datagrid
        /// </summary>
        /// <returns></returns>
        protected DataColumnCollection colonneObj()
        {
            DS_magazzino.V_DettMagPartDataTable tabella = new DS_magazzino.V_DettMagPartDataTable();
            DataColumnCollection colonne = tabella.Columns;
            return colonne;
        }
        /// <summary>
        /// inizializzazione valori di default
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        /// <summary>
        /// segnalo nuovo valore filtro attivo...
        /// </summary>
        private void checkFixOds()
        {
            grView.DataBind();
        }
        /// <summary>
        /// aggiorno visualizzazione
        /// </summary>
        private void updateOdsDaFiltro()
        {
            grView.DataBind();
        }
        /// <summary>
        /// chiamata post page change gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grView_PageIndexChanged(object sender, EventArgs e)
        {
            // sistemazione dell'ods post evento cambio pagina
            checkFixOds();
        }
        /// <summary>
        /// chiamata post sort gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grView_Sorted(object sender, EventArgs e)
        {
            // sistemazione dell'ods post evento sort
            checkFixOds();
        }
        /// <summary>
        /// gestione cambio selezione valore
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // leggo chiave
            string DescStato    = grView.SelectedDataKey["DescStato"].ToString();
            string Esponente    = grView.SelectedDataKey["Esponente"].ToString();
            string CodMag       = grView.SelectedDataKey["CodMag"].ToString();
            int IdxBlocco       = Convert.ToInt32(grView.SelectedDataKey["IdxBlocco"]);
            string CodMagLog    = grView.SelectedDataKey["CodMagLog"].ToString();
            // salvo in session
            SteamWare.memLayer.ML.setSessionVal("CodMag_sel", CodMag, false);
            SteamWare.memLayer.ML.setSessionVal("IdxBlocco_sel", IdxBlocco, false);
            memLayer.ML.setSessionVal("CodMagLogico_sel", CodMagLog, false);
            // sollevo evento nuovo valore...
            if (eh_selValore != null)
            {
                eh_selValore(this, new EventArgs());
            }
        }

        /// <summary>
        /// resetta la selezione dei valori in caso di modifiche su altri controlli
        /// </summary>
        public void resetSelezione()
        {
            //SteamWare.memLayer.ML.emptySessionVal("DescStato_sel");
            //SteamWare.memLayer.ML.emptySessionVal("Esponente_sel");
            grView.SelectedIndex = -1;
            grView.DataBind();
            lblWarning.Visible = false;
            if (eh_resetSelezione != null)
            {
                eh_resetSelezione(this, new EventArgs());
            }
        }
        #endregion
    }
}