示例#1
0
 public bool AddComponentToItem(long progressivoOggetto, long progressivoComponente)
 {
     try
     {
         long? numeroMassimo = null;
         var ingredienti = (from componenti in context.NewFormules
                                     where componenti.Risultato == progressivoOggetto
                                     orderby componenti.NumeroIngrediente descending
                                     select componenti.NumeroIngrediente);
         if (ingredienti.Count() > 0)
         {
             numeroMassimo = ingredienti.Max();
         }
         if (!numeroMassimo.HasValue)
         {
             numeroMassimo = -1;
         }
         NewOggetti item = (from oggetti in context.NewElementis
                            where oggetti.Progressivo == progressivoOggetto
                            select oggetti).OfType<NewOggetti>().FirstOrDefault();
         NewFormule ingrediente = new NewFormule();
         ingrediente.Ingrediente = progressivoComponente;
         ingrediente.NumeroIngrediente = numeroMassimo.Value + 1;
         item.Componenti.Add(ingrediente);
         return true;
     }
     catch
     {
         return false;
     }
 }
示例#2
0
 public bool CloneItem(long progressivo, string nome, string desc, string effetto, string urlImmagine, float costo, long disponibilita, DateTime? scadenza, string modoUso, long tipoSostanza, long valoreEfficacia)
 {
     try
     {
         //Creo l'oggetto nuovo (la clonatura in realtà è avvenuta in Form, qui "clono" solo i Componenti
         NewSostanze newItem = new NewSostanze();
         newItem.Costo = costo;
         newItem.DataScadenza = scadenza;
         newItem.Descrizione = desc;
         newItem.Disponibilita = disponibilita;
         newItem.Effetto = effetto;
         newItem.Immagine = urlImmagine;
         newItem.Nome = nome;
         newItem.ModoUso = modoUso;
         newItem.ValoreEfficacia = valoreEfficacia;
         newItem.Tipo = tipoSostanza;
         context.AddToNewElementis(newItem);
         //Ora "clono" i componenti dall'oggetto originale
         IEnumerable<NewFormule> components = from componenti in context.NewFormules
                                              where componenti.Risultato == progressivo
                                              orderby componenti.NumeroIngrediente ascending
                                              select componenti;
         foreach (NewFormule singleComponent in components)
         {
             NewFormule newComponent = new NewFormule();
             newComponent.Ingrediente = singleComponent.Ingrediente;
             newComponent.NumeroIngrediente = singleComponent.NumeroIngrediente;
             newItem.Componenti.Add(newComponent);
         }
         //ora creo i dieci GUID che servono a fare i QR differenziati
         for (int i = 0; i < 10; i++)
         {
             CodiciQr codice = new CodiciQr();
             codice.Codice = Guid.NewGuid();
             newItem.CodiciQrs.Add(codice);
         }
         context.AddToNewElementis(newItem);
         return true;
     }
     catch
     {
         return false;
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the NewFormules EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToNewFormules(NewFormule newFormule)
 {
     base.AddObject("NewFormules", newFormule);
 }
 /// <summary>
 /// Create a new NewFormule object.
 /// </summary>
 /// <param name="risultato">Initial value of the Risultato property.</param>
 /// <param name="numeroIngrediente">Initial value of the NumeroIngrediente property.</param>
 public static NewFormule CreateNewFormule(global::System.Int64 risultato, global::System.Int64 numeroIngrediente)
 {
     NewFormule newFormule = new NewFormule();
     newFormule.Risultato = risultato;
     newFormule.NumeroIngrediente = numeroIngrediente;
     return newFormule;
 }