Пример #1
0
 //Ingredienti
 private void button2_Click(object sender, EventArgs e)
 {
     gestor.disableShowingSearch();
     gestor.clearPane();
     gestor.setPanel(PaneFactory.getIngredientPane());
 }
Пример #2
0
        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());
                }
            }
        }