예제 #1
0
파일: Manual.cs 프로젝트: RES2020/Tim21
        public void ManualWriteToHistory()
        {
            var konti = new PodaciDBContext();

            Podaci p = konti.Tabela.FirstOrDefault(i => i.Code == kod);

            if (p == null)
            {
                var novi = new Podaci
                {
                    Code        = kod,
                    Timestamp   = datum,
                    AreaID      = id,
                    Consumption = potrosnja,
                    Time        = DateTime.Now.ToShortTimeString()
                };
                konti.Tabela.Add(novi);
                konti.SaveChanges();
            }
            else
            {
                p.Timestamp   = datum;
                p.AreaID      = id;
                p.Consumption = potrosnja;
                p.Time        = DateTime.Now.ToShortTimeString();
            }
            konti.SaveChanges();
        }
예제 #2
0
파일: Get.cs 프로젝트: RES2020/Tim21
        public string GetValue()
        {
            string str      = "";
            var    kontekst = new PodaciDBContext();
            Podaci p        = kontekst.Tabela.FirstOrDefault(i => i.Code == Kod);


            if (p != null)
            {
                str = "Za trazeni kod - " + Kod + " pronadjena su vrijednosti: " + Environment.NewLine + "Timestamp: " + p.Timestamp + Environment.NewLine + "Id geografskog podrucja: " + p.AreaID + Environment.NewLine + "Potrosnja: " + p.Consumption + Environment.NewLine + "Vrijeme upisa: " + p.Time;
            }
            else
            {
                str = "Nema podatka sa tim kodom!";
            }
            return(str);
        }
예제 #3
0
        public void Recive(DeltaCD data)
        {
            PackInLD pakovanje = new PackInLD();

            pakovanje.GetLD(data, descs);

            ILogovanje Logovanje = new HistoricalLogovanje();
            //string p = "dataset u deltacd add " + data.Add.dataset + " kod1= " + data.Add.DumpingPropertyCollection[0].kod.ToString() + " kod2= " + data.Add.DumpingPropertyCollection[1].kod.ToString() + Environment.NewLine;
            //Logovanje.Loguj(p);

            string poruka = "Primljen je novi DeltaCD sa TransactionID: " + data.transactionID + " i upakovan je u LD" + Environment.NewLine;

            Logovanje.Loguj(poruka);

            var context = new PodaciDBContext();

            foreach (Description d in descs.list)
            {
                if (d.use == "ADD")
                {
                    string k = d.props[0].kod.ToString();
                    Podaci p = context.Tabela.FirstOrDefault(i => i.Code == k);

                    if (p == null)
                    {
                        var podatak = new Podaci
                        {
                            Code        = d.props[0].kod.ToString(),
                            Timestamp   = d.props[0].HistoricalValue.timestamp.ToShortDateString(),
                            AreaID      = d.props[0].HistoricalValue.id.ToString(),
                            Consumption = d.props[0].HistoricalValue.potrosnja.ToString(),
                            Time        = DateTime.Now.ToShortTimeString()
                        };
                        context.Tabela.Add(podatak);
                        context.SaveChanges();
                    }



                    string k1 = d.props[1].kod.ToString();
                    Podaci p1 = context.Tabela.FirstOrDefault(i => i.Code == k1);
                    if (p1 == null)
                    {
                        var podatak = new Podaci
                        {
                            Code        = d.props[1].kod.ToString(),
                            Timestamp   = d.props[1].HistoricalValue.timestamp.ToShortDateString(),
                            AreaID      = d.props[1].HistoricalValue.id.ToString(),
                            Consumption = d.props[1].HistoricalValue.potrosnja.ToString(),
                            Time        = DateTime.Now.ToShortTimeString()
                        };
                        context.Tabela.Add(podatak);
                        context.SaveChanges();
                    }
                }
                else if (d.use == "UPDATE")
                {
                    if (d.props.Count() != 0 && d.props != null)
                    {
                        string k = d.props[0].kod.ToString();
                        Podaci p = context.Tabela.FirstOrDefault(i => i.Code == k);

                        if (p != null)
                        {
                            if (d.props[0].kod == Code.CODE_DIGITAL)
                            {
                                p.Timestamp   = d.props[0].HistoricalValue.timestamp.ToShortDateString();
                                p.AreaID      = d.props[0].HistoricalValue.id.ToString();
                                p.Consumption = d.props[0].HistoricalValue.potrosnja.ToString();
                                p.Time        = DateTime.Now.ToShortTimeString();
                                context.SaveChanges();
                            }
                            else
                            {
                                if ((Convert.ToDouble(p.Consumption) + (Convert.ToDouble(p.Consumption)) / 50) < d.props[0].HistoricalValue.potrosnja)
                                {
                                    p.Timestamp   = d.props[0].HistoricalValue.timestamp.ToShortDateString();
                                    p.AreaID      = d.props[0].HistoricalValue.id.ToString();
                                    p.Consumption = d.props[0].HistoricalValue.potrosnja.ToString();
                                    p.Time        = DateTime.Now.ToShortTimeString();
                                    context.SaveChanges();
                                }
                            }
                        }

                        string k1 = d.props[1].kod.ToString();
                        Podaci p1 = context.Tabela.FirstOrDefault(i => i.Code == k1);

                        if (p1 != null)
                        {
                            if (d.props[1].kod == Code.CODE_DIGITAL)
                            {
                                p1.Timestamp   = d.props[1].HistoricalValue.timestamp.ToShortDateString();
                                p1.AreaID      = d.props[1].HistoricalValue.id.ToString();
                                p1.Consumption = d.props[1].HistoricalValue.potrosnja.ToString();
                                p1.Time        = DateTime.Now.ToShortTimeString();
                                context.SaveChanges();
                            }
                            else
                            {
                                if ((Convert.ToDouble(p1.Consumption) + (Convert.ToDouble(p1.Consumption)) / 50) < d.props[1].HistoricalValue.potrosnja)
                                {
                                    p1.Timestamp   = d.props[1].HistoricalValue.timestamp.ToShortDateString();
                                    p1.AreaID      = d.props[1].HistoricalValue.id.ToString();
                                    p1.Consumption = d.props[1].HistoricalValue.potrosnja.ToString();
                                    p1.Time        = DateTime.Now.ToShortTimeString();
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
                else if (d.use == "DELETE")
                {
                    if (d.props.Count() != 0 && d.props != null)
                    {
                        string k = d.props[0].kod.ToString();
                        Podaci p = context.Tabela.FirstOrDefault(i => i.Code == k);

                        if (p != null)
                        {
                            context.Tabela.Remove(p);
                            context.SaveChanges();
                        }

                        string k1 = d.props[1].kod.ToString();
                        Podaci p1 = context.Tabela.FirstOrDefault(i => i.Code == k1);

                        if (p1 != null)
                        {
                            context.Tabela.Remove(p1);
                            context.SaveChanges();
                        }
                    }
                }
            }

            descs.list.Clear();
        }
예제 #4
0
 public void CleanTable(PodaciDBContext context)
 {
     context.Database.ExecuteSqlCommand("TRUNCATE TABLE Podacis");
 }