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

namespace GMW.WebUserControls
{
  public partial class mod_anagKit : ApplicationUserControl
  {
    /// <summary>
    /// reset della selezione
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReset_Click(object sender, EventArgs e)
    {
      resetSelezione();
    }
    /// <summary>
    /// resetta la selezione dei valori in caso di modifiche su altri controlli
    /// </summary>
    public void resetSelezione()
    {
      grView.SelectedIndex = -1;
      grView.DataBind();
      raiseEvent(ucEvType.Reset);
    }
    /// <summary>
    /// gestione evento richiesta nuovo valore (mostra footer, ...)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnNew_Click(object sender, EventArgs e)
    {
      // conto quanti record e uso codice KINAN + num progressivo...
      int newIdx = MagClass.magazzino.taAK.GetData().Count + 1;
      MagClass.magazzino.taAK.insertQuery(string.Format("KITAN{0:00000}", newIdx), "Descrizione KIT", 1);
      // reset selezione...
      resetSelezione();
    }
    /// <summary>
    /// determina se sia eliminabile il record (=non usato)
    /// </summary>
    /// <param name="idxMaker"></param>
    /// <returns></returns>
    public bool delEnabled(object idxObj)
    {
      bool answ = isWritable();

      return answ;
    }

    /// <summary>
    /// elenco colonne del datagrid
    /// </summary>
    /// <returns></returns>
    protected DataColumnCollection colonneObj()
    {
      DS_DataMatrix.TabSpecDtxDataTable tabella = new DS_DataMatrix.TabSpecDtxDataTable();
      DataColumnCollection colonne = tabella.Columns;
      return colonne;
    }
   
    protected void grView_SelectedIndexChanged(object sender, EventArgs e)
    {
      raiseEvent(ucEvType.Selected);
    }

    protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
      //if (e.InputParameters["DataFormat"] == null) e.InputParameters["DataFormat"] = "";
    }

    public string CodKITSel
    {
      get
      {
        string answ = "";
        try
        {
          answ = grView.SelectedValue.ToString();        
        }
        catch
        { }
        return answ;
      }
    }

    public bool toBool(object value)
    {
      bool answ = false;
      try
      {
        answ = Convert.ToBoolean(value);
      }
      catch
      { }
      return answ;
    }
  }
}