protected void LoadPorfolioWatch(databases.tmpDS.porfolioWatchDataTable tbl, string investorCode) { databases.tmpDS.investorStockDataTable investorStockTbl = DataAccess.Libs.GetOwnedStockSum_ByInvestor(investorCode); if (investorStockTbl == null) { return; } databases.tmpDS.porfolioWatchRow porfolioWatchRow; for (int idx1 = 0; idx1 < investorStockTbl.Count; idx1++) { porfolioWatchRow = tbl.FindBycode(investorStockTbl[idx1].stockCode); if (porfolioWatchRow == null) { databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(investorStockTbl[idx1].stockCode); if (stockCodeRow == null) { continue; } porfolioWatchRow = tbl.NewporfolioWatchRow(); databases.AppLibs.InitData(porfolioWatchRow); porfolioWatchRow.code = investorStockTbl[idx1].stockCode; porfolioWatchRow.stockExchange = stockCodeRow.stockExchange; porfolioWatchRow.name = stockCodeRow.name; porfolioWatchRow.nameEn = stockCodeRow.nameEn; tbl.AddporfolioWatchRow(porfolioWatchRow); } //TUAN - 29 Sept 2012 remove for no flicker when refresh data else { databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(investorStockTbl[idx1].stockCode); if (stockCodeRow == null) { continue; } porfolioWatchRow = tbl.NewporfolioWatchRow(); databases.AppLibs.InitData(porfolioWatchRow); porfolioWatchRow.code = investorStockTbl[idx1].stockCode; porfolioWatchRow.stockExchange = stockCodeRow.stockExchange; porfolioWatchRow.name = stockCodeRow.name; porfolioWatchRow.nameEn = stockCodeRow.nameEn; } //TUAN - 29 Sept 2012 remove for no flicker when refresh data porfolioWatchRow.qty += investorStockTbl[idx1].qty; porfolioWatchRow.boughtAmt += investorStockTbl[idx1].buyAmt; } UpdatePrice(tbl); SetListColor(); }
protected void UpdatePrice(databases.tmpDS.porfolioWatchDataTable reportTbl) { databases.baseDS.lastPriceDataDataTable lastOpenPriceTbl = DataAccess.Libs.myLastDailyOpenPrice; databases.baseDS.lastPriceDataDataTable lastClosePriceTbl = DataAccess.Libs.myLastDailyClosePrice; databases.tmpDS.porfolioWatchRow reportRow; databases.baseDS.lastPriceDataRow priceRow; databases.baseDS.stockExchangeRow stockExchangeRow; for (int idx1 = 0; idx1 < reportTbl.Count; idx1++) { reportRow = reportTbl[idx1]; stockExchangeRow = DataAccess.Libs.myStockExchangeTbl.FindBycode(reportRow.stockExchange); if (stockExchangeRow == null || stockExchangeRow.priceRatio == 0) { continue; } decimal priceWeight = stockExchangeRow.priceRatio; decimal volumeWeight = stockExchangeRow.volumeRatio; reportRow.boughtPrice = (reportRow.qty == 0 ? 0 : reportRow.boughtAmt / reportRow.qty) / priceWeight; priceRow = lastClosePriceTbl.FindBystockCode(reportRow.code); if (priceRow != null) { reportRow.price = priceRow.value; priceRow = lastOpenPriceTbl.FindBystockCode(reportRow.code); if (priceRow != null) { reportRow.priceVariant = reportRow.price - priceRow.value; } else { reportRow.priceVariant = 0; } } reportRow.amt = reportRow.qty * reportRow.price * priceWeight; reportRow.profitVariantAmt = reportRow.amt - reportRow.boughtAmt; reportRow.profitVariantPerc = (reportRow.boughtAmt == 0 ? 0 : reportRow.profitVariantAmt / reportRow.boughtAmt) * 100; } }