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}"); } }
private void BindGrid() { try { grdFruttiInGruppo.DataSource = CompGruppoFrutDAO.GetCompGruppo(Convert.ToInt32(ddlScegliGruppo.SelectedValue)); grdFruttiInGruppo.DataBind(); txtQuantitàFrutto.Text = ""; btnInserisciFruttoInGruppo.Visible = true; btnModificaFruttoInGruppo.Visible = !btnInserisciFruttoInGruppo.Visible; } catch (Exception ex) { (Master as layout).SetAlert("alert-danger", $"Errore durante il BindGrid - {ex.Message}"); } }
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}"); } }
protected void btnInserisciFruttoInGruppo_Click(object sender, EventArgs e) { try { if (txtQuantitàFrutto.Text != "" && txtQuantitàFrutto.Text != "0") { CompGruppoFrutDAO.Insert(new CompGruppoFrut { IdTblGruppo = Convert.ToInt32(ddlScegliGruppo.SelectedValue), IdTblFrutto = Convert.ToInt32(ddlScegliFrutto.SelectedValue), Qta = Convert.ToInt32(txtQuantitàFrutto.Text) }); (Master as layout).SetAlert("alert-success", "Frutto inserito con successo"); BindGrid(); } } catch (Exception ex) { (Master as layout).SetAlert("alert-danger", $"Errore durante l'inserimento del frutto selezionato - {ex.Message}"); } }
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(); }
protected void MostraComponentiGruppo(int idGruppo) { lblPanelTitleGroupName.Text = GruppiFruttiDAO.GetSingle(idGruppo).NomeGruppo; componentiGruppo = CompGruppoFrutDAO.GetCompGruppo(idGruppo); }
/* HELPERS */ protected void BindGrid() { grdFruttiInGruppo.DataSource = CompGruppoFrutDAO.GetFruttiInGruppi(ddlScegliGruppo.SelectedItem?.Value ?? ""); grdFruttiInGruppo.DataBind(); }