using System;
using System.Windows.Forms;
using TradeIdeas.MiscSupport;
using TradeIdeas.TIProData.Interfaces;
namespace TradeIdeas.TIProGUI
{
///
/// TopListHistoricalTimeFrame class. Enables User to view a history
/// "snapshot" (or keep real time) for a TopList Form.
///
public partial class TopListHistoricalTimeFrame : Form
{
private const float DEFAULT_FONT_SIZE = 8.25F;
private FontManager _fontManager;
private DateTime dateTimePickerVal;
public bool isOK = false;
///
///
///
///
/// This can be null.
/// In that case we'll pick an appropriate time.
///
public TopListHistoricalTimeFrame(DateTime? initialTime = null)
{
InitializeComponent();
_fontManager = new FontManager(this, DEFAULT_FONT_SIZE);
_fontManager.selectTheFont();
Font = GuiEnvironment.FontSettings;
populateStrings();
if (initialTime.HasValue)
{
try
{
historyDateTimePicker.Value = initialTime.Value;
}
catch
{
historyDateTimePicker.Value = historyDateTimePicker.MinDate;
}
}
// Open window in the center of the parent
this.StartPosition = FormStartPosition.CenterParent;
Icon = GuiEnvironment.Icon;
}
public void populateStrings()
{
historyDateTimePicker.CustomFormat = GuiEnvironment.DateTimePickerFormat;
/* limit the maximum and minimum dates that the user can choose (like with 'history time frame' in Alert window)..*/
historyDateTimePicker.MaxDate = ServerFormats.Now.AddDays(1);
IConnectionMaster connectionMaster = GuiEnvironment.FindConnectionMaster("");
if (null != connectionMaster && null != connectionMaster.SendManager)
{
DateTime? oldestAlert = GuiEnvironment.GetGeneralInfo(connectionMaster.SendManager).GetOldestAlert();
if (oldestAlert.HasValue)
historyDateTimePicker.MinDate = oldestAlert.Value;
else
historyDateTimePicker.MinDate = historyDateTimePicker.MaxDate.AddDays(-50);
}
else
historyDateTimePicker.MinDate = historyDateTimePicker.MaxDate.AddDays(-50);
}
public DateTime getDateTimeValue()
{
return dateTimePickerVal;
}
private void btnCancel_Click(object sender, EventArgs e)
{
isOK = false;
this.Close();
}
private void btnOK_Click(object sender, EventArgs e)
{
isOK = true;
dateTimePickerVal = historyDateTimePicker.Value;
this.Close();
}
}
}