private void btnAggiungi_Click(object sender, EventArgs e) { if (lstInfezioni.SelectedItems.Count == 1 && numeroPG.HasValue) { DialogResult res = MessageBox.Show("Vuoi aggiungere questa malattia al personaggio " + numeroPG.Value.ToString() + "?", "Sei sicuro?", MessageBoxButtons.YesNo); long progressivo = (long)lstInfezioni.SelectedValue; if (res == System.Windows.Forms.DialogResult.Yes) { using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); bool result = manager.AddInfectionToCharacter(numeroPG.Value, progressivo); if (result) { databaseContext.SaveChanges(); MessageBox.Show("Infezione aggiunta al personaggio"); this.Close(); } else { MessageBox.Show("C'è stato un problema durante il salvataggio"); } } } } }
private void btnRimuoviInfezione_Click(object sender, EventArgs e) { if (grdMalattie.SelectedRows.Count == 1) { DialogResult res = MessageBox.Show("Vuoi rimuovere questa malattia dal personaggio?", "Sei sicuro?", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { long numeroPG = (long)grdPersonaggi.SelectedRows[0].Cells["NumeroPG"].Value; long progressivo = (long)grdMalattie.SelectedRows[0].Cells["Progressivo"].Value; using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); bool result = manager.RemoveInfectionFromCharacter(numeroPG, progressivo); if (result) { databaseContext.SaveChanges(); MessageBox.Show("Infezione eliminata correttamente"); LoadMalattie(); } else { MessageBox.Show("C'è stato un errore nel salvataggio"); LoadMalattie(); } } } } }
private void LoadData() { using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); lstInfezioni.DataSource = manager.GetAllInfections(); } }
private void lstInfezioni_SelectedValueChanged(object sender, EventArgs e) { if (lstInfezioni.SelectedValue != null) { long progressivo = (long)lstInfezioni.SelectedValue; using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); txtDescrizioneSelezionato.Text = manager.GetInfectionDescription(progressivo); } } else { txtDescrizioneSelezionato.Text = string.Empty; } }
private void btnSalva_Click(object sender, EventArgs e) { if (ValidateForm()) { using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); bool res = manager.InsertNewInfection(txtNome.Text, txtDescrizioneNuovo.Text); if (res) { databaseContext.SaveChanges(); MessageBox.Show("Infezione inserita correttamente"); this.Close(); } else { MessageBox.Show("C'è stato un errore durante il salvataggio"); } } } }
private void LoadMalattie() { if (grdPersonaggi.SelectedRows.Count == 1) { long numeroPG = (long)grdPersonaggi.SelectedRows[0].Cells["NumeroPG"].Value; using (databaseContext = CreateDatabaseContext()) { InfezioniManager manager = new InfezioniManager(databaseContext); grdMalattie.DataSource = manager.GetInfectionsByCharacter(numeroPG); } } else { grdMalattie.DataSource = new List<Infezione>(); } }