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 static System.Windows.Forms.CheckedListBox; using static System.Windows.Forms.ListBox; using static TradeIdeas.TIProData.InsiderTrade; namespace TradeIdeas.TIProGUI.EnhancedSingleStockWindow { public partial class TransactionsWindow : Form { //EnhancedSingleStockWindow _eWin; / PRO-384: Commented references to EnhancedSingleStockWindow. EnhancedSingleStockDockWindow _eWinDock; //public TransactionsWindow(EnhancedSingleStockWindow eWin) //{ // _eWin = eWin; // this.StartPosition = FormStartPosition.CenterParent; // InitializeComponent(); // Icon = GuiEnvironment.Icon; // Font = GuiEnvironment.FontSettings; // customCheckedListBox1.Font = Font; // //add the items to the listbox // customCheckedListBox1.Items.Add(new ListBoxObject("Buys", InsiderTransactionType.Buy)); // customCheckedListBox1.Items.Add(new ListBoxObject("Automatic Buys", InsiderTransactionType.AutomaticBuy)); // customCheckedListBox1.Items.Add(new ListBoxObject("Acquisition (Non Open Market)", InsiderTransactionType.AcquisitionNonOpenMarket)); // customCheckedListBox1.Items.Add(new ListBoxObject("Sells", InsiderTransactionType.Sell)); // customCheckedListBox1.Items.Add(new ListBoxObject("Automatic Sells", InsiderTransactionType.AutomaticSell)); // customCheckedListBox1.Items.Add(new ListBoxObject("Disposition (Non Open Market)", InsiderTransactionType.DispositionNonOpenMarket)); // //^^ this is the order that the items will appear in the window. Now we must check the appropriate boxes if the // //window's insider grid is already filtered. we'll do this before we add the event handler. // setSelectedCheckboxes(_eWin.getSelectedFIlterList()); // customCheckedListBox1.ItemCheck += CustomCheckedListBox1_ItemCheck; //} // new constructor for use with the new docked version - RVH20210716 public TransactionsWindow(EnhancedSingleStockDockWindow eWin) { _eWinDock = eWin; this.StartPosition = FormStartPosition.CenterParent; InitializeComponent(); Icon = GuiEnvironment.Icon; Font = GuiEnvironment.FontSettings; customCheckedListBox1.Font = Font; //add the items to the listbox customCheckedListBox1.Items.Add(new ListBoxObject("Buys", InsiderTransactionType.Buy)); customCheckedListBox1.Items.Add(new ListBoxObject("Automatic Buys", InsiderTransactionType.AutomaticBuy)); customCheckedListBox1.Items.Add(new ListBoxObject("Acquisition (Non Open Market)", InsiderTransactionType.AcquisitionNonOpenMarket)); customCheckedListBox1.Items.Add(new ListBoxObject("Sells", InsiderTransactionType.Sell)); customCheckedListBox1.Items.Add(new ListBoxObject("Automatic Sells", InsiderTransactionType.AutomaticSell)); customCheckedListBox1.Items.Add(new ListBoxObject("Disposition (Non Open Market)", InsiderTransactionType.DispositionNonOpenMarket)); //^^ this is the order that the items will appear in the window. Now we must check the appropriate boxes if the //window's insider grid is already filtered. we'll do this before we add the event handler. // modifiy to handle new dock version also - RVH20210716 setSelectedCheckboxes(_eWinDock.getSelectedFIlterList()); customCheckedListBox1.ItemCheck += CustomCheckedListBox1_ItemCheck; } private void CustomCheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { List selectedItems = new List(); ListBoxObject selectedFilter = (ListBoxObject)customCheckedListBox1.Items[e.Index]; if (e.NewValue == CheckState.Checked) { ListBoxObject lbObj = (ListBoxObject)selectedFilter; selectedItems.Add(lbObj.getTag()); } CheckedItemCollection items = customCheckedListBox1.CheckedItems; for (int i = 0; i < items.Count; i++) { InsiderTransactionType t = ((ListBoxObject)items[i]).getTag(); if (!selectedItems.Contains(t)) selectedItems.Add(t); } try { ListBoxObject obj = (ListBoxObject)customCheckedListBox1.Items[e.Index]; InsiderTransactionType currentType = obj.getTag(); if (e.NewValue == CheckState.Checked && !selectedItems.Contains(currentType)) selectedItems.Add(currentType); else if (e.NewValue == CheckState.Unchecked && selectedItems.Contains(currentType)) selectedItems.Remove(currentType); } catch { } // modifiy to handle new dock version also - RVH20210716 if (_eWinDock != null) _eWinDock.receiveCheckedFilters(selectedItems); //else // _eWin.receiveCheckedFilters(selectedItems); } private void BtnOK_Click(object sender, EventArgs e) { this.Close(); } private void setSelectedCheckboxes(List filters) { foreach (InsiderTransactionType t in filters) { switch (t) { case InsiderTransactionType.Buy: customCheckedListBox1.SetItemChecked(0, true); break; case InsiderTransactionType.AutomaticBuy: customCheckedListBox1.SetItemChecked(1, true); break; case InsiderTransactionType.AcquisitionNonOpenMarket: customCheckedListBox1.SetItemChecked(2, true); break; case InsiderTransactionType.Sell: customCheckedListBox1.SetItemChecked(3, true); break; case InsiderTransactionType.AutomaticSell: customCheckedListBox1.SetItemChecked(4, true); break; case InsiderTransactionType.DispositionNonOpenMarket: customCheckedListBox1.SetItemChecked(5, true); break; } } } private void TransactionsWindow_FormClosing(object sender, FormClosingEventArgs e) { //if(_eWin != null) // _eWin.setFilterPopupInUse(false); // modify to handle new dock version also - RVH20210716 if (_eWinDock != null) _eWinDock.setFilterPopupInUse(false); } } public class ListBoxObject { private string _title; private InsiderTransactionType _tag; public ListBoxObject(string title, InsiderTransactionType tag) { _title = title; _tag = tag; } public string getTitle() { return _title; } public InsiderTransactionType getTag() { return _tag; } public override string ToString() { return _title; } } }