using CefSharp.DevTools.CSS; 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; using TradeIdeas.MiscSupport; using TradeIdeas.TIProData.Configuration; using TradeIdeas.TIProGUI; using TradeIdeas.XML; namespace TradeIdeas.TIProGUI { public partial class MissingSymbolCheckFormChooser : Form { private const float DEFAULT_FONT_SIZE = 8.25F; private FontManager _fontManager; private SymbolLookupB _symbolLookup; public MissingSymbolCheckFormChooser(Form form) { InitializeComponent(); _fontManager = new FontManager(this, DEFAULT_FONT_SIZE); _fontManager.selectTheFont(); Font = GuiEnvironment.FontSettings; GuiEnvironment.DefaultIcon.SetIcon(this, false); StartPosition = FormStartPosition.CenterParent; SetDatetimePickersDisplayFormat(GuiEnvironment.DateTimePickerFormat); string apiURL = GuiEnvironment.AppConfig.Node("SYMBOL_LOOKUP").Property("API_URL", ""); int symbolLimit = GuiEnvironment.AppConfig.Node("SYMBOL_LOOKUP").Property("SYMBOL_LIMIT", -1); int keystrokePause = GuiEnvironment.AppConfig.Node("SYMBOL_LOOKUP").Property("KEYSTROKE_PAUSE", -1); _symbolLookup = new SymbolLookupTextBox() { ApiUrl = apiURL, SymbolLimit = symbolLimit, KeyStrokePause = keystrokePause, FontSize = this.Font.SizeInPoints, TextBoxFont = Font, }; this.Controls.Add(_symbolLookup); _symbolLookup.Top = SymbolLabel.Top - 2; _symbolLookup.Left = SymbolLabel.Right; _symbolLookup.Size = new Size(60, 20); _symbolLookup.Margin = new Padding(3, 3, 3, 3); _symbolLookup.AutoSetHeight(); _symbolLookup.symbolSelected += SetSymbol; SetSymbol("SPY"); checkedListBox1.Items.Clear(); checkBoxFiltersToColumns.Hide(); checkBoxRunHistory.Hide(); // Set end time to the pre market start time using user's time zone. dateTimePickerEndTime.Value = GuiEnvironment.GetPreMarketStartLocalTime(ServerFormats.Now); checkBoxRunHistory.Checked = true; if (!form.IsDisposed) { AlertForm alertForm = form as AlertForm; if (null != alertForm) { checkedListBox1.Items.Add(alertForm.GetWindowName()); _allForms.Add(form); checkedListBox1.SetItemChecked(0, true); _setAlertControls(); } MultiStrategy multiStrategyForm = form as MultiStrategy; if (null != multiStrategyForm) { foreach (var strategy in multiStrategyForm.MultiStrategyConfiguration.Strategies) { if (strategy.Config != null) { var index = checkedListBox1.Items.Add(strategy.Name); StrategyConfig strategyConfig; strategyConfig.Config = strategy.Config; strategyConfig.ConfigurationType = ConfigurationType.Alerts; _strategyConfigs.Add(strategyConfig); } } _allForms.Add(form); checkBoxFiltersToColumns.Top = dateTimePickerEndTime.Top; } } } private void _setAlertControls() { this.Height = this.Height - checkedListBox1.Height; _symbolLookup.Top = SymbolLabel.Top - 2; checkedListBox1.Hide(); } private void SetSymbol(string symbol) { if (symbol != null) { _symbolLookup.SetSymbol(symbol); } } public MissingSymbolCheckFormChooser() { InitializeComponent(); LoadOpenForms(); checkedListBox1.CheckOnClick = true; } public void SetDatetimePickersDisplayFormat(string format) { dateTimePickerStartTime.CustomFormat = format; dateTimePickerEndTime.CustomFormat = format; } private List
_allForms = new List(); private List _strategyConfigs = new List(); private void LoadOpenForms() { checkedListBox1.Items.Clear(); foreach (Form form in Application.OpenForms) { if (!form.IsDisposed) { AlertForm alertForm = form as AlertForm; if (null != alertForm) { checkedListBox1.Items.Add(alertForm.GetWindowName()); _allForms.Add(alertForm); } MultiStrategy multiStrategyForm = form as MultiStrategy; if (null != multiStrategyForm) { checkedListBox1.Items.Add(multiStrategyForm.BaseWindowName); _allForms.Add(multiStrategyForm); } } } } private void buttonOK_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; Close(); } private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } public List CheckedAlertForms { get { List toReturn = new List(); foreach (int index in checkedListBox1.CheckedIndices) { if (index < _allForms.Count) { AlertForm alertForm = _allForms[index] as AlertForm; if (null != alertForm) toReturn.Add(alertForm); } } return toReturn; } } public List CheckedMultiStrategyForms { get { List toReturn = new List(); foreach (int index in checkedListBox1.CheckedIndices) { if (index < _allForms.Count) { MultiStrategy multiStrategyForm = _allForms[index] as MultiStrategy; if (null != multiStrategyForm) toReturn.Add(multiStrategyForm); } } return toReturn; } } public List GetSelectedStrategies () { List toReturn = new List(); foreach (int index in checkedListBox1.CheckedIndices) { toReturn.Add(_strategyConfigs[index]); } return toReturn; } public string Symbol { get { return _symbolLookup.GetSymbol(); } } public bool FilterToColumns { get { return checkBoxFiltersToColumns.Checked; } } public bool RunHistory { get { return checkBoxRunHistory.Checked; } } public DateTime StartTime { get { return dateTimePickerStartTime.Value; } } public DateTime EndTime { get { return dateTimePickerEndTime.Value; } } private void checkBoxRunHistory_CheckedChanged(object sender, EventArgs e) { dateTimePickerStartTime.Enabled = checkBoxRunHistory.Checked; dateTimePickerEndTime.Enabled = checkBoxRunHistory.Checked; checkBoxFiltersToColumns.Checked = !checkBoxRunHistory.Checked; } private void checkBoxFiltersToColumns_CheckedChanged(object sender, EventArgs e) { checkBoxRunHistory.Checked = !checkBoxFiltersToColumns.Checked; _symbolLookup.Enabled = !checkBoxFiltersToColumns.Checked; } private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { if (e.NewValue == CheckState.Checked && checkedListBox1.CheckedItems.Count > 0) { checkedListBox1.ItemCheck -= checkedListBox1_ItemCheck; checkedListBox1.SetItemChecked(checkedListBox1.CheckedIndices[0], false); checkedListBox1.ItemCheck += checkedListBox1_ItemCheck; } } } }