Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int filterReference;
- public int focusReference;
- public MainWindow()
- {
- InitializeComponent();
- PlotListView.SelectionChanged += PlotListView_SelectionChanged;
- // Establish MySQL connection
- var dbObject = new DbConnect();
- dbObject.OpenConnection();
- // Reset plot (job/bid)
- ResetPlot(filterReference);
- // Refresh plot (job/bid)
- RefreshPlotTimer();
- }
- public void PlotListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (PlotListView.SelectedItems.Count == 0) return;
- var selectedItem = (DbConnect.PlotList) PlotListView.SelectedItems[0];
- focusReference = Convert.ToInt32(selectedItem.PlotId);
- Console.Write("PlotListView_SelectionChanged " + focusReference);
- }
- public void ResetPlot(int filterReference)
- {
- // Get current plot number;
- int? plotNumber = filterReference;
- // Establish MySQL connection
- var dbObject = new DbConnect();
- dbObject.OpenConnection();
- // Fill plot list view
- List<DbConnect.PlotList> plotList = dbObject.SelectPlotLists(filterReference);
- // Find the plot list in the new list
- DbConnect.PlotList selectPlotList =
- plotNumber.HasValue
- ? plotList.Where(x => Convert.ToInt32(x.PlotId) == plotNumber.Value).FirstOrDefault()
- : null;
- Dispatcher.BeginInvoke(
- new ThreadStart(() => PlotListView.ItemsSource = plotList));
- // Re-select plot list if found in the new list.
- if (selectPlotList != null)
- {
- PlotListView.SelectedItem = selectPlotList;
- }
- int jobSum = 0;
- int bidSum = 0;
- foreach (DbConnect.PlotList item in PlotListView.Items)
- {
- jobSum += Convert.ToInt32(item.Jobs);
- bidSum += Convert.ToInt32(item.Bids);
- }
- // Determine job/bid list ratio
- Dispatcher.BeginInvoke(
- new ThreadStart(() => JobBidRatioTextBlock.Text = jobSum + " jobs - " + bidSum + " bids"));
- }
- public void RefreshPlotTimer()
- {
- // Create a timer
- var refreshTimer = new Timer();
- // Tell the timer what top do once it elapses
- refreshTimer.Elapsed += (sender, e) => RefreshPlot(sender, e);
- // Set it to go off at a predefined interval
- refreshTimer.Interval = 2500;
- // Start the timer
- refreshTimer.Enabled = true;
- }
- public void RefreshPlot(object source, ElapsedEventArgs e)
- {
- var dbObject = new DbConnect();
- dbObject.OpenConnection();
- dbObject.RefreshPlot();
- Console.WriteLine("\rBefore refresh " + focusReference);
- Dispatcher.Invoke(() =>
- {
- if (!string.IsNullOrWhiteSpace(FilterTextBox.Text) &&
- (!Regex.IsMatch(FilterTextBox.Text, "[^0-9]")))
- {
- filterReference = Convert.ToInt32(FilterTextBox.Text);
- }
- });
- ResetPlot(filterReference);
- Console.WriteLine("After refresh " + focusReference);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement