private void AggiungiAgevolazioneEccezionale(object sender, EventArgs args) { ElementoNoleggio elementoNoleggio = (ElementoNoleggio)Adapter <ElementoNoleggio, ElementoNoleggioAdapted> .Revert((ElementoNoleggioAdapted)_target.ElementiNoleggioDataGridView.CurrentRow.DataBoundItem); using (ChooseForm form = new ChooseForm()) { //creazione filtro (che in realtà è solo un messaggio) Label messaggio = new Label(); messaggio.Text = "Seleziona l'agevolazione eccezionale"; messaggio.Width = 300; Panel p = new Panel(); p.Controls.Add(messaggio); form.AddFilter(p); //form form.DataGridView.MultiSelect = false; //popolamento tabella form.DataGridView.DataSource = Negozio.GetInstance().AgevolazioniEccezionali.Cast <Agevolazione>().ToList(); if (form.ShowDialog() == DialogResult.OK) { elementoNoleggio.AgevolazioneEccezionale = (IAgevolazioneEccezionale)form.DataGridView.CurrentRow.DataBoundItem; Console.WriteLine((elementoNoleggio.AgevolazioneEccezionale as Agevolazione).Nome); _target.ElementiNoleggioDataGridView.Refresh(); /*La nuova agevolazione eccezionale non è visualizzata nella tabella perchè è un'interfaccia, * anche se da come si vede dalla stampa su console l'oggetto viene aggiornato*/ _target.PrezzoTotaleLabel.Text = string.Format("Prezzo totale: {0}", _noleggio.CalcolaPrezzo(_durataEffettiva, Negozio.MINUTI_TOLLERANZA).ToEuroString()); } ShowPrezzoSingoloElemento(this, EventArgs.Empty); } }
private void RefreshDataGrid(object sender, ChangedEventArgs e) { if (e.TipoEvento == TipoEvento.InserimentoNuovoTipoElemento || e.TipoEvento == TipoEvento.ModificaTipoElemento || e.TipoEvento == TipoEvento.DisattivazioneTipoElemento || e.TipoEvento == TipoEvento.CambiamentoFiltro) { _target.DataGridView.DataSource = typeof(BindingList <>); _target.DataGridView.DataSource = Negozio.GetTipiPerCategoria(_filterBox.SelectedItem.ToString()).ToList(); } }
/// <summary> /// Crea un edificio del tipo specificato alla posizione specificata e sottrae soldi. /// <para>0: industria, 1: fabbrica, 2: negozio; default: 0</para> /// </summary> /// <param name="x">Coordinata x</param> /// <param name="y">Coordinata y</param> /// <param name="tipo">Tipo dell'edificio</param> /// <param name="fenoglioIlPortafoglio">Portafoglio del giocatore che crea l'edificio</param> public bool AggiungiEdificio(int row, int col, int tipo, Giocatore gio) { Edificio tmp; switch (tipo) { default: case 0: tmp = new Industria(gio, CelleMateriali[row, col]); if (gio.portafogli.Soldi >= tmp.Prezzo) { gio.portafogli.Soldi -= tmp.Prezzo; } else { return(false); } break; case 1: tmp = new Fabbrica(gio); if (gio.portafogli.Soldi >= tmp.Prezzo) { gio.portafogli.Soldi -= tmp.Prezzo; } else { return(false); } break; case 2: tmp = new Negozio(gio); if (gio.portafogli.Soldi >= tmp.Prezzo) { gio.portafogli.Soldi -= tmp.Prezzo; } else { return(false); } break; } CelleEdifici[row, col] = tmp; return(true); }
// Crea, inizializza e aggiunge al Target.TableLayoutPanel nell’ordine: una Label e una TextBox. private void AddRow(EditingProperty editingProperty) { // Per inizializzare la Label: // assegnare alla proprietà Text il valore della proprietà Label di editableAttribute; // assegnare alla proprietà AutoSize il valore true, in modo che il testo venga visualizzato correttamente. // Per inizializzare la TextBox: // dimensionare il controllo in modo che // la larghezza sia pari al valore della proprietà Width di editableAttribute e // l’altezza sia pari al valore della proprietà PreferredHeight del controllo stesso; // se la editingProperty è read-only, // disabilitare la TextBox (utilizzare la proprietà Enabled); // assegnare alla proprietà Tag il valore di editingProperty; // infine, collegare all’evento Validating della TextBox il gestore ValidatingHandler. Label label = new Label(); label.Text = editingProperty.Label; label.AutoSize = true; Target.TableLayoutPanel.Controls.Add(label); Control tb = null; if (editingProperty.Mode == "Combo") { tb = new ComboBox(); if (editingProperty.Label.StartsWith("Tipo")) { Type categoria = typeof(Elemento).GetSubtypes().Where(t => t.Name.ToUpper() == editingProperty.Label.Substring(4).ToUpper()).First(); ((ComboBox)tb).Items.AddRange(Negozio.GetInstance().GetTipiPerCategoria(categoria).ToArray()); ((ComboBox)tb).SelectedItem = ((ComboBox)tb).Items.OfType <TipoElemento>().First(); } else if (editingProperty.Label.StartsWith("Stato")) { ((ComboBox)tb).Items.AddRange(Negozio.GetInstance().StatiElemento.ToArray()); ((ComboBox)tb).SelectedItem = ((ComboBox)tb).Items.OfType <StatoElemento>().First(); } } else { tb = new TextBox(); tb.Height = ((TextBox)tb).PreferredHeight; } tb.Width = editingProperty.Width; tb.Enabled = checkIfEnabled(editingProperty); tb.Tag = editingProperty; tb.Validating += ValidatingHandler; Target.TableLayoutPanel.Controls.Add(tb); }
public static void AggiungiDipendenti() { // Creare un nuovo elemento (servizio di Negozio) // Invocare il metodo Modifica // In caso di successo, aggiungere l'elemento al negozio (servizio di Negozio) IDipendente nuovo = Negozio.NuovoDipendente(); if (NoleggioServices.Modifica(nuovo, true)) { if (!Negozio.InserisciNuovoDipendente(nuovo)) { MessageBox.Show("Impossibile aggiungere questo dipendente. Il nome utente esiste già.", "Errore inserimento dipendente", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static void AggiungiElementi() { // Creare un nuovo elemento (servizio di Negozio) // Invocare il metodo Modifica // In caso di successo, aggiungere l'elemento al negozio (servizio di Document) string categoria = null; //Faccio scegliere la categoria using (ListForm listForm = new ListForm()) { listForm.EditButton.Enabled = false; listForm.AddButton.Enabled = false; listForm.DeleteButton.Enabled = false; listForm.DataSource = Negozio.Categorie; listForm.Text = "Scelta categoria elemento"; Label label = new Label(); label.Text = "Scegliere la categoria dell'elemento"; label.TextAlign = ContentAlignment.MiddleCenter; label.Anchor = AnchorStyles.Top; label.AutoSize = true; listForm.SetFilter(label); listForm.Size = new Size(568, 355); listForm.OkButton.DialogResult = DialogResult.OK; if (listForm.ShowDialog() == DialogResult.OK && listForm.DataGridView.CurrentRow != null) { categoria = listForm.DataGridView.CurrentRow.DataBoundItem.ToString(); } else { return; } } Elemento elemento = Negozio.NuovoElemento(categoria); if (NoleggioServices.Modifica(elemento, true)) { Negozio.InserisciNuovoElemento(elemento); } }
private static void Test_Prodotti() { Negozio n = new Negozio(); for (int i = 0; i < 3; i++) { string s = System.Console.ReadLine(); string[] arrSp = s.Split(new char[] { ' ' }); int cod = Int32.Parse(arrSp[0]); string desc = arrSp[1]; double price = Convert.ToDouble(arrSp[2]); double sconto = Convert.ToDouble(arrSp[3]); Prodotto p = new Prodotto(cod, desc, price, sconto); n.Prodotti.Add(p); } foreach (Prodotto p in n.Prodotti) { System.Console.WriteLine("Codice: " + p.Codice.ToString() + " - Descrizione: " + p.Descrizione.ToString() + " - Prezzo: " + p.Prezzo.ToString() + "$"); } }
private static void Test_ProdottiInOfferta() { Negozio n = new Negozio("mario"); for (int i = 0; i < 3; i++) { string s = System.Console.ReadLine(); string[] arrSp = s.Split(new char[] { ' ' }); int cod = Int32.Parse(arrSp[0]); string desc = arrSp[1]; double price = Convert.ToDouble(arrSp[2]); double sconto = Convert.ToDouble(arrSp[3]); string[] numDataIn = arrSp[4].Split(new char[] { '/' }); int giornoIn = Int32.Parse(numDataIn[0]); int meseIn = Int32.Parse(numDataIn[1]); int annoIn = Int32.Parse(numDataIn[2]); string[] numDataEnd = arrSp[5].Split(new char[] { '/' }); int giornoEnd = Int32.Parse(numDataEnd[0]); int meseEnd = Int32.Parse(numDataEnd[1]); int annoEnd = Int32.Parse(numDataEnd[2]); DateTime dataIn = new DateTime(annoIn, meseIn, giornoIn); DateTime dataEnd = new DateTime(annoEnd, meseEnd, giornoEnd); ProdottoInOfferta p = new ProdottoInOfferta(cod, desc, price, sconto, dataIn, dataEnd); n.ProdottiInOfferta.Add(p); } foreach (ProdottoInOfferta p in n.ProdottiInOfferta) { DateTime thisDay = DateTime.Today; if (thisDay.Date >= p.DataInizio && thisDay.Date <= p.DataFine) { System.Console.WriteLine("Codice: " + p.Codice + " - Descrizione: " + p.Descrizione + " - Prezzo: " + p.Prezzo + "$"); } } }
public static void AggiungiTipologieElementi() { string categoria = null; //Faccio scegliere la categoria using (ListForm listForm = new ListForm()) { listForm.EditButton.Enabled = false; listForm.AddButton.Enabled = false; listForm.DeleteButton.Enabled = false; listForm.DataSource = Negozio.Categorie; listForm.Text = "Scelta categoria elemento"; Label label = new Label(); label.Text = "Scegliere la categoria dell'elemento"; label.TextAlign = ContentAlignment.MiddleCenter; label.Anchor = AnchorStyles.Top; label.AutoSize = true; listForm.SetFilter(label); listForm.Size = new Size(568, 355); listForm.OkButton.DialogResult = DialogResult.OK; if (listForm.ShowDialog() == DialogResult.OK && listForm.DataGridView.CurrentRow != null) { categoria = listForm.DataGridView.CurrentRow.DataBoundItem.ToString(); } else { return; } } TipoElemento tipo_elemento = Negozio.NuovoTipoElemento(categoria); if (NoleggioServices.Modifica(tipo_elemento, true)) { Negozio.InserisciNuovoTipoElemento(tipo_elemento); } }
void AggiornaInfoGrafiche() { LordoTotale.Text = "Lordo: " + giocatore.portafogli.Reddito + "$"; SpeseTotali.Text = "Spese: " + giocatore.portafogli.Spese + "$"; GuadagnoGiornaliero.Text = "Guadagno giornaliero: " + giocatore.portafogli.Bilancio + "$"; portafoglio_label.Text = "Portafoglio: " + giocatore.portafogli.Soldi + "$"; immagineAzienda_label.Text = "Immagine azienda: " + giocatore.FamaAziendale + "/10"; richiesteLavoro_label.Text = "Richieste lavoro: " + giocatore.DipendentiDisponibili; if (edificioSelezionato != null) { indicatoreDipendenti.Text = edificioSelezionato.Dipendenti.Quantita + "/" + edificioSelezionato.Dipendenti.MassimoDipendenti; indicatoreFelicita.Text = "+" + edificioSelezionato.Dipendenti.Felicita; gestione_button.BackgroundImage = Properties.Resources.ingranaggio; if (gestioneEdificio_panel.Visible) { stipendiPerc_label.Text = edificioSelezionato.Dipendenti.StipendiPerc + "%"; guadagnoEdificio.Text = "GUADAGNO " + edificioSelezionato.Bilancio + "$"; lordoEdificio.Text = "LORDO " + edificioSelezionato.Reddito + "$"; puntiProduzione.Text = "+" + edificioSelezionato.PuntiProduzione; minimoDipendenti_label.Text = "(min " + edificioSelezionato.Dipendenti.MinimoDipendenti + ")"; //Magazzino (GUI) if (edificioSelezionato.GetType() == typeof(Industria)) { Industria industria = (Industria)edificioSelezionato; materiali_comuni.Text = industria.SlotMateriali.GetElemento("MaterialeComune").Quantita.ToString(); materiali_rari.Text = industria.SlotMateriali.GetElemento("MaterialeRaro").Quantita.ToString(); materiali_preziosi.Text = industria.SlotMateriali.GetElemento("MaterialePrezioso").Quantita.ToString(); prodotti_comuni.Text = "--"; prodotti_rari.Text = "--"; prodotti_preziosi.Text = "--"; prodotti_comuniRari.Text = "--"; prodotti_comuniPreziosi.Text = "--"; prodotti_rariPreziosi.Text = "--"; //BottoneProduzione if (((Industria)edificioSelezionato).RisorsaTerreno == "MaterialeComune") { gestione_button.BackgroundImage = Properties.Resources.comuni; } else if (((Industria)edificioSelezionato).RisorsaTerreno == "MaterialeRaro") { gestione_button.BackgroundImage = Properties.Resources.rari; } else if (((Industria)edificioSelezionato).RisorsaTerreno == "MaterialePrezioso") { gestione_button.BackgroundImage = Properties.Resources.preziosi; } } else if (edificioSelezionato.GetType() == typeof(Fabbrica)) { Fabbrica fabbrica = (Fabbrica)edificioSelezionato; materiali_comuni.Text = fabbrica.SlotMateriali.GetElemento("MaterialeComune").Quantita.ToString(); materiali_rari.Text = fabbrica.SlotMateriali.GetElemento("MaterialeRaro").Quantita.ToString(); materiali_preziosi.Text = fabbrica.SlotMateriali.GetElemento("MaterialePrezioso").Quantita.ToString(); prodotti_comuni.Text = fabbrica.SlotProdotti.GetElemento("ProdottoComune").Quantita.ToString(); prodotti_rari.Text = fabbrica.SlotProdotti.GetElemento("ProdottoRaro").Quantita.ToString(); prodotti_preziosi.Text = fabbrica.SlotProdotti.GetElemento("ProdottoPrezioso").Quantita.ToString(); prodotti_comuniRari.Text = fabbrica.SlotProdotti.GetElemento("ProdottoComuneRaro").Quantita.ToString(); prodotti_comuniPreziosi.Text = fabbrica.SlotProdotti.GetElemento("ProdottoComunePrezioso").Quantita.ToString(); prodotti_rariPreziosi.Text = fabbrica.SlotProdotti.GetElemento("ProdottoRaroPrezioso").Quantita.ToString(); } else if (edificioSelezionato.GetType() == typeof(Negozio)) { Negozio negozio = (Negozio)edificioSelezionato; materiali_comuni.Text = "--"; materiali_rari.Text = "--"; materiali_preziosi.Text = "--"; prodotti_comuni.Text = negozio.SlotProdotti.GetElemento("ProdottoComune").Quantita.ToString(); prodotti_rari.Text = negozio.SlotProdotti.GetElemento("ProdottoRaro").Quantita.ToString(); prodotti_preziosi.Text = negozio.SlotProdotti.GetElemento("ProdottoPrezioso").Quantita.ToString(); prodotti_comuniRari.Text = negozio.SlotProdotti.GetElemento("ProdottoComuneRaro").Quantita.ToString(); prodotti_comuniPreziosi.Text = negozio.SlotProdotti.GetElemento("ProdottoComunePrezioso").Quantita.ToString(); prodotti_rariPreziosi.Text = negozio.SlotProdotti.GetElemento("ProdottoRaroPrezioso").Quantita.ToString(); } } } //Punti esclamativi for (int r = 0; r < mappa.Righe; r++) { for (int c = 0; c < mappa.Colon; c++) { if (mappa.CelleEdifici[r, c] != null) { if (!mappa.CelleEdifici[r, c].EdificioAttivo) { attenzione[r, c].Visible = true; } else { attenzione[r, c].Visible = false; } } } } }
private void conferma_button_Click(object sender, EventArgs e) { Fabbrica fab = null; Negozio neg = null; //Una soluzione orrenda ma è comunque una soluzione if (edificio.GetType() == typeof(Fabbrica)) { fab = (Fabbrica)edificio; switch (indice) { case 0: fab.CambiaProduzione("ProdottoComune"); break; case 1: fab.CambiaProduzione("ProdottoRaro"); break; case 2: fab.CambiaProduzione("ProdottoPrezioso"); break; case 3: fab.CambiaProduzione("ProdottoComuneRaro"); break; case 4: fab.CambiaProduzione("ProdottoComunePrezioso"); break; case 5: fab.CambiaProduzione("ProdottoRaroPrezioso"); break; } } else if (edificio.GetType() == typeof(Negozio)) { neg = (Negozio)edificio; switch (indice) { case 0: neg.CambiaProdottiVendita("ProdottoComune"); break; case 1: neg.CambiaProdottiVendita("ProdottoRaro"); break; case 2: neg.CambiaProdottiVendita("ProdottoPrezioso"); break; case 3: neg.CambiaProdottiVendita("ProdottoComuneRaro"); break; case 4: neg.CambiaProdottiVendita("ProdottoComunePrezioso"); break; case 5: neg.CambiaProdottiVendita("ProdottoRaroPrezioso"); break; } } //Chiusura del form this.Close(); }