Example #1
0
        public static bool UpdateExRate(ExRateItem item)
        {
            string query = string.Format("update {0} set RATE_CZK = {2}, RATE_PLN = {3}, RATE_HUF = {4} where DATE = \"{1}\"", T_EXCH_RATE, item.Date, GetReal(item.RateCZK), GetReal(item.RatePLN), GetReal(item.RateHUF));

            try
            {
                ExecuteNonQuery(query);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Example #2
0
        public static bool InsertExRate(ExRateItem item)
        {
            if (ExistsExRate(item))
                return UpdateExRate(item);

            string query = string.Format("insert into {0} values ( {1}, \"{2}\", {3}, {4}, {5} )", T_EXCH_RATE, "null", item.Date, GetReal(item.RateCZK), GetReal(item.RatePLN), GetReal(item.RateHUF));

            try
            {
                ExecuteNonQuery(query);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Example #3
0
        public static bool ExistsExRate(ExRateItem item)
        {
            string query = string.Format("select * from {0} where DATE = \"{1}\"", T_EXCH_RATE, item.Date);
            try
            {
                var res = ExecuteQuery(query);

                if (res != null && res.Tables != null && res.Tables.Count > 0 && res.Tables[0].Rows.Count > 0)
                    return true;    // zaznam existuje
            }
            catch (Exception)
            {
                return false;
            }

            return false;
        }
Example #4
0
        public static ExRateItem GetExRate(string date)
        {
            string query = string.Format("select ID,DATE,RATE_CZK,RATE_PLN,RATE_HUF from {0} where DATE = \"{1}\"", T_EXCH_RATE, date);
            try
            {
                var res = ExecuteQuery(query);

                if (res != null && res.Tables != null && res.Tables.Count > 0 && res.Tables[0].Rows.Count > 0)
                {
                    ExRateItem ret = new ExRateItem();
                    ret.Id = int.Parse(res.Tables[0].Rows[0].ItemArray[0].ToString());
                    ret.Date = res.Tables[0].Rows[0][1] as string;
                    ret.RateCZK = (double)res.Tables[0].Rows[0][2];
                    ret.RatePLN = (double)res.Tables[0].Rows[0][3];
                    ret.RateHUF = (double)res.Tables[0].Rows[0][4];

                    return ret;
                }
            }
            catch (Exception)
            {
                return null;
            }

            return null;
        }
Example #5
0
        void DownloadExchangeRateXML()
        {
            var address = Properties.Settings.Default.ExchRateXMLAddress;
            XmlTextReader reader = new XmlTextReader(address);
            string currName = "currency";
            string rateName = "rate";
            string timeName = "time";
            ExRateItem newRate = new ExRateItem();
            newRate.Date = DateTime.Now.ToString("yyyy-MM-dd");

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element: // The node is an element.
                        {
                            string curr = null;
                            string rate = null;

                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name.ToLower() == timeName)  // datum
                                    newRate.Date = reader.Value;

                                if (reader.Name.ToLower() == currName)  // mena
                                    curr = reader.Value;
                                if (reader.Name.ToLower() == rateName)  // kurz
                                    rate = reader.Value;
                            }

                            if (curr == "CZK")
                                newRate.RateCZK = Common.GetPrice(rate);
                            if (curr == "PLN")
                                newRate.RatePLN = Common.GetPrice(rate);
                            if (curr == "HUF")
                                newRate.RateHUF = Common.GetPrice(rate);
                        }
                        break;
                }
            }

            DBProvider.InsertExRate(newRate);
        }