예제 #1
0
        public static DollarCostAvgCollection GetAll()
        {
            DollarCostAvgCollection obj = new DollarCostAvgCollection();
            DataSet ds = new DAL.DollarCostAvg().GetAll();

            obj.MapObjects(ds);
            return(obj);
        }
예제 #2
0
        public static void CalculateDollarCostAvg()
        {
            DollarCostAvgCollection all = DollarCostAvgCollection.GetAll();

            decimal btc = 587M;
            decimal usd = 0M;



            foreach (DollarCostAvg avg in all)
            {
                decimal diff = (btc * avg.BtcUsd) - usd;

                avg.Btc = btc;
                avg.Usd = usd;

                if (diff >= 0)
                {
                    if (diff < 0)
                    {
                        diff = diff * -1;
                    }
                    avg.Btc = avg.Btc - ((diff / 2) / avg.BtcUsd);
                    avg.Usd = avg.Usd + ((diff / 2));
                }
                else
                {
                    if (diff < 0)
                    {
                        diff = diff * -1;
                    }
                    avg.Btc = avg.Btc + ((diff / 2) / avg.BtcUsd);
                    avg.Usd = avg.Usd - ((diff / 2));
                }

                avg.Save();

                btc = avg.Btc;
                usd = avg.Usd;
            }
        }