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;
            }
        }
Beispiel #4
0
        public void LoadData(Options[] options)
        {
            common.myKeyValueExt item;
            this.Items.Clear();
            if (InList(options, Options.All))
            {
                item = new common.myKeyValueExt(Settings.sysString_All_Description, Settings.sysString_All_Code);
                item.Attribute1 = ((byte)Options.All).ToString();
                this.Items.Add(item);
            }

            //stockExchange
            if (InList(options, Options.StockExchange))
            {
                databases.baseDS.stockExchangeDataTable stockExchangeTbl = DataAccess.Libs.myStockExchangeTbl;
                for (int idx = 0; idx < stockExchangeTbl.Count; idx++)
                {
                    item = new common.myKeyValueExt(stockExchangeTbl[idx].code, stockExchangeTbl[idx].code);
                    item.Attribute1 = ((byte)Options.StockExchange).ToString();
                    this.Items.Add(item);
                }
            }
            //System Watch List
            databases.baseDS.portfolioDataTable portfolioTbl;
            if (InList(options, Options.SysWatchList))
            {
                portfolioTbl = DataAccess.Libs.GetSystemWatchList();
                if (portfolioTbl.Count > 0)
                {
                    item = new common.myKeyValueExt("--" + Languages.Libs.GetString("system") + "--", "");
                    item.Attribute1 = ((byte)Options.SysWatchList).ToString();
                    this.Items.Add(item);
                }
                for (int idx = 0; idx < portfolioTbl.Count; idx++)
                {
                    item = new common.myKeyValueExt(portfolioTbl[idx].name, portfolioTbl[idx].code);
                    item.Attribute1 = ((byte)Options.SysWatchList).ToString();
                    this.Items.Add(item);
                }
            }
            //User watch list
            if (InList(options, Options.WatchList))
            {
                portfolioTbl = DataAccess.Libs.GetPortfolio_ByInvestorAndType(commonClass.SysLibs.sysLoginCode, AppTypes.PortfolioTypes.WatchList);
                if (portfolioTbl.Count > 0)
                {
                    item = new common.myKeyValueExt("--" + Languages.Libs.GetString("watchList") + "--","");
                    item.Attribute1 = ((byte)Options.WatchList).ToString();
                    this.Items.Add(item);
                }
                for (int idx = 0; idx < portfolioTbl.Count; idx++)
                {
                    item = new common.myKeyValueExt(portfolioTbl[idx].name, portfolioTbl[idx].code);
                    item.Attribute1 = ((byte)Options.WatchList).ToString();
                    this.Items.Add(item);
                }
            }
            //User Portfolio
            if (InList(options, Options.UserPorfolio))
            {
                portfolioTbl = DataAccess.Libs.GetPortfolio_ByInvestorAndType(commonClass.SysLibs.sysLoginCode, AppTypes.PortfolioTypes.Portfolio);
                if (portfolioTbl.Count > 0)
                {
                    item = new common.myKeyValueExt("--" + Languages.Libs.GetString("portfolio") + "--", "");
                    item.Attribute1 = ((byte)Options.UserPorfolio).ToString();
                    this.Items.Add(item);
                }
                for (int idx = 0; idx < portfolioTbl.Count; idx++)
                {
                    item = new common.myKeyValueExt(portfolioTbl[idx].name, portfolioTbl[idx].code);
                    item.Attribute1 = ((byte)Options.UserPorfolio).ToString();
                    this.Items.Add(item);
                }
            }

            if (InList(options, Options.Sectors))
            {
                item = new common.myKeyValueExt("--" + Languages.Libs.GetString("bySectors") + "--", "");
                item.Attribute1 = ((byte)Options.Sectors).ToString();
                this.Items.Add(item);
            }

            if (this.Items.Count > 0)
            {
                this.MaxDropDownItems = this.Items.Count;
                this.SelectedIndex = 0;
            }
            lastOptions = options;
        }