public static GruppiFrutti GetSingle(int idGruppo, DBTransaction tr) { GruppiFrutti ret = new GruppiFrutti(); StringBuilder sql = new StringBuilder("SELECT * FROM TblGruppiFrutti WHERE Id = @idGruppo"); try { ret = tr.Connection.Query <GruppiFrutti>(sql.ToString(), new { idGruppo }, tr.Transaction).FirstOrDefault(); } catch (Exception ex) { throw new Exception("Errore durante la GetSingle in GruppiFruttiDAO", ex); } return(ret); }
public static GruppiFrutti GetByNome(string nomeGruppo) { GruppiFrutti ret = new GruppiFrutti(); StringBuilder sql = new StringBuilder("SELECT * FROM TblGruppiFrutti WHERE NomeGruppo = @nomeGruppo"); try { using (SqlConnection cn = GetConnection()) { ret = cn.Query <GruppiFrutti>(sql.ToString(), new { nomeGruppo }).FirstOrDefault(); } } catch (Exception ex) { throw new Exception("Errore durante la GetByNome in GruppiFruttiDAO", ex); } return(ret); }
protected void grdGruppi_RowCommand(object sender, GridViewCommandEventArgs e) { try { int idGruppo = Convert.ToInt32(e.CommandArgument); GruppiFrutti gruppo = GruppiFruttiDAO.GetSingle(idGruppo); if (e.CommandName == "Visualizza") { txtNomeGruppo.Enabled = txtDescrizioneGruppo.Enabled = false; txtNomeGruppo.Text = gruppo.NomeGruppo; txtDescrizioneGruppo.Text = gruppo.Descrizione; btnInserisciGruppo.Visible = btnModificaGruppo.Visible = false; } if (e.CommandName == "Modifica") { txtNomeGruppo.Enabled = txtDescrizioneGruppo.Enabled = true; txtNomeGruppo.Text = gruppo.NomeGruppo; txtDescrizioneGruppo.Text = gruppo.Descrizione; hfIdGruppo.Value = idGruppo.ToString(); btnInserisciGruppo.Visible = false; btnModificaGruppo.Visible = !btnInserisciGruppo.Visible; } if (e.CommandName == "Elimina") { if (CompGruppoFrutDAO.GetCompGruppo(idGruppo).Count <= 0) { GruppiFruttiDAO.DeleteGruppo(idGruppo); (Master as layout).SetAlert("alert-success", $"Gruppo {gruppo.NomeGruppo} eliminato con successo"); BindGrid(); } else { (Master as layout).SetAlert("alert-danger", $"Impossibile eliminare il gruppo, perchè contiene dei componenti"); } } } catch (Exception ex) { (Master as layout).SetAlert("alert-danger", $"Errore durante il grdGruppi_RowCommand in GestisciGruppi - {ex.Message}"); } }
public static bool UpdateGruppo(GruppiFrutti item) { bool ret = false; StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE TblGruppiFrutti"); sql.AppendLine("SET NomeGruppo = @NomeGruppo, Descrizione = @Descrizione"); sql.AppendLine("WHERE Id = @Id"); try { using (SqlConnection cn = GetConnection()) { ret = cn.Execute(sql.ToString(), item) > 0; } } catch (Exception ex) { throw new Exception("Errore durante l'aggiornamento di un gruppo", ex); } return(ret); }
protected void btnClonaGruppo_Click(object sender, EventArgs e) { DBTransaction tr = new DBTransaction(); tr.Begin(); try { int idGruppo = Convert.ToInt32(ddlScegliGruppo.SelectedItem.Value); GruppiFrutti gf = GruppiFruttiDAO.GetSingle(idGruppo, tr); int idGruppoCopia = GruppiFruttiDAO.InserisciGruppo("Copia" + gf.NomeGruppo, gf.Descrizione, tr); List <CompGruppoFrut> components = CompGruppoFrutDAO.GetCompGruppo(idGruppo, tr); components.ForEach(f => f.IdTblGruppo = idGruppoCopia); CompGruppoFrutDAO.InsertList(components, tr); tr.Commit(); } catch (Exception ex) { tr.Rollback(); (Master as layout).SetAlert("alert-danger", $"Errore durante la clonazione del gruppo selezionato - {ex.Message}"); } (Master as layout).SetAlert("alert-success", "Gruppo clonato con successo"); BindGrid(); }