private void DoFilter() { common.myKeyValueExt item = (common.myKeyValueExt)codeGroupCb.SelectedItem; cbStockSelection.Options watchListType = (cbStockSelection.Options) byte.Parse(item.Attribute1); StringCollection stocCodeList = new StringCollection(); switch (watchListType) { case cbStockSelection.Options.All: stockSource.Filter = ""; break; case cbStockSelection.Options.StockExchange: stockSource.Filter = this.myStockTbl.stockExchangeColumn.ColumnName + "='" + item.Value + "'"; break; case cbStockSelection.Options.SysWatchList: case cbStockSelection.Options.WatchList: string cacheKey = watchListType.ToString();; StringCollection watchList = new StringCollection(); //All stock codes of specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; watchList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } watchList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); StringCollection selectStockList = null; object obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { selectStockList = (obj as StringCollection); } else { selectStockList = common.system.List2Collection(DataAccess.Libs.GetStockList_ByWatchList(watchList)); DataAccess.Libs.AddCache(cacheKey, selectStockList); } myStockTbl.Columns[myStockTbl.selectedColumn.ColumnName].ReadOnly = false; for (int idx = 0; idx < this.myStockTbl.Count; idx++) { this.myStockTbl[idx].selected = (selectStockList.Contains(this.myStockTbl[idx].code)?1:0); } stockSource.Filter = this.myStockTbl.selectedColumn + "=1"; break; } }
private void DoFilter(bool notUseCache) { string cacheKey; common.myKeyValueExt item = (common.myKeyValueExt)common.Threading.GetValue(codeGroupCb, "SelectedItem"); cbStockSelection.Options watchListType = (cbStockSelection.Options) byte.Parse(item.Attribute1); StringCollection stocCodeList = new StringCollection(); myStockTbl.Columns[myStockTbl.selectedColumn.ColumnName].ReadOnly = false; switch (watchListType) { case cbStockSelection.Options.All: stockSource.Filter = ""; break; case cbStockSelection.Options.StockExchange: stockSource.Filter = this.myStockTbl.stockExchangeColumn.ColumnName + "='" + item.Value + "'"; break; case cbStockSelection.Options.SysWatchList: case cbStockSelection.Options.WatchList: cacheKey = watchListType.ToString();; StringCollection watchList = new StringCollection(); //All stock codes of specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; watchList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } watchList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); if (notUseCache) { DataAccess.Libs.ClearCache(cacheKey); } StringCollection selectStockList = null; object obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { selectStockList = (obj as StringCollection); } else { selectStockList = common.system.List2Collection(DataAccess.Libs.GetStockList_ByWatchList(watchList)); DataAccess.Libs.AddCache(cacheKey, selectStockList); } for (int idx = 0; idx < this.myStockTbl.Count; idx++) { this.myStockTbl[idx].selected = (selectStockList.Contains(this.myStockTbl[idx].code)?1:0); } stockSource.Filter = this.myStockTbl.selectedColumn + "=1"; break; case cbStockSelection.Options.UserPorfolio: cacheKey = watchListType.ToString();; StringCollection porfolioList = new StringCollection(); //All stock codes of the specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; porfolioList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } porfolioList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); if (notUseCache) { DataAccess.Libs.ClearCache(cacheKey); } databases.tmpDS.stockCodeDataTable codeTbl = null; obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { codeTbl = (obj as databases.tmpDS.stockCodeDataTable); } else { codeTbl = DataAccess.Libs.GetStock_InPortfolio(porfolioList); DataAccess.Libs.AddCache(cacheKey, codeTbl); } for (int idx = 0; idx < this.myStockTbl.Count; idx++) { this.myStockTbl[idx].selected = (codeTbl.FindBycode(this.myStockTbl[idx].code) != null ? 1 : 0); } stockSource.Filter = this.myStockTbl.selectedColumn + "=1"; break; } }
/// <summary> /// Load Stock List depends on cbStockSelection.Options /// </summary> public override void LoadStockList() { DataView stockCodeView = null; common.myKeyValueExt item = (common.myKeyValueExt)codeGroupCb.SelectedItem; cbStockSelection.Options watchListType = (cbStockSelection.Options) byte.Parse(item.Attribute1); StringCollection stockCodeList = new StringCollection(); string cacheKey = watchListType.ToString(); object obj; switch (watchListType) { case cbStockSelection.Options.All: stockCodeClb.myDataTbl = this.myStockCodeTbl; break; case cbStockSelection.Options.StockExchange: cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey + "-" + item.Value); obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { stockCodeList = (obj as StringCollection); } else { stockCodeView = new DataView(myStockCodeTbl); stockCodeView.Sort = myStockCodeTbl.codeColumn.ColumnName; stockCodeView.RowFilter = myStockCodeTbl.stockExchangeColumn.ColumnName + "='" + item.Value + "'"; string codeColumnName = myStockCodeTbl.codeColumn.ColumnName; for (int idx = 0; idx < stockCodeView.Count; idx++) { stockCodeList.Add(stockCodeView[idx][codeColumnName].ToString()); } } stockCodeClb.myItemValues = stockCodeList; break; case cbStockSelection.Options.SysWatchList: case cbStockSelection.Options.WatchList: StringCollection watchList = new StringCollection(); //All stock codes of specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; watchList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } watchList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { stockCodeList = (obj as StringCollection); } else { stockCodeList = common.system.List2Collection(DataAccess.Libs.GetStockList_ByWatchList(watchList)); DataAccess.Libs.AddCache(cacheKey, stockCodeList); } stockCodeClb.myItemValues = stockCodeList; break; case cbStockSelection.Options.Sectors: base.LoadStockList(); break; } }