private void LoadProducts(string dataSource) { List <AbstractExchange> cExchanges = ProductManager.Manager.Exchanges; int iCount = cExchanges.Count; if (iCount > 0) { for (int i = 0; i < iCount; i++) { AbstractExchange cExchange = cExchanges[i]; int iIndex = 0; string sExchangeName = cExchange.ShortName; ESymbolCategory[] cCategorys = Enum.GetValues(typeof(ESymbolCategory)) as ESymbolCategory[]; foreach (ESymbolCategory cCategory in cCategorys) { List <string> cSymbols = cExchange.GetProductClassify(cCategory); if (cSymbols != null && cSymbols.Count > 0) { ++iIndex; tabControl_Products.TabPages.Add(cCategory.ToString()); if (iIndex == __cSources.Count) { SimpleBoundList <_ProductInfo> cList = new SimpleBoundList <_ProductInfo>(cSymbols.Count); cList.AllowSort = true; cList.SetComparers(__cComparison); __cSources.Add(cList); } foreach (string sSymbolId in cSymbols) { AbstractProductProperty cProperty = cExchange.GetProperty(sSymbolId, dataSource); if (cProperty != null) { _ProductInfo cProductInfo = new _ProductInfo() { ProductId = sSymbolId, Description = cProperty.Description, ExchangeName = sExchangeName }; __cSources[0].Add(cProductInfo); __cSources[iIndex].Add(cProductInfo); } } } } } } }
private static _ProductInfo CreateProductInfo(string exchangeName, string dataSource, Product product, AbstractProductProperty property) { _ProductInfo cProductInfo = new _ProductInfo() { CommodityId = (property == null) ? string.Empty : property.CommodityId, Description = (property == null) ? string.Empty : property.Description, DataSource = (dataSource == null) ? string.Empty : dataSource, ExchangeName = exchangeName, ProductId = product.SymbolId, ProductName = product.SymbolName }; return(cProductInfo); }
private void dataGrid_DoubleClick(object sender, EventArgs e) { object[] cRows = this.dataGrid.SelectedDataRows; if (cRows != null && cRows.Length > 0) { _ProductInfo cProductInfo = this.dataGrid.SelectedDataRows[0] as _ProductInfo; string sSymbolId = cProductInfo.ProductId; if (!__cAddSymbolIds.ContainsKey(sSymbolId)) { comboProduct.Items.Insert(0, sSymbolId); comboProduct.SelectedIndex = 0; __cAddSymbolIds.Add(cProductInfo.ProductId, cProductInfo.ExchangeName); } } }
private void RefreshSymbolCategorys(string exchangeName, ESymbolCategory category) { AbstractExchange cExchange = ProductManager.Manager.GetExchange(exchangeName); List <string> cSymbols = cExchange.GetProductClassify(category); __cAllData.Clear(); __cBasicData.Clear(); __cCustomData.Clear(); int iCount = cSymbols.Count; int iSourceCount = __cDataSources.Count; for (int i = 0; i < iCount; i++) { string sSymbol = cSymbols[i]; Product cProduct = cExchange.GetProduct(sSymbol); AbstractProductProperty cBaseProperty = cExchange.GetProperty(sSymbol); _ProductInfo cBasicInfo = CreateProductInfo(exchangeName, null, cProduct, cBaseProperty); __cAllData.Add(cBasicInfo); if (cBaseProperty != null) { __cBasicData.Add(cBasicInfo); for (int j = 0; j < iSourceCount; j++) { string sDataSource = __cDataSources[j]; AbstractProductProperty cProperty = cExchange.GetProperty(sSymbol, sDataSource); if (cProperty != cBaseProperty) { _ProductInfo cProductInfo = CreateProductInfo(exchangeName, sDataSource, cProduct, cProperty); __cAllData.Add(cProductInfo); __cCustomData.Add(cProductInfo); } } } } source.Refresh(); if (__cSortRangeRowEvent != null) { this.dataGrid.SortRangeRows(__cSortRangeRowEvent.Range, __cSortRangeRowEvent.KeyColumn, __cSortRangeRowEvent.Ascending, __cSortRangeRowEvent.CellComparer); } }
private void toolItem_Modify_Click(object sender, EventArgs e) { ToolStripButton cButton = sender as ToolStripButton; int iIndex = int.Parse(cButton.Tag as string); string sExchange = null; string sDataSource = null; Product cProduct = null; AbstractProductProperty cProperty = null; switch (iIndex) { case 1: //新增 frmCreateProduct frmCreateProduct = new frmCreateProduct(); DialogResult cResult = frmCreateProduct.ShowDialog(); if (cResult == DialogResult.OK) { sDataSource = frmCreateProduct.DataSource; sExchange = frmCreateProduct.ExchangeName; cProduct = frmCreateProduct.Product; cProperty = frmCreateProduct.Property; ESymbolCategory cCategory = cProduct.Category; RefreshCategoryNode(sExchange, cCategory); //更新樹狀結構 RefreshSymbolCategorys(sExchange, cCategory); //更新表格 } break; case 2: //修改 case 3: //刪除 if (dataGrid.SelectedDataRows.Length > 0) { object oData = dataGrid.SelectedDataRows[0]; if (oData != null) { _ProductInfo cProductInfo = oData as _ProductInfo; string sSymbolId = cProductInfo.ProductId; sExchange = cProductInfo.ExchangeName; sDataSource = cProductInfo.DataSource; sDataSource = (sDataSource.Length == 0) ? null : sDataSource; AbstractExchange cExchange = ProductManager.Manager.GetExchange(sExchange); cProduct = cExchange.GetProduct(sSymbolId); if (iIndex == 2) //修改動作 { cProperty = cExchange.GetProperty(sSymbolId, sDataSource); } else //刪除動作 { bool bDeleteProperty = sDataSource != null; if (!bDeleteProperty) { DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_001, __sMessageHeader_001, MessageBoxButtons.YesNo, MessageBoxIcon.Question); bDeleteProperty |= cDeleteResult == DialogResult.Yes; } if (bDeleteProperty) { DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_002, __sMessageHeader_002, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (cDeleteResult == DialogResult.Yes) { cExchange.RemoveProperty(sSymbolId, sDataSource); //要先移除屬性設定(因為屬性會從 Product 結構取得商品資訊, 所以要先移除屬性設定) } if (sDataSource == null) //如果資料報價來源是 null 才可以移除商品(如果為 null 會詢問使用者是否要刪除) { cExchange.RemoveProduct(sSymbolId); } ESymbolCategory cCategory = cProduct.Category; RefreshCategoryNode(sExchange, cCategory); //更新樹狀結構 RefreshSymbolCategorys(sExchange, cCategory); //更新表格 } return; } } } break; } if (cProduct != null && cProperty != null) { frmProductPropertySettings frmProductPropertySettings = new frmProductPropertySettings(); frmProductPropertySettings.SetParameters(sExchange, sDataSource, cProduct, cProperty.Clone()); DialogResult cResult = frmProductPropertySettings.ShowDialog(); if (cResult == DialogResult.OK) { string sExchangeName = __cSelectedNode.Parent.Text; ESymbolCategory cCategory = (ESymbolCategory)__cSelectedNode.Tag; RefreshSymbolCategorys(sExchangeName, cCategory); //更新表格 } } }