Beispiel #1
0
 public bool AddComponentToSubstance(long progressivoSostanza, long progressivoIngrediente)
 {
     try
     {
         long?numeroMassimo = null;
         var  ingredienti   = (from componenti in context.NewFormules
                               where componenti.Risultato == progressivoSostanza
                               orderby componenti.NumeroIngrediente descending
                               select componenti.NumeroIngrediente);
         if (ingredienti.Count() > 0)
         {
             numeroMassimo = ingredienti.Max();
         }
         if (!numeroMassimo.HasValue)
         {
             numeroMassimo = -1;
         }
         NewSostanze item = (from oggetti in context.NewElementis
                             where oggetti.Progressivo == progressivoSostanza
                             select oggetti).OfType <NewSostanze>().FirstOrDefault();
         NewFormule ingrediente = new NewFormule();
         ingrediente.Ingrediente       = progressivoIngrediente;
         ingrediente.NumeroIngrediente = numeroMassimo.Value + 1;
         item.Componenti.Add(ingrediente);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #2
0
 public bool SaveSubstance(long?progressivo, string nome, string desc, string effetto, string urlImmagine, float costo, long disponibilita, DateTime?scadenza, string modoUso, long tipoSostanza, long valoreEfficacia)
 {
     try
     {
         if (!progressivo.HasValue)
         {
             return(SaveNewSubstance(nome, desc, effetto, urlImmagine, costo, disponibilita, scadenza, modoUso, tipoSostanza, valoreEfficacia));
         }
         NewSostanze itemToEdit = GetSubstanceFromNumber(progressivo.Value);
         itemToEdit.Costo           = costo;
         itemToEdit.DataScadenza    = scadenza;
         itemToEdit.Descrizione     = desc;
         itemToEdit.Disponibilita   = disponibilita;
         itemToEdit.Effetto         = effetto;
         itemToEdit.Immagine        = urlImmagine;
         itemToEdit.Nome            = nome;
         itemToEdit.ModoUso         = modoUso;
         itemToEdit.ValoreEfficacia = valoreEfficacia;
         itemToEdit.Tipo            = tipoSostanza;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #3
0
 public bool SaveNewSubstance(string nome, string desc, string effetto, string urlImmagine, float costo, long disponibilita, DateTime?scadenza, string modoUso, long tipoSostanza, long valoreEfficacia)
 {
     try
     {
         //creo l'oggetto
         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;
         //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);
     }
 }
Beispiel #4
0
        private void qrReader_OnCodeDecoded(object sender, EventArgs e)
        {
            string myCode = qrReader.Code;

            if (!string.IsNullOrEmpty(myCode))
            {
                Guid uniqueCode;
                try
                {
                    lblDescrizione.Text = string.Empty;
                    uniqueCode          = new Guid(myCode);
                }
                catch
                {
                    lblDescrizione.Text = "Cartellino non valido";                     //Se il codice è un codice ad cazzum, non un GUID, è ovviamente un QR Code sbagliato
                    return;
                }
                SostanzeManager manager  = new SostanzeManager(DatabaseContext);
                NewSostanze     sostanza = manager.GetSubstanceFromQRCode(uniqueCode);
                if (sostanza == null)
                {
                    lblDescrizione.Text = "Non è un cartellino sostanza";
                }
                else
                {
                    txtElencoIngredienti.Text += sostanza.Nome + "\r\n";
                    hidField.Value            += sostanza.Progressivo + ";";
                    lblDescrizione.Text        = "Ingrediente inserito";
                    btnCrea.Enabled            = true;
                }
            }
        }
Beispiel #5
0
        public long GetEffectValueOfSubstance(long progressivo)
        {
            var substance = (from oggetto in context.NewElementis
                             where oggetto.Progressivo == progressivo
                             select oggetto).FirstOrDefault();
            NewSostanze sostanza = substance as NewSostanze;

            return(sostanza.ValoreEfficacia);
        }
Beispiel #6
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            Timer1.Enabled = false;
            string[]     ingredientiLetti       = hidField.Value.Split(';');
            List <long?> progressiviIngredienti = new List <long?>();

            for (int i = 0; i < ingredientiLetti.Length; i++)
            {
                if (!string.IsNullOrWhiteSpace(ingredientiLetti[i]))
                {
                    long progressivo = long.Parse(ingredientiLetti[i]);
                    progressiviIngredienti.Add(progressivo);
                }
            }
            SostanzeManager manager  = new SostanzeManager(DatabaseContext);
            NewSostanze     sostanza = manager.GetSubstanceFromListOfComponents(progressiviIngredienti);

            ElaborazioneViews.SetActiveView(viewRisultato);
            if (sostanza != null)
            {
                if (sostanza.Tipo == 0 || sostanza.Tipo == 2 || sostanza.Tipo == 3)
                {
                    lblNome.Text = sostanza.Nome;
                    if (!string.IsNullOrWhiteSpace(sostanza.Descrizione))
                    {
                        lblDescrizione.Text = sostanza.Descrizione.Replace("\r", "<br />");
                    }
                    if (!string.IsNullOrWhiteSpace(sostanza.Effetto))
                    {
                        lblEffetto.Text = sostanza.Effetto.Replace("\r", "<br />");
                    }
                    lblData.Text      = sostanza.DataScadenza.HasValue ? sostanza.DataScadenza.Value.ToString("dd/MM/yyyy") : string.Empty;
                    lblCosto.Text     = sostanza.Costo.ToString();
                    lblEfficacia.Text = sostanza.ValoreEfficacia.ToString();
                    lblTipo.Text      = sostanza.TipoSostanze.Descrizione;
                    lblModoUso.Text   = sostanza.ModoUso;
                    if (!string.IsNullOrWhiteSpace(sostanza.Immagine))
                    {
                        imgOggetto.Visible  = true;
                        imgOggetto.ImageUrl = sostanza.Immagine;
                    }
                    btnCrea.Enabled = false;
                }
                else
                {
                    resetResults();
                    ElaborazioneViews.SetActiveView(viewAttesa);
                    lblDescrizione.Text = "Gli ingredienti inseriti non hanno dato un risultato";
                }
            }
            else
            {
                resetResults();
                ElaborazioneViews.SetActiveView(viewAttesa);
                lblDescrizione.Text = "Gli ingredienti inseriti non hanno dato un risultato";
            }
        }
Beispiel #7
0
        void qrReader_OnCodeDecoded(object sender, EventArgs e)
        {
            string myCode = qrReader.Code;

            svuotaControlli();
            if (!string.IsNullOrEmpty(myCode))
            {
                Guid uniqueCode;
                try
                {
                    uniqueCode = new Guid(myCode);
                }
                catch
                {
                    lblDescrizione.Text = "Cartellino non valido"; //Se il codice è un codice ad cazzum, non un GUID, è ovviamente un QR Code sbagliato
                    return;
                }
                SostanzeManager manager = new SostanzeManager(DatabaseContext);
                NewSostanze     myItem  = manager.GetSubstanceFromQRCode(uniqueCode);
                if (myItem == null)
                {
                    lblDescrizione.Text = "Non è un cartellino di un composto";
                    return;
                }
                if (myItem.Tipo == 0 || myItem.Tipo == 2 || myItem.Tipo == 3)
                {
                    lblNome.Text = myItem.Nome;
                    if (!string.IsNullOrWhiteSpace(myItem.Descrizione))
                    {
                        lblDescrizione.Text = myItem.Descrizione.Replace("\r", "<br />");
                    }
                    if (!string.IsNullOrWhiteSpace(myItem.Effetto))
                    {
                        lblEffetto.Text = myItem.Effetto.Replace("\r", "<br />");
                    }
                    lblData.Text      = myItem.DataScadenza.HasValue ? myItem.DataScadenza.Value.ToString("dd/MM/yyyy") : string.Empty;
                    lblCosto.Text     = myItem.Costo.ToString();
                    lblEfficacia.Text = myItem.ValoreEfficacia.ToString();
                    lblTipo.Text      = myItem.TipoSostanze.Descrizione;
                    lblModoUso.Text   = myItem.ModoUso;
                    if (!string.IsNullOrWhiteSpace(myItem.Immagine))
                    {
                        imgOggetto.Visible  = true;
                        imgOggetto.ImageUrl = myItem.Immagine;
                    }
                }
                else
                {
                    lblDescrizione.Text = "La sostanza non è nè un ingrediente nè una tossina o droga (forse medicinale?)";
                }
            }
        }
Beispiel #8
0
        public NewSostanze GetSubstanceFromListOfComponents(List <long?> ingredienti)
        {
            //var query = (from sostanze in context.NewElementis
            //             join formule in context.NewFormules on sostanze equals formule.Composto
            //             where ingredienti.Contains(formule.NewElementi.Progressivo)
            //             && sostanze.Componenti.Count() == ingredienti.Count
            //             select sostanze);

            var query = from formule in context.NewFormules
                        where ingredienti.Contains(formule.Ingrediente)
                        group formule by formule.Risultato into selezione
                        select new { numero = selezione.Key, elementi = selezione };
            NewSostanze sostanza = null;

            foreach (var element in query)
            {
                var query2 = (from sostanze in context.NewElementis
                              where sostanze.Progressivo == element.numero &&
                              sostanze.Componenti.Count == ingredienti.Count
                              select sostanze).OfType <NewSostanze>().FirstOrDefault();
                //sostanza = GetSubstanceFromNumber(element.numero);
                if (query2 != null && query2 is NewSostanze)
                {
                    //controlliamo l'ORDINE degli ingredienti
                    var componenti = (from components in query2.Componenti
                                      orderby components.NumeroIngrediente
                                      select components).ToList();
                    bool found = true;
                    for (int i = 0; i < ingredienti.Count; i++)
                    {
                        if (ingredienti[i] != componenti[i].Ingrediente)
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found)
                    {
                        return((NewSostanze)query2);
                    }
                }
            }
            return(sostanza);
        }
Beispiel #9
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);
     }
 }
Beispiel #10
0
 public InsertSostanza(long itemToEdit)
     : this()
 {
     originalItem = itemToEdit;
     using (databaseContext = CreateDatabaseContext())
     {
         SostanzeManager manager  = new SostanzeManager(databaseContext);
         NewSostanze     original = manager.GetSubstanceFromNumber(itemToEdit);
         txtNome.Text                   = original.Nome;
         txtDescrizione.Text            = original.Descrizione;
         txtEffetto.Text                = original.Effetto;
         mstxCosto.Text                 = original.Costo.ToString();
         mstxEfficacia.Text             = original.ValoreEfficacia.ToString();
         cmbDisponibilita.SelectedValue = original.Disponibilita;
         cmbTipo.SelectedValue          = original.Tipo;
         cmbModoUso.SelectedItem        = original.ModoUso;
         calScadenza.SelectionStart     = calScadenza.SelectionEnd = original.DataScadenza.HasValue ? original.DataScadenza.Value : DateTime.Today;
     }
 }
Beispiel #11
0
        public bool RemoveComponentFromSubstance(long progressivoOggetto, long numeroIngrediente)
        {
            try
            {
                var ingrediente = (from componenti in context.NewFormules
                                   where componenti.Risultato == progressivoOggetto &&
                                   componenti.NumeroIngrediente == numeroIngrediente
                                   select componenti).FirstOrDefault();

                if (ingrediente != null)
                {
                    NewSostanze item = (from sostanze in context.NewElementis
                                        where sostanze.Progressivo == progressivoOggetto
                                        select sostanze).OfType <NewSostanze>().FirstOrDefault();
                    item.Componenti.Remove(ingrediente);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }