예제 #1
0
        public void prikazSenz()
        {
            IspisUpisSG iu = IspisUpisSG.getInstance();

            iu.print("");

            if (db.dajSenzore().Count > 0)
            {
                iu.print("\t\t***SENZORI***");
                iu.print(iu.pofarbaj("crvena") + "\t[Naziv]\t\t[ID]\t[TIP]\t[Vrsta]\t\t[Min/Max]" + iu.pofarbaj("bijela"));
                foreach (Senzor s in db.dajSenzore())
                {
                    if (s.dohvatiNaziv().Length < 8)
                    {
                        iu.print(s.dohvatiNaziv() + "\t\t\t  " + s.ID.ToString() + "\t   " + s.dohvatiTip() + "\t\t" + s.dohvatiVrstu() + "\t " + s.dohvatiMinVrijednost() + "/" + s.dohvatiMaxVrijednost());
                    }
                    else if (s.dohvatiNaziv().Length >= 8 && s.dohvatiNaziv().Length < 13)
                    {
                        iu.print(s.dohvatiNaziv() + "\t\t  " + s.ID.ToString() + "\t   " + s.dohvatiTip() + "\t\t" + s.dohvatiVrstu() + "\t " + s.dohvatiMinVrijednost() + "/" + s.dohvatiMaxVrijednost());
                    }
                    else
                    {
                        iu.print(s.dohvatiNaziv() + "\t  " + s.ID.ToString() + "\t   " + s.dohvatiTip() + "\t\t" + s.dohvatiVrstu() + "\t " + s.dohvatiMinVrijednost() + "/" + s.dohvatiMaxVrijednost());
                    }


                    //iu.print("\tTip : " + s.dohvatiTip()+ "\tVrsta : " + s.dohvatiVrstu()+"\tMin vrijednost: " + s.dohvatiMinVrijednost() + "\tMax vrijednost : " + s.dohvatiMaxVrijednost());

                    // if (s.komentar != null) iu.print("\tKomentar : " + s.dohvatiKomentar());
                }
            }
        }
예제 #2
0
        public bool postojiSenzor(int id)
        {
            bool exists = false;

            foreach (Senzor s in db.dajSenzore())
            {
                if (s.ID == id)
                {
                    exists = true;
                }
            }
            return(exists);
        }
예제 #3
0
        public void spari()
        {
            int c = 0;

            try
            {
                List <Mjesto>   lm = db.dajMjesta();
                List <Senzor>   ls = db.dajSenzore();
                List <Aktuator> la = db.dajAktuatore();

                string[] linije = System.IO.File.ReadAllLines(filename);
                foreach (string l in linije)
                {
                    if (c > 2)
                    {
                        string[] splitano = l.Split(';');

                        try
                        {
                            if (Int32.Parse(splitano[0]) == 0)
                            {
                                foreach (Mjesto m in lm)
                                {
                                    if (m.ID == Int32.Parse(splitano[1]))
                                    {
                                        if (Int32.Parse(splitano[2]) == 1)
                                        {
                                            //aktuator
                                            if (m.broj_aktuatora > m.la.Count())
                                            {
                                                foreach (Aktuator a in la)
                                                {
                                                    if (a.ID == Int32.Parse(splitano[3]))
                                                    {
                                                        Aktuator b = (Aktuator)a.kloniraj(a.naziv, a.tip, a.vrsta, a.min_vrijednost, a.max_vrijednost);
                                                        b.inicijaliziraj();
                                                        b.generirajVrijednost();
                                                        b.dodijeliID(Int32.Parse(splitano[4]));
                                                        if (b.tip == m.tip || b.tip == 2)
                                                        {
                                                            m.la.Add(b);
                                                        }
                                                        else
                                                        {
                                                            iu.print("Tip aktuatora " + b.naziv + " ne paše mjestu " + m.naziv + "!");
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                iu.print(iu.pofarbaj("crvena") + "***" + m.naziv + " ima max.broj aktuatora.***" + iu.pofarbaj("bijela"));
                                            }
                                        }
                                        if (Int32.Parse(splitano[2]) == 0)
                                        {
                                            //senzor

                                            if (m.broj_senzora > m.ls.Count())
                                            {
                                                foreach (Senzor a in ls)
                                                {
                                                    if (a.ID == Int32.Parse(splitano[3]))
                                                    {
                                                        Senzor b = (Senzor)a.kloniraj(a.naziv, a.tip, a.vrsta, a.min_vrijednost, a.max_vrijednost);
                                                        b.inicijaliziraj();
                                                        b.generirajVrijednost();
                                                        b.dodijeliID(Int32.Parse(splitano[4]));
                                                        if (b.tip == m.tip || b.tip == 2)
                                                        {
                                                            m.ls.Add(b);
                                                        }
                                                        else
                                                        {
                                                            iu.print("Tip senzora " + b.naziv + " ne paše mjestu " + m.naziv + "!");
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                iu.print(iu.pofarbaj("crvena") + "***" + m.naziv + " ima max.broj senzora.***" + iu.pofarbaj("bijela"));
                                            }
                                        }
                                    }
                                }
                            }
                            if (Int32.Parse(splitano[0]) == 1)
                            {
                                foreach (Mjesto m in lm)
                                {
                                    foreach (Aktuator a in m.la)
                                    {
                                        if (Int32.Parse(splitano[1]) == a.ID)
                                        {
                                            string[] senzori = splitano[2].Split(',');

                                            foreach (string snz in senzori)
                                            {
                                                foreach (Senzor s in m.ls)
                                                {
                                                    if (s.ID == Int32.Parse(snz))
                                                    {
                                                        a.lss.Add(s);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            db.aktualizirajMjesta(lm);
                        }
                        catch (Exception e)
                        {
                            //iu.print(e.ToString());
                            iu.print("[Greška!] Došlo je do greške pri raspoređivanju uređaja.");
                            iu.print("Redak : " + l);
                        };
                    }
                    c++;
                }
            }
            catch (Exception)
            {
                iu.print(" [Raspored] Datoteka s nazivom '" + filename + "' ne postoji. Završetak rada.");
            }
        }