protected void grdGruppi_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         int            idCompGruppoFrutto = Convert.ToInt32(e.CommandArgument);
         CompGruppoFrut componente         = CompGruppoFrutDAO.GetSingle(idCompGruppoFrutto);
         if (e.CommandName == "Visualizza")
         {
             ddlScegliFrutto.Enabled            = txtQuantitàFrutto.Enabled = false;
             ddlScegliFrutto.SelectedValue      = componente.IdTblFrutto.ToString();
             txtQuantitàFrutto.Text             = componente.Qta.ToString();
             btnInserisciFruttoInGruppo.Visible = btnModificaFruttoInGruppo.Visible = false;
         }
         if (e.CommandName == "Modifica")
         {
             ddlScegliFrutto.Enabled            = txtQuantitàFrutto.Enabled = true;
             hfIdCompGruppoFrutto.Value         = idCompGruppoFrutto.ToString();
             ddlScegliFrutto.SelectedValue      = componente.IdTblFrutto.ToString();
             txtQuantitàFrutto.Text             = componente.Qta.ToString();
             btnInserisciFruttoInGruppo.Visible = false;
             btnModificaFruttoInGruppo.Visible  = !btnInserisciFruttoInGruppo.Visible;
         }
         if (e.CommandName == "Elimina")
         {
             CompGruppoFrutDAO.Delete(idCompGruppoFrutto);
             (Master as layout).SetAlert("alert-success", $"Frutto \"{componente.NomeFrutto}\" eliminato con successo");
             BindGrid();
         }
     }
     catch (Exception ex)
     {
         (Master as layout).SetAlert("alert-danger", $"Errore durante il grdGruppi_RowCommand in GestisciGruppi - {ex.Message}");
     }
 }
示例#2
0
        // UPDATE
        public static bool Update(CompGruppoFrut item)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder("UPDATE TblCompGruppoFrut SET IdTblGruppo = @IdTblGruppo, IdTblFrutto = @IdTblFrutto, Qta = @Qta WHERE Id = @Id");

            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), item) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante la Update in CompGruppoFrutDAO", ex);
            }
            return(ret);
        }
示例#3
0
        // INSERT
        public static bool Insert(CompGruppoFrut item)
        {
            bool          ret = false;
            StringBuilder sql = new StringBuilder("INSERT INTO TblCompGruppoFrut(IdTblGruppo,IdTblFrutto,Qta) VALUES (@IdTblGruppo,@IdTblFrutto,@Qta)");

            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Execute(sql.ToString(), item) > 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante la Insert in CompGruppoFrutDAO", ex);
            }
            return(ret);
        }
示例#4
0
        // SELECT
        public static CompGruppoFrut GetSingle(int idCompGruppoFrutto)
        {
            CompGruppoFrut ret = new CompGruppoFrut();
            StringBuilder  sql = new StringBuilder();

            sql.AppendLine("SELECT CGF.Id, F.descr001 'NomeFrutto', CGF.IdTblFrutto, Qta");
            sql.AppendLine("FROM TblCompGruppoFrut AS CGF");
            sql.AppendLine("INNER JOIN TblFrutti AS F ON CGF.IdTblFrutto = F.ID1");
            sql.AppendLine("WHERE Id = @idCompGruppoFrutto");
            sql.AppendLine("ORDER BY CGF.Id ASC");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Query <CompGruppoFrut>(sql.ToString(), new { idCompGruppoFrutto }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante la GetSingle in CompGruppoFrutDAO", ex);
            }
            return(ret);
        }