Exemple #1
0
 public List <RoborHistoric> GetRobors(DateTime from, DateTime to)
 {
     using (var sqlConn = new SqlConnection(this.connection))
     {
         using (var cmd = sqlConn.CreateCommand())
         {
             cmd.CommandText = "select r.* from dbo.Rates r where @from<=r.RateDate and r.RateDate<=@to";
             cmd.Parameters.Add("@from", SqlDbType.DateTime).Value = from;
             cmd.Parameters.Add("@to", SqlDbType.DateTime).Value   = to;
             sqlConn.Open();
             try
             {
                 using (var reader = cmd.ExecuteReader())
                 {
                     var lst = new List <RoborHistoric>();
                     while (reader.Read())
                     {
                         var obj = new RoborHistoric();
                         obj.Data     = reader.GetDateTime(reader.GetOrdinal("RateDate"));
                         obj.Robid12M = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid12M)));
                         obj.Robor12M = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor12M)));
                         obj.Robid3M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid3M)));
                         obj.Robor3M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor3M)));
                         obj.Robid6M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid6M)));
                         obj.Robor6M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor6M)));
                         obj.Robid9M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid9M)));
                         obj.Robor9M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor9M)));
                         lst.Add(obj);
                     }
                     return(lst);
                 }
             }
             finally
             {
                 sqlConn.Close();
             }
         }
     }
 }
Exemple #2
0
 public RoborHistoric GetRoborRecent()
 {
     using (var sqlConn = new SqlConnection(this.connection))
     {
         using (var cmd = sqlConn.CreateCommand())
         {
             cmd.CommandText = "SELECT Top 1 x.* from dbo.Rates x order by x.RateDate desc";
             sqlConn.Open();
             try
             {
                 using (var reader = cmd.ExecuteReader())
                 {
                     var lst = new List <RoborHistoric>();
                     while (reader.Read())
                     {
                         var obj = new RoborHistoric();
                         obj.Data     = reader.GetDateTime(reader.GetOrdinal("RateDate"));
                         obj.Robid12M = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid12M)));
                         obj.Robor12M = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor12M)));
                         obj.Robid3M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid3M)));
                         obj.Robor3M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor3M)));
                         obj.Robid6M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid6M)));
                         obj.Robor6M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor6M)));
                         obj.Robid9M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robid9M)));
                         obj.Robor9M  = reader.GetDecimal(reader.GetOrdinal(nameof(obj.Robor9M)));
                         lst.Add(obj);
                     }
                     return(lst.FirstOrDefault() ?? new RoborHistoric());
                 }
             }
             finally
             {
                 sqlConn.Close();
             }
         }
     }
 }