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.TIProGUI; using TradeIdeas.XML; namespace TIProAutoTradeExtension { public partial class AddPositionCreateForm : Form { private FontManager _fontManager; private const float DEFAULT_FONT_SIZE = 8.25F; private SymbolLookupB _symbolLookup; public string Symbol { get { return _symbolLookup.GetSymbol(); } } public Account SelectedAccount { get { return ComboxAccounts.SelectedItem as Account; } } public string Id { get; set; } public AddPositionCreateForm(List _accounts) { InitializeComponent(); Icon = GuiEnvironment.Icon; MinimizeBox = false; _fontManager = new FontManager(this, DEFAULT_FONT_SIZE); _fontManager.selectTheFont(); 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, }; tableLayoutPanelGrid.Controls.Add(_symbolLookup, 1, 0); _symbolLookup.Size = new Size(60, 20); _symbolLookup.Margin = new Padding(3, 3, 3, 3); _symbolLookup.AutoSetHeight(); _symbolLookup.symbolSelected += SetSymbol; buttonSave.Enabled = false; ComboxAccounts.DataSource = _accounts; ComboxAccounts.DisplayMember = "Name"; SetTabOrder(); } private void SetTabOrder() { // NEW SYMBOL LOOKUP //if (GuiEnvironment.DevelopmentMode) _symbolLookup.TabIndex = 0; //else // _textBoxSymbol.TabIndex = 0; flowLayoutPanelAddPosition.TabIndex = 1; textBoxPrice.TabIndex = 2; textBoxShares.TabIndex = 3; flowLayoutPanelButtons.TabIndex = 7; buttonSave.TabIndex = 8; buttonCancel.TabIndex = 9; } private void SetSymbol(string symbol) { if (symbol != null) { _symbolLookup.SetSymbol(symbol); UpdateEnabledStatus(); } } public double EntryPrice { get { double toReturn = -1; if (double.TryParse(textBoxPrice.Text, out toReturn)) return toReturn; return -1; } set { textBoxPrice.Text = value.ToString(); UpdateEnabledStatus(); } } public short IsLong { get { return radioButtonSideLong.Checked ? (short)1 : (short)0; } } public int Shares { get { int toReturn = -1; if (int.TryParse(textBoxShares.Text, out toReturn)) { return Math.Abs(toReturn); } return -1; } set { textBoxShares.Text = value.ToString(); UpdateEnabledStatus(); } } public DateTime EntryDate { get { DateTime _entryTime = new DateTime(dateTimePickerEntryDate.Value.Year, dateTimePickerEntryDate.Value.Month, dateTimePickerEntryDate.Value.Day, dateTimePickerEntryTime.Value.Hour, dateTimePickerEntryTime.Value.Minute, dateTimePickerEntryTime.Value.Second); return _entryTime; } } private void AddPositionCreateForm_Shown(object sender, EventArgs e) { _symbolLookup.SetTextBoxFocus(); } private bool FormIsValid() { return Symbol != null && Symbol != "" && EntryPrice != -1 && Shares != -1 && ComboxAccounts.Items.Count > 0 && ComboxAccounts.SelectedItem != null; } private void UpdateEnabledStatus() { buttonSave.Enabled = FormIsValid(); } private void textBoxPrice_TextChanged(object sender, EventArgs e) { UpdateEnabledStatus(); } private void textBoxShares_TextChanged(object sender, EventArgs e) { UpdateEnabledStatus(); } private void AddPositionCreateForm_FormClosing(object sender, FormClosingEventArgs e) { _symbolLookup.symbolSelected -= SetSymbol; _symbolLookup.UnsubscribeEvents(); } } }