public BettingHelperController(BettingHelperWindow window)
 {
     this.window                          = window ?? throw new ArgumentException("Window must not be null.");
     backgroundWorker                     = new BackgroundWorker();
     backgroundWorker.DoWork             += new DoWorkEventHandler(RunExcelWork);
     backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkComplete);
 }
Esempio n. 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var window     = new BettingHelperWindow();
            var controller = new BettingHelperController(window);

            window.Controller = controller;
            Application.Run(window);
        }
        public async void LoadButtonClicked(BettingHelperWindow window)
        {
            window.SetTextForAllStatusLabels("Hämtar data...");
            window.ToggleLoadButton(false);

            var svsTask = dataLoader?.DownloadSvenskaSpelData();

            try
            {
                Dictionary <string, SvenskaSpelDraw> svsData = await svsTask;
                ProcessData(svsData);
            }
            catch (OperationCanceledException exc)
            {
                window.ToggleLoadButton(true);
                window.ShowErrorMessage(window, "Timeout", "Kunde inte hämta data från spelbolag.");
            }
            catch (Exception ex)
            {
                window.ToggleLoadButton(true);
                window.ShowErrorMessage(window, "Fel!", "Ett oväntat fel har inträffat!");
            }
        }
        public void OpenFileClicked(BettingHelperWindow window)
        {
            string excelPath = window.ShowOpenFileDialog();

            if (excelPath == null)
            {
                return;
            }
            try
            {
                dataLoader = new BettingDataLoader(excelPath);
                window.TogglePickFileButton(false);
                window.SetPickFileButtonText("Öppnar fil...");
                window.SetPickFileButtonText("Öppna Excel-fil");
                window.SetStatusLabelText($"Laddad Excel-fil: {excelPath}");
                window.ToggleLoadButton(true);
                window.TogglePickFileButton(true);
                _excelPath = excelPath;
            }
            catch (IOException exc)
            {
                window.ShowErrorMessage(window, "Fel!", exc.Message);
            }
        }