Example #1
0
 public SerieViewModel(ref SerieOnline serie)
 {
     WindowTitle = serie.Name;
     Serie       = serie;
     Name        = serie.Name;
     Dm          = serie.Dm;
     Multipliers = new ObservableCollection <KeyValuePair <string, double> >()
     {
         new KeyValuePair <string, double>("1000", 1000),
         new KeyValuePair <string, double>("100", 100),
         new KeyValuePair <string, double>("10", 10),
         new KeyValuePair <string, double>("1 (Brak mnożnika)", 1),
         new KeyValuePair <string, double>("0,1", 0.1),
         new KeyValuePair <string, double>("0,01", 0.01),
         new KeyValuePair <string, double>("0,001", 0.001)
     };
     try
     {
         double multiplication = serie.Multiplier;
         MultiplierSelectedItem = Multipliers.Where(x => x.Value.Equals(multiplication)).First();
     } catch
     {
         MultiplierSelectedItem = new KeyValuePair <string, double>("1 (Brak mnożnika)", 1);
     }
     Save   = new RelayCommand(SaveAction, CanSave);
     Cancel = new RelayCommand(CancelAction, CanCancel);
 }
Example #2
0
 private bool ExportSeriesXML(string path)
 {
     try
     {
         //Export only Series Online
         ObservableCollection <SerieOnline> toExport = new ObservableCollection <SerieOnline>();
         foreach (Serie serie in Series)
         {
             SerieOnline serieOnline = serie as SerieOnline;
             if (serieOnline != null)
             {
                 toExport.Add(serieOnline);
             }
         }
         System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(toExport.GetType());
         FileStream fs = new FileStream(path, FileMode.Create);
         serializer.Serialize(fs, toExport);
         //IP in last line as comment
         byte[] connectionInfo = Encoding.ASCII.GetBytes("<!--|" + ConnectionViewModel.Ip + "|" + ConnectionViewModel.Port + "|-->");
         fs.Write(connectionInfo, 0, connectionInfo.Length);
         fs.Close();
         return(true);
     }
     catch {
         MessageBox.Show("Nie udało się wyeksportować serii", "Eksport", MessageBoxButton.OK, MessageBoxImage.Error);
         return(false);
     }
 }
        private void GetValuesTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            OnPropertyChanged("ConnectionStatus");
            OnPropertyChanged("ButtonConnectDisconnectContent");
            OnPropertyChanged("CanEditConnectionSetting");
            for (int i = 0; i < Series.Count; i++)
            {
                SerieOnline serie = Series[i];
                int?        value = plc.getValue(serie.Dm);
                if (value != null)
                {
                    int      _value = (int)value;
                    DateTime now    = DateTime.Now;
                    now = new DateTime(
                        now.Year,
                        now.Month,
                        now.Day,
                        now.Hour,
                        now.Minute,
                        now.Second);
                }
            }
            try
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() => CollectionViewSource.GetDefaultView(Series).Refresh()));
                ChartMove();
                Plot.InvalidatePlot(true);
            }
            catch { }

            if (SelectedItemTableView == null)
            {
                OnPropertyChanged("TableView");
            }
        }
        //Dodac powyższe w ścieżce niżej

        private void GetValuesTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (plc.ConnectionStatus == ConnectionStatusEnum.CONNECTED)
            {
                for (int i = 0; i < SeriesOnline.Count; i++)
                {
                    SerieOnline serie = SeriesOnline[i] as SerieOnline;
                    if (serie != null)
                    {
                        int?     value = plc.GetValue(serie.Dm);
                        DateTime now   = DateTime.Now;
                        if (value != null)
                        {
                            int _value = (int)value;
                            now = new DateTime(
                                now.Year,
                                now.Month,
                                now.Day,
                                now.Hour,
                                now.Minute,
                                now.Second);
                            serie.add(now, _value);

                            try
                            {
                                StringBuilder.Clear();
                                using (FileStream fs = new FileStream(Path.Combine(LogsFolderPath ?? string.Empty, StringBuilder.Append(LogsFilePrefix).Append(DateTime.Now.ToString("yyyy.MM.dd")).Append(".txt").ToString()), FileMode.Append))
                                {
                                    StringBuilder.Clear();
                                    var    lineToWrite  = StringBuilder.Append(serie.Name).Append("\t").Append(now).Append("\t").Append(_value * serie.Multiplier).Append("\r\n").ToString();
                                    byte[] bytesToWrite = new UTF8Encoding(true).GetBytes(lineToWrite);
                                    fs.Write(bytesToWrite, 0, bytesToWrite.Length);
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"{ex.Message}");
                            }
                        }
                    }
                }
                try
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => CollectionViewSource.GetDefaultView(SeriesOnline).Refresh()));
                    PlotViewModel.ChartMove();
                    PlotViewModel.InvalidatePlot(true);
                }
                catch { }

                //if (SelectedItemTableView == null)
                //{
                TableViewModel.Refresh();
                //}
            }
        }
        private void EditSerieAction(object obj)
        {
            SerieOnline selectedItem = obj as SerieOnline;

            if (selectedItem != null)
            {
                new AddEditSerieWindow(ref selectedItem).ShowDialog();
                CollectionViewSource.GetDefaultView(Series).Refresh();
                OnPropertyChanged("TableView");
                Plot.InvalidatePlot(true);
            }
        }
        private void EditSerieAction(object obj)
        {
            SerieOnline selectedItem = obj as SerieOnline;

            if (selectedItem != null)
            {
                new AddEditSerieWindow(ref selectedItem).ShowDialog();
                CollectionViewSource.GetDefaultView(Series).Refresh();
                Command("Table.Refresh");
                Command("Plot.Refresh");
            }
        }
        //private SerieOnline selectedItem;
        //public SerieOnline SelectedItem
        //{
        //    get { return selectedItem; }
        //    set
        //    {
        //        selectedItem = value;
        //        OnPropertyChanged("ButtonHideShowSerieContent");
        //    }
        //}



        //public string FilePath { get; set; }


        private void AddSerieAction(object obj)
        {
            SerieOnline     newSerie     = new SerieOnline("Nowa seria", 0);
            Nullable <bool> dialogResult = new AddEditSerieWindow(ref newSerie).ShowDialog();

            if (dialogResult == true)
            {
                Series.Add(newSerie);
            }
            Command("Table.Refresh");
            Command("Plot.Refresh");
        }
        private void HideShowSerieAction(object obj)
        {
            SerieOnline selectedItem = obj as SerieOnline;

            if (selectedItem != null)
            {
                selectedItem.Visibility = !selectedItem.Visibility;
            }
            OnPropertyChanged("ButtonHideShowSerieContent");
            CollectionViewSource.GetDefaultView(Series).Refresh();
            OnPropertyChanged("TableView");
            Plot.InvalidatePlot(true);
        }
        private void AddSerieAction(object obj)
        {
            SerieOnline     newSerie     = new SerieOnline("Nowa seria", 0);
            Nullable <bool> dialogResult = new AddEditSerieWindow(ref newSerie).ShowDialog();

            if (dialogResult == true)
            {
                Series.Add(newSerie);
                newSerie.Data.CollectionChanged += Data_CollectionChanged;
            }
            OnPropertyChanged("TableView");
            Plot.InvalidatePlot(true);
        }
        private void DeleteSerieAction(object obj)
        {
            SerieOnline selectedItem = obj as SerieOnline;

            if (selectedItem != null)
            {
                if (MessageBox.Show("Usunąć serię " + selectedItem.Name + "?", "Potwierdzenie", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == (MessageBoxResult.Yes))
                {
                    Series.Remove(selectedItem);
                    CollectionViewSource.GetDefaultView(Series).Refresh();
                    OnPropertyChanged("TableView");
                    Plot.InvalidatePlot(true);
                }
            }
        }
Example #11
0
        private void GetValuesTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (plc.ConnectionStatus == ConnectionStatusEnum.CONNECTED)
            {
                for (int i = 0; i < Series.Count; i++)
                {
                    SerieOnline serie = Series[i] as SerieOnline;
                    if (serie != null)
                    {
                        int?     value = plc.getValue(serie.Dm);
                        DateTime now   = DateTime.Now;
                        if (value != null)
                        {
                            int _value = (int)value;
                            now = new DateTime(
                                now.Year,
                                now.Month,
                                now.Day,
                                now.Hour,
                                now.Minute,
                                now.Second);
                            serie.add(now, _value);
                        }
                    }
                }
                try
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => CollectionViewSource.GetDefaultView(Series).Refresh()));
                    PlotViewModel.ChartMove();
                    PlotViewModel.InvalidatePlot(true);
                }
                catch { }

                //if (SelectedItemTableView == null)
                //{
                TableViewModel.Refresh();
                //}
            }
        }
 public AddEditSerieWindow(ref SerieOnline serie)
 {
     InitializeComponent();
     DataContext = new SerieViewModel(ref serie);
 }