Пример #1
0
        public override Response ConvertValue(string day, Currency source, Currency target, CurrencyValueType type, decimal?amount)
        {
            GetTCMBLogger().Info(string.Format("{0}-{1}-{2}-{3}-{4}", day, source, target, type, amount));

            var response = new Response();

            if (source == target)
            {
                response.Value = amount ?? 0;
                return(response);
            }

            try
            {
                var value = GetValueDbWork(day, source, target, type);
                response.Value = value * (amount ?? 0);
            }
            catch (Exception ex)
            {
                response.Message = ResponseMessage.SystemError;

                var logger = GetTCMBLogger();
                logger.Error(ex);
            }

            return(response);
        }
Пример #2
0
        private static decimal GetValueDbWork(string day, Currency source, Currency target, CurrencyValueType type)
        {
            GetTCMBLogger().Info(string.Format("{0}-{1}-{2}-{3}", day, source, target, type));
            if (source == target)
            {
                return(1);
            }

            object result;

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Para"].ConnectionString))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = @"IF NOT EXISTS (SELECT Value
			                                           FROM [CurrencyValue] 
                                                       WHERE [Day] = @day
				                                             AND [Source] = @source
				                                             AND [Target] = @target
				                                             AND [ValueSource] = @valueSource
				                                             AND [ValueType] = @valueType)
	                                        BEGIN
		                                        SELECT TOP 1 Value
		                                        FROM [CurrencyValue] 
		                                        WHERE [Source] = @source
				                                        AND [Target] = @target
				                                        AND [ValueSource] = @valueSource
				                                        AND [ValueType] = @valueType
		                                        ORDER BY [Day] DESC
	                                        END
                                        ELSE
	                                        BEGIN
		                                        SELECT Value
		                                        FROM [CurrencyValue] 
		                                        WHERE [Day] = @day
				                                        AND [Source] = @source
				                                        AND [Target] = @target
				                                        AND [ValueSource] = @valueSource
				                                        AND [ValueType] = @valueType
	                                        END"    ;

                    cmd.Parameters.AddWithValue("@day", day);
                    cmd.Parameters.AddWithValue("@source", source.ToString());
                    cmd.Parameters.AddWithValue("@target", target.ToString());
                    cmd.Parameters.AddWithValue("@valueSource", CurrencyValueSource.TCMB.ToString());
                    cmd.Parameters.AddWithValue("@valueType", type.ToString());

                    conn.Open();
                    result = cmd.ExecuteScalar();
                }
            }

            return(Convert.ToDecimal(result));
        }
Пример #3
0
 public abstract Response ConvertValue(string day, Currency source, Currency target, CurrencyValueType type, decimal?amount);
Пример #4
0
        public override Response GetValue(string day, Currency source, Currency target, CurrencyValueType type)
        {
            var response = new Response();

            try
            {
                response.Value = GetValueDbWork(day, source, target, type);
            }
            catch (Exception ex)
            {
                response.Message = ResponseMessage.SystemError;

                var logger = GetTCMBLogger();
                logger.Error(ex);
            }

            return(response);
        }
Пример #5
0
 public abstract Response GetValue(string day, Currency source, Currency target, CurrencyValueType type);