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 { public partial class OrderMaxControl : UserControl { private bool _valid = true; private bool _largeView = true; private Size _origSize; private Font _statusFont; private float _origStatusFontSize; private decimal _dollars; private decimal _shares; /// /// Order Maximum validation control. /// public OrderMaxControl() { InitializeComponent(); _origSize = Size; _statusFont = lblStatus.Font; _origStatusFontSize = lblStatus.Font.Size; } /// /// Status font. /// public Font StatusFont { get { return _statusFont; } set { _statusFont = value; lblStatus.Font = _statusFont; } } /// /// Get the original Status font size. /// public float OrigStatusFontSize { get { return _origStatusFontSize; } } /// /// Set Validate to whether or not the Order Maximum is observed. /// public bool Valid { get { return _valid; } set { _valid = value; if (_valid) { picStatus.Image = Properties.Resources.GreenCheck; lblStatus.Text = "Valid"; } else { picStatus.Image = Properties.Resources.RedX; lblStatus.Text = "Invalid"; } } } /// /// Set Large View to show Status text also. /// public bool LargeView { get { return _largeView; } set { _largeView = value; if (_largeView) { Size = _origSize; lblStatus.Visible = true; } else { Width = Height; lblStatus.Visible = false; } } } /// /// Dollars to be validated. /// public decimal Dollars { get { return _dollars; } set { _dollars = value; ValidateMaximums(); } } /// /// Shares to be validated. /// public decimal Shares { get { return _shares; } set { _shares = value; ValidateMaximums(); } } /// /// Validate Dollars and Shares against Order Maximums. /// private void ValidateMaximums() { bool dollarsValid = true; bool sharesValid = true; string toolTipText = ""; // Validate Dollars. if (GuiEnvironment.OEPOrderMaximumDollars > 0 && _dollars > 0) { if (_dollars > GuiEnvironment.OEPOrderMaximumDollars) { dollarsValid = false; toolTipText += $"{_dollars.ToString("N2")} Dollars exceeds Order Maximum of {GuiEnvironment.OEPOrderMaximumDollars.ToString("N2")}."; } else { toolTipText += $"{_dollars.ToString("N2")} Dollars adheres to Order Maximum of {GuiEnvironment.OEPOrderMaximumDollars.ToString("N2")}."; } } // Validate Shares. if (GuiEnvironment.OEPOrderMaximumShares > 0 && _shares > 0) { if (toolTipText.Length > 0) toolTipText += " "; if (_shares > GuiEnvironment.OEPOrderMaximumShares) { sharesValid = false; toolTipText += $"{_shares.ToString("N0")} Shares exceeds Order Maximum of {GuiEnvironment.OEPOrderMaximumShares.ToString("N0")}."; } else { toolTipText += $"{_shares.ToString("N0")} Shares adheres to Order Maximum of {GuiEnvironment.OEPOrderMaximumShares.ToString("N0")}."; } } // Set Valid. Valid = dollarsValid && sharesValid; // Set tooltip. toolTip1.SetToolTip(picStatus, toolTipText); } } }