using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using TradeIdeas.TIProData;
using TradeIdeas.TIProGUI;
// TODO override the way we save to the layout.
namespace TradeIdeas.Dashboard
{
public partial class WatchList : TopListForm
{
private readonly int _listId;
private readonly IConnectionMaster _connectionMaster;
private readonly SymbolListsCacheManager _symbolListsCacheManager;
///
/// This data is just a sample. For real we'd want the colors. Possibly more, like the secondary sort.
/// However, keeping it simple would be a good idea, too.
/// We could start from the saved format, and work backwards to see what
/// we don't need (like position and size of window). In face, instead of this, we
/// should be starting from an XML file, maybe even a saved layout.
///
private static readonly Dictionary COLUMN_SETTINGS =
new Dictionary { { "Common", "form=1&show0=D_Symbol&show1=Price&show2=FCP&show3=TV&show4=RD&col_ver=1&SL=X1o5&sort=MinFCP&X_NYSE=on&X_ARCA=on&X_AMEX=on&XN=on&X_OTC=on&X_PINK=on&X_CAT=on&X_CAV=on&XX=on&count=1000" },
{ "Fundamentals", "form=1&show0=D_Symbol&show1=Price&show2=FCP&show3=MCap&show4=PERatio&col_ver=1&SL=X1o5&sort=MinFCP&X_NYSE=on&X_ARCA=on&X_AMEX=on&XN=on&X_OTC=on&X_PINK=on&X_CAT=on&X_CAV=on&XX=on&count=1000" },
{ "Day Trader", "form=1&show0=D_Symbol&show1=Price&show2=FCP&show3=Vol5&show4=Range5P&show5=DUp5&col_ver=1&SL=X1o5&sort=MinFCP&X_NYSE=on&X_ARCA=on&X_AMEX=on&XN=on&X_OTC=on&X_PINK=on&X_CAT=on&X_CAV=on&XX=on&count=1000" },
{ "Swing Trader", "form=1&show0=D_Symbol&show1=Price&show2=FCP&show3=MA200P&show4=GUD&show5=RV&col_ver=1&SL=X1o5&sort=MinFCP&X_NYSE=on&X_ARCA=on&X_AMEX=on&XN=on&X_OTC=on&X_PINK=on&X_CAT=on&X_CAV=on&XX=on&count=1000" } };
private static string DefautColumnListName
{
get
{
foreach (var kvp in COLUMN_SETTINGS)
return kvp.Key;
// There must be at least one setting!
// But keep the compiler happy.
throw new Exception();
}
}
private string _columnListName = null;
///
/// This is an index into a table.
/// If you specify an unknown or invalid name, it will be ignored.
/// Note that this is public.
/// The main program might want to change all of these at once.
/// Currently there is no need for the main program to read or set this,
/// but it brings up interesting possibilities.
///
public string ColumnListName
{
get
{
return _columnListName;
}
set
{
if ((value != _columnListName) && (COLUMN_SETTINGS.ContainsKey(value)))
{
_columnListName = value;
_symbolListsCacheManager.RenameList(_listId, "Watchlists|" + ColumnListName + "|" + UserVisibleName());
RequestData();
foreach (ToolStripMenuItem item in columnsToolStripMenuItem.DropDown.Items)
item.Checked = item.Text == value;
}
}
}
private void RequestData()
{
Config = COLUMN_SETTINGS[_columnListName] + "&SL=" + _listId + "&WN=" + System.Web.HttpUtility.UrlEncode(UserVisibleName());
}
///
/// The list id should never be reused.
/// Use or to create a new window.
/// These will set the list id appropriately.
///
///
///
private WatchList(IConnectionMaster connectionMaster, int listId) :
base(connectionMaster, null)
{
if (listId <= 0)
throw new ArgumentOutOfRangeException("listId", listId, "Should be positive.");
_listId = listId;
_connectionMaster = connectionMaster;
_symbolListsCacheManager = GuiEnvironment.GetSymbolListsCacheManager(_connectionMaster);
InitializeComponent();
ParsedName parsedName = new ParsedName(_symbolListsCacheManager.GetListName(listId));
if (parsedName.OneOfOurs)
ColumnListName = parsedName.ColumnListName;
// It doesn't matter if we never set this, or if the setting failed.
if (null == ColumnListName)
ColumnListName = DefautColumnListName;
}
///
/// Look for an existing window that follows this list.
/// You will probably use instead of this, but this allows for some interesting
/// GUI possibilities. For example, the main program might show open windows differently than
/// new windows.
///
///
///
/// The window, if it exists, or null if no such window exists.
public static WatchList Find(IConnectionMaster connectionMaster, int listId)
{
foreach (Form form in Application.OpenForms.Cast