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

namespace GMW.WebUserControls
{
    public partial class mod_confMag : SteamWare.ApplicationUserControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        public void doUpdate()
        {
            bindControlli();
        }

        protected override void bindControlli()
        {
            fixLabels();
            fixValues();
        }

        private void fixValues()
        {
            lblTotaleImpieghi.Text = traduci("lblTotaleImpieghi");
            lblTotCelleDaTipo.Text = traduci("lblTotCelleDaTipo");
            lblTotCapacita.Text = traduci("lblTotCapacita");
            lblTotCelleCreate.Text = traduci("lblTotCelleCreate");
            lblTotCelleDaBlocchi.Text = traduci("lblTotCelleDaBlocchi");
            lblDettImpieghiBlocchi.Text = traduci("lblDettImpieghiBlocchi");
            lblAttive.Text = traduci("lblAttive");
            lblInattive.Text = traduci("lblInattive");
            lblAss.Text = traduci("lblAss");
            lblNonAss.Text = traduci("lblNonAss");
        }

        private void fixLabels()
        {
            showImpieghiTotali();
            showImpieghiBlocco();
        }

        private void showImpieghiBlocco()
        {
            // calcolo valori: attive assegnate
            int? celleAttiveAss = 0;
            utils.obj.taSTP.stp_ContaCelleBlocco(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), true, true, ref celleAttiveAss);
            if (!celleAttiveAss.HasValue) celleAttiveAss = 0;
            // calcolo valori: attive NON assegnate
            int? celleAttiveNonAss = 0;
            utils.obj.taSTP.stp_ContaCelleBlocco(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), true, false, ref celleAttiveNonAss);
            if (!celleAttiveNonAss.HasValue) celleAttiveNonAss = 0;

            // calcolo valori: NON attive assegnate
            int? celleNonAttiveAss = 0;
            utils.obj.taSTP.stp_ContaCelleBlocco(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), false, true, ref celleNonAttiveAss);
            if (!celleNonAttiveAss.HasValue) celleNonAttiveAss = 0;
            // calcolo valori: NON attive assegnate
            int? celleNonAttiveNonAss = 0;
            utils.obj.taSTP.stp_ContaCelleBlocco(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), false, false, ref celleNonAttiveNonAss);
            if (!celleNonAttiveNonAss.HasValue) celleNonAttiveNonAss = 0;
            // altri valori
            lblAssAtt.Text = celleAttiveAss.ToString();
            lblAssInatt.Text = celleNonAttiveAss.ToString();
            lblNonAssAtt.Text = celleAttiveNonAss.ToString();
            lblNonAssInatt.Text = celleNonAttiveNonAss.ToString();
        }

        private void showImpieghiTotali()
        {
            // calcolo valori
            int? totCapa = 0;
            utils.obj.taSTP.stp_ContaCelleCapa(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), ref totCapa);
            if (!totCapa.HasValue) totCapa = 0;
            int? totCelleTipo = 0;
            utils.obj.taSTP.stp_ContaCelle4Tipo(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), ref totCelleTipo);
            if (!totCelleTipo.HasValue) totCelleTipo = 0;
            int? totCelleBlocchi = 0;
            utils.obj.taSTP.stp_ContaCelle4Blocchi(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), ref totCelleBlocchi);
            if (!totCelleBlocchi.HasValue) totCelleBlocchi = 0;
            int? totCelleCreate = 0;
            utils.obj.taSTP.stp_ContaCelleCreate(memLayer.ML.cdv("CodCS"), memLayer.ML.StringSessionObj("CodMag_sel"), ref totCelleCreate);
            if (!totCelleCreate.HasValue) totCelleCreate = 0;
            // controllo cosa inserire nel check...
            Style ctrlStyle = new Style();
            if ((totCelleBlocchi == totCelleTipo) && (totCelleTipo == totCelleCreate))
            {
                ctrlStyle.CssClass = "text-success";
            }
            else
            {
                ctrlStyle.CssClass = "text-danger";
            }
            // applico style
            lblNumCelleDaTipo.ApplyStyle(ctrlStyle);
            lblNumCelleDaBlocchi.ApplyStyle(ctrlStyle);
            lblNumCelleCreate.ApplyStyle(ctrlStyle);
            // inserisco valori
            lblNumCapacita.Text = totCapa.ToString();
            lblNumCelleDaTipo.Text = totCelleTipo.ToString();
            lblNumCelleDaBlocchi.Text = totCelleBlocchi.ToString();
            lblNumCelleCreate.Text = totCelleCreate.ToString();
        }
    }
}