[Quantproject-developers] QuantDownloader/Downloader GroupEditor.cs,1.1,1.2 TickerGroupsViewer.cs,1.
Brought to you by:
glauco_1
|
From: <mi...@us...> - 2004-02-09 17:24:21
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22862/Downloader Modified Files: GroupEditor.cs TickerGroupsViewer.cs Log Message: TickerGroupsViewer is now usable (it will be completed soon). It is now possible to do these operations: - adding, renaming, removing groups from the treeView (the structure); - selecting tickers from the listView (the content of the selected node in the structure view) and performing, on those tickers, validation or download from the web. Index: GroupEditor.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/GroupEditor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GroupEditor.cs 4 Feb 2004 19:27:10 -0000 1.1 --- GroupEditor.cs 9 Feb 2004 17:21:06 -0000 1.2 *************** *** 1,2 **** --- 1,24 ---- + /* + 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; *************** *** 33,37 **** // this.tickerGroupsViewer = tickerGroupsViewer; ! this.Text = "Add new group"; this.buttonModify.Visible = false; // --- 55,60 ---- // this.tickerGroupsViewer = tickerGroupsViewer; ! this.Text = "Add new group inside: " + ! this.tickerGroupsViewer.SelectedGroupDescription; this.buttonModify.Visible = false; // *************** *** 98,102 **** this.textBoxGroupID.Size = new System.Drawing.Size(112, 20); this.textBoxGroupID.TabIndex = 1; ! this.textBoxGroupID.Text = "textBoxGroupID"; // // labelGroupID --- 121,125 ---- this.textBoxGroupID.Size = new System.Drawing.Size(112, 20); this.textBoxGroupID.TabIndex = 1; ! this.textBoxGroupID.Text = "GroupID"; // // labelGroupID *************** *** 121,125 **** this.textBoxGroupDescription.Size = new System.Drawing.Size(252, 20); this.textBoxGroupDescription.TabIndex = 3; ! this.textBoxGroupDescription.Text = "textBoxGroupID"; // // buttonModify --- 144,148 ---- this.textBoxGroupDescription.Size = new System.Drawing.Size(252, 20); this.textBoxGroupDescription.TabIndex = 3; ! this.textBoxGroupDescription.Text = "Group Description"; // // buttonModify *************** *** 151,162 **** #endregion ! private void buttonOK_Click(object sender, System.EventArgs e) { ! if(this.textBoxGroupID == null || ! this.textBoxGroupDescription == null) { ! MessageBox.Show("Type Group ID and Group Description!"); ! return; } if(this.tickerGroupsViewer.SelectedGroupID == "") // it is a group to be added under the root node --- 174,198 ---- #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 *************** *** 178,187 **** private void buttonModify_Click(object sender, System.EventArgs e) { ! if(this.textBoxGroupID == null || ! this.textBoxGroupDescription == null) ! { ! MessageBox.Show("Type Group ID and Group Description!"); return; - } this.tickerGroupsViewer.ModifyGroup((string)this.selectedNodeInTickerGroupsViewer.Tag, --- 214,219 ---- private void buttonModify_Click(object sender, System.EventArgs e) { ! if(this.FormIsNotComplete()) return; this.tickerGroupsViewer.ModifyGroup((string)this.selectedNodeInTickerGroupsViewer.Tag, Index: TickerGroupsViewer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerGroupsViewer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TickerGroupsViewer.cs 4 Feb 2004 19:27:10 -0000 1.1 --- TickerGroupsViewer.cs 9 Feb 2004 17:21:06 -0000 1.2 *************** *** 52,61 **** private System.Windows.Forms.MenuItem menuItemOpenTickerSelector; private string selectedGroupID; ! ! /// <summary> ! /// Components ! /// </summary> ! private System.ComponentModel.Container components = null; ! public TickerGroupsViewer() { --- 52,66 ---- private System.Windows.Forms.MenuItem menuItemOpenTickerSelector; private string selectedGroupID; ! private string selectedGroupDescription; ! private System.Windows.Forms.ImageList imageListGroupsAndTickers; ! private System.ComponentModel.IContainer components; ! private const int GROUP_IMAGE = 0; ! private System.Windows.Forms.MenuItem menuItemPasteSelectedTickers; ! private System.Windows.Forms.MenuItem menuItem1; ! 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() { *************** *** 64,68 **** // ! // TODO: // } --- 69,81 ---- // ! 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); // } *************** *** 83,87 **** } /// <summary> ! /// It gets the groupID of the selected node in the treeView control of the class /// </summary> public string SelectedGroupID --- 96,100 ---- } /// <summary> ! /// It gets the groupID of the selected node in the treeView control of the object /// </summary> public string SelectedGroupID *************** *** 92,96 **** --- 105,174 ---- } } + /// <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(); + } + } + + + internal DataTable GetTableOfSelectedTickers() + { + DataTable tableOfSelectedTickers = new DataTable(); + tableOfSelectedTickers.Columns.Add("tickerID"); + tableOfSelectedTickers.Columns["tickerID"].Unique = true; + tableOfSelectedTickers.Columns.Add("tickerCompanyName"); + 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 represents a group of tickers + { + MessageBox.Show("NOT IMPLEMENTED YET"); + } + + } + return tableOfSelectedTickers; + } #region Windows Form Designer generated code *************** *** 100,103 **** --- 178,183 ---- 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(); *************** *** 105,108 **** --- 185,189 ---- 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(); *************** *** 111,114 **** --- 192,197 ---- this.menuItemDownloadQuotesOfCurrentGroup = new System.Windows.Forms.MenuItem(); this.menuItemOpenTickerSelector = new System.Windows.Forms.MenuItem(); + this.menuItemPasteSelectedTickers = new System.Windows.Forms.MenuItem(); + this.menuItem1 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // *************** *** 117,125 **** this.treeViewGroups.ContextMenu = this.contextMenuTickerGroupsTreeView; this.treeViewGroups.Dock = System.Windows.Forms.DockStyle.Left; ! this.treeViewGroups.ImageIndex = -1; this.treeViewGroups.Name = "treeViewGroups"; - this.treeViewGroups.SelectedImageIndex = -1; this.treeViewGroups.Size = new System.Drawing.Size(120, 326); this.treeViewGroups.TabIndex = 0; this.treeViewGroups.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewGroups_AfterSelect); // --- 200,208 ---- 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); // *************** *** 149,152 **** --- 232,242 ---- 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 // *************** *** 160,168 **** // listViewGroupsAndTickers // 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(301, 326); this.listViewGroupsAndTickers.TabIndex = 2; // // contextMenuTickerGroupsListView --- 250,263 ---- // listViewGroupsAndTickers // + this.listViewGroupsAndTickers.Activation = System.Windows.Forms.ItemActivation.TwoClick; + this.listViewGroupsAndTickers.ContextMenu = this.contextMenuTickerGroupsListView; 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); // // contextMenuTickerGroupsListView *************** *** 171,175 **** this.menuItemValidateGroup, this.menuItemDownloadQuotesOfCurrentGroup, ! this.menuItemOpenTickerSelector}); // // menuItemValidateGroup --- 266,272 ---- this.menuItemValidateGroup, this.menuItemDownloadQuotesOfCurrentGroup, ! this.menuItemOpenTickerSelector, ! this.menuItemPasteSelectedTickers, ! this.menuItem1}); // // menuItemValidateGroup *************** *** 177,180 **** --- 274,278 ---- this.menuItemValidateGroup.Index = 0; this.menuItemValidateGroup.Text = "&Validate"; + this.menuItemValidateGroup.Click += new System.EventHandler(this.menuItemValidateGroup_Click); // // menuItemDownloadQuotesOfCurrentGroup *************** *** 182,185 **** --- 280,284 ---- this.menuItemDownloadQuotesOfCurrentGroup.Index = 1; this.menuItemDownloadQuotesOfCurrentGroup.Text = "&Download quotes"; + this.menuItemDownloadQuotesOfCurrentGroup.Click += new System.EventHandler(this.menuItemDownloadQuotesOfCurrentGroup_Click); // // menuItemOpenTickerSelector *************** *** 188,195 **** this.menuItemOpenTickerSelector.Text = "&Open Ticker Selector"; // // TickerGroupsViewer // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(424, 326); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listViewGroupsAndTickers, --- 287,305 ---- this.menuItemOpenTickerSelector.Text = "&Open Ticker Selector"; // + // menuItemPasteSelectedTickers + // + this.menuItemPasteSelectedTickers.Index = 3; + this.menuItemPasteSelectedTickers.Text = "&Paste Tickers"; + this.menuItemPasteSelectedTickers.Click += new System.EventHandler(this.menuItemPasteSelectedTickers_Click); + // + // menuItem1 + // + this.menuItem1.Index = 4; + this.menuItem1.Text = "&Remove selected Items"; + // // 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, *************** *** 253,257 **** { Cursor.Current = Cursors.WaitCursor; ! this.oleDbConnection.Open(); fillTreeViewAtRootLevel(); foreach(TreeNode node in this.treeViewGroups.Nodes[0].Nodes) --- 363,368 ---- { Cursor.Current = Cursors.WaitCursor; ! if(this.oleDbConnection.State != ConnectionState.Open) ! this.oleDbConnection.Open(); fillTreeViewAtRootLevel(); foreach(TreeNode node in this.treeViewGroups.Nodes[0].Nodes) *************** *** 275,310 **** #region Paint Child Nodes During selection ! private void treeViewGroups_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { ! this.selectedGroupID = (string)this.treeViewGroups.SelectedNode.Tag; ! // It updates the member used by the property SelectedGroupID ! if((string)this.treeViewGroups.SelectedNode.Tag != "" && ! this.treeViewGroups.SelectedNode.Nodes.Count == 0) ! // if the selected node is not the root node and it hasn't got child nodes ! // it has to be filled with its child nodes (if any) { ! try ! { ! Cursor.Current = Cursors.WaitCursor; this.oleDbConnection.Open(); ! foreach(TreeNode node in this.treeViewGroups.SelectedNode.Nodes) { ! addNodeChildsToCurrentNode(node); } } - catch(Exception ex) - { - MessageBox.Show(ex.ToString()); - } - finally - { - Cursor.Current = Cursors.Default; - this.oleDbConnection.Close(); - } } } #endregion #region Add group private void addNodeGroupToCurrentNode(string groupID, --- 386,491 ---- #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, *************** *** 315,318 **** --- 496,500 ---- node.Tag = groupID; this.treeViewGroups.SelectedNode.Nodes.Add(node); + this.updateListView(this.treeViewGroups.SelectedNode); } *************** *** 326,330 **** { Cursor.Current = Cursors.WaitCursor; ! this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription, tgTgId) " + --- 508,513 ---- { Cursor.Current = Cursors.WaitCursor; ! if(this.oleDbConnection.State != ConnectionState.Open) ! this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription, tgTgId) " + *************** *** 333,338 **** groupDescription + "','" + parentGroupID + "')", this.oleDbConnection); ! this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery(); ! this.addNodeGroupToCurrentNode(groupID, groupDescription); } catch(Exception ex) --- 516,523 ---- groupDescription + "','" + parentGroupID + "')", this.oleDbConnection); ! int numRowInserted = ! this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery(); ! if(numRowInserted > 0) ! this.addNodeGroupToCurrentNode(groupID, groupDescription); } catch(Exception ex) *************** *** 354,358 **** { Cursor.Current = Cursors.WaitCursor; ! this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription) " + --- 539,544 ---- { Cursor.Current = Cursors.WaitCursor; ! if(this.oleDbConnection.State != ConnectionState.Open) ! this.oleDbConnection.Open(); this.oleDbDataAdapter.InsertCommand = new OleDbCommand("INSERT INTO tickerGroups(tgId, tgDescription) " + *************** *** 393,402 **** this.oleDbConnection.Open(); this.oleDbDataAdapter.UpdateCommand = ! new OleDbCommand("UPDATE tickerGroups SET tgId =' " + ! newGroupID + "', tgDescription =' " + ! groupDescription + "' WHERE tgId =' " + oldGroupID + "'", this.oleDbConnection); ! this.oleDbDataAdapter.UpdateCommand.ExecuteNonQuery(); ! this.modifyCurrentNode(newGroupID, groupDescription); } catch(Exception ex) --- 579,590 ---- 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) *************** *** 430,434 **** } deleteCurrentGroup(this.treeViewGroups.SelectedNode); - this.treeViewGroups.SelectedNode.Remove(); } --- 618,621 ---- *************** *** 444,448 **** nodeCorrespondingToGroup.Tag + "'", this.oleDbConnection); ! this.oleDbDataAdapter.DeleteCommand.ExecuteNonQuery(); } catch(Exception ex) --- 631,638 ---- nodeCorrespondingToGroup.Tag + "'", this.oleDbConnection); ! int numDeletedRows = ! this.oleDbDataAdapter.DeleteCommand.ExecuteNonQuery(); ! if (numDeletedRows > 0) ! this.treeViewGroups.SelectedNode.Remove(); } catch(Exception ex) *************** *** 483,486 **** --- 673,804 ---- } + 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 menuItemPasteSelectedTickers_Click(object sender, System.EventArgs e) + { + try + { + //initialize table of tickers to be copied + IDataObject iDataObject = Clipboard.GetDataObject(); + DataTable tickers = (DataTable)iDataObject.GetData(DataFormats.Serializable); + // some checks are performed + if(tickers == null) + { + MessageBox.Show("No ticker has been copied to ClipBoard!\n\n" + + "Select some tickers before trying again!", + "Paste operation fail", 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 fail", 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(); + } + } + + 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; + } + } + + } + } + + private void menuItemDownloadQuotesOfCurrentGroup_Click(object sender, System.EventArgs e) + { + DataTable tableOfSelectedTickers = this.GetTableOfSelectedTickers(); + if(tableOfSelectedTickers.Rows.Count == 0) + { + MessageBox.Show("No ticker has been selected!\n\n" + + "Select some tickers or groups containing tickers!", "QuantDownloader error message", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + WebDownloader webDownloader = new WebDownloader(tableOfSelectedTickers); + webDownloader.Show(); + } + + private void menuItemValidateGroup_Click(object sender, System.EventArgs e) + { + DataTable tableOfSelectedTickers = this.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(this.GetTableOfSelectedTickers()); + validateForm.Show(); + } + + + |