예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //if (user.Content.ToString() != "(" + DBSyncController.Handler().GetUserName() + ")")
            //{
            //    MessageBox.Show("用户已改变");
            //    this.Close();
            //    return;
            //}
            List <StockHoldEntity> SHEL;

            DBC.StockHoldReadAll(out SHEL);
            if (SHEL.Count == 0)
            {
                MessageBox.Show("无任何股票");
                return;
            }
            idl = SHEL.Select(s => s.id).ToList();
            NetState.IdConvert(ref idl);

            DateTime date;
            int      days;

            try
            {
                date = Convert.ToDateTime(StartDate.Text);
                if (date > DateTime.Now)
                {
                    throw new Exception();
                }
                days = Convert.ToInt32(DateLong.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确的日期");
                return;
            }
            ThreadDate td = new ThreadDate();

            td.date   = date;
            td.days   = days;
            td.Width  = (int)yield.Width;
            td.Height = (int)yield.Height;

            Thread get = new Thread(new ParameterizedThreadStart(ThreadImageGet));

            get.Start(td);
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //if (user.Content.ToString() != "(" + DBSyncController.Handler().GetUserName() + ")")  
            //{
            //    MessageBox.Show("用户已改变");
            //    this.Close();
            //    return;
            //}
            List<StockHoldEntity> SHEL;
            DBC.StockHoldReadAll(out SHEL);
            if (SHEL.Count == 0)
            {
                MessageBox.Show("无任何股票");
                return;
            }
            idl = SHEL.Select(s => s.id).ToList();
            NetState.IdConvert(ref idl);

            DateTime date;
            int days;
            try
            {
                date = Convert.ToDateTime(StartDate.Text);
                if (date > DateTime.Now)
                    throw new Exception();
                days = Convert.ToInt32(DateLong.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确的日期");
                return;
            }
            ThreadDate td = new ThreadDate();
            td.date = date;
            td.days = days;
            td.Width = (int)yield.Width;
            td.Height = (int)yield.Height;

            Thread get = new Thread(new ParameterizedThreadStart(ThreadImageGet));
            get.Start(td);
        }
예제 #3
0
        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());
        }