示例#1
0
 public static databases.tmpDS.stockCodeRow FindAndCache(databases.tmpDS.stockCodeDataTable tbl, string code)
 {
     databases.tmpDS.stockCodeRow row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     databases.tmpDSTableAdapters.stockCodeTA dataTA = new databases.tmpDSTableAdapters.stockCodeTA();
     dataTA.ClearBeforeFill = false;
     dataTA.FillByCode(tbl, code);
     row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     return(null);
 }
        private void DoRefreshPrice(databases.tmpDS.stockCodeDataTable dataTbl)
        {
            databases.baseDS.lastPriceDataDataTable openPriceTbl  = DataAccess.Libs.myLastDailyOpenPrice;
            databases.baseDS.lastPriceDataDataTable closePriceTbl = DataAccess.Libs.myLastDailyClosePrice;
            //databases.baseDS.lastPriceDataDataTable volumeTbl = DataAccess.Libs.myLastDailyVolume;

            if (openPriceTbl == null || closePriceTbl == null)
            {
                return;
            }

            dataTbl.priceColumn.ReadOnly        = false;
            dataTbl.priceVariantColumn.ReadOnly = false;

            databases.tmpDS.stockCodeRow      stockCodeRow;
            databases.baseDS.lastPriceDataRow openPriceRow, closePriceRow;
            //databases.baseDS.lastPriceDataRow volumeRow;
            for (int idx = 0; idx < stockGV.RowCount; idx++)
            {
                //Lay stock code
                stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString());
                if (stockCodeRow == null)
                {
                    continue;
                }

                //Lay gia dong cua
                closePriceRow = closePriceTbl.FindBystockCode(stockCodeRow.code);
                if (closePriceRow == null)
                {
                    continue;
                }

                if (stockCodeRow.price == closePriceRow.value)
                {
                    continue;
                }

                //Lay chenh lech Open/Close
                stockCodeRow.price = closePriceRow.value;
                openPriceRow       = openPriceTbl.FindBystockCode(stockCodeRow.code);
                if (openPriceRow != null && openPriceRow.value != 0)
                {
                    stockCodeRow.priceVariant = (closePriceRow.value - openPriceRow.value) / openPriceRow.value;
                }
                else
                {
                    stockCodeRow.priceVariant = 0;
                }

                //Lay volume
                //volumeRow = volumeTbl.FindBystockCode(stockCodeRow.code);
                //if (volumeRow == null) continue;
                //if (stockCodeRow.volume == volumeRow.value) continue;
                //stockCodeRow.volume = volumeRow.value;
            }
            SetColor();
        }
        private void DoRefreshPrice(databases.tmpDS.stockCodeDataTable dataTbl)
        {
            databases.baseDS.lastPriceDataDataTable openPriceTbl  = DataAccess.Libs.myLastDailyOpenPrice;
            databases.baseDS.lastPriceDataDataTable closePriceTbl = DataAccess.Libs.myLastDailyClosePrice;
            if (openPriceTbl == null || closePriceTbl == null)
            {
                return;
            }

            dataTbl.priceColumn.ReadOnly        = false;
            dataTbl.priceVariantColumn.ReadOnly = false;

            databases.tmpDS.stockCodeRow      stockCodeRow;
            databases.baseDS.lastPriceDataRow openPriceRow, closePriceRow;
            for (int idx = 0; idx < stockGV.RowCount; idx++)
            {
                stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString());
                if (stockCodeRow == null)
                {
                    continue;
                }
                closePriceRow = closePriceTbl.FindBystockCode(stockCodeRow.code);
                if (closePriceRow == null)
                {
                    continue;
                }

                if (stockCodeRow.price == closePriceRow.value)
                {
                    continue;
                }
                stockCodeRow.price = closePriceRow.value;
                openPriceRow       = openPriceTbl.FindBystockCode(stockCodeRow.code);
                if (openPriceRow != null)
                {
                    stockCodeRow.priceVariant = closePriceRow.value - openPriceRow.value;
                }
                else
                {
                    stockCodeRow.priceVariant = 0;
                }
            }
            SetColor();
        }
        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;
            }
        }