Пример #1
0
        private void saveToDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path = Directory.GetCurrentDirectory() + @"\Database.db";

            using (var db = new LiteDatabase(@path))
            {
                LiteCollection <DB_SensorDataItem> col = db.GetCollection <DB_SensorDataItem>("ChartData");

                foreach (DictionaryEntry line in lineSeriesTable)
                {
                    LineSeries lineSeries = (LineSeries)line.Value;

                    var title = lineSeries.Title;

                    List <object> values = new List <object>();
                    List <object> times  = new List <object>();
                    foreach (DataPoint it in lineSeries.Points)
                    {
                        values.Add(it.Y);
                        times.Add(it.X);
                    }

                    DB_SensorDataItem item = new DB_SensorDataItem()
                    {
                        title  = title,
                        values = values,
                        times  = times
                    };
                    col.Insert(item);
                }
            }
        }
Пример #2
0
        private void UIdatabaseCollectionList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (UIdatabaseCollectionList.SelectedIndices.Count > 0)
            {
                plotModel.Series.Clear();

                for (int i = 0; i < UIdatabaseCollectionList.SelectedIndices.Count; i++)
                {
                    ListViewItem item = UIdatabaseCollectionList.Items[UIdatabaseCollectionList.SelectedIndices[i]];

                    using (LiteDatabase db = new LiteDatabase(databasePath))
                    {
                        LiteCollection <DB_SensorDataItem> col = db.GetCollection <DB_SensorDataItem>(collectionName);

                        if (item.Tag != null)
                        {
                            DB_SensorDataItem result = col.FindById(new BsonValue(item.Tag));

                            plotModel.ResetAllAxes();

                            List <DataPoint> values = new List <DataPoint>();

                            for (int j = 0; j < result.values.Count; j++)
                            {
                                values.Add(new DataPoint(Convert.ToDouble(result.times[j]), Convert.ToDouble(result.values[j])));
                            }

                            LineSeries lineSeries = new LineSeries();
                            lineSeries.Title = result.title;
                            plotModel.Series.Add(lineSeries);
                            lineSeries.Points.AddRange(values);

                            plotModel.InvalidatePlot(true);

                            UIdatabasePlotView.Visible = true;
                        }
                    }
                }
            }
        }