Exemplo n.º 1
0
        public static void nextWeekPredictions(int date, Action t1_OnProgressUpdate)
        {
            ItemConsumption.readAllItemData(date);
            OnProgressUpdate += t1_OnProgressUpdate;
            List <string> allCustomers = new List <string>();

            var    connectionString = ConfigurationManager.ConnectionStrings[name : "PED"].ConnectionString;
            string Table            = ConfigurationManager.AppSettings[name : "PurchaseHistory"];
            string CustomerID       = ConfigurationManager.AppSettings[name : "PurchaseHistory_CustomerID"];
            string PurchaseDate     = ConfigurationManager.AppSettings[name : "PurchaseHistory_PurchaseDate"];

            string queryString = "select distinct(" + CustomerID + ") from " + Table + " where " + PurchaseDate + "< @date";

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                var command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@date", date);

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        allCustomers.Add(reader[0].ToString());
                    }
                }
            }

            int custCount = allCustomers.Count();
            var listCust  = allCustomers.ToList();

            Tcount = custCount;
            Dcount = 0;
            Parallel.For(0, custCount, new ParallelOptions {
                MaxDegreeOfParallelism = 50
            }, i =>
            {
                Customer newCustomer = new Customer()
                {
                    custNo = listCust[i]
                };

                newCustomer.PredictAllItems(date);
                Dcount++;

                OnProgressUpdate?.Invoke();
            });
        }
 public void addData(ItemConsumption dataToAdd)
 {
     allData.Add(dataToAdd);
 }