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(); }
//private static void SaveLastRunTime(DateTime onTime) //{ // StringCollection aFields = new StringCollection(); // StringCollection aValues = new StringCollection(); // aFields.Add(Configuration.configKeys.sysTradeAlertLastRun.ToString()); // aValues.Add(onTime.ToString()); // application.Configuration.SaveConfig(aFields, aValues); //} //withAplicableCheckInAlert = true : Sell alerts only create when user owned stock that is applible to sell /// <summary> /// Create alerts for all stock in portfolio and return number of alerts created /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> private static int CreateTradeAlert(TradeAlertItem[] alertList) { int noAlertCreated = 0; string msg; StringCollection timeScaleList; databases.baseDS.tradeAlertRow tradeAlertRow; databases.baseDS.tradeAlertDataTable tradeAlertTbl = new databases.baseDS.tradeAlertDataTable(); //Watch list : sort by Stock code + Strategy code databases.baseDS.portfolioDetailDataTable watchlistTbl = databases.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList }); DataView watchlistView = new DataView(watchlistTbl); watchlistView.Sort = watchlistTbl.codeColumn.ColumnName + "," + watchlistTbl.subCodeColumn.ColumnName; //Portfolio : Sort by Stock code databases.tmpDS.investorStockDataTable investorStockTbl = new databases.tmpDS.investorStockDataTable(); databases.DbAccess.LoadStockOwnedByAll(investorStockTbl); DataView investorStockView = new DataView(investorStockTbl); investorStockView.Sort = investorStockTbl.stockCodeColumn.ColumnName; DataRowView[] foundRows; // Only create alerts for codes in user's watchlist. for (int alertId = 0; alertId < alertList.Length; alertId++) { databases.baseDS.portfolioDetailRow portfolioDetailRow; //=============================================== // Check if alert's strategy in user's wish list //=============================================== foundRows = watchlistView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < foundRows.Length; dataIdx++) { // Check if alert's time scale in user's wish list ?? portfolioDetailRow = ((databases.baseDS.portfolioDetailRow)foundRows[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDetailRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) { continue; } //Ignore duplicate alerts. tradeAlertRow = databases.DbAccess.GetOneAlert(alertList[alertId].OnDateTime, portfolioDetailRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) { continue; } string infoText = alertList[alertId].TradePoint.BusinessInfo.ToText().Trim(); infoText = (infoText != "" ? infoText : common.Consts.constNotAvailable); //Create alert template message, AlertMessageText() will convert it to specified-language text. msg = Consts.constTextMergeMarkerLEFT + "price" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "volume" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "marketInfo" + Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, portfolioDetailRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); noAlertCreated++; } //=============================================== // Create alerts for all codes in user's porfolio //=============================================== foundRows = investorStockView.FindRows(new object[] { alertList[alertId].StockCode }); for (int dataIdx = 0; dataIdx < foundRows.Length; dataIdx++) { // Check if alert's time scale in user's wish list ?? databases.tmpDS.investorStockRow investorStockRow = ((databases.tmpDS.investorStockRow)foundRows[dataIdx].Row); if (investorStockRow.qty == 0) { continue; } //Ignore duplicate alerts. tradeAlertRow = databases.DbAccess.GetOneAlert(alertList[alertId].OnDateTime, investorStockRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) { continue; } string infoText = alertList[alertId].TradePoint.BusinessInfo.ToText().Trim(); infoText = (infoText != "" ? infoText : common.Consts.constNotAvailable); //Create alert template message, AlertMessageText() will convert it to specified-language text. msg = Consts.constTextMergeMarkerLEFT + "price" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "volume" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "marketInfo" + Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; msg += Consts.constTextMergeMarkerLEFT + "ownedQty" + Consts.constTextMergeMarkerRIGHT + " : " + investorStockRow.qty.ToString() + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, investorStockRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); noAlertCreated++; } } databases.DbAccess.UpdateData(tradeAlertTbl); return(noAlertCreated); }
//private static void SaveLastRunTime(DateTime onTime) //{ // StringCollection aFields = new StringCollection(); // StringCollection aValues = new StringCollection(); // aFields.Add(Configuration.configKeys.sysTradeAlertLastRun.ToString()); // aValues.Add(onTime.ToString()); // application.Configuration.SaveConfig(aFields, aValues); //} //withAplicableCheckInAlert = true : Sell alerts only create when user owned stock that is applible to sell /// <summary> /// Create alerts for all stock in portfolio and return number of alerts created /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> private static int CreateTradeAlert(TradeAlertItem[] alertList) { int noAlertCreated = 0; string msg; StringCollection timeScaleList; databases.baseDS.tradeAlertRow tradeAlertRow; databases.baseDS.tradeAlertDataTable tradeAlertTbl = new databases.baseDS.tradeAlertDataTable(); //Watch list : sort by Stock code + Strategy code databases.baseDS.portfolioDetailDataTable watchlistTbl = databases.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList}); DataView watchlistView = new DataView(watchlistTbl); watchlistView.Sort = watchlistTbl.codeColumn.ColumnName + "," + watchlistTbl.subCodeColumn.ColumnName; //Portfolio : Sort by Stock code databases.tmpDS.investorStockDataTable investorStockTbl = new databases.tmpDS.investorStockDataTable(); databases.DbAccess.LoadStockOwnedByAll(investorStockTbl); DataView investorStockView = new DataView(investorStockTbl); investorStockView.Sort = investorStockTbl.stockCodeColumn.ColumnName; DataRowView[] foundRows; // Only create alerts for codes in user's watchlist. for (int alertId = 0; alertId < alertList.Length; alertId++) { databases.baseDS.portfolioDetailRow portfolioDetailRow; //=============================================== // Check if alert's strategy in user's wish list //=============================================== foundRows = watchlistView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < foundRows.Length; dataIdx++) { // Check if alert's time scale in user's wish list ?? portfolioDetailRow = ((databases.baseDS.portfolioDetailRow)foundRows[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDetailRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) continue; //Ignore duplicate alerts. tradeAlertRow = databases.DbAccess.GetOneAlert(alertList[alertId].OnDateTime, portfolioDetailRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) continue; string infoText = alertList[alertId].TradePoint.BusinessInfo.ToText().Trim(); infoText = (infoText != "" ? infoText : common.Consts.constNotAvailable); //Create alert template message, AlertMessageText() will convert it to specified-language text. msg = Consts.constTextMergeMarkerLEFT + "price" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "volume" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "marketInfo" + Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, portfolioDetailRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); noAlertCreated++; } //=============================================== // Create alerts for all codes in user's porfolio //=============================================== foundRows = investorStockView.FindRows(new object[] { alertList[alertId].StockCode }); for (int dataIdx = 0; dataIdx < foundRows.Length; dataIdx++) { // Check if alert's time scale in user's wish list ?? databases.tmpDS.investorStockRow investorStockRow = ((databases.tmpDS.investorStockRow)foundRows[dataIdx].Row); if (investorStockRow.qty == 0) continue; //Ignore duplicate alerts. tradeAlertRow = databases.DbAccess.GetOneAlert(alertList[alertId].OnDateTime, investorStockRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) continue; string infoText = alertList[alertId].TradePoint.BusinessInfo.ToText().Trim(); infoText = (infoText != "" ? infoText : common.Consts.constNotAvailable); //Create alert template message, AlertMessageText() will convert it to specified-language text. msg = Consts.constTextMergeMarkerLEFT + "price" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "volume" + Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + Consts.constTextMergeMarkerLEFT + "marketInfo" + Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; msg += Consts.constTextMergeMarkerLEFT + "ownedQty" + Consts.constTextMergeMarkerRIGHT + " : " + investorStockRow.qty.ToString() + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, investorStockRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); noAlertCreated++; } } databases.DbAccess.UpdateData(tradeAlertTbl); return noAlertCreated; }
public databases.tmpDS.investorStockDataTable GetOwnedStockSum_ByInvestor(string investorCode) { try { databases.tmpDS.investorStockDataTable tbl = new databases.tmpDS.investorStockDataTable(); databases.DbAccess.LoadData(tbl, investorCode); return tbl; } catch (Exception ex) { WriteSysLogLocal("WS035", ex); } return null; }