Beispiel #1
0
        public ExchangeRateTable Select(long id)
        {
            string sql = "select ID,Source, Currency, Quotes,CreateTime,LastChangeTime from ExchangeRate where id=@id";

            ExchangeRateTable result = null;

            using (SQLiteCommand cmd = new SQLiteCommand(sql))
            {
                cmd.Parameters.AddWithValue("@id", id);

                var reader = SQLiteHelper.SQLiteHelper.ExecuteReader(con, cmd);
                while (reader.Read())
                {
                    result = new ExchangeRateTable()
                    {
                        ID             = long.Parse(reader["id"].ToString()),
                        Currency       = reader["Currency"].ToString(),
                        Quotes         = double.Parse(reader["Quotes"].ToString()),
                        Source         = reader["Source"].ToString(),
                        CreateTime     = DateTime.Parse(reader["CreateTime"].ToString()),
                        LastChangeTime = DateTime.Parse(reader["LastChangeTime"].ToString()),
                    };
                }
            }

            return(result);
        }
Beispiel #2
0
        public void Insert(ExchangeRateTable obj)
        {
            string sql = "insert into ExchangeRate(Source, Currency, Quotes,CreateTime,LastChangeTime) values(@Source,@Currency, @Quotes,datetime('now', 'localtime'),datetime('now', 'localtime'))";

            using (SQLiteCommand cmd = new SQLiteCommand(sql))
            {
                cmd.Parameters.AddWithValue("@Source", obj.Source);
                cmd.Parameters.AddWithValue("@Currency", obj.Currency);
                cmd.Parameters.AddWithValue("@Quotes", obj.Quotes);

                SQLiteHelper.SQLiteHelper.ExecuteNonQuery(con, cmd);
            }
        }
Beispiel #3
0
        public void Update(ExchangeRateTable obj)
        {
            string sql = "UPDATE ExchangeRate set Source=@Source, Currency=@Currency, Quotes=@Quotes,LastChangeTime=datetime('now', 'localtime') where id=@ID";

            using (SQLiteCommand cmd = new SQLiteCommand(sql))
            {
                cmd.Parameters.AddWithValue("@ID", obj.ID);
                cmd.Parameters.AddWithValue("@Source", obj.Source);
                cmd.Parameters.AddWithValue("@Currency", obj.Currency);
                cmd.Parameters.AddWithValue("@Quotes", obj.Quotes);

                SQLiteHelper.SQLiteHelper.ExecuteNonQuery(con, cmd);
            }
        }
        public static decimal findExchangeRate(ProjectDBUtil paramProjectDBUtil, string paramString, DateTime paramDate)
        {
            if (paramProjectDBUtil == null || StringUtils.isNullOrBlank(paramString))
            {
                return(BigDecimalMath.ONE);
            }
            Currency currency = s_interface.findCurrencyBySymbol(paramProjectDBUtil.Properties.getProperty("project.currency.symbol"));

            if (currency.Code.Equals(paramString))
            {
                return(BigDecimalMath.ONE);
            }
            string  str         = constructKey(paramProjectDBUtil, currency.Code, paramString, paramDate);
            decimal bigDecimal1 = (decimal)s_exchangeRateCache[str];

            if (bigDecimal1 != null)
            {
                return(bigDecimal1);
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH);
            DateTime         date1            = paramProjectDBUtil.Properties.getDateProperty("project.submission.date");
            int i = paramProjectDBUtil.Properties.getIntProperty("project.constructionduration");

            if (i <= 0)
            {
                i = 1;
            }
            GregorianCalendar gregorianCalendar = new GregorianCalendar();

            gregorianCalendar.Time = date1;
            gregorianCalendar.set(5, 1);
            gregorianCalendar.set(11, 0);
            gregorianCalendar.set(12, 0);
            gregorianCalendar.set(13, 0);
            gregorianCalendar.set(14, 0);
            date1 = gregorianCalendar.Time;
            gregorianCalendar.add(2, i);
            DateTime date2   = gregorianCalendar.Time;
            bool     @bool   = !paramProjectDBUtil.hasOpenedSession() ? 1 : 0;
            Session  session = paramProjectDBUtil.currentSession();
            Query    query   = session.createQuery("from ExchangeRateTable o where o.projectId = :prjId and (o.fromCurrency = :fromCurrency and o.toCurrency = :toCurrency and o.rateDate >= :startDate and o.rateDate <= :endDate) order by o.rateDate asc");

            query.setString("fromCurrency", paramString);
            query.setString("toCurrency", currency.Code);
            query.setDate("startDate", date1);
            query.setDate("endDate", date2);
            query.setLong("prjId", paramProjectDBUtil.ProjectUrlId.Value);
            query.Cacheable = true;
            System.Collections.IEnumerator iterator = query.list().GetEnumerator();
            decimal bigDecimal2 = BigDecimalMath.ONE;
            sbyte   b;

            for (b = 0; iterator.MoveNext(); b++)
            {
                ExchangeRateTable exchangeRateTable = (ExchangeRateTable)iterator.Current;
                if (!b)
                {
                    bigDecimal2 = exchangeRateTable.Rate;
                }
                if (paramDate == null)
                {
                    bigDecimal1 = exchangeRateTable.Rate;
                    break;
                }
                string str1 = simpleDateFormat.format(paramDate);
                string str2 = simpleDateFormat.format(exchangeRateTable.RateDate);
                if (str1.Equals(str2))
                {
                    bigDecimal1 = exchangeRateTable.Rate;
                    break;
                }
            }
            if (@bool)
            {
                paramProjectDBUtil.closeSession();
            }
            if (bigDecimal1 == null)
            {
                bigDecimal1 = bigDecimal2;
            }
            s_exchangeRateCache[str] = bigDecimal1;
            return(bigDecimal1);
        }