private void startGeneralModelToolStripMenuItem_Click(object sender, EventArgs e) { //交易模式 if (!Market) { timer1.Enabled = true; Market = true; ModelTimer.Enabled = true; startGeneralModelToolStripMenuItem.Text = "Market Model (√)"; GoldPrice.BalloonTipTitle = "交易模式已启动"; //设置系统托盘启动时显示的文本 GoldPrice.BalloonTipText = "只接收每天9点到18点数据"; //设置系统托盘启动时显示的文本 GoldPrice.BalloonTipIcon = ToolTipIcon.Info; GoldPrice.Visible = true; GoldPrice.ShowBalloonTip(3000); } else { timer1.Enabled = true; Market = false; ModelTimer.Enabled = false; startGeneralModelToolStripMenuItem.Text = "Start Market Model"; GoldPrice.BalloonTipTitle = "交易模式已关闭";//设置系统托盘启动时显示的文本 GoldPrice.BalloonTipIcon = ToolTipIcon.Info; GoldPrice.Visible = true; GoldPrice.ShowBalloonTip(3000); } }
private static void HandleGoldData(object sender, MsgHandlerEventArgs args) { var logger = CreateLogger <Program>(); var message = args.Message; try { var upload = JsonConvert.DeserializeObject <GoldPriceUpload>(Encoding.UTF8.GetString(message.Data)); if (upload.Prices.Length != upload.Timestamps.Length) { throw new Exception("Different list lengths"); } using var context = new ConfiguredContext(); for (var i = 0; i < upload.Prices.Length; i++) { var price = upload.Prices[i]; var timestamp = new DateTime(upload.Timestamps[i], DateTimeKind.Utc); var dbGold = context.GoldPrices.FirstOrDefault(x => x.Timestamp == timestamp); if (dbGold != null) { if (dbGold.Price != price) { dbGold.Price = price; context.GoldPrices.Update(dbGold); } } else { var goldPrice = new GoldPrice() { Price = price, Timestamp = timestamp }; context.GoldPrices.Add(goldPrice); } updatedGoldCounter++; } context.SaveChanges(); logger.LogInformation(GetLogMessage(upload.Prices.Length, "Gold Records", updatedGoldCounter)); } catch (Exception ex) { logger.LogError(ex, "Error handling gold data"); } }
private void concernModelToolStripMenuItem_Click(object sender, EventArgs e) { if (!concern) { concern = true; ModelTimer.Enabled = true; concernModelToolStripMenuItem.Text = "Concern Model (√)"; GoldPrice.BalloonTipTitle = "关注模式已启动"; //设置系统托盘启动时显示的文本 GoldPrice.BalloonTipText = "仅每天下午的2点到4点显示报表"; //设置系统托盘启动时显示的文本 GoldPrice.BalloonTipIcon = ToolTipIcon.Info; GoldPrice.Visible = true; GoldPrice.ShowBalloonTip(3000); } else { concern = false; ModelTimer.Enabled = false; concernModelToolStripMenuItem.Text = "Start Concern Model"; this.Visible = true; GoldPrice.BalloonTipTitle = "关注模式已关闭";//设置系统托盘启动时显示的文本 GoldPrice.BalloonTipIcon = ToolTipIcon.Info; GoldPrice.Visible = true; GoldPrice.ShowBalloonTip(3000); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { GoldPrice.Dispose(); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //释放托盘 GoldPrice.Dispose(); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { GoldPrice.Dispose(); System.Environment.Exit(0); }