Esempio n. 1
0
 public static bool isShareBind(Share share)
 {
     return(bindCode.IndexOf(share.shareInfo.shareUrlCode) != -1);
 }
Esempio n. 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            // Update stock list current price information
            Share share = null;

            foreach (ListViewItem lvi in listView_StockList.Items)
            {
                share = GetShareByCode(lvi.Text);
                // if (!IsTradingTime(share.shareData.dataTime)) continue;
                lvi.SubItems[subitemIndex_CurrentPrice].Text = share.shareData.currentPrice;
                if (lvi.SubItems[subitemIndex_CurrentPrice].Text != "")
                {
                    int   warningType  = -1;
                    float currentPrice = float.Parse(lvi.SubItems[subitemIndex_CurrentPrice].Text);
                    float upPrice      = lvi.SubItems[subitemIndex_UpPrice].Text == "" ? 0 : float.Parse(lvi.SubItems[subitemIndex_UpPrice].Text);
                    float downPrice    = lvi.SubItems[subitemIndex_DownPrice].Text == "" ? 0 : float.Parse(lvi.SubItems[subitemIndex_DownPrice].Text);

                    if (currentPrice == 0)
                    {
                        continue;
                    }

                    // Warning Type jugement
                    if (upPrice != 0 && upPrice <= currentPrice)
                    {
                        warningType = 0;
                    }
                    if (downPrice != 0 && downPrice >= currentPrice)
                    {
                        warningType = 1;
                    }

                    if (warningType != -1)
                    {
                        // Highlight warning item in listview
                        lvi.ForeColor = warningType == 0 ? Color.Red : Color.Green;

                        if (!WarningMessageBox.isShareBind(share))
                        {
                            // Wechat notify
                            int            retry          = 3;
                            string         title          = "[" + share.shareInfo.shareUrlCode + "] " + share.shareData.shareName + " 触发" + (warningType == 0 ? "上" : "下") + "破价格 " + lvi.SubItems[subitemIndex_DownPrice].Text;
                            string         content        = title + ", 现价 " + share.shareData.currentPrice;
                            WechatNotifier wechatNotifier = new WechatNotifier(Notify_SCKEY);
                            if (wechatNotify.Checked)
                            {
                                int i = 1;
                                for ( ; i <= retry; i++)
                                {
                                    if (wechatNotifier.SendNotifier(title, content))
                                    {
                                        break;
                                    }
                                }
                                if (i > retry)
                                {
                                    Console.WriteLine("微信提醒失败,请检查 SCKEY 是否填写正确");
                                }
                            }

                            // Create Warning Messagebox
                            WarningMessageBox msg = new WarningMessageBox(share, warningType, lvi.SubItems[subitemIndex_DownPrice].Text, this);
                            msg.Show();
                        }

                        // Play sound
                        warningdPlayer.Play();
                    }
                    else
                    {
                        lvi.ForeColor = Color.Black;
                    }
                }
            }

            // Update Infomation Panal
            if (Get2DisplayShareInfomationByCode(textBox_StockCode.Text))
            {
                this.Text = Formtitle + " (Stock data has update: " + System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + " )";
            }
            else
            {
                this.Text = Formtitle + " (Request Error!)";
                pictureBox_StockImage.Image = null;
            }
            if (--GCTimeFlow < 0)
            {
                GC.Collect();
                GCTimeFlow = GCTime;
            }

            // Update notifyIcon text
            int bindCount = WarningMessageBox.getBindCount();

            if (bindCount == 0)
            {
                notifyIcon1.Text = "当前无预警触发";
            }
            else
            {
                notifyIcon1.Text = "当前有" + String.Concat(bindCount) + "条预警被触发!";
            }
        }