コード例 #1
0
ファイル: Yield.xaml.cs プロジェクト: zjxbetter/gupiao
        private void ThreadImageGet(object data)
        {
            ThreadDate td = (ThreadDate)data;
            List<HistoryStockHoldEntity> HSHELNoSort;
            DBC.HistoryStockHoldReadByRange(td.date, td.days, out HSHELNoSort);

            Dictionary<string, int> hold = new Dictionary<string, int>();
            List<HistoryStockHoldEntity> HSHEL = HSHELNoSort.OrderBy(g => g.date).ToList();
            double pri = DBC.PrincipalRead();
            double now = pri;
            foreach (HistoryStockHoldEntity HSHE in HSHEL)
            {
                if (!hold.ContainsKey(HSHE.id))
                {
                    hold.Add(HSHE.id, 0);
                }
            }

            Dictionary<string, Dictionary<DateTime, double>> moneydict = new Dictionary<string, Dictionary<DateTime, double>>();
            foreach (string x in idl)
            {
                Dictionary<DateTime, double> money = new Dictionary<DateTime, double>();
                NetDataController.HistoryMoney(x, td.date, td.days, out money);
                moneydict.Add(x, money);
            }

            List<DrawDataEntity> DDEL = new List<DrawDataEntity>();
            DrawDataEntity DDE = new DrawDataEntity();
            int index = 0;
            DateTime dt = td.date;
            if (dt.DayOfWeek == DayOfWeek.Saturday) dt = dt.AddDays(2);
            if (dt.DayOfWeek == DayOfWeek.Sunday) dt = dt.AddDays(1);
            for (int i = 0; i < td.days; i++)
            {
                dt = dt.AddDays(1);
                if (dt > DateTime.Now)
                {
                    break;
                }
                if (!moneydict.First().Value.ContainsKey(dt))
                {
                    foreach (var x in moneydict)
                    {
                        x.Value.Add(dt, x.Value[dt.AddDays(-1)]);
                    }
                }
                DDE.date = dt;
                while (index < HSHEL.Count - 1 && HSHEL[index].date <= dt)
                {
                    hold[HSHEL[index].id] += HSHEL[index].change;
                    now += -HSHEL[index].change * HSHEL[index].money;
                    index++;
                }
                double money = 0;
                foreach (var x in hold)
                {
                    if (x.Value != 0)
                    {
                        string id = idl.Where(s => s.Substring(1) == x.Key).First();
                        if (id == null)
                            continue;
                        double m = moneydict[id][dt];
                        money += x.Value * m;
                    }
                }
                DDE.money = (money + now - pri) * 100 / pri;
                DDEL.Add(DDE);
            }
            DrawDataController DDC = new DrawDataController(td.Width, td.Height);
            DDC.DrawData(DDEL);
            Action<Image, System.Drawing.Bitmap> updateAction = new Action<Image, System.Drawing.Bitmap>(UpdateImage);
            yield.Dispatcher.BeginInvoke(updateAction, yield, DDC.GetImage());
        }
コード例 #2
0
ファイル: Structure.xaml.cs プロジェクト: zjxbetter/gupiao
 private void ShowImage(object sender, RoutedEventArgs e)
 {
     if (user.Content.ToString() != "(" + UserPanelController.Handler().DBControllerByName(name).GetUserName() + ")")
     {
         MessageBox.Show("用户已改变!");
         this.Close();
         return;
     }
     if(select.Count == 0)
     {
         MessageBox.Show("请选择股票");
         return;
     }
     DateTime date;
     int days;
     try
     {
         date = Convert.ToDateTime(StartDate.Text);
         days = Convert.ToInt32(DateLong.Text);
     }
     catch(Exception)
     {
         MessageBox.Show("请输入正确的日期");
         return;
     }
     Dictionary<DateTime, double> money;
     List<HistoryStockHoldEntity> HSHEL;
     DrawDataController DDC = new DrawDataController((int)(hold.Width), (int)(hold.Height));
     Dictionary<System.Drawing.Color, List<DrawDataEntity>> dict = new Dictionary<System.Drawing.Color, List<DrawDataEntity>>();
     double max = 0;
     foreach(string id in select)
     {
         DrawDataEntity DDE = new DrawDataEntity();
         List<DrawDataEntity> DDEL = new List<DrawDataEntity>();
         UserPanelController.Handler().DBControllerByName(name).HistoryStockHoldReadByRange(id.Substring(1), date, days, out HSHEL);
         if(HSHEL.Count == 0)
             continue;
         NetDataController.HistoryMoney(id, date, days, out money);
         int index = 0;
         DateTime usable = DateTime.Parse("1970-01-01");
         for (int i = 0; i < days; i++) 
         {
             DateTime dt = date.AddDays(i);
             DDE.date = dt;
             if (dt > DateTime.Now)
             {
                 break;
             }
             if (money.ContainsKey(dt))
             {
                 usable = dt;
             }
             else
             {
                 if (usable == DateTime.Parse("1970-01-01"))
                     continue;
             }
             if (dt < HSHEL[index].date)
             {
                 DDE.money = HSHEL[index].number * money[usable];
             }
             else
             {
                 if (index >= HSHEL.Count - 1)
                 {
                     DDE.money = (HSHEL[index].number + HSHEL[index].change) * money[usable];
                 }
                 else
                 {
                     while (index + 1 < HSHEL.Count && HSHEL[index].date == HSHEL[index + 1].date)
                         index++;
                     if (index < HSHEL.Count - 1)
                         index++;
                     DDE.money = HSHEL[index].number * money[usable];
                 }
             }
             if (max < DDE.money)
                 max = DDE.money;
             DDEL.Add(DDE);
         }
         dict.Add(Adapter.ImageAdapter.ColorConvert(stockcolor[id]), DDEL);
     }
     DDC.DrawData(dict, max);
     hold.Source = Adapter.ImageAdapter.ImageConvert(DDC.GetImage());
 }