aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs
blob: e7d263a1c177dbf85be510d2e9940f4d80dbb675 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using OxyPlot;
using OxyPlot.Axes;
using System;
using System.Threading.Tasks;
using System.Windows;
using Tango.DispenserAnalyzer.UI.ViewModels;

namespace Tango.DispenserAnalyzer.UI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MainWindowVM _vm;

        public string WindowTitle
        {
            get
            {
                Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                return "Dispenser Analyzer - Version" + version;
            }
        }
        

        public MainWindow()
        {
            InitializeComponent();
            _vm = new MainWindowVM();
            DataContext = _vm;
            _vm.PlotControl = PressurePlot;
            _vm.ResultsPanel = resultItems;
            
            foreach (var ax in PressurePlot.Axes)
                ax.Maximum = ax.Minimum = Double.NaN;
        }

        public async void GenerateResultsInBackground( string[] filePathArr)
        {
            if(_vm != null)
            {
                for (int index = 0; index < filePathArr.Length; index++)
                {
                    await _vm.GenerateInBackground(filePathArr[index]);
                    if(index < filePathArr.Length)
                    {
                        await Task.Delay(500);
                    }
                }
            }
            await Task.Delay(500);
            Application.Current.Shutdown();
        }

        private void TextBlock_PreviewDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files != null && files.Length != 0 && System.IO.Path.GetExtension(files[0]).ToUpperInvariant() == ".CSV")
            {
                tbPath.Text = files[0];
            }
            e.Handled = true;
        }
        
        private void TextBox_PreviewDragOver(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files == null || files.Length == 0 || System.IO.Path.GetExtension(files[0]).ToUpperInvariant() != ".CSV")
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
            else
            {
                e.Effects = DragDropEffects.All;
                e.Handled = true;
            }
        }

        private void RangeToCountPlot_Loaded(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

        }
    }
}