private bool checkOk() { try { db.SubmitChanges(); return(true); } catch (Exception exc) { AllertGestor.defaultError("Errore nel database contattare il tecnico..\n Eccezione = " + exc.ToString()); return(false); } }
private void checkValues(object sender, ItemCheckEventArgs e) { if (e.CurrentValue == CheckState.Unchecked) { Form input = new Form(); Size basicSize = new Size(input.Size.Width, 100); input.Size = basicSize; FlowLayoutPanel pane = new FlowLayoutPanel(); TextBox box = new TextBox(); Button click = new Button(); click.Text = "Aggiungi.."; click.Click += (o, a) => input.Close(); box.Size = new Size(100, 20); pane.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top; pane.Controls.Add(box); pane.Controls.Add(click); input.StartPosition = FormStartPosition.CenterParent; input.MaximumSize = basicSize; input.MinimumSize = basicSize; input.Text = "Inserisci le calorie"; input.Icon = Properties.Resources.iconmain; input.Controls.Add(pane); double kcal = 0; do { input.ShowDialog(); if (box.Text.Length == 0) { AllertGestor.defaultError("Devi almeno una unità di misura"); } else if (!Double.TryParse(box.Text, out kcal)) { AllertGestor.defaultError("Deve essere numerica!"); } else { this.ingrUdm.Add(this.unitàDiMisura.Items[e.Index].ToString(), kcal); } } while (box.Text.Length == 0 || !Double.TryParse(box.Text, out kcal)); } else { this.ingrUdm.Remove(this.unitàDiMisura.Items[e.Index].ToString()); } }
public Tuple <String, int> getQuantity() { int quantity = 1; do { this.ShowDialog(); if (this.comboBox1.SelectedItem == null) { AllertGestor.defaultError("Devi inserire l'unità di misura!"); } else if (this.textBox1.Enabled && !Int32.TryParse(this.textBox1.Text, out quantity)) { AllertGestor.defaultError("Deve essere numerica!"); } else { return(new Tuple <String, int>(this.comboBox1.SelectedItem.ToString(), quantity)); } } while (this.comboBox1.SelectedItem == null || !Int32.TryParse(this.textBox1.Text, out quantity)); return(null); }
public MenuInsert() { pane.AutoScroll = true; Size basicSize = new Size(400, 20); List <Ricetta> listRicette = (from c in db.Ricetta select c).ToList(); //Label Label textNome = labelFactory.createAdvanceLabel("Scegli il nome del menu..", labelFactory.getGeneralFont(), basicSize, Color.Black, ContentAlignment.TopLeft); Label textTipo = labelFactory.createAdvanceLabel("Scegli il tipo del menu..", labelFactory.getGeneralFont(), basicSize, Color.Black, ContentAlignment.TopLeft); Label textRicette = labelFactory.createAdvanceLabel("Scegli ricette.", labelFactory.getGeneralFont(), basicSize, Color.Black, ContentAlignment.TopLeft); //TextBox TextBox nomeText = new TextBox(); nomeText.Size = basicSize; nomeText.MaxLength = (int)textConst.NOME_MENU; TextBox tipoText = new TextBox(); tipoText.Size = basicSize; tipoText.MaxLength = (int)textConst.NOME_TIPO; //List view CheckedListBox ricette = new CheckedListBox(); ricette.Size = new Size(400, 150); //Button Button aggiunge = new Button(); aggiunge.Text = "Inserisci il menu"; aggiunge.Size = basicSize; listRicette.ForEach(x => ricette.Items.Add(x.Nome)); //nome this.pane.Controls.Add(textNome); this.pane.Controls.Add(nomeText); //tipo this.pane.Controls.Add(textTipo); this.pane.Controls.Add(tipoText); //ricette this.pane.Controls.Add(textRicette); this.pane.Controls.Add(ricette); //Inserimento this.pane.Controls.Add(aggiunge); //action aggiunge.Click += (obj, args) => { if (nomeText.Text.Length == 0) { AllertGestor.defaultError("Devi scegliere un nome"); } else if (tipoText.Text.Length == 0) { AllertGestor.defaultError("Devi scegliere un tipo"); } else if (ricette.SelectedItems.Count == 0) { AllertGestor.defaultError("Devi almeno una ricetta"); } else { Menù menu = new Menù(); menu.Nome = nomeText.Text; menu.Tipo = tipoText.Text; db.Menù.InsertOnSubmit(menu); db.SubmitChanges(); foreach (int i in ricette.CheckedIndices) { Assemblaggio assemblaggio = new Assemblaggio(); assemblaggio.idMenù = menu.idMenù; assemblaggio.idRicetta = listRicette[i].idRicetta; db.Assemblaggio.InsertOnSubmit(assemblaggio); } db.SubmitChanges(); AllertGestor.defaultShowOk("Menu inserito correttamente"); MainPaneGestor.getInstance().setPanel(PaneFactory.getMenuPane()); MainPaneGestor.getInstance().enableShowingSearch(); RicettarioDB.refresh(); } }; }
public ricettaStrumentoInsert(int idRicettaStrumento) { InitializeComponent(); //Initializzation this.currentStep = new HashSet <Step>(); this.ingredientiSelezionati = new Dictionary <Tuple <String, int>, int>(); this.stepIngredientiSelezionati = new Dictionary <int, Tuple <String, int> >(); this.idRicettaStrumento = idRicettaStrumento; this.ingredientVisualizzator.HorizontalScrollbar = true; //Strumenti List <Strumento> strumenti = (from c in db.Strumento select c).ToList(); List <Strumento> elettrodomestici = (from c in strumenti where c.Tipo.Equals("Elettrodomestico") select c).ToList(); elettrodomestici.ForEach(x => this.RSStrumentiSelector.Items.Add(x.Nome)); strumenti.ForEach(x => this.strumentiStep.Items.Add(x.Nome + " " + x.Tipo)); List <Ingrediente> ingredienti = (from c in db.Ingrediente select c).ToList(); ingredienti.ForEach(x => this.ingredientiSelector.Items.Add(x.Nome)); this.nomeStep.MaxLength = (int)textConst.NOME_STEP; //gestione list this.stepListing.HorizontalScrollbar = true; //Action this.ingredientiSelector.ItemCheck += (obj, args) => { int keyIndex = ingredienti[args.Index].idIngrediente; if (args.CurrentValue == CheckState.Unchecked) { Tuple <String, int> res = new selIngrediente(keyIndex).getQuantity(); Tuple <String, int> key = new Tuple <string, int>(res.Item1, keyIndex); this.stepIngredientiSelezionati.Add(keyIndex, res); if (this.ingredientiSelezionati.ContainsKey(key)) { int qnt = this.ingredientiSelezionati[key]; qnt += res.Item2; this.ingredientiSelezionati.Remove(key); this.ingredientiSelezionati.Add(key, qnt); } else { this.ingredientiSelezionati.Add(key, res.Item2); } this.ingredientVisualizzator.Items.Clear(); this.refreshIngredient(); } else { Tuple <String, int> qnt = this.stepIngredientiSelezionati[keyIndex]; this.stepIngredientiSelezionati.Remove(keyIndex); Tuple <String, int> key = new Tuple <String, int>(qnt.Item1, keyIndex); int qntTot = this.ingredientiSelezionati[key]; if (qnt.Item2 == qntTot) { this.ingredientiSelezionati.Remove(key); } else { qntTot -= qnt.Item2; this.ingredientiSelezionati.Remove(key); this.ingredientiSelezionati.Add(key, qntTot); } this.ingredientVisualizzator.Items.Clear(); this.refreshIngredient(); } }; //Aggiungi step this.AggiungiStep.Click += (obj, args) => { //Controllo dei parametri esatti if (this.nomeStep.TextLength == 0) { AllertGestor.defaultError("Devi inserire un nome univoco per ogni step"); } else if (this.descrizione.TextLength == 0) { AllertGestor.defaultError("Devi inserire una descrizione"); } else if (this.Immagine.Text.Equals("")) { AllertGestor.defaultError("Devi inserire un'immagine"); } else { //Inserisco nello step le caratteristiche principali Step main = new Step(); main.idRicettaStrum = this.idRicettaStrumento; main.Nome = this.nomeStep.Text; main.Immagine = this.Immagine.Text; main.NumOrdine = countStep; main.Descrizione = this.descrizione.Text; this.currentStep.Add(main); //Consumo table this.stepIngredientiSelezionati.ToList().ForEach(x => { Consumo cons = new Consumo(); cons.idIngrediente = x.Key; cons.idRicettaStrum = this.idRicettaStrumento; cons.NomeStep = this.nomeStep.Text; cons.Quantità = x.Value.Item2; cons.NomeUDM = x.Value.Item1; main.Consumo.Add(cons); }); //Uso table foreach (int i in this.strumentiStep.CheckedIndices) { Uso uso = new Uso(); uso.idRicettaStrum = this.idRicettaStrumento; uso.NomeStep = this.nomeStep.Text; uso.idStrumento = strumenti[i].idStrumento; main.Uso.Add(uso); } //Pulisco la pagina corrente this.strumentiStep.Items.Clear(); strumenti.ForEach(x => this.strumentiStep.Items.Add(x.Nome + " " + x.Tipo)); this.ingredientiSelector.Items.Clear(); ingredienti.ForEach(x => this.ingredientiSelector.Items.Add(x.Nome)); this.nomeStep.Clear(); this.descrizione.Clear(); this.Immagine.Text = ""; this.stepIngredientiSelezionati.Clear(); this.countStep++; this.stepListing.Items.Add(main.Nome + " " + main.NumOrdine); //aggiungo lo step ai step da aggiungere this.steps.Add(main); } }; //Azione per aggiungere un'immagine this.immageOpen.Click += (obj, args) => { try { this.Immagine.Text = UtilityImage.findFileCheckImage(); }catch (ArgumentException exc) { this.Immagine.Text = ""; AllertGestor.defaultError("Devi selezionare un'immagine valida!"); } }; //Azione per aggiungere la ricetta strumento this.addRS.Click += (obj, args) => { if (this.currentStep.Count == 0) { AllertGestor.defaultError("Devi inserire almeno uno step "); } else { RicettaStrumento rs = new RicettaStrumento(); rs.idRicettaStrum = this.idRicettaStrumento; try { rs.Kcal = (int)Double.Parse(this.kcalTot.Text); } catch (Exception e) { rs.Kcal = 0; } bool begin = true; foreach (int i in this.RSStrumentiSelector.CheckedIndices) { Utilizzo utilizzo = new Utilizzo(); utilizzo.idRicettaStrum = this.idRicettaStrumento; utilizzo.idStrumento = elettrodomestici[i].idStrumento; rs.Utilizzo.Add(utilizzo); } HashSet <int> specifiche = new HashSet <int>(); this.ingredientiSelezionati.ToList().ForEach(x => { Presenta presenta = new Presenta(); presenta.idIngrediente = x.Key.Item2; presenta.idRicettaStrum = this.idRicettaStrumento; presenta.NomeUDM = x.Key.Item1; presenta.Quantità = x.Value; rs.Presenta.Add(presenta); if (begin) { specifiche = this.populateCatatteristiche(x.Key.Item2); begin = false; } else { HashSet <int> otherSpecifiche = this.populateCatatteristiche(x.Key.Item2); specifiche.ToList().ForEach(z => { if (!otherSpecifiche.Contains(z)) { specifiche.Remove(z); } }); } }); specifiche.ToList().ForEach(x => Console.WriteLine(x)); specifiche.ToList().ForEach(x => { Definito def = new Definito(); def.idCaratteristica = x; def.idRicettaStrum = this.idRicettaStrumento; rs.Definito.Add(def); }); this.ricettaStrumentoSet.Add(rs); this.Close(); } }; }
private void queryInsert(object sender, EventArgs e) { if (this.box.Text.Length == 0) { AllertGestor.defaultError("Devi scegliere un nome"); } else if (this.categorie.SelectedItem == null) { AllertGestor.defaultError("Devi scegliere una categoria"); } else if (this.unitàDiMisura.SelectedItems.Count == 0) { AllertGestor.defaultError("Devi almeno una unità di misura"); } else { Ingrediente ing = new Ingrediente(); ing.Nome = box.Text; ing.NomeCat = categorie.SelectedItem.ToString(); db.Ingrediente.InsertOnSubmit(ing); try { db.SubmitChanges(); } catch (Exception exc) { AllertGestor.defaultError("Ingrediente già presente!"); return; } int max = ing.idIngrediente; foreach (int i in this.checkCaratteristiche.CheckedIndices) { Tuple <int, String> value = this.caratteristiche[i]; Caratterizzante cat = new Caratterizzante(); cat.idCaratteristica = value.Item1; cat.idIngrediente = max; db.Caratterizzante.InsertOnSubmit(cat); } this.ingrUdm.ToList().ForEach(x => { IngrUDM ingUdm = new IngrUDM(); ingUdm.kcalPerUnità = (float)x.Value; ingUdm.NomeUDM = x.Key; ingUdm.idIngrediente = max; db.IngrUDM.InsertOnSubmit(ingUdm); }); foreach (int i in this.alternativeBox.CheckedIndices) { Alternativo alt = new Alternativo(); alt.idIngrediente = max; alt.AltIdIngrediente = this.ingredienti[i].idIngrediente; Alternativo alt2 = new Alternativo(); alt2.AltIdIngrediente = max; alt2.idIngrediente = this.ingredienti[i].idIngrediente; db.Alternativo.InsertOnSubmit(alt); db.Alternativo.InsertOnSubmit(alt2); } //se qualcosa è andato storto elimino l'ingrediente if (this.checkOk() == false) { db.Ingrediente.DeleteOnSubmit(ing); try { db.SubmitChanges(); } catch (Exception exc) { RicettarioDB.refresh(); this.db = RicettarioDB.getInstance(); AllertGestor.defaultError("Qualcosa non va"); MainPaneGestor.getInstance().setPanel(PaneFactory.getIngredientPane()); } } else { RicettarioDB.refresh(); AllertGestor.defaultShowOk("Ingrediente inserito!"); MainPaneGestor.getInstance().setPanel(PaneFactory.getIngredientPane()); } } }
public RicettaInsert() { HashSet <RicettaStrumento> rsToInsert = new HashSet <RicettaStrumento>(); HashSet <Step> stepToInsert = new HashSet <Step>(); mainPanel = new TableLayoutPanel(); this.mainPanel.AutoScroll = true; Size size = new Size(300, 20); //Label Label textRicetta = labelFactory.createAdvanceLabel("Inserisci il nome della ricetta", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textTCottura = labelFactory.createAdvanceLabel("Inserisci il tempo di cottura in minuti", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textTPreparazione = labelFactory.createAdvanceLabel("Inserisci il tempo di preparazione in minuti", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textDifficolta = labelFactory.createAdvanceLabel("Inserisci la difficoltà", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textPersone = labelFactory.createAdvanceLabel("Inserisci il numero di persone", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textPortata = labelFactory.createAdvanceLabel("Seleziona la portata desiderata", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); Label textImage = labelFactory.createAdvanceLabel("", labelFactory.getGeneralFont(), new Size(400, 20), Color.Black, ContentAlignment.TopLeft); Label textDescrizione = labelFactory.createAdvanceLabel("Inserisci la descrizione", labelFactory.getGeneralFont(), size, Color.Black, ContentAlignment.TopLeft); //TextBox TextBox ricettaText = new TextBox(); ricettaText.Size = size; ricettaText.MaxLength = (int)textConst.NOME_RICETTA; TextBox cotturaText = new TextBox(); cotturaText.Size = size; cotturaText.MaxLength = 3; TextBox preparazioneText = new TextBox(); preparazioneText.Size = size; preparazioneText.MaxLength = 3; TextBox personeText = new TextBox(); personeText.Size = new Size(20, 20); personeText.MaxLength = 2; //RichTextBox RichTextBox descrizione = new RichTextBox(); descrizione.Size = new Size(400, 100); //ComboBox ComboBox difficoltàBox = new ComboBox(); DifficoltàUtilities.getDifficulties().ForEach(x => difficoltàBox.Items.Add(DifficoltàUtilities.getDifficulty(x))); ComboBox portataBox = new ComboBox(); portataBox.Items.AddRange((from c in db.Portata select c.Nome).ToArray()); //ListView ListView listRs = new ListView(); listRs.View = View.List; //Button Button insertImage = new Button(); insertImage.Text = "Scegli un'immagine per la tua ricetta.."; insertImage.Size = size; insertImage.Click += (obj, arg) => { try { textImage.Text = UtilityImage.findFileCheckImage(); } catch (ArgumentException exc) { textImage.Text = ""; AllertGestor.defaultError("Devi selezionare un'immagine valida"); } }; Button addRicetta = new Button(); addRicetta.Text = "Aggiungi la ricetta.."; addRicetta.Size = new Size(200, 25); addRicetta.Enabled = false; //Cosa fare quando la ricetta deve essere inserita addRicetta.Click += (obj, args) => { int tcottura, tpreparazione, persone; if (ricettaText.TextLength == 0) { AllertGestor.defaultError("Devi inserire un nome!"); } else if (cotturaText.TextLength == 0) { AllertGestor.defaultError("Devi inserire il tempo di cottura"); } else if (!Int32.TryParse(cotturaText.Text, out tcottura)) { AllertGestor.defaultError("il tempo di cottura deve essere numerico"); } else if (preparazioneText.TextLength == 0) { AllertGestor.defaultError("Devi inserire il tempo di preparazione"); } else if (!Int32.TryParse(preparazioneText.Text, out tpreparazione)) { AllertGestor.defaultError("il tempo di preparazione deve essere numerico"); } else if (textImage.Text.Equals("")) { AllertGestor.defaultError("Devi inserire un'immagine"); } else if (descrizione.TextLength == 0) { AllertGestor.defaultError("Devi inserire una descrizione!"); } else if (difficoltàBox.SelectedItem == null) { AllertGestor.defaultError("Devi inserire una difficoltà!"); } else if (portataBox.SelectedItem == null) { AllertGestor.defaultError("Devi inserire una portata!"); } else if (personeText.TextLength == 0) { AllertGestor.defaultError("Devi inserire il numero di persone corretto!"); } else if (!Int32.TryParse(personeText.Text, out persone)) { AllertGestor.defaultError("le persone devono avere un'indice numerico!"); } else { Ricetta ricetta = new Ricetta(); ricetta.Nome = ricettaText.Text; ricetta.TCottura = tcottura; ricetta.Persone = persone; ricetta.TPreparazione = tpreparazione; ricetta.Difficoltà = difficoltàBox.SelectedIndex; ricetta.portata = portataBox.SelectedItem.ToString(); string localFile = FileGestor.copyFileToLocalFolder(textImage.Text, ricetta.Nome); ricetta.Immagine = localFile; ricetta.Descrizione = descrizione.Text; db.Ricetta.InsertOnSubmit(ricetta); bool insert = true; try { db.SubmitChanges(); } catch (Exception exc) { insert = false; RicettarioDB.refresh(); this.db = RicettarioDB.getInstance(); AllertGestor.defaultError("Il nome della ricetta è già stato inserito! controlla nel menù principale\n" + exc); } if (insert) { //Aggiustamento dei vari valori trovati stepToInsert.ToList().ForEach(x => { x.Immagine = FileGestor.copyFileToLocalFolder(x.Immagine, "" + ricetta.idRicetta + "" + x.idRicettaStrum + "" + x.Nome); }); rsToInsert.ToList().ForEach(x => { x.idRicetta = ricetta.idRicetta; x.Presenta.ToList().ForEach(z => { Presenta p = new Presenta(); p.idRicetta = ricetta.idRicetta; p.idRicettaStrum = z.idRicettaStrum; p.idIngrediente = z.idIngrediente; p.Quantità = z.Quantità; p.NomeUDM = z.NomeUDM; x.Presenta.Remove(z); x.Presenta.Add(p); }); x.Definito.ToList().ForEach(z => { Definito d = new Definito(); d.idRicetta = ricetta.idRicetta; d.idRicettaStrum = z.idRicettaStrum; d.idCaratteristica = z.idCaratteristica; x.Definito.Remove(z); x.Definito.Add(d); }); x.Utilizzo.ToList().ForEach(z => { Utilizzo u = new Utilizzo(); u.idRicetta = ricetta.idRicetta; u.idRicettaStrum = z.idRicettaStrum; u.idStrumento = z.idStrumento; x.Utilizzo.Remove(z); x.Utilizzo.Add(u); }); }); stepToInsert.ToList().ForEach(x => { x.idRicetta = ricetta.idRicetta; x.Uso.ToList().ForEach(z => { Uso u = new Uso(); u.idRicetta = ricetta.idRicetta; u.idRicettaStrum = z.idRicettaStrum; u.idStrumento = z.idStrumento; u.NomeStep = z.NomeStep; x.Uso.Remove(z); x.Uso.Add(u); }); x.Consumo.ToList().ForEach(z => { Consumo p = new Consumo(); p.idRicetta = ricetta.idRicetta; p.idRicettaStrum = z.idRicettaStrum; p.idIngrediente = z.idIngrediente; p.Quantità = z.Quantità; p.NomeUDM = z.NomeUDM; p.NomeStep = z.NomeStep; x.Consumo.Remove(z); x.Consumo.Add(p); }); }); db.RicettaStrumento.InsertAllOnSubmit(rsToInsert.AsEnumerable()); db.Step.InsertAllOnSubmit(stepToInsert.AsEnumerable()); try { db.SubmitChanges(); AllertGestor.defaultShowOk("Ricetta Inserita!"); } catch (Exception exc) { AllertGestor.defaultError("errore grave consultare il tecnico: \n traccia : " + exc.ToString()); } } RicettarioDB.refresh(); MainPaneGestor.getInstance().enableShowingSearch(); MainPaneGestor.getInstance().setPanel(PaneFactory.getRicettaPane()); } }; Button addSteps = new Button(); addSteps.Text = "Inserisci gli step..."; addSteps.Size = new Size(200, 25); //Cosa fare quando gli step devono essere inseriti addSteps.Click += (obj, args) => { ricettaStrumentoInsert popup = new ricettaStrumentoInsert(ricettaStrumentoIndex); popup.StartPosition = FormStartPosition.CenterParent; popup.setRicettaStrumento(rsToInsert); popup.setSteps(stepToInsert); popup.ShowDialog(); if (rsToInsert.Count != 0) { addRicetta.Enabled = true; } listRs.Items.Clear(); ricettaStrumentoIndex++; rsToInsert.ToList().ForEach(x => listRs.Items.Add("Famiglia Step id :" + x.idRicettaStrum)); }; //Name Ricetta mainPanel.Controls.Add(textRicetta); mainPanel.Controls.Add(ricettaText); //Tempo Cottura mainPanel.Controls.Add(textTCottura); mainPanel.Controls.Add(cotturaText); //Tempo Preparazione mainPanel.Controls.Add(textTPreparazione); mainPanel.Controls.Add(preparazioneText); //Difficoltà mainPanel.Controls.Add(textDifficolta); mainPanel.Controls.Add(difficoltàBox); //Persone mainPanel.Controls.Add(textPersone); mainPanel.Controls.Add(personeText); //portata mainPanel.Controls.Add(textPortata); mainPanel.Controls.Add(portataBox); //Immagine mainPanel.Controls.Add(insertImage); mainPanel.Controls.Add(textImage); //Descrizione mainPanel.Controls.Add(textDescrizione); mainPanel.Controls.Add(descrizione); //Inserimento mainPanel.Controls.Add(addSteps); //ListView mainPanel.Controls.Add(listRs); //Inserimento Ricetta mainPanel.Controls.Add(addRicetta); }