public bool IsCompatibleWith(COMMANDE cmd)
        {
            bool isCompatible = false;

            using (var context = new PalaisDuBonbonEntities())
            {
                string cmd_cond = context.CONDITIONNEMENTs.Where(c => c.CONDITIONNEMENT_ID == cmd.CONDITIONNEMENT_ID).FirstOrDefault().CONDITIONNEMENT_NOM;
                if (type == cmd_cond)
                {
                    isCompatible = true;
                }
                return(isCompatible);
            }
        }
        public bool IsCompatibleWith(COMMANDE cmd)
        {
            bool isCompatible = false;

            using (var context = new PalaisDuBonbonEntities())
            {
                string bonbon_variante = context.BONBONs.Where(b => b.BONBON_ID == cmd.BONBON_ID).FirstOrDefault().VARIANTE.VARIANTE_NOM;
                if (variantes.Contains(bonbon_variante))
                {
                    isCompatible = true;
                }
            }

            return(isCompatible);
        }
Esempio n. 3
0
        public static void GenerateOrders()
        {
            var configData = GetConfigOrderGenerationDataJSON();

            int  total_orders        = (int)configData.nb_commandes.Value;
            bool useRandom_countries = configData.useRandom_countries.Value;
            bool useRandom_candies   = configData.useRandom_candies.Value;

            List <COMMANDE>        _generated_orders     = new List <COMMANDE>();
            Dictionary <PAYS, int> Countries_OrdersCount = new Dictionary <PAYS, int>();

            Console.WriteLine("---- Starting ORDERS GENERATION");

            using (var context = new PalaisDuBonbonEntities())
            {
                foreach (PAYS p in context.PAYS)
                {
                    PAYS pays        = p;
                    int  ordersCount = (int)(p.RATIO_COMMANDE * total_orders) / 100;
                    Countries_OrdersCount.Add(p, ordersCount);
                }

                if (!useRandom_countries)
                {
                    foreach (KeyValuePair <PAYS, int> pays in Countries_OrdersCount)
                    {
                        for (int i = 0; i < pays.Value; i++) // pays.value = nb de cmds d'un pays
                        {
                            int      num_commande         = rnd.Next(100000, 999999);
                            int      data_generation_year = (int)configData.generation_fabrication_data_date;
                            DateTime date_commande        = DateTime.Now;
                            int      nb_lots = rnd.Next((int)configData.lots_min.Value, (int)configData.lots_max.Value); // nb de lots a generer

                            for (int n = 0; n < nb_lots; n++)
                            {
                                COMMANDE commande = new COMMANDE();

                                commande.COMMANDE_NUM_COMMANDE         = num_commande;
                                commande.COMMANDE_ETAT                 = false;
                                commande.COMMANDE_DATE_COMMANDE        = date_commande;
                                commande.COMMANDE_DATE_FABRICATION     = null;
                                commande.COMMANDE_DATE_CONDITIONNEMENT = null;
                                commande.COMMANDE_DATE_EXPEDITION      = null;
                                commande.PAYS_ID           = pays.Key.PAYS_ID;
                                commande.PAY               = pays.Key;
                                commande.COMMANDE_QUANTITE = nb_lots;

                                int cond_count         = context.CONDITIONNEMENTs.Count();
                                int rndConditionnement = rnd.Next(1, cond_count + 1);
                                commande.CONDITIONNEMENT    = context.CONDITIONNEMENTs.Where(cd => cd.CONDITIONNEMENT_ID == rndConditionnement).First();
                                commande.CONDITIONNEMENT_ID = commande.CONDITIONNEMENT.CONDITIONNEMENT_ID;

                                int randomBonbon = rnd.Next(0, 100);

                                var bonbon_probas = GetFactoryDataJSON().taux_ventes_2016;
                                //   int selected_bonbon = 0;
                                // int selected_bonbon_id = 0;
                                float  myValue            = 0f;
                                string choosed_candy_name = "";
                                foreach (var prob in bonbon_probas)
                                {
                                    float valeur = prob.valeur;
                                    myValue += valeur;
                                    if (myValue >= randomBonbon)
                                    {
                                        choosed_candy_name = prob.type_bonbon;
                                        break;
                                    }

                                    /*selected_bonbon_id++;
                                     * int val = prob.valeur;
                                     * selected_bonbon += val;
                                     * if (selected_bonbon >= randomBonbon)
                                     * {
                                     *  break;
                                     * }*/
                                }
                                List <BONBON> bonbons_available = context.BONBONs.Where(b => b.BONBON_TYPE == choosed_candy_name).ToList();
                                commande.BONBON    = bonbons_available.ElementAt(rnd.Next(bonbons_available.Count));
                                commande.BONBON_ID = commande.BONBON.BONBON_ID;

                                PRIX_LOT test = context.PRIX_LOT.Where(pl => pl.CONDITIONNEMENT_ID == commande.CONDITIONNEMENT.CONDITIONNEMENT_ID).Single(pl => pl.BONBON.BONBON_TYPE == commande.BONBON.BONBON_TYPE);


                                commande.COMMANDE_PRIX_LOT = commande.COMMANDE_QUANTITE * test.PRIX_LOT_PRIX;

                                _generated_orders.Add(commande);
                                Console.WriteLine("-------- Order Generated");
                            }
                        }
                    }
                }

                int counter = 0;
                foreach (COMMANDE com in _generated_orders)
                {
                    Console.WriteLine("-------- Pushing Order No (" + counter + "/" + _generated_orders.Count + ")");
                    context.COMMANDEs.Add(com);
                    if ((counter % 100) == 0)
                    {
                        Console.WriteLine("-------- Saving changes....");
                        context.SaveChanges();
                    }
                    counter++;
                }
                Console.WriteLine("-------- Saving changes....");
                context.SaveChanges();
                Console.WriteLine("---- ORDERS GENERATION DONE");
                Console.WriteLine("---- WRITING GENERATED DATA TO generated_orders.json");
                //  string jsonCommandes = JsonConvert.SerializeObject(_generated_orders);
                //   GenerateOrdersJSONFile(jsonCommandes);
                Console.WriteLine("---- CLOSING CONNEXION...");
            }

            Console.WriteLine("---- WRITING DONE ! END OF FUNC");
        }
 public void PickOrder(COMMANDE order, ref List <COMMANDE> to_process)
 {
     this.cmd = order;
     to_process.Remove(order);
     ProcessOrder();
 }