示例#1
0
文件: Access.cs 项目: bonkoskk/peps
 public static CashDB getCashDB(DateTime date)
 {
     using (var context = new qpcptfaw())
     {
         int i;
         System.Linq.IQueryable<AccessBD.CashDB> cash = null;
         DateTime dateLoop = date;
         for (i = 0; i < 20; i++)
         {
             cash = from p in context.Cash
                    where p.date == dateLoop
                             select p;
             if (cash.Count() > 0)
             {
                 break;
             }
             dateLoop = dateLoop - TimeSpan.FromDays(1);
         }
         if (cash == null || cash.Count() == 0) throw new ArgumentException("No data for this date", date.ToString());
         CashDB cash0 = new CashDB { date = date, value = cash.First().value };
         // if data from past date, save at the right date
         if (i > 1)
         {
             context.Cash.Add(cash0);
             context.SaveChanges();
         }
         return cash0;
     }
 }
示例#2
0
文件: Write.cs 项目: bonkoskk/peps
            /*public static void storeVolVect(DateTime date, double[] vol)
        {
            using (var context = new qpcptfaw())
            {
                // si la date existe déjà dans la table des prix on la remplace
                if (Access.ContainsCorrelKey(context, date))//list_pair_db.Contains(new KeyValuePair<int, DateTime>(id, date)))
                {
                    var mats = from m in context.CorrelVol
                               where m.date == date
                               select m;
                    mats.First().vol = vol;
                    context.SaveChanges();
                    return;
                }
                else
                {
                    // sinon on l'ajoute
                    //PortfolioComposition p = new PortfolioComposition { AssetDBId = assetId, date = date, quantity = quantity };
                    CorrelDB data = new CorrelDB { date = date, vol = vol };
                    context.CorrelVol.Add(data);
                    context.SaveChanges();
                    return;
                }
            }

        }*/

            public static void storeCashValue(DateTime date, double value)
            {
                using (var context = new qpcptfaw())
                {

                    var ev = from e in context.Cash
                             where e.date == date 
                             select e;
                    // si la date existe déjà dans la table des prix on la remplace
                    if (ev.Count() == 1) //list_pair_db.Contains(new KeyValuePair<int, DateTime>(id, date)))
                    {
                        // on vérifie que la valeur de prix est différente
                        // si identiques on return (rien à faire)
                        if (ev.First().value == value)
                        {
                            return;
                        }
                        // sinon on remplace
                        ev.First().value = value;
                        context.SaveChanges();
                        return;
                    }
                    else if (ev.Count() == 0)
                    {
                        CashDB c = new CashDB { date = date, value = value };
                        context.Cash.Add(c);
                        context.SaveChanges();
                        return;
                    }else
                    {
                        throw new Exception("Problème dans la BD.");
                    }
                }

            }