Exemple #1
0
        private void calcWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            #region Pre-calculation Stuff
            //clear all of the previous calc stuff out.
            calcitems.Clear();
            StoreDictionary.Clear();
            storeid.Clear();
            blacklistdic.Clear();
            matches              = new List <FinalMatch>();
            displayreport        = false;
            longcount            = 0;
            storeprogresscounter = 0;
            matchesfound         = false;
            calcfail             = false;

            calcitems = dt2item(dt[currenttab]);

            // Slicker way to remove the unwanted elements.  CAC, 2015-07-01
            for (int i = calcitems.Count - 1; i >= 0; i--)
            {
                Item item = calcitems[i];
                if ((item.status == "X") || (item.qty == 0))
                {
                    calcitems.RemoveAt(i);
                }
            }

            if (calcWorker.CancellationPending)
            {
                return;
            }

            GetValidStores();

            if (calcWorker.CancellationPending)
            {
                return;
            }

            GetPGPages(settings.login);

            // This removes from consideration any stores that don't have any of the wanted items
            // since they cannot contribute to a solution.  This can reduce the number of stores
            // that need to be considered significantly.
            RemoveStoresWitoutAnyWantedItems(); // Added by CAC, 2015-07-01

            if (calcWorker.CancellationPending)
            {
                return;
            }

            if (calcfail == true)
            {
                AddStatus(Environment.NewLine + "Some items were unavailable. Calculation cancelled." + Environment.NewLine);
                ResetProgressBar();
                EnableMenu();
                return;
            }

            if (calcWorker.CancellationPending)
            {
                return;
            }

            AddMissingItemsToStores();

            StoreList      = StoreDictionaryToList(StoreDictionary);
            WantedItemList = new List <Item>(calcitems);

            ReportStart();
            #endregion

            switch (whichAlgToRun)
            {
            case RUN_OLD:
                runTheAlgorithm(settings.minstores, settings.maxstores, settings.cont, StoreList, WantedItemList, RunOldAlgorithmOn, StandardPreProcess);
                break;

            case RUN_NEW:
                runTheAlgorithm(settings.minstores, settings.maxstores, settings.cont, StoreList, WantedItemList, KStoreCalc, StandardPreProcess);
                break;

            case RUN_CUSTOM:
                runTheAlgorithm(settings.minstores, settings.maxstores, settings.cont, StoreList, WantedItemList, CustomAlgorithm, CustomPreProcess);
                break;

            case RUN_APPROX:
                runApproxAlgorithm(settings.minstores, settings.maxstores, settings.approxtime * 1000, StoreList, WantedItemList, KStoreCalc, StandardPreProcess);
                break;

            case RUN_CUSTOM_APPROX:
                runApproxAlgorithm(settings.minstores, settings.maxstores, settings.approxtime * 1000, StoreList, WantedItemList, CustomApproximationAlgorithm, CustomApproximationPreProcess);
                break;
            }

            #region Post-Calculation stuff
            EnableMenu();
            DisableCalcStop();
            ResetProgressBar();
            statusQueueTimer.Stop();

            if (displayreport == true)
            {
                try
                {
                    System.Diagnostics.Process.Start(outputfilename);
                }
                catch
                {
                    AddStatus("Error displaying report in your default web browser." + Environment.NewLine +
                              "Report file is available here: " + outputfilename + Environment.NewLine);
                }
            }
            AddStatus(Environment.NewLine + "Done." + Environment.NewLine + Environment.NewLine);
            #endregion
        }