Exemplo n.º 1
0
        public static Recepta DonamRecepta(string id, IEnumerable <Ingredient> ingredients)
        {
            Recepta recepta = new Recepta(id);

            recepta.Afegir(ingredients);
            return(recepta);
        }
Exemplo n.º 2
0
        public decimal EsPodenFer(Estoc estoc, Recepta recepta)
        {
            decimal quantiatMin = Decimal.MaxValue;
            decimal quantiatAct = 0;

            if (ReceptaOriginal.PrimaryKey != new Recepta().PrimaryKey)
            {
                try {
                    foreach (Ingredient ingredient in recepta)
                    {
                        quantiatAct = estoc[ingredient.Producte.PrimaryKey].QuantitatTotal / ingredient.Quantitat;
                        if (quantiatAct < quantiatMin)
                        {
                            quantiatMin = quantiatAct;
                        }
                    }
                } catch {
                    quantiatMin = 0;
                }
            }
            else
            {
                quantiatMin = 0;
            }
            return(quantiatMin);
        }
Exemplo n.º 3
0
 public Producte(string idProducte)
     : base("Productes", idProducte, "IdProducte")
 {
     semaforAltaBaixa = new Semaphore(1, 1);
     AltaCanvi("IdRecepta");
     AltaCanvi("InfoExtra");
     AltaCanvi("RutaImatge");
     AltaCanvi("Categoria");
     AltaCanvi("Unitat");
     AltaCanvi("TempsUnCopFet");
     AltaCanvi("TempsUnCopObert");
     AltaCanvi("TempsAvisPerCaducar");
     AltaCanvi("QuantitatMinimaEstoc");
     AltaCanvi("QuantitatNormalEstoc");
     receptaOri           = new Recepta();
     unitats              = new SortedList <ulong, UnitatProducte>();
     unitatsBaixaProducte = new SortedList <ulong, UnitatProducte>();
     tempsAvisPerCaducar  = new TimeSpan(3, 0, 0, 0);
     tempsUnCopFet        = new TimeSpan();
     tempsUnCopObert      = new TimeSpan();
     unitat               = "SenseUnitat";
     categoria            = "SenseCategoria";
     quantitatMinimaEstoc = 0;
     quantitatNormalEstoc = 0;
     rutaImatge           = "";
     infoExtra            = "";
 }
Exemplo n.º 4
0
        public override dynamic Restaurar()
        {
            Estoc estocDessat = new Estoc();

            try
            {
                BaseDeDades.Desconecta();
                BaseDeDades.Conecta();
                Recepta[]        receptes  = Recepta.ReceptesDessades(BaseDeDades);
                Producte[]       productes = Producte.ProductesDessats(BaseDeDades, receptes);
                UnitatProducte[] unitats   = UnitatProducte.UnitatsDessades(BaseDeDades, receptes, productes);
                estocDessat.Afegir(productes);
                //poso els objectes en el control!
                Afegir(receptes);
                for (int i = 0; i < receptes.Length; i++)
                {
                    foreach (Ingredient ingredient in receptes[i])
                    {
                        Afegir(ingredient);
                    }
                }
                Afegir(productes);
                Afegir(unitats);
            }
            catch { }
            return(estocDessat);
        }
Exemplo n.º 5
0
        public static UnitatProducte[] FabricaElMax(Producte producte, Estoc estoc, Recepta recepta)
        {
            List <UnitatProducte> unitatsFetes = new List <UnitatProducte>();
            UnitatProducte        unitatFeta   = Fabrica(producte, estoc, recepta);

            while (unitatFeta != null)
            {
                unitatsFetes.Add(unitatFeta);
                unitatFeta = Fabrica(producte, estoc, recepta);
            }
            return(unitatsFetes.ToArray <UnitatProducte>());
        }
Exemplo n.º 6
0
        public static UnitatProducte[] FabricaElMax(Producte producte, Recepta recepta, IEnumerable <Producte> productesPerFerLo)
        {
            List <UnitatProducte> unitatsFetes = new List <UnitatProducte>();
            UnitatProducte        unitatFeta   = Fabrica(producte, recepta, productesPerFerLo);

            while (unitatFeta != null)
            {
                unitatsFetes.Add(unitatFeta);
                unitatFeta = Fabrica(producte, recepta, productesPerFerLo);
            }
            return(unitatsFetes.ToArray <UnitatProducte>());
        }
Exemplo n.º 7
0
 public UnitatProducte(Producte producte, decimal quantiat, DateTime dataCaducitat, DateTime dataObertura, Recepta recepta)
     : this(producte, quantiat, dataCaducitat, dataObertura)
 {
     if (recepta != null)
     {
         this.recepta = recepta;
     }
     else
     {
         this.recepta = new Recepta();
     }
 }
Exemplo n.º 8
0
 public Producte(string idProducte, string categoria, string unitat, TimeSpan tempsAvisPerCaducar, TimeSpan tempsUnCopObert, TimeSpan tempsUnCopFet, Recepta receptaOriginal)
     : this(idProducte, categoria, unitat, tempsAvisPerCaducar, tempsUnCopObert)
 {
     if (receptaOriginal != null)
     {
         this.receptaOri = receptaOriginal;
     }
     else
     {
         this.receptaOri = new Recepta();
     }
     this.tempsUnCopFet = tempsUnCopFet;
 }
Exemplo n.º 9
0
 public UnitatProducte(Producte producte)
 {
     if (producte == null)
     {
         throw new Exception("La unitatProducte Ha de tenir un producte associat!! ");
     }
     AltaCanvi("DataObertura");
     AltaCanvi("DataCaducitat");
     AltaCanvi("IdProducte");
     AltaCanvi("IdRecepta");
     AltaCanvi("Quantitat");
     this.producte    = producte;
     dataCaducitat    = new DateTime();
     dataQueEsVaObrir = new DateTime();
     recepta          = new Recepta();
     CampPrimaryKey   = "IdUnitat";
     PrimaryKey       = producte.PrimaryKey + ";unitat";      //algo para hacerlo unico...quizas se autoGenera y no hace falta...
     Taula            = "UnitatsProductes";
     producte.AltaUnitat(this);
 }
Exemplo n.º 10
0
        public static UnitatProducte Fabrica(Producte producte, Recepta recepta, IEnumerable <Producte> productesPerFerLo)
        {
            UnitatProducte unitatFeta = null;
            SortedList <string, Producte> productesIndex = new SortedList <string, Producte>();

            foreach (Producte productePerFer in productesPerFerLo)
            {
                try {
                    productesIndex.Add(productePerFer.PrimaryKey, productePerFer);
                } catch {
                }
            }
            bool esPotFer = true;
            bool acabat   = false;
            IEnumerator <Ingredient> ingredients = recepta.GetEnumerator();

            while (esPotFer && !acabat)
            {
                acabat = !ingredients.MoveNext();
                if (!acabat)
                {
                    esPotFer = productesIndex.ContainsKey(ingredients.Current.Producte.PrimaryKey);
                    if (esPotFer)
                    {
                        esPotFer = (productesIndex[ingredients.Current.Producte.PrimaryKey].QuantitatTotal / ingredients.Current.Quantitat) >= 1;
                    }
                }
            }
            if (esPotFer)
            {
                foreach (Ingredient ingredient in recepta)
                {
                    productesIndex[ingredient.Producte.PrimaryKey].TreuQuantitat(ingredient.Quantitat);
                }
                unitatFeta = new UnitatProducte(producte, 1M, new DateTime(), new DateTime(), recepta);
            }
            return(unitatFeta);
        }
Exemplo n.º 11
0
        public override bool Equals(object obj)
        {
            Recepta recepta = obj as Recepta;
            bool    iguals = recepta != null;
            bool    potPrimer = true, potSegon = false;
            IEnumerator <Ingredient> ingredients = null, ingredientsAComparar = null;

            if (iguals)
            {
                iguals = PrimaryKey == recepta.PrimaryKey;
                if (iguals)
                {
                    ingredients          = this.GetEnumerator();
                    ingredientsAComparar = recepta.GetEnumerator();
                    while (iguals && potPrimer)
                    {
                        potPrimer = ingredients.MoveNext();
                        potSegon  = ingredientsAComparar.MoveNext();
                        if (potSegon.Equals(potPrimer))
                        {
                            if (potPrimer)
                            {
                                iguals = ingredients.Current.Equals(ingredientsAComparar.Current);
                            }
                        }
                        else
                        {
                            iguals = false;
                        }
                    }
                    if (iguals)
                    {
                        iguals = ingredients.MoveNext().Equals(ingredientsAComparar.MoveNext());
                    }
                }
            }
            return(iguals);
        }
Exemplo n.º 12
0
        public static UnitatProducte Fabrica(Producte producte, Estoc estoc, Recepta recepta)
        {
            List <Producte> productesRecepta = new List <Producte>();
            Producte        producteR        = null;

            try {
                if (recepta.PrimaryKey == new Recepta().PrimaryKey)
                {
                    throw new Exception();
                }
                foreach (Ingredient ingredient in recepta)
                {
                    producteR = estoc[ingredient.Producte.PrimaryKey];
                    if (producteR == null)
                    {
                        throw new Exception();
                    }
                    productesRecepta.Add(producteR);
                }
            } catch {
                return(null);
            }
            return(Fabrica(producte, recepta, productesRecepta));
        }
Exemplo n.º 13
0
 public Ingredient(Producte producte, Recepta recepta, decimal quantitat)
     : this(producte, quantitat)
 {
     Recepta = recepta;
     DessaCanvis();
 }
Exemplo n.º 14
0
 public UnitatProducte(Producte producte, decimal quantiat, Recepta recepta)
     : this(producte, quantiat)
 {
     this.recepta = recepta;
 }
Exemplo n.º 15
0
 public static UnitatProducte[] UnitatsDessades(Gabriel.Cat.BaseDeDades baseDeDades)
 {
     Recepta[] receptesDessades = Recepta.ReceptesDessades(baseDeDades);
     return(UnitatsDessades(baseDeDades, receptesDessades, Producte.ProductesDessats(baseDeDades, receptesDessades)));
 }
Exemplo n.º 16
0
 public Producte(string idProducte, string categoria, string unitat, TimeSpan tempsAvisPerCaducar, TimeSpan tempsUnCopObert, TimeSpan tempsUnCopFet, Recepta receptaOriginal, decimal quantitatMinimaEstoc, decimal quantitatNormalEstoc)
     : this(idProducte, categoria, unitat, tempsAvisPerCaducar, tempsUnCopObert, tempsUnCopFet, receptaOriginal)
 {
     this.quantitatMinimaEstoc = Convert.ToInt32(quantitatMinimaEstoc * 100);
     this.quantitatNormalEstoc = Convert.ToInt32(quantitatNormalEstoc * 100);
 }
Exemplo n.º 17
0
 public decimal MaximQuePotHaver(Estoc estoc, Recepta recepta)
 {
     return(QuantitatTotal + EsPodenFer(estoc, recepta));
 }
Exemplo n.º 18
0
 public static Producte[] ProductesDessats(Gabriel.Cat.BaseDeDades baseDeDades)
 {
     return(ProductesDessats(baseDeDades, Recepta.ReceptesDessades(baseDeDades)));
 }