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

namespace GMW.WebUserControls
{
  public partial class mod_confLinea : ApplicationUserControl
  {

    public string codLinea
    {
      get
      {
        return hfCodLinea.Value;
      }
      set
      {
        hfCodLinea.Value = value;
        grView.DataBind();
      }
    }
    /// <summary>
    /// Calcola css da Modo (1 = passa, 0 = non passa)
    /// </summary>
    /// <param name="_modo"></param>
    /// <returns></returns>
    public static string cssFromModo(object _modo)
    {
      int val = 0;
      string answ = "";
      bool convOk = int.TryParse(_modo.ToString(), out val);
      switch (val)
      {
        case 0:
          answ = "text-danger fa fa-ban";
          break;
        case 1:
          answ = "text-success fa fa-check";
          break;
        default:
          answ = "fa fa-question";
          break;
      }
      return answ;
    }
    /// <summary>
    /// Aggiunta nuovo record...
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtAddNew_Click(object sender, EventArgs e)
    {
      // creo un NUOVO record con funzionalità "PASS" di default...
      MagClass.magazzino.taConfLin.Insert(codLinea, "Particolare", "Cod Particolare", 1);
      grView.DataBind();
      resetRedisCache();
    }

    protected void ods_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
    {
      resetRedisCache();
    }

    protected void ods_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
      resetRedisCache();
    }

    private void resetRedisCache()
    {
      // effettua reset in redis di EVENTUALI chaivi segnalate...
      string mHash = memLayer.ML.redHash($"lineePartVeto");
      memLayer.ML.redFlushKey(mHash);
    }
  }
}