Exemple #1
0
        public MainWindowViewModel()
        {
            //Load settings from settings.xml
            //string settingsFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "settings.xml");
            string settingsFileName = "settings.xml";

            LoadSettings(settingsFileName);
            //As default in properties region

            if (Series == default(ObservableCollection <Serie>))
            {
                Series = new ObservableCollection <Serie>();
            }

            ConnectionViewModel = new ConnectionViewModel(plc);
            ConnectionViewModel.CommandHandler += ViewModel_CommandHandler;
            PlotViewModel = new PlotViewModel(plot, Series);
            PlotViewModel.CommandHandler += ViewModel_CommandHandler;
            TableViewModel = new TableViewModel(Series);
            TableViewModel.CommandHandler += ViewModel_CommandHandler;
            SeriesOnlineDataGridViewModel  = new SeriesOnlineDataGridModelView(Series);
            SeriesOnlineDataGridViewModel.CommandHandler += ViewModel_CommandHandler;
            SeriesArchiveDataGridViewModel = new SeriesArchiveDataGridModelView(Series);
            SeriesArchiveOnlineDataGridViewModel.CommandHandler += ViewModel_CommandHandler;

            plc.ConnectionStatusChanged += Plc_ConnectionStatusChanged;
            plc.ConnectionStatusChanged += PlotViewModel.ConnectionStatusChanged;
            //ConnectionViewModel.Refresh();



            Series.CollectionChanged += Series_CollectionChanged;
            //suszarka = new Serie("Suszarka", 150);
            getValuesTimer          = new System.Timers.Timer();
            getValuesTimer.Elapsed += GetValuesTimer_Elapsed;


            //Series.Add(suszarka);



            //TODO
            //Strzałka aby rozciągnąć Y na górę i dół na maksa


            //getValuesTimer.Interval = interval * 1000;
            //getValuesTimer.Enabled = true;
        }
Exemple #2
0
        private bool ImportSeriesXML(string path)
        {
            try
            {
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection <SerieOnline>));
                FileStream fs = new FileStream(path, FileMode.Open);

                ObservableCollection <SerieOnline> seriesRead = (ObservableCollection <SerieOnline>)serializer.Deserialize(fs);
                fs.Position = fs.Position - 30;
                try
                {
                    if (ConnectionViewModel.CanEditConnectionSetting)
                    {
                        byte[] result = new byte[30];
                        fs.Read(result, 0, 30);
                        string   str = Encoding.ASCII.GetString(result);
                        string   ip;
                        string   port;
                        string[] splitted = str.Split('|');
                        ip   = splitted[1];
                        port = splitted[2];

                        ConnectionViewModel.Ip   = IPAddress.Parse(ip);
                        ConnectionViewModel.Port = ushort.Parse(port);
                        ConnectionViewModel.Refresh();
                    }
                }
                catch { };
                fs.Close();
                foreach (SerieOnline s in seriesRead)
                {
                    Series.Add(s);
                }
                return(true);
            }
            catch {
                MessageBox.Show("Nie udało się zaimportować serii", "Import", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
        public MainWindowViewModel()
        {
            this.ParentViewModel = null;
            this.StringBuilder   = new StringBuilder();
            SeriesOnline         = new ObservableCollection <Serie>();
            SeriesArchive        = new ObservableCollection <Serie>();
            SeriesUsb            = new ObservableCollection <Serie>();

            ConnectionViewModel = new ConnectionViewModel(this, plc);
            ConnectionViewModel.CommandHandler += ViewModel_CommandHandler;

            //Load settings from settings.xml
            //string settingsFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "settings.xml")

            //As default in properties region


            PlotViewModel = new PlotViewModel(this, plot, SeriesOnline);
            PlotViewModel.CommandHandler += ViewModel_CommandHandler;
            TableViewModel = new TableViewModel(this, SeriesOnline);
            TableViewModel.CommandHandler += ViewModel_CommandHandler;
            SeriesOnlineDataGridViewModel  = new SeriesOnlineDataGridModelView(this, SeriesOnline);
            SeriesOnlineDataGridViewModel.CommandHandler += ViewModel_CommandHandler;

            PlotArchiveViewModel = new PlotViewModel(this, plotArchive, SeriesArchive);
            PlotArchiveViewModel.CommandHandler += ViewModel_CommandHandler;
            TableArchiveViewModel = new TableViewModel(this, SeriesArchive);
            TableArchiveViewModel.CommandHandler          += ViewModel_CommandHandler;
            SeriesArchiveDataGridViewModel                 = new SeriesArchiveDataGridViewModel(this, SeriesArchive);
            SeriesArchiveDataGridViewModel.CommandHandler += ViewModel_CommandHandler;

            ConnectionTerminalViewModel                = new ConnectionTerminalViewModel(this);
            PlotUsbViewModel                           = new PlotViewModel(this, plotUsb, SeriesUsb);
            PlotUsbViewModel.CommandHandler           += ViewModel_CommandHandler;
            TableUsbViewModel                          = new TableViewModel(this, SeriesUsb);
            TableUsbViewModel.CommandHandler          += ViewModel_CommandHandler;
            SeriesUsbDataGridViewModel                 = new SeriesUsbDataGridViewModel(this, SeriesUsb);
            SeriesUsbDataGridViewModel.CommandHandler += ViewModel_CommandHandler;

            EditSettings = new RelayCommand(EditSettingsAction);
            LoadSettings();

            plc.ConnectionStatusChanged += Plc_ConnectionStatusChanged;
            plc.ConnectionStatusChanged += PlotViewModel.ConnectionStatusChanged;
            //ConnectionViewModel.Refresh();



            SeriesOnline.CollectionChanged += Series_CollectionChanged;
            //suszarka = new Serie("Suszarka", 150);
            getValuesTimer          = new System.Timers.Timer();
            getValuesTimer.Elapsed += GetValuesTimer_Elapsed;
            SelectedTabIndex        = 0;

            //Series.Add(suszarka);



            //TODO
            //Strzałka aby rozciągnąć Y na górę i dół na maksa


            //getValuesTimer.Interval = interval * 1000;
            //getValuesTimer.Enabled = true;
        }