Esempio n. 1
0
        public ElementP PribaviElementP(int id)
        {
            ElementP element = _context.ElementiP.FirstOrDefault(el => el.ElementPId == id);

            Console.WriteLine(element.ToString());

            return(element);
        }
Esempio n. 2
0
        public List <ElementP> GetData(string time)
        {
            List <ElementP> elementPs = new List <ElementP>();

            try
            {
                con.Open();
                DateTime dateTime = DateTime.Parse(time);
                dateTime = new DateTime(2000, 1, 1, dateTime.Hour, dateTime.Minute, dateTime.Second);

                string sqlP = "SELECT IdentifikacioniKod,RedniBroj,DatumPretrage FROM ElementP";

                SqlCommand cmdP = new SqlCommand(sqlP, con);

                using (SqlDataReader oReader = cmdP.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        if (dateTime < DateTime.Parse(oReader["DatumPretrage"].ToString()))
                        {
                            ElementP ELP = new ElementP();
                            ELP.IdentifikacioniKod = oReader["IdentifikacioniKod"].ToString();
                            ELP.RedniBroj          = Int32.Parse(oReader["RedniBroj"].ToString());
                            elementPs.Add(ELP);
                            Console.WriteLine("Citanje Podataka P");
                        }
                    }
                }

                foreach (var item in elementPs)
                {
                    List <ElementC> elementCs = new List <ElementC>();
                    string          IDenKod   = item.IdentifikacioniKod;
                    string          sqlC      = "SELECT Grupa,Vrednost FROM ElementC WHERE IDKOD=@IDenKod";
                    SqlCommand      cmdC      = new SqlCommand(sqlC, con);
                    cmdC.Parameters.AddWithValue("@IDenKod", IDenKod);
                    using (SqlDataReader oReader = cmdC.ExecuteReader())
                    {
                        while (oReader.Read())
                        {
                            ElementC ELC = new ElementC(oReader["Grupa"].ToString().ToCharArray()[0], Int32.Parse(oReader["Vrednost"].ToString()));
                            elementCs.Add(ELC);
                        }
                    }
                    item.AddCs(elementCs);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                con.Close();
            }
            return(elementPs);
        }
Esempio n. 3
0
        public void AddData(ElementP elP)
        {
            Console.WriteLine("ADDDING DATA IN TO THE DATABASE >>> \n\n\n");
            try
            {
                con.Open();
                string sql = "INSERT INTO ElementP (IdentifikacioniKod,RedniBroj,DatumPretrage) values (@ID,@RB,@DP)";

                cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@ID", SqlDbType.VarChar);
                cmd.Parameters["@ID"].Value = elP.IdentifikacioniKod;

                cmd.Parameters.Add("@RB", SqlDbType.Int);
                cmd.Parameters["@RB"].Value = elP.RedniBroj;

                cmd.Parameters.Add("@DP", SqlDbType.Time);
                cmd.Parameters["@DP"].Value = DateTime.Now.TimeOfDay;

                cmd.ExecuteNonQuery();

                ElementC[] elementCs = elP.Elementi;

                foreach (var item in elementCs)
                {
                    sql = "INSERT INTO ElementC (IDKOD,Grupa,Vrednost) values (@IDK,@G,@V)";

                    cmd = new SqlCommand(sql, con);
                    cmd.Parameters.Add("@IDK", SqlDbType.VarChar);
                    cmd.Parameters["@IDK"].Value = elP.IdentifikacioniKod;

                    cmd.Parameters.Add("@G", SqlDbType.VarChar);
                    cmd.Parameters["@G"].Value = item.Grupa;

                    cmd.Parameters.Add("@V", SqlDbType.Int);
                    cmd.Parameters["@V"].Value = item.Vrednost;

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                con.Close();
            }
        }
Esempio n. 4
0
 public void Post([FromBody] ElementP value)
 {
     Console.WriteLine($"\n\n\nPOST REQUEST WITH VALUE : {value}\n\n\n");
     dBS.AddData(value);
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                var ctx = new ElementiContext();

                _elementPService = new ElementPService(ctx);
                _pretragaService = new PretragaService(ctx);
                _elementCService = new ElementCService(ctx);

                Random rnd = new Random();

                int n = 0;
                int k = 0;
                int p = 0;

                int brojPretraga = 0;

                Console.WriteLine("Unesite zeljeni broj elemenata tipa ElementP.");
                n = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Unesite zeljeni broj elemenata tipa ElementC.");
                k = Convert.ToInt32(Console.ReadLine());

                for (int i = 0; i < n; i++)
                {
                    string   idenTifikacioniKod = String.Format("elementp_{0}", i);
                    ElementP elP = new ElementP()
                    {
                        IdentifikacioniKod = idenTifikacioniKod, RedniBroj = i
                    };

                    for (int j = 0; j < k; j++)
                    {
                        char grupa    = (char)rnd.Next(97, 122);
                        int  vrednost = rnd.Next(1, 9);

                        ElementC elC = new ElementC()
                        {
                            Grupa = grupa, Vrednost = vrednost
                        };
                        elP.Elementi.Add(elC);
                    }

                    _elementPService.KreirajElementP(elP);
                }

                Console.WriteLine("Unesite zeljeni broj pretraga: ");
                brojPretraga = Convert.ToInt32(Console.ReadLine());

                for (int i = 0; i < brojPretraga; i++)
                {
                    Console.WriteLine("Unesite zeljeni prag za koji će se vršiti pretraga Elemenata P  po sumi njihovih članova ElementC");
                    p = Convert.ToInt32(Console.ReadLine());

                    List <DataLayer.Models.ElementP> elementiP = _elementPService.VratiSvePSaSumomCVecomOd(p);

                    Pretraga pret = new Pretraga()
                    {
                        VremePretrage = DateTime.Now
                    };
                    foreach (var el in elementiP)
                    {
                        pret.PronadjeniElementi.Add(el);
                    }

                    _pretragaService.KreirajElementP(pret);
                }

                ctx.Dispose();
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 6
0
        public ElementP PribaviElementPPoIdKodu(string identifikacioniKod)
        {
            ElementP pronadjeniElement = _context.ElementiP.FirstOrDefault(el => el.IdentifikacioniKod == identifikacioniKod);

            return(pronadjeniElement);
        }
Esempio n. 7
0
 public void KreirajElementP(ElementP element)
 {
     _context.ElementiP.Add(element);
     _context.SaveChanges();
 }