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

namespace GMW.WebUserControls
{
  public partial class mod_part2kit : 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>
    /// inserisce nuovo valore da footer
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lblIns_click(object sender, EventArgs e)
    {
      // click su inserimento, chiamo il metodo insert dell'ObjectDataSource
      ods.Insert();
    }
    /// <summary>
    /// gestione evento richiesta nuovo valore (mostra footer, ...)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnNewFromEmpty_Click(object sender, EventArgs e)
    {
      // creo nuova riga "standard"                                                     
      creaNuova();
      // reset selezione...
      resetSelezione();
    }
    /// <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)
    {
      // creo nuova riga NON ATTIVA!!!
      creaNuova();
      // reset selezione...
      resetSelezione();
    }
    /// <summary>
    /// Creo una nuova linea andando a creare prima tutte el dipendenze...
    /// </summary>
    private void creaNuova()
    {
      MagClass.magazzino.taRK2P.insertQuery(CodKIT, ddlParticolari.SelectedValue, 1);
      doUpdate();
    }

    public void doUpdate()
    {
      ddlParticolari.DataBind();
      grView.DataBind();
    }

    /// <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);
    }

    public string CodKIT
    {
      get
      {
        return hfCodKIT.Value;
      }
      set
      {
        if (string.IsNullOrEmpty(value)) value = "###";
        hfCodKIT.Value = value;
      }
    }

    protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
    }
    /// <summary>
    /// Verifica NON sia linea root (=termina x 00)
    /// </summary>
    /// <param name="_codLinea"></param>
    /// <returns></returns>
    public bool isNotRoot(object _codLinea)
    {
      bool answ = false;
      if (!_codLinea.ToString().EndsWith("00")) answ = true;
      return answ;
    }

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

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