static void Main(string[] args)
        {
            Connect();

            while (true)
            {
                // List<string> saljiUBazu = proxyDanasnji.InsertIntoTable(ResidentE.listaUbacenihVrednostiWhile);

                listaUbacenihVrednostiWhile = new List <Dictionary <Tuple <int, string>, Tuple <DateTime, float> > >();

                List <PodaciIzBaze> podaci = proxyDanasnji.DanasnjiDatum();

                listaUbacenihVrednostiWhile.Add(Automatic(podaci));


                foreach (var item in listaUbacenihVrednostiWhile)
                {
                    foreach (var item1 in item)
                    {
                        Console.WriteLine(item1.Key.Item1 + " " + item1.Key.Item2 + " " + item1.Value.Item1 + " " + item1.Value.Item2);
                    }
                }


                List <string> uBazu = InsertIntoTable(listaUbacenihVrednostiWhile);

                DuplexSample(uBazu);

                podaci = new List <PodaciIzBaze>();

                Thread.Sleep(20000);
            }

            // Console.ReadKey();

            //Disconnect();
        }
        public List <string> InsertIntoTable(List <Dictionary <Tuple <int, string>, Tuple <DateTime, float> > > listaUbacenihVrednostiWhile)
        {
            #region CatchExceptions

            if (listaUbacenihVrednostiWhile == null)
            {
                throw new ArgumentNullException();
            }

            foreach (var item in listaUbacenihVrednostiWhile)
            {
                if (item == null)
                {
                    throw new ArgumentNullException();
                }
                foreach (var itemDict in item)
                {
                    if (itemDict.Value == null || itemDict.Key == null)
                    {
                        throw new ArgumentNullException();
                    }

                    if (itemDict.Key.Item1 < 1 || itemDict.Key.Item1 > 3)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    if (String.IsNullOrEmpty(itemDict.Key.Item2))
                    {
                        throw new ArgumentNullException();
                    }

                    if (itemDict.Value.Item1 > DateTime.Now)
                    {
                        throw new VremeException();
                    }
                    if (itemDict.Value.Item2 >= float.MaxValue || itemDict.Value.Item2 < 0)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            #endregion

            List <string>       retVal              = new List <string>();
            List <PodaciIzBaze> traziDatum          = proxyDanasnji.DanasnjiDatum().OrderByDescending(o => o.ID).ThenBy(n => n.Vreme).ToList();
            List <PodaciIzBaze> traziNajnovijiDatum = SamoPoJednoPodrucje(traziDatum);

            foreach (var itemDatum in traziNajnovijiDatum)
            {
                foreach (var itemLista in listaUbacenihVrednostiWhile)
                {
                    foreach (var itemDict in itemLista)
                    {
                        if (itemDict.Key.Item1 == 1 && itemDatum.ID == itemDict.Key.Item2 &&
                            (ProveriZaIf(itemDict.Key.Item2, SqlDateTime.Parse(itemDatum.Vreme.ToString()), itemDict.Key.Item1)))
                        {
                            retVal.Add("INSERT INTO FunkcijaAverage (IDGeoPodrucja, VremeProracuna, AverageVrednost, PoslednjeVreme) " +
                                       "VALUES ('" + itemDict.Key.Item2 + "'," +
                                       "'" + SqlDateTime.Parse(itemDict.Value.Item1.ToString()) + "'," +
                                       itemDict.Value.Item2 + "," +
                                       "'" + SqlDateTime.Parse(itemDatum.Vreme.ToString()) + "')");
                        }

                        else if (itemDict.Key.Item1 == 2 && itemDatum.ID == itemDict.Key.Item2 &&
                                 (ProveriZaIf(itemDict.Key.Item2, SqlDateTime.Parse(itemDatum.Vreme.ToString()), itemDict.Key.Item1)))
                        {
                            retVal.Add("INSERT INTO FunkcijaMaximum (IDGeoPodrucja, VremeProracuna, MaximalnaVrednost, PoslednjeVreme) " +
                                       "VALUES ('" + itemDict.Key.Item2 + "'," +
                                       "'" + SqlDateTime.Parse(itemDict.Value.Item1.ToString()) + "'," +
                                       itemDict.Value.Item2 + "," +
                                       "'" + SqlDateTime.Parse(itemDatum.Vreme.ToString()) + "')");
                        }

                        else if (itemDict.Key.Item1 == 3 && itemDatum.ID == itemDict.Key.Item2 &&
                                 (ProveriZaIf(itemDict.Key.Item2, SqlDateTime.Parse(itemDatum.Vreme.ToString()), itemDict.Key.Item1)))
                        {
                            retVal.Add("INSERT INTO FunkcijaMinimum (IDGeoPodrucja, VremeProracuna, MinimalnaVrednost, PoslednjeVreme) " +
                                       "VALUES ('" + itemDict.Key.Item2 + "'," +
                                       "'" + SqlDateTime.Parse(itemDict.Value.Item1.ToString()) + "'," +
                                       itemDict.Value.Item2 + "," +
                                       "'" + SqlDateTime.Parse(itemDatum.Vreme.ToString()) + "')");
                        }
                    }
                }
            }

            return(retVal);
        }