/* GRID VIEW EVENTS */
 protected void grdFrutti_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         int idFrutto = Convert.ToInt32(e.CommandArgument);
         if (e.CommandName == "Modifica")
         {
             Frutto frutto = FruttiDAO.GetSingle(idFrutto);
             txtNomeFrutto.Text       = frutto.Descr001;
             hfIdFrutto.Value         = frutto.Id1.ToString();
             btnInsFrutto.Visible     = false;
             btnSaveModFrutto.Visible = !btnInsFrutto.Visible;
         }
         else if (e.CommandName == "Elimina")
         {
             bool isDeleted = FruttiDAO.DeleteFrutto(idFrutto);
             if (isDeleted)
             {
                 lblMsg.Text      = $"Frutto eliminato con successo";
                 lblMsg.ForeColor = Color.Blue;
             }
             else
             {
                 lblMsg.Text      = $"Impossibile eliminare il frutto, verificare che non sia referenziato in altre tabelle";
                 lblMsg.ForeColor = Color.Red;
             }
             BindGrid();
         }
     }
     catch (Exception ex)
     {
         lblMsg.Text = $"Errore durante il grdFrutti_RowCommand in GestisciFrutti.aspx.cs ===> {ex.Message}";
     }
 }
Esempio n. 2
0
        public static bool UpdateFrutto(Frutto item)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder("UPDATE TblFrutti SET descr001 = @Descr001 WHERE ID1 = @Id1");

            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), item) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante l'aggiornamento di un frutto", ex);
            }
            return(ret);
        }