private void DoRefreshPrice(data.tmpDS.stockCodeDataTable dataTbl) { //Open price is the same all day. if (openPriceTbl == null || openPriceDate != DateTime.Today) { openPriceTbl = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Open); openPriceDate = DateTime.Today; } data.baseDS.lastPriceDataDataTable priceTbl = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Close); if (priceTbl == null) { return; } data.tmpDS.stockCodeRow stockCodeRow; data.baseDS.lastPriceDataRow openPriceRow, closePriceRow; dataTbl.priceColumn.ReadOnly = false; dataTbl.priceVariantColumn.ReadOnly = false; for (int idx = 0; idx < stockGV.RowCount; idx++) { stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (stockCodeRow == null) { continue; } closePriceRow = priceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (stockCodeRow.price != closePriceRow.value) { stockCodeRow.price = closePriceRow.value; openPriceRow = openPriceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (openPriceRow != null) { stockCodeRow.priceVariant = closePriceRow.value - openPriceRow.value; } else { stockCodeRow.priceVariant = 0; } } } }
public data.baseDS.lastPriceDataDataTable GetLastPrice(commonClass.PriceDataType type) { string cacheName = "lastPrice-" + type.ToString(); data.baseDS.lastPriceDataDataTable dataTbl = null; object obj = sysDataCache.Find(cacheName); if (obj == null) { dataTbl = DbAccess.GetLastPrice(type); sysDataCache.Add(cacheName, new DataCacheItem(dataTbl)); return(dataTbl); } if ((obj as DataCacheItem).timeStamp + TimeSpan.FromSeconds(commonClass.Settings.sysDataDelayTimeInSecs).Ticks > DateTime.Now.Ticks) { return((data.baseDS.lastPriceDataDataTable)(obj as DataCacheItem).data); } dataTbl = DbAccess.GetLastPrice(type); sysDataCache.Add(cacheName, new DataCacheItem(dataTbl)); return(dataTbl); }
private void DoRefreshPrice(data.tmpDS.stockCodeDataTable dataTbl) { //Open price is the same all day. if (openPriceTbl == null || openPriceDate != DateTime.Today) { openPriceTbl = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Open); openPriceDate = DateTime.Today; } data.baseDS.lastPriceDataDataTable priceTbl = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Close); if (priceTbl == null) return; data.tmpDS.stockCodeRow stockCodeRow; data.baseDS.lastPriceDataRow openPriceRow, closePriceRow; dataTbl.priceColumn.ReadOnly = false; dataTbl.priceVariantColumn.ReadOnly = false; for (int idx = 0; idx < stockGV.RowCount; idx++) { stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString() ); if (stockCodeRow == null) continue; closePriceRow = priceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (stockCodeRow.price != closePriceRow.value) { stockCodeRow.price = closePriceRow.value; openPriceRow = openPriceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (openPriceRow!=null) stockCodeRow.priceVariant = closePriceRow.value - openPriceRow.value; else stockCodeRow.priceVariant = 0; } } }