[Quantproject-developers] QuantDownloader/Downloader/TickerSelectors GroupEditor.cs,NONE,1.1 ITicker
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-04-17 14:12:44
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/TickerSelectors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5077/Downloader/TickerSelectors Added Files: GroupEditor.cs ITickerReceiver.cs ITickerSelector.cs TickerGroupsListViewMenu.cs TickerGroupsViewer.cs TickerViewer.cs TickerViewerMenu.cs Log Message: GroupEditor, TickerGroupsViewer and TickerViewer have been moved to a dedicated folder Added interfaces ITickerSelector and ITickerReceiver Added context menus to be used on Forms that implements these interfaces --- NEW FILE: TickerViewerMenu.cs --- /* QuantDownloader - Quantitative Finance Library TickerViewerMenu.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Windows.Forms; using QuantProject.DataAccess.Tables; namespace QuantProject.Applications.Downloader.TickerSelectors { /// <summary> /// The Context Menu used by TickerViewer /// It is the base class from which it is possible to derive /// other context menus used by any Form implementing ITickerSelector /// </summary> public class TickerViewerMenu : ContextMenu { // the form which contains the context Menu protected Form parentForm; private MenuItem menuItemSelectAll = new MenuItem("&Select all items"); private MenuItem menuItemDownload = new MenuItem("&Download selection"); private MenuItem menuItemValidate = new MenuItem("&Validate selection"); private MenuItem menuItemCopy = new MenuItem("&Copy selection"); //private MenuItem menuItemPaste = new MenuItem("&Paste"); private MenuItem menuItemQuotesEditor = new MenuItem("&Open Quotes Editor"); public TickerViewerMenu(Form ITickerSelectorForm) { this.parentForm = ITickerSelectorForm; //this.parentForm.ContextMenu = this; this.menuItemSelectAll.Click += new System.EventHandler(this.selectAllTickers); this.menuItemDownload.Click += new System.EventHandler(this.downloadSelectedTickers); this.menuItemValidate.Click += new System.EventHandler(this.validateSelectedTickers); this.menuItemCopy.Click += new System.EventHandler(this.copySelectedTickers); this.menuItemQuotesEditor.Click += new System.EventHandler(this.openQuotesEditor); this.MenuItems.Add(this.menuItemSelectAll); this.MenuItems.Add(this.menuItemDownload); this.MenuItems.Add(this.menuItemValidate); this.MenuItems.Add(this.menuItemCopy); this.MenuItems.Add(this.menuItemQuotesEditor); } private void selectAllTickers(object sender, System.EventArgs e) { ITickerSelector iTickerSelector = (ITickerSelector)this.parentForm; iTickerSelector.SelectAllTickers(); } private void copySelectedTickers(object sender, System.EventArgs e) { ITickerSelector iTickerSelector = (ITickerSelector)this.parentForm; Tickers.Clipboard = iTickerSelector.GetTableOfSelectedTickers(); } private void downloadSelectedTickers(object sender, System.EventArgs e) { ITickerSelector iTickerSelector = (ITickerSelector)this.parentForm; TickerDataTable tableOfSelectedTickers = iTickerSelector.GetTableOfSelectedTickers(); if(tableOfSelectedTickers.Rows.Count == 0) { MessageBox.Show("No ticker has been selected!\n\n" + "Click on the grey area on the left to " + "select a ticker", "QuantDownloader error message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } WebDownloader webDownloader = new WebDownloader(tableOfSelectedTickers); webDownloader.Show(); } private void validateSelectedTickers(object sender, System.EventArgs e) { ITickerSelector iTickerSelector = (ITickerSelector)this.parentForm; TickerDataTable tableOfSelectedTickers = iTickerSelector.GetTableOfSelectedTickers(); if(tableOfSelectedTickers.Rows.Count == 0) { MessageBox.Show("No ticker has been selected!\n\n" + "Click on the grey area on the left to " + "select a ticker", "QuantDownloader error message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } QuantProject.Applications.Downloader.Validate.ValidateForm validateForm = new Validate.ValidateForm(tableOfSelectedTickers); validateForm.Show(); } private void openQuotesEditor(object sender, System.EventArgs e) { ITickerSelector iTickerSelector = (ITickerSelector)this.parentForm; TickerDataTable tableOfSelectedTickers = iTickerSelector.GetTableOfSelectedTickers(); if(tableOfSelectedTickers.Rows.Count != 1) { MessageBox.Show("Choose just one ticker for the quote editor!\n\n" + "Click on the grey area on the left to " + "select only one ticker", "QuantDownloader error message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } QuotesEditor quotesEditor = new QuotesEditor((string)tableOfSelectedTickers.Rows[0][0]); quotesEditor.Show(); } /* private void paste(object sender, System.EventArgs e) { MessageBox.Show("Possible only if ITickerReceiver"); } */ } } --- NEW FILE: TickerGroupsListViewMenu.cs --- /* QuantDownloader - Quantitative Finance Library TickerGroupsListViewMenu.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using System.Windows.Forms; using QuantProject.DataAccess.Tables; namespace QuantProject.Applications.Downloader.TickerSelectors { /// <summary> /// It is the context menu used by the list view of the ticker groups viewer /// </summary> public class TickerGroupsListViewMenu : TickerViewerMenu { private MenuItem menuItemPaste = new MenuItem("&Paste copied tickers"); private MenuItem menuItemRemoveSelectedItems = new MenuItem("&Remove selected items"); public TickerGroupsListViewMenu(Form ITickerSelectorForm) : base(ITickerSelectorForm) { this.menuItemPaste.Click += new System.EventHandler(this.paste); this.menuItemRemoveSelectedItems.Click += new System.EventHandler(this.removeSelectedItems); this.MenuItems.Add(this.menuItemPaste); this.MenuItems.Add(this.menuItemRemoveSelectedItems); } private void paste(object sender, System.EventArgs e) { ITickerReceiver iTickerReceiver = (ITickerReceiver)this.parentForm; iTickerReceiver.ReceiveTickers(Tickers.Clipboard); } private void removeSelectedItems(object sender, System.EventArgs e) { MessageBox.Show(".... NOT IMPLEMENTED YET .... "); } } } --- NEW FILE: TickerGroupsViewer.cs --- /* QuantDownloader - Quantitative Finance Library TickerGroupsViewer.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data.OleDb; using System.Data; using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; namespace QuantProject.Applications.Downloader.TickerSelectors { /// <summary> /// TickerGroupsViewer. /// </summary> public class TickerGroupsViewer : System.Windows.Forms.Form, ITickerSelector, ITickerReceiver { private OleDbConnection oleDbConnection = ConnectionProvider.OleDbConnection; private OleDbDataAdapter oleDbDataAdapter; private DataTable table; private System.Windows.Forms.TreeView treeViewGroups; private System.Windows.Forms.Splitter splitter1; private System.Windows.Forms.ListView listViewGroupsAndTickers; private System.Windows.Forms.ContextMenu contextMenuTickerGroupsTreeView; private System.Windows.Forms.MenuItem menuItemAddNewGroup; private System.Windows.Forms.MenuItem menuItemRemoveGroup; private System.Windows.Forms.MenuItem menuItemRenameGroup; private string selectedGroupID; private string selectedGroupDescription; private System.Windows.Forms.ImageList imageListGroupsAndTickers; private System.ComponentModel.IContainer components; private const int GROUP_IMAGE = 0; private const int TICKER_IMAGE = 1; private const string FIRST_COLUMN_NAME = "Element Name"; private const string SECOND_COLUMN_NAME = "Element Type"; private const string THIRD_COLUMN_NAME = "Element Description"; public TickerGroupsViewer() { InitializeComponent(); // this.listViewGroupsAndTickers.ContextMenu = new TickerGroupsListViewMenu(this); this.listViewGroupsAndTickers.Columns.Add(FIRST_COLUMN_NAME, this.listViewGroupsAndTickers.Width - 30, HorizontalAlignment.Left); this.listViewGroupsAndTickers.Columns.Add(SECOND_COLUMN_NAME, this.listViewGroupsAndTickers.Width - 60, HorizontalAlignment.Left); this.listViewGroupsAndTickers.Columns.Add(THIRD_COLUMN_NAME, this.listViewGroupsAndTickers.Width - 90, HorizontalAlignment.Left); // } /// <summary> /// Clean all resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } /// <summary> /// It gets the groupID of the selected node in the treeView control of the object /// </summary> public string SelectedGroupID { get { return this.selectedGroupID; } } /// <summary> /// It gets the group Description of the selected node in the treeView control of the object /// </summary> public string SelectedGroupDescription { get { return this.selectedGroupDescription; } } private void addTickersToTable(DataTable tableToFill) { try { ; } catch(Exception ex) { string notUsed = ex.ToString(); } } private void addTickerToTable(DataTable tableToFill, string tickerID, string tickerDescription) { try { DataRow newRow = tableToFill.NewRow(); newRow[0] = tickerID; newRow[1] = tickerDescription; tableToFill.Rows.Add(newRow); } catch(Exception ex) { string notUsed = ex.ToString(); } } // implementation of ITickerSelector interface public void SelectAllTickers() { foreach(ListViewItem item in this.listViewGroupsAndTickers.Items) { item.Selected = true; } } public TickerDataTable GetTableOfSelectedTickers() { TickerDataTable tableOfSelectedTickers = new TickerDataTable(); foreach(ListViewItem item in this.listViewGroupsAndTickers.SelectedItems) { if(item.Tag is System.String) // the item contains in Tag property the ticker ID { this.addTickerToTable(tableOfSelectedTickers, (string)item.Tag, item.SubItems[2].Text); } else // the item references to a node in the treeView : // so it stands for a group of tickers { MessageBox.Show("NOT IMPLEMENTED YET"); } } return tableOfSelectedTickers; } #region Windows Form Designer generated code /// <summary> /// Don't modify content with the code editor /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TickerGroupsViewer)); this.treeViewGroups = new System.Windows.Forms.TreeView(); this.contextMenuTickerGroupsTreeView = new System.Windows.Forms.ContextMenu(); this.menuItemAddNewGroup = new System.Windows.Forms.MenuItem(); this.menuItemRemoveGroup = new System.Windows.Forms.MenuItem(); this.menuItemRenameGroup = new System.Windows.Forms.MenuItem(); this.imageListGroupsAndTickers = new System.Windows.Forms.ImageList(this.components); this.splitter1 = new System.Windows.Forms.Splitter(); this.listViewGroupsAndTickers = new System.Windows.Forms.ListView(); this.SuspendLayout(); // // treeViewGroups // this.treeViewGroups.ContextMenu = this.contextMenuTickerGroupsTreeView; this.treeViewGroups.Dock = System.Windows.Forms.DockStyle.Left; this.treeViewGroups.ImageList = this.imageListGroupsAndTickers; this.treeViewGroups.Name = "treeViewGroups"; this.treeViewGroups.Size = new System.Drawing.Size(120, 326); this.treeViewGroups.TabIndex = 0; this.treeViewGroups.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.treeViewGroups_AfterExpand); this.treeViewGroups.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewGroups_AfterSelect); // // contextMenuTickerGroupsTreeView // this.contextMenuTickerGroupsTreeView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItemAddNewGroup, this.menuItemRemoveGroup, this.menuItemRenameGroup}); // // menuItemAddNewGroup // this.menuItemAddNewGroup.Index = 0; this.menuItemAddNewGroup.Text = "&Add New Group"; this.menuItemAddNewGroup.Click += new System.EventHandler(this.menuItemAddNewGroup_Click); // // menuItemRemoveGroup // this.menuItemRemoveGroup.Index = 1; this.menuItemRemoveGroup.Text = "&Remove"; this.menuItemRemoveGroup.Click += new System.EventHandler(this.menuItemRemoveGroup_Click); // // menuItemRenameGroup // this.menuItemRenameGroup.Index = 2; this.menuItemRenameGroup.Text = "&Modify"; this.menuItemRenameGroup.Click += new System.EventHandler(this.menuItemRenameGroup_Click); // // imageListGroupsAndTickers // this.imageListGroupsAndTickers.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageListGroupsAndTickers.ImageSize = new System.Drawing.Size(16, 16); this.imageListGroupsAndTickers.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListGroupsAndTickers.ImageStream"))); this.imageListGroupsAndTickers.TransparentColor = System.Drawing.Color.Transparent; // // splitter1 // this.splitter1.BackColor = System.Drawing.SystemColors.Highlight; this.splitter1.Location = new System.Drawing.Point(120, 0); this.splitter1.Name = "splitter1"; this.splitter1.Size = new System.Drawing.Size(3, 326); this.splitter1.TabIndex = 1; this.splitter1.TabStop = false; // // listViewGroupsAndTickers // this.listViewGroupsAndTickers.Activation = System.Windows.Forms.ItemActivation.TwoClick; this.listViewGroupsAndTickers.Dock = System.Windows.Forms.DockStyle.Fill; this.listViewGroupsAndTickers.Location = new System.Drawing.Point(123, 0); this.listViewGroupsAndTickers.Name = "listViewGroupsAndTickers"; this.listViewGroupsAndTickers.Size = new System.Drawing.Size(397, 326); this.listViewGroupsAndTickers.SmallImageList = this.imageListGroupsAndTickers; this.listViewGroupsAndTickers.TabIndex = 2; this.listViewGroupsAndTickers.View = System.Windows.Forms.View.Details; this.listViewGroupsAndTickers.ItemActivate += new System.EventHandler(this.listViewGroupsAndTickers_ItemActivate); // // TickerGroupsViewer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(520, 326); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listViewGroupsAndTickers, this.splitter1, this.treeViewGroups}); this.Name = "TickerGroupsViewer"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Ticker-Groups Viewer"; this.Load += new System.EventHandler(this.TickerGroupsViewer_Load); this.ResumeLayout(false); } #endregion #region Tree View Paintig on Load /// <summary> /// fill Tree View with existing groups (at root level) /// </summary> private void fillTreeViewAtRootLevel() { this.oleDbDataAdapter = new OleDbDataAdapter("SELECT * FROM tickerGroups WHERE tgTgId IS NULL" , this.oleDbConnection); this.table = new DataTable(); this.oleDbDataAdapter.Fill(this.table); TreeNode rootNode = new TreeNode("GROUPS"); rootNode.Tag = ""; this.treeViewGroups.Nodes.Add(rootNode); foreach (DataRow row in this.table.Rows) { TreeNode node = new TreeNode((string)row["tgDescription"]); node.Tag = (string)row["tgId"]; rootNode.Nodes.Add(node); } } /// <summary> /// fill the current node with existing groups from the DB /// </summary> private void addNodeChildsToCurrentNode(TreeNode currentNode) { this.oleDbDataAdapter.SelectCommand.CommandText = "SELECT * FROM tickerGroups WHERE tgTgId = '" + (string)currentNode.Tag + "'"; DataTable groupsChild = new DataTable(); this.oleDbDataAdapter.Fill(groupsChild); foreach (DataRow row in groupsChild.Rows) { TreeNode node = new TreeNode((string)row["tgDescription"]); node.Tag = (string)row["tgId"]; currentNode.Nodes.Add(node); } } private void TickerGroupsViewer_Load(object sender, System.EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); fillTreeViewAtRootLevel(); foreach(TreeNode node in this.treeViewGroups.Nodes[0].Nodes) { addNodeChildsToCurrentNode(node); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } #endregion #region Paint Child Nodes During selection private void treeViewGroups_AfterExpand(object sender, System.Windows.Forms.TreeViewEventArgs e) { if((string)this.treeViewGroups.SelectedNode.Tag != "") return; try { Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); foreach(TreeNode node in this.treeViewGroups.SelectedNode.Nodes) { foreach(TreeNode childNode in node.Nodes) { if(childNode.Nodes.Count == 0) addNodeChildsToCurrentNode(childNode); } } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } #endregion private void treeViewGroups_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { this.selectedGroupID = (string)this.treeViewGroups.SelectedNode.Tag; this.selectedGroupDescription = this.treeViewGroups.SelectedNode.Text; this.updateListView(this.treeViewGroups.SelectedNode); } #region Update List View private void updateGroupsInListView(TreeNode selectedNode) { foreach(TreeNode node in selectedNode.Nodes) { ListViewItem listViewItem = new ListViewItem(node.Text, GROUP_IMAGE); listViewItem.Tag = node; this.listViewGroupsAndTickers.Items.Add(listViewItem); listViewItem.SubItems.Add("Group"); } } private void updateTickersInListView(TreeNode selectedNode) { try { Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); this.oleDbDataAdapter.SelectCommand.CommandText = "SELECT ttTiId, tiCompanyName, ttTgId FROM tickers INNER JOIN " + "tickers_tickerGroups ON tickers.tiTicker = tickers_tickerGroups.ttTiId WHERE ttTgId ='" + (string)selectedNode.Tag + "'"; DataTable tickers = new DataTable(); this.oleDbDataAdapter.Fill(tickers); foreach (DataRow row in tickers.Rows) { ListViewItem listViewItem = new ListViewItem((string)row[0], TICKER_IMAGE); listViewItem.Tag = (string)row[0]; this.listViewGroupsAndTickers.Items.Add(listViewItem); listViewItem.SubItems.Add("Ticker"); listViewItem.SubItems.Add((string)row[1]); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } private void updateListView(TreeNode selectedNode) { this.listViewGroupsAndTickers.Items.Clear(); this.updateGroupsInListView(selectedNode); this.updateTickersInListView(selectedNode); } #endregion #region Add group private void addNodeGroupToCurrentNode(string groupID, string groupDescription) { TreeNode node = new TreeNode(groupDescription); node.Tag = groupID; this.treeViewGroups.SelectedNode.Nodes.Add(node); this.updateListView(this.treeViewGroups.SelectedNode); } internal void AddNewGroupToDataBase(string groupID, string groupDescription, string parentGroupID) { try { Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription, tgTgId) " + "VALUES('" + groupID + "','" + groupDescription + "','" + parentGroupID + "')", this.oleDbConnection); int numRowInserted = this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery(); if(numRowInserted > 0) this.addNodeGroupToCurrentNode(groupID, groupDescription); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } internal void AddNewGroupToDataBase(string groupID, string groupDescription) { try { Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription) " + "VALUES('" + groupID + "','" + groupDescription + "')", this.oleDbConnection); this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery(); this.addNodeGroupToCurrentNode(groupID, groupDescription); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } #endregion #region Modify current Node private void modifyCurrentNode(string newTag, string newText) { this.treeViewGroups.SelectedNode.Text = newText; this.treeViewGroups.SelectedNode.Tag = newTag; } internal void ModifyGroup(string oldGroupID, string groupDescription, string newGroupID) { try { Cursor.Current = Cursors.WaitCursor; this.oleDbConnection.Open(); this.oleDbDataAdapter.UpdateCommand = new OleDbCommand("UPDATE tickerGroups SET tgId ='" + newGroupID + "', tgDescription ='" + groupDescription + "' WHERE tgId ='" + oldGroupID + "'", this.oleDbConnection); int numUpdatedRows = this.oleDbDataAdapter.UpdateCommand.ExecuteNonQuery(); if(numUpdatedRows >0) this.modifyCurrentNode(newGroupID, groupDescription); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } #endregion #region Remove current Node private void removeCurrentNodeAndGroup() { if((string)this.treeViewGroups.SelectedNode.Tag == "") { MessageBox.Show("You can not delete the root node!", "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if(MessageBox.Show("Do you really want to delete the current group and " + "all its groups and tickers?", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { return; } deleteCurrentGroup(this.treeViewGroups.SelectedNode); } private void deleteCurrentGroup(TreeNode nodeCorrespondingToGroup) { try { Cursor.Current = Cursors.WaitCursor; this.oleDbConnection.Open(); this.oleDbDataAdapter.DeleteCommand = new OleDbCommand("DELETE * FROM tickerGroups WHERE tgId = '" + nodeCorrespondingToGroup.Tag + "'", this.oleDbConnection); int numDeletedRows = this.oleDbDataAdapter.DeleteCommand.ExecuteNonQuery(); if (numDeletedRows > 0) this.treeViewGroups.SelectedNode.Remove(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } #endregion private void menuItemAddNewGroup_Click(object sender, System.EventArgs e) { GroupEditor groupEditor = new GroupEditor(this); groupEditor.Show(); } private void menuItemRemoveGroup_Click(object sender, System.EventArgs e) { this.removeCurrentNodeAndGroup(); } private void menuItemRenameGroup_Click(object sender, System.EventArgs e) { if((string)this.treeViewGroups.SelectedNode.Tag == "") // it is the root node { MessageBox.Show("The root node can't be modified!"); return; } GroupEditor groupEditor = new GroupEditor(this, this.treeViewGroups.SelectedNode); groupEditor.Show(); } private bool isRowInsertedInDataBase(DataRow row) { try { this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickers_tickerGroups(ttTiId, ttTgId) " + "VALUES('" + (string)row[0] + "','" + (string)this.treeViewGroups.SelectedNode.Tag + "')", this.oleDbConnection); if(this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery()>0) { return true; } else { return false; } } catch(Exception ex) { string neverUsed = ex.ToString(); return false; } } private void listViewGroupsAndTickers_ItemActivate(object sender, System.EventArgs e) { if(this.listViewGroupsAndTickers.SelectedItems[0].Tag is TreeNode) { this.treeViewGroups.SelectedNode.Expand(); foreach (TreeNode node in this.treeViewGroups.SelectedNode.Nodes) { if(node.Equals(this.listViewGroupsAndTickers.SelectedItems[0].Tag)) { node.Expand(); this.treeViewGroups.SelectedNode = node; this.updateListView(this.treeViewGroups.SelectedNode); break; } } } } //implementation of ITickerReceiver interface for this object public void ReceiveTickers(TickerDataTable tickers) { try { if(tickers == null) { MessageBox.Show("No ticker has been copied to ClipBoard!\n\n" + "Select some tickers before trying again!", "Paste operation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if((string)this.treeViewGroups.SelectedNode.Tag == "") { MessageBox.Show("Selected tickers can't be copied inside " + "the root node: change group and try again!", "Paste operation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // end of checks Cursor.Current = Cursors.WaitCursor; if(this.oleDbConnection.State != ConnectionState.Open) this.oleDbConnection.Open(); int numRowsInserted = 0; foreach (DataRow row in tickers.Rows) { if(this.isRowInsertedInDataBase(row)) numRowsInserted ++; } if(numRowsInserted != tickers.Rows.Count) MessageBox.Show("Some selected tickers have not been added", "Warning after paste operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.updateListView(this.treeViewGroups.SelectedNode); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; this.oleDbConnection.Close(); } } } } --- NEW FILE: ITickerReceiver.cs --- /* QuantDownloader - Quantitative Finance Library ITickerReceiver.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using QuantProject.DataAccess.Tables; namespace QuantProject.Applications.Downloader.TickerSelectors { /// <summary> /// Interface to be implemented by objects that can receive tickers /// </summary> public interface ITickerReceiver { void ReceiveTickers(TickerDataTable tickersToReceive); } } --- NEW FILE: TickerViewer.cs --- /* QuantDownloader - Quantitative Finance Library TickerViewer.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; namespace QuantProject.Applications.Downloader.TickerSelectors { /// <summary> /// It finds tickers that match criteria entered by the user /// </summary> public class TickerViewer : System.Windows.Forms.Form, ITickerSelector { private System.Windows.Forms.TextBox textBoxStringToFind; private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.DataGrid dataGrid1; private System.Windows.Forms.Button buttonFindTickers; private System.ComponentModel.IContainer components; private System.Windows.Forms.TextBox textBoxStringToFindInName; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Splitter splitter1; private System.Windows.Forms.GroupBox groupBoxDateQuoteFilter; private System.Windows.Forms.RadioButton radioButtonDateQuoteFilter; private System.Windows.Forms.RadioButton radioButtonAnyTicker; private System.Windows.Forms.DateTimePicker dateTimePickerFirstDate; private System.Windows.Forms.DateTimePicker dateTimePickerLastDate; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label7; private System.Windows.Forms.ComboBox comboBoxFirstOperator; private System.Windows.Forms.ComboBox comboBoxSecondOperator; private DataTable tableTickers; public TickerViewer() { InitializeComponent(); this.dataGrid1.ContextMenu = new TickerViewerMenu(this); this.tableTickers = new DataTable("tickers"); this.dataGrid1.DataSource = this.tableTickers; this.setStyle_dataGrid1(); } /// <summary> /// clean up /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// do not modify the content with the editor /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.textBoxStringToFind = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.textBoxStringToFindInName = new System.Windows.Forms.TextBox(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.buttonFindTickers = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); this.groupBoxDateQuoteFilter = new System.Windows.Forms.GroupBox(); this.comboBoxSecondOperator = new System.Windows.Forms.ComboBox(); this.comboBoxFirstOperator = new System.Windows.Forms.ComboBox(); this.label7 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.dateTimePickerLastDate = new System.Windows.Forms.DateTimePicker(); this.dateTimePickerFirstDate = new System.Windows.Forms.DateTimePicker(); this.radioButtonDateQuoteFilter = new System.Windows.Forms.RadioButton(); this.radioButtonAnyTicker = new System.Windows.Forms.RadioButton(); this.splitter1 = new System.Windows.Forms.Splitter(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.panel2.SuspendLayout(); this.groupBoxDateQuoteFilter.SuspendLayout(); this.SuspendLayout(); // // textBoxStringToFind // this.textBoxStringToFind.Location = new System.Drawing.Point(48, 40); this.textBoxStringToFind.Name = "textBoxStringToFind"; this.textBoxStringToFind.Size = new System.Drawing.Size(88, 20); this.textBoxStringToFind.TabIndex = 0; this.textBoxStringToFind.Text = "%"; this.toolTip1.SetToolTip(this.textBoxStringToFind, "Type chars to filter tickers (you can use % and _ ) "); // // label1 // this.label1.Location = new System.Drawing.Point(48, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(96, 16); this.label1.TabIndex = 1; this.label1.Text = "Ticker is like"; // // textBoxStringToFindInName // this.textBoxStringToFindInName.AllowDrop = true; this.textBoxStringToFindInName.Location = new System.Drawing.Point(216, 40); this.textBoxStringToFindInName.Name = "textBoxStringToFindInName"; this.textBoxStringToFindInName.Size = new System.Drawing.Size(120, 20); this.textBoxStringToFindInName.TabIndex = 4; this.textBoxStringToFindInName.Text = "%"; this.toolTip1.SetToolTip(this.textBoxStringToFindInName, "Type chars to filter companies (you can use % and _ ) "); // // dataGrid1 // this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.dataGrid1.DataMember = ""; this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Left; this.dataGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(432, 478); this.dataGrid1.TabIndex = 2; // // buttonFindTickers // this.buttonFindTickers.Location = new System.Drawing.Point(136, 256); this.buttonFindTickers.Name = "buttonFindTickers"; this.buttonFindTickers.Size = new System.Drawing.Size(104, 24); this.buttonFindTickers.TabIndex = 3; this.buttonFindTickers.Text = "Find Tickers"; this.buttonFindTickers.Click += new System.EventHandler(this.buttonFindTickers_Click); // // label3 // this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.label3.Location = new System.Drawing.Point(160, 40); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(32, 16); this.label3.TabIndex = 6; this.label3.Text = "AND"; // // label2 // this.label2.Location = new System.Drawing.Point(216, 16); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(120, 16); this.label2.TabIndex = 5; this.label2.Text = "Company Name is like"; // // panel2 // this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] { this.groupBoxDateQuoteFilter, this.textBoxStringToFind, this.buttonFindTickers, this.textBoxStringToFindInName, this.label2, this.label3, this.label1}); this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; this.panel2.ForeColor = System.Drawing.SystemColors.ControlText; this.panel2.Location = new System.Drawing.Point(432, 0); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(392, 478); this.panel2.TabIndex = 7; // // groupBoxDateQuoteFilter // this.groupBoxDateQuoteFilter.Controls.AddRange(new System.Windows.Forms.Control[] { this.comboBoxSecondOperator, this.comboBoxFirstOperator, this.label7, this.label5, this.label6, this.dateTimePickerLastDate, this.dateTimePickerFirstDate, this.radioButtonDateQuoteFilter, this.radioButtonAnyTicker}); this.groupBoxDateQuoteFilter.Location = new System.Drawing.Point(8, 80); this.groupBoxDateQuoteFilter.Name = "groupBoxDateQuoteFilter"; this.groupBoxDateQuoteFilter.Size = new System.Drawing.Size(376, 160); this.groupBoxDateQuoteFilter.TabIndex = 14; this.groupBoxDateQuoteFilter.TabStop = false; this.groupBoxDateQuoteFilter.Text = "Quote filter"; // // comboBoxSecondOperator // this.comboBoxSecondOperator.Enabled = false; this.comboBoxSecondOperator.Items.AddRange(new object[] { "<=", ">="}); this.comboBoxSecondOperator.Location = new System.Drawing.Point(200, 96); this.comboBoxSecondOperator.Name = "comboBoxSecondOperator"; this.comboBoxSecondOperator.Size = new System.Drawing.Size(48, 21); this.comboBoxSecondOperator.TabIndex = 22; this.comboBoxSecondOperator.Text = "<="; // // comboBoxFirstOperator // this.comboBoxFirstOperator.Enabled = false; this.comboBoxFirstOperator.Items.AddRange(new object[] { "<=", ">="}); this.comboBoxFirstOperator.Location = new System.Drawing.Point(200, 64); this.comboBoxFirstOperator.Name = "comboBoxFirstOperator"; this.comboBoxFirstOperator.Size = new System.Drawing.Size(48, 21); this.comboBoxFirstOperator.TabIndex = 21; this.comboBoxFirstOperator.Text = ">="; // // label7 // this.label7.Location = new System.Drawing.Point(256, 96); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(32, 16); this.label7.TabIndex = 20; this.label7.Text = "than"; // // label5 // this.label5.Location = new System.Drawing.Point(256, 64); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(32, 16); this.label5.TabIndex = 18; this.label5.Text = "than"; // // label6 // this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.label6.Location = new System.Drawing.Point(24, 96); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(152, 16); this.label6.TabIndex = 17; this.label6.Text = "and last available quote is"; // // dateTimePickerLastDate // this.dateTimePickerLastDate.Enabled = false; this.dateTimePickerLastDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; this.dateTimePickerLastDate.Location = new System.Drawing.Point(288, 96); this.dateTimePickerLastDate.Name = "dateTimePickerLastDate"; this.dateTimePickerLastDate.Size = new System.Drawing.Size(88, 20); this.dateTimePickerLastDate.TabIndex = 15; // // dateTimePickerFirstDate // this.dateTimePickerFirstDate.Enabled = false; this.dateTimePickerFirstDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; this.dateTimePickerFirstDate.Location = new System.Drawing.Point(288, 64); this.dateTimePickerFirstDate.Name = "dateTimePickerFirstDate"; this.dateTimePickerFirstDate.Size = new System.Drawing.Size(88, 20); this.dateTimePickerFirstDate.TabIndex = 13; // // radioButtonDateQuoteFilter // this.radioButtonDateQuoteFilter.Location = new System.Drawing.Point(8, 56); this.radioButtonDateQuoteFilter.Name = "radioButtonDateQuoteFilter"; this.radioButtonDateQuoteFilter.Size = new System.Drawing.Size(184, 24); this.radioButtonDateQuoteFilter.TabIndex = 12; this.radioButtonDateQuoteFilter.Text = "Only tickers whose first quote is"; this.radioButtonDateQuoteFilter.CheckedChanged += new System.EventHandler(this.radioButtonDateQuoteFilter_CheckedChanged); // // radioButtonAnyTicker // this.radioButtonAnyTicker.Checked = true; this.radioButtonAnyTicker.Location = new System.Drawing.Point(8, 24); this.radioButtonAnyTicker.Name = "radioButtonAnyTicker"; this.radioButtonAnyTicker.Size = new System.Drawing.Size(248, 24); this.radioButtonAnyTicker.TabIndex = 10; this.radioButtonAnyTicker.TabStop = true; this.radioButtonAnyTicker.Text = "Any ticker, with or without quotes"; // // splitter1 // this.splitter1.BackColor = System.Drawing.SystemColors.Highlight; this.splitter1.Location = new System.Drawing.Point(432, 0); this.splitter1.Name = "splitter1"; this.splitter1.Size = new System.Drawing.Size(3, 478); this.splitter1.TabIndex = 8; this.splitter1.TabStop = false; // // TickerViewer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(824, 478); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.splitter1, this.panel2, this.dataGrid1}); this.Name = "TickerViewer"; this.Text = "Ticker Viewer"; ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.panel2.ResumeLayout(false); this.groupBoxDateQuoteFilter.ResumeLayout(false); this.ResumeLayout(false); } #endregion #region Style for dataGrid1 private void setStyle_dataGrid1() { DataGridTableStyle dataGrid1TableStyle = new DataGridTableStyle(); dataGrid1TableStyle.MappingName = this.tableTickers.TableName; dataGrid1TableStyle.ColumnHeadersVisible = true; dataGrid1TableStyle.ReadOnly = true; dataGrid1TableStyle.SelectionBackColor = Color.DimGray ; DataGridTextBoxColumn columnStyle_tiTicker = new DataGridTextBoxColumn(); columnStyle_tiTicker.MappingName = "tiTicker"; columnStyle_tiTicker.HeaderText = "Ticker"; columnStyle_tiTicker.TextBox.Enabled = false; columnStyle_tiTicker.NullText = ""; columnStyle_tiTicker.Width = 60; DataGridTextBoxColumn columnStyle_tiCompanyName = new DataGridTextBoxColumn(); columnStyle_tiCompanyName.MappingName = "tiCompanyName"; columnStyle_tiCompanyName.HeaderText = "Company Name"; columnStyle_tiCompanyName.TextBox.Enabled = false; columnStyle_tiCompanyName.NullText = ""; columnStyle_tiCompanyName.Width = 150; DataGridTextBoxColumn columnStyle_FirstQuote = new DataGridTextBoxColumn(); columnStyle_FirstQuote.MappingName = "FirstQuote"; columnStyle_FirstQuote.HeaderText = "First Quote"; columnStyle_FirstQuote.TextBox.Enabled = false; columnStyle_FirstQuote.NullText = ""; columnStyle_FirstQuote.Width = 80; DataGridTextBoxColumn columnStyle_LastQuote = new DataGridTextBoxColumn(); columnStyle_LastQuote.MappingName = "LastQuote"; columnStyle_LastQuote.HeaderText = "Last Quote"; columnStyle_LastQuote.TextBox.Enabled = false; columnStyle_LastQuote.NullText = ""; columnStyle_LastQuote.Width = 80; dataGrid1TableStyle.GridColumnStyles.Add(columnStyle_tiTicker); dataGrid1TableStyle.GridColumnStyles.Add(columnStyle_tiCompanyName); dataGrid1TableStyle.GridColumnStyles.Add(columnStyle_FirstQuote); dataGrid1TableStyle.GridColumnStyles.Add(columnStyle_LastQuote); this.dataGrid1.TableStyles.Add(dataGrid1TableStyle); } #endregion private void buttonFindTickers_Click(object sender, System.EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if(this.radioButtonAnyTicker.Checked) //all tickers with or without quotes { this.tableTickers = Tickers.GetTableOfFilteredTickers(this.textBoxStringToFind.Text, this.textBoxStringToFindInName.Text); } else //all tickers with first date quote and last date quote within a specified interval { this.tableTickers = Tickers.GetTableOfFilteredTickers(this.textBoxStringToFind.Text, this.textBoxStringToFindInName.Text, this.comboBoxFirstOperator.Text, this.dateTimePickerFirstDate.Value, this.comboBoxSecondOperator.Text, this.dateTimePickerLastDate.Value); } // these two lines in order to avoid "strange" exceptions ... this.dataGrid1.DataSource = null; this.dataGrid1.DataSource = this.tableTickers; // this.dataGrid1.Refresh(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; } } // implementation of ITickerSelector interface public TickerDataTable GetTableOfSelectedTickers() { DataTable dataTableOfDataGrid1 = (DataTable)this.dataGrid1.DataSource; TickerDataTable tableOfSelectedTickers = new TickerDataTable(); int indexOfRow = 0; while(indexOfRow != dataTableOfDataGrid1.Rows.Count) { if(this.dataGrid1.IsSelected(indexOfRow)) { DataRow dataRow = tableOfSelectedTickers.NewRow(); dataRow[0] = (string)dataTableOfDataGrid1.Rows[indexOfRow][0]; dataRow[1] = (string)dataTableOfDataGrid1.Rows[indexOfRow][1]; tableOfSelectedTickers.Rows.Add(dataRow); } indexOfRow++; } return tableOfSelectedTickers; } public void SelectAllTickers() { DataTable dataTableOfDataGrid1 = (DataTable)this.dataGrid1.DataSource; int indexOfRow = 0; while(indexOfRow != dataTableOfDataGrid1.Rows.Count) { this.dataGrid1.Select(indexOfRow); indexOfRow++; } } private void radioButtonDateQuoteFilter_CheckedChanged(object sender, System.EventArgs e) { if(this.radioButtonDateQuoteFilter.Checked == true) { this.dateTimePickerFirstDate.Enabled = true; this.dateTimePickerLastDate.Enabled = true; this.comboBoxFirstOperator.Enabled = true; this.comboBoxSecondOperator.Enabled = true; } else { this.dateTimePickerFirstDate.Enabled = false; this.dateTimePickerLastDate.Enabled = false; this.comboBoxFirstOperator.Enabled = false; this.comboBoxSecondOperator.Enabled = false; } } } } --- NEW FILE: GroupEditor.cs --- /* QuantDownloader - Quantitative Finance Library TickerGroupsViewer.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using QuantProject.Applications.Downloader.TickerSelectors; namespace QuantProject.Applications.Downloader { /// <summary> /// It has to be used for editing group names and ID in the /// TickerGroupsViewer passed as the actual parameter in the constructor /// </summary> public class GroupEditor : System.Windows.Forms.Form { private System.Windows.Forms.Label labelGroupID; private System.Windows.Forms.Label labelGroupDescription; private System.Windows.Forms.TextBox textBoxGroupDescription; private System.Windows.Forms.TextBox textBoxGroupID; private TickerGroupsViewer tickerGroupsViewer; private TreeNode selectedNodeInTickerGroupsViewer; private System.Windows.Forms.Button buttonAdd; private System.Windows.Forms.Button buttonModify; /// <summary> /// components /// </summary> private System.ComponentModel.Container components = null; public GroupEditor(TickerGroupsViewer tickerGroupsViewer) { InitializeComponent(); // this.tickerGroupsViewer = tickerGroupsViewer; this.Text = "Add new group inside: " + this.tickerGroupsViewer.SelectedGroupDescription; this.buttonModify.Visible = false; // } public GroupEditor(TickerGroupsViewer tickerGroupsViewer, TreeNode nodeToBeModified) { InitializeComponent(); // this.tickerGroupsViewer = tickerGroupsViewer; this.selectedNodeInTickerGroupsViewer = nodeToBeModified; this.Text = "Modify group"; this.textBoxGroupDescription.Text = nodeToBeModified.Text; this.textBoxGroupID.Text = (string)nodeToBeModified.Tag; this.buttonAdd.Visible = false; this.buttonModify.Location = new System.Drawing.Point(144,112); // } /// <summary> /// Clean up resources being used /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Metodo necessario per il supporto della finestra di progettazione. Non modificare /// il contenuto del metodo con l'editor di codice. /// </summary> private void InitializeComponent() { this.buttonAdd = new System.Windows.Forms.Button(); this.textBoxGroupID = new System.Windows.Forms.TextBox(); this.labelGroupID = new System.Windows.Forms.Label(); this.labelGroupDescription = new System.Windows.Forms.Label(); this.textBoxGroupDescription = new System.Windows.Forms.TextBox(); this.buttonModify = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonAdd // this.buttonAdd.Location = new System.Drawing.Point(144, 112); this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.TabIndex = 0; this.buttonAdd.Text = "&ADD"; this.buttonAdd.Click += new System.EventHandler(this.buttonOK_Click); // // textBoxGroupID // this.textBoxGroupID.Location = new System.Drawing.Point(144, 24); this.textBoxGroupID.Name = "textBoxGroupID"; this.textBoxGroupID.Size = new System.Drawing.Size(112, 20); this.textBoxGroupID.TabIndex = 1; this.textBoxGroupID.Text = "GroupID"; // // labelGroupID // this.labelGroupID.Location = new System.Drawing.Point(8, 24); this.labelGroupID.Name = "labelGroupID"; this.labelGroupID.Size = new System.Drawing.Size(128, 23); this.labelGroupID.TabIndex = 2; this.labelGroupID.Text = "Group ID (max 8 chr)"; // // labelGroupDescription // this.labelGroupDescription.Location = new System.Drawing.Point(8, 64); this.labelGroupDescription.Name = "labelGroupDescription"; this.labelGroupDescription.TabIndex = 4; this.labelGroupDescription.Text = "Group Description"; // // textBoxGroupDescription // this.textBoxGroupDescription.Location = new System.Drawing.Point(144, 64); this.textBoxGroupDescription.Name = "textBoxGroupDescription"; this.textBoxGroupDescription.Size = new System.Drawing.Size(252, 20); this.textBoxGroupDescription.TabIndex = 3; this.textBoxGroupDescription.Text = "Group Description"; // // buttonModify // this.buttonModify.Location = new System.Drawing.Point(232, 112); this.buttonModify.Name = "buttonModify"; this.buttonModify.TabIndex = 5; this.buttonModify.Text = "&MODIFY"; this.buttonModify.Click += new System.EventHandler(this.buttonModify_Click); // // GroupEditor // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(418, 152); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.buttonModify, this.labelGroupDescription, this.textBoxGroupDescription, this.labelGroupID, this.textBoxGroupID, this.buttonAdd}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "GroupEditor"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Group Editor"; this.ResumeLayout(false); } #endregion private bool FormIsNotComplete() { if(this.textBoxGroupID.Text == "" || this.textBoxGroupDescription.Text == "") { MessageBox.Show("Type both Group ID and Group Description!", "Updating or Adding group not possible", MessageBoxButtons.OK, MessageBoxIcon.Error); return true; } else { return false; } } private void buttonOK_Click(object sender, System.EventArgs e) { if(this.FormIsNotComplete()) return; if(this.tickerGroupsViewer.SelectedGroupID == "") // it is a group to be added under the root node { this.tickerGroupsViewer.AddNewGroupToDataBase(this.textBoxGroupID.Text, this.textBoxGroupDescription.Text); } else //// it is a group to be added under the selected group { this.tickerGroupsViewer.AddNewGroupToDataBase(this.textBoxGroupID.Text, this.textBoxGroupDescription.Text, this.tickerGroupsViewer.SelectedGroupID); } this.Close(); } private void buttonModify_Click(object sender, System.EventArgs e) { if(this.FormIsNotComplete()) return; this.tickerGroupsViewer.ModifyGroup((string)this.selectedNodeInTickerGroupsViewer.Tag, this.textBoxGroupDescription.Text, this.textBoxGroupID.Text); this.Close(); } } } --- NEW FILE: ITickerSelector.cs --- /* QuantDownloader - Quantitative Finance Library ITickerSelector.cs Copyright (C) 2003 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it wi... [truncated message content] |