Ejemplo n.º 1
0
        private void LoadBarChartData(string formatted)
        {
            //moramo prvo formatirati datum zbog baze
            DateTime from = Convert.ToDateTime(formatted + " 00:00");
            DateTime to   = Convert.ToDateTime(formatted + " 23:59");

            using (var context = new InfosDbContext())
            {
                var query = context.Infos.Where(s => s.Time >= from && s.Time <= to);
                Start = query.Select(x => x.Time).Min();

                batteryDbValues   = (query.Select(x => x.BatteryPower)).ToList();
                panelDbValues     = (query.Select(x => x.PanelPower)).ToList();
                consumersDbValues = (query.Select(x => x.ConsumersPower)).ToList();
                utilityDbValues   = (query.Select(x => x.UtilityMoney)).ToList();
                tempUtilityMoney  = (query.Select(x => x.UtilityMoney)).ToList();
            }

            //da bi bilo optimizovanije saljem true ili false jer se poslednja malo razlikuje,
            //ali u sustini koristi isti kod pa da ne bih kucao 2 identicne metode
            GetKeyValuePairs(batteryDbValues, listBattery, false);
            GetKeyValuePairs(panelDbValues, listPanel, false);
            GetKeyValuePairs(consumersDbValues, listConsumers, false);
            GetKeyValuePairs(utilityDbValues, listUtility, true);
            GetKeyValuePairs(tempUtilityMoney, listUtilityMoney, false);

            ((LineSeries)sr.Series[0]).ItemsSource = listPanel.ToArray();
            ((LineSeries)sr.Series[1]).ItemsSource = listBattery.ToArray();
            ((LineSeries)sr.Series[2]).ItemsSource = listUtility.ToArray();
            ((LineSeries)sr.Series[3]).ItemsSource = listConsumers.ToArray();
        }
Ejemplo n.º 2
0
        public static void PerformDatabaseOperations(double batteryPower, double panelPower, double consumersPower, double utilityMoney)
        {
            using (var db = new InfosDbContext())
            {
                var info = new Infos
                {
                    BatteryPower   = batteryPower,
                    PanelPower     = panelPower,
                    ConsumersPower = consumersPower,
                    UtilityMoney   = utilityMoney,
                    Time           = DateTime.Now
                };

                db.Infos.Add(info);
                db.SaveChanges();
            }
        }