using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TradeIdeas.TIProGUI.RealTimeStockRace
{
public partial class RaceWinnerControl : UserControl
{
private double _currentX;
private double _currentY;
private double _incrementX;
private double _incrementY;
private Point _endPoint;
private string _symbol;
private Color _symbol1Color;
private string _symbolSecondPlace;
private Color _symbol2Color;
private string _symbolThirdPlace;
private Color _symbol3Color;
public Action FinishMoveAction;
public RaceWinnerControl(string symbol, int numWins, string basedOn, string sortOn, string raceTime, string finishDetails, Point startPoint, Point endPoint, Color textColor, Color backColor,
Color symbol1Color, string symbolSecondPlace, Color symbol2Color, string symbolThirdPlace, Color symbol3Color)
{
InitializeComponent();
_symbol = symbol;
_symbol1Color = symbol1Color;
_symbolSecondPlace = symbolSecondPlace;
_symbol2Color = symbol2Color;
_symbolThirdPlace = symbolThirdPlace;
_symbol3Color = symbol3Color;
lblSymbol.Text = $"{symbol} - {numWins}"; //symbol;
lblFinishDetails.Text = finishDetails;
BackColor = backColor;
lblSymbol.ForeColor = textColor;
lblFinishDetails.ForeColor = textColor;
// Add tool tip with details.
toolTip1.SetToolTip(lblSymbol, $"Based On: {basedOn}, Sort On: {sortOn}, Race Time: {raceTime}");
toolTip1.SetToolTip(lblFinishDetails, finishDetails);
// Set the control start point.
this.Location = startPoint;
_endPoint = endPoint;
// Calculate the increments to move the control to the end point.
_currentX = startPoint.X;
_currentY = startPoint.Y;
if (endPoint.X > _currentX)
_incrementX = (endPoint.X - _currentX) / 100;
else
_incrementX = (_currentX - endPoint.X) / 100;
if (endPoint.Y > _currentY)
_incrementY = (endPoint.Y - _currentY) / 100;
else
_incrementY = (_currentY - endPoint.Y) / 100;
}
public void StartMoveTimer()
{
// Start the move timer.
moveTimer.Start();
}
private void moveTimer_Tick(object sender, EventArgs e)
{
// Stop the timer.
moveTimer.Stop();
// Calculate the next increment position.
Point currentPoint;
if (_currentX < _endPoint.X)
_currentX += _incrementX;
else
_currentX -= _incrementX;
if (_currentY < _endPoint.Y)
_currentY += _incrementY;
else
_currentY -= _incrementY;
// See if we are at the end point.
if (_currentX >= _endPoint.X || _currentY <= _endPoint.Y)
{
//moveTimer.Stop();
currentPoint = _endPoint;
}
else
{
currentPoint = new Point(Convert.ToInt32(Math.Round(_currentX)), Convert.ToInt32(Math.Round(_currentY)));
}
// Move the control to the next increment position.
this.Location = currentPoint;
// Restart time if needed.
if (this.Location != _endPoint)
moveTimer.Start();
else if (FinishMoveAction != null)
FinishMoveAction();
}
private void SendToExternalLinking(string symbol)
{
Panel raceWinnersPanel = Parent as Panel;
if (raceWinnersPanel != null)
{
Panel raceWinnersHolderPanel = raceWinnersPanel.Parent as Panel;
if (raceWinnersHolderPanel != null)
{
Panel finishLinePanel = raceWinnersHolderPanel.Parent as Panel;
if (finishLinePanel != null)
{
Panel mainPanel = finishLinePanel.Parent as Panel;
if (mainPanel != null)
{
RealTimeStockRaceForm realTimeStockRaceForm = mainPanel.Parent as RealTimeStockRaceForm;
if (realTimeStockRaceForm != null)
{
realTimeStockRaceForm.SendToExternalLinking(symbol);
}
}
}
}
}
}
///
/// Show the Top Race Winners popup.
///
///
///
///
private void ShowTopRaceWinnersPopup(string symbol1, Color symbol1Color, string symbol2, Color symbol2Color, string symbol3, Color symbol3Color)
{
Panel raceWinnersPanel = Parent as Panel;
if (raceWinnersPanel != null)
{
Panel raceWinnersHolderPanel = raceWinnersPanel.Parent as Panel;
if (raceWinnersHolderPanel != null)
{
Panel finishLinePanel = raceWinnersHolderPanel.Parent as Panel;
if (finishLinePanel != null)
{
Panel mainPanel = finishLinePanel.Parent as Panel;
if (mainPanel != null)
{
RealTimeStockRaceForm realTimeStockRaceForm = mainPanel.Parent as RealTimeStockRaceForm;
if (realTimeStockRaceForm != null)
{
realTimeStockRaceForm.ShowTopRaceWinnersPopup(this, symbol1, symbol1Color, symbol2, symbol2Color, symbol3, symbol3Color);
}
}
}
}
}
}
private void lblSymbol_Click(object sender, EventArgs e)
{
SendToExternalLinking(_symbol);
ShowTopRaceWinnersPopup(_symbol, _symbol1Color, _symbolSecondPlace, _symbol2Color, _symbolThirdPlace, _symbol3Color);
}
private void lblFinishDetails_Click(object sender, EventArgs e)
{
SendToExternalLinking(_symbol);
ShowTopRaceWinnersPopup(_symbol, _symbol1Color, _symbolSecondPlace, _symbol2Color, _symbolThirdPlace, _symbol3Color);
}
private void RaceWinnerControl_Click(object sender, EventArgs e)
{
SendToExternalLinking(_symbol);
ShowTopRaceWinnersPopup(_symbol, _symbol1Color, _symbolSecondPlace, _symbol2Color, _symbolThirdPlace, _symbol3Color);
}
}
}