private void DataBinding(BindingSource dataSource) { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); this.onTimeEd.DataBindings.Clear(); this.onTimeEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSource, tbl.onTimeColumn.ColumnName, true)); this.codeEd.DataBindings.Clear(); this.codeEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSource, tbl.idColumn.ColumnName, true)); this.subjectEd.DataBindings.Clear(); this.subjectEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSource, tbl.subjectColumn.ColumnName, true)); this.messageEd.DataBindings.Clear(); this.messageEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSource, tbl.msgColumn.ColumnName, true)); this.strategyCb.DataBindings.Clear(); this.strategyCb.DataBindings.Add(new System.Windows.Forms.Binding("myValue", dataSource, tbl.strategyColumn.ColumnName, true)); this.portpolioCb.DataBindings.Clear(); this.portpolioCb.DataBindings.Add(new System.Windows.Forms.Binding("myValue", dataSource, tbl.portpolioColumn.ColumnName, true)); this.statusCb.DataBindings.Clear(); this.statusCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSource, tbl.statusColumn.ColumnName, true)); this.actionCb.DataBindings.Clear(); this.actionCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSource, tbl.tradeActionColumn.ColumnName, true)); }
/// <summary> /// Create alerts for all stock in portfolio /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> /// <param name="frDate">Alert will only create alert in range [frDate,toDate]. /// It also ensure that in the same day,there in ONLY one new alert of the same type</param> /// <param name="toDate"></param> private static void CreateTradeAlert(TradeAlert[] alertList,DateTime frDate,DateTime toDate) { decimal availabeQty; string msg; StringCollection timeScaleList; data.baseDS.tradeAlertRow tradeAlertRow; data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); data.baseDS.portfolioDetailDataTable portfolioDetailTbl = new data.baseDS.portfolioDetailDataTable(); DataView portfolioDetailView = new DataView(portfolioDetailTbl); //Sort by Stock code + Strategy code portfolioDetailView.Sort = portfolioDetailTbl.codeColumn.ColumnName + "," + portfolioDetailTbl.subCodeColumn.ColumnName; DataRowView[] portfolioDetailFound; data.baseDS.portfolioDetailRow portfolioDataRow; portfolioDetailTbl = data.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList, AppTypes.PortfolioTypes.Portfolio }); // Only alert on stock codes that were selected by user. for (int alertId = 0; alertId < alertList.Length; alertId++) { // Check if alert's strategy in user's wish list ?? portfolioDetailFound = portfolioDetailView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < portfolioDetailFound.Length; dataIdx++) { // Check if time alert's time scale in user's wish list ?? portfolioDataRow = ((data.baseDS.portfolioDetailRow)portfolioDetailFound[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDataRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) continue; //Do not crete alert if there is a NEW one. tradeAlertRow = data.DbAccess.GetLastAlert( frDate, toDate, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, (byte)AppTypes.CommonStatus.New); if (tradeAlertRow != null) continue; //Availabe stock if (withAplicableCheckInAlert) { availabeQty = data.AppLibs.GetAvailableStock(alertList[alertId].StockCode, portfolioDataRow.portfolio, Settings.sysStockSell2BuyInterval, alertList[alertId].OnDateTime); } else availabeQty = int.MaxValue; //Aplicable to sell if ((alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.Sell || alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.ClearAll) && (availabeQty <= 0)) continue; msg = " - Giá : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + " - K/L giao dịch : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + " - Xu hướng : (" + alertList[alertId].TradePoint.BusinessInfo.ToString() + "," + alertList[alertId].TradePoint.BusinessInfo.LongTermTrend + ")" + common.Consts.constCRLF + " - K/L sở hữu hợp lệ : " + availabeQty.ToString() + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, toDate, msg); } } data.DbAccess.UpdateData(tradeAlertTbl); }
public static data.baseDS.tradeAlertRow UpdateData(data.baseDS.tradeAlertRow row) { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); tbl.ImportRow(row); myClient.UpdateTradeAlert(ref tbl); row.AcceptChanges(); return(tbl[0]); }
public string GetSQL() { data.baseDS.portfolioDataTable portfolioTbl = new data.baseDS.portfolioDataTable(); data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); string condCmd = ""; condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.portfolioColumn.ColumnName + " IN (" + " SELECT " + portfolioTbl.codeColumn.ColumnName + " FROM " + portfolioTbl.TableName + " WHERE " + portfolioTbl.investorCodeColumn.ColumnName + "=N'" + commonClass.SysLibs.sysLoginCode + "'))"; if (dateRangeChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.onTimeColumn.ColumnName + " BETWEEN '" + common.system.ConvertToSQLDateString(dateRange.frDate, false) + "' AND '" + common.system.ConvertToSQLDateString(dateRange.toDate.AddDays(1).AddSeconds(-1), false) + "')"; } if (statusChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.statusColumn.ColumnName + " & " + ((byte)statusCb.myValue).ToString() + ">0)"; } if (portfolioChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.portfolioColumn.ColumnName + "=N'" + portfolioCb.myValue + "')"; } if (strategyChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.strategyColumn.ColumnName + "=N'" + strategyCb.myValue + "')"; } if (timeScaleChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.timeScaleColumn.ColumnName + "='" + timeScaleCb.myValue.Code + "')"; } if (codeChk.Checked) { condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.stockCodeColumn.ColumnName + "=N'" + codeEd.Text.Trim() + "')"; } string sqlCmd = "SELECT * FROM " + tradeAlertTbl.TableName + (condCmd == "" ? "" : " WHERE " + condCmd) + " ORDER BY " + tradeAlertTbl.onTimeColumn.ColumnName + " DESC"; return(sqlCmd); }
public static data.baseDS.tradeAlertRow GetAlert(DateTime onDateTime, string portfolio, string stockCode, string strategy, string timeScale, commonClass.AppTypes.CommonStatus status) { data.baseDS.tradeAlertDataTable tbl = tradeAlertTA.GetOne(onDateTime, onDateTime, portfolio, stockCode, strategy, timeScale, ((byte)status).ToString()); if (tbl == null || tbl.Count == 0) { return(null); } return(tbl[0]); }
public static data.baseDS.tradeAlertRow GetLastAlert(DateTime frDate, DateTime toDate, string portfolio, string stockCode, string strategy, string timeScale, byte statusMask) { data.baseDS.tradeAlertDataTable tbl = tradeAlertTA.GetOne(frDate, toDate, portfolio, stockCode, strategy, timeScale, statusMask.ToString()); if (tbl == null || tbl.Count == 0) { return(null); } return(tbl[0]); }
private static void CreateTradeAlert(data.baseDS.tradeAlertDataTable tradeAlertTbl, string portfolioCode, string stockCode, string strategy, AppTypes.TimeScale timeScale, TradePointInfo info, DateTime onTime, string msg) { data.baseDS.tradeAlertRow row = tradeAlertTbl.NewtradeAlertRow(); commonClass.AppLibs.InitData(row); row.onTime = onTime; row.portfolio = portfolioCode; row.stockCode = stockCode; row.timeScale = timeScale.Code; row.strategy = strategy; row.status = (byte)AppTypes.CommonStatus.New; row.tradeAction = (byte)info.TradeAction; row.subject = info.TradeAction.ToString(); row.msg = msg; tradeAlertTbl.AddtradeAlertRow(row); }
protected void UpdateRealTime(data.tmpDS.portfolioListDataTable reportTbl, string[] portfolioCodes) { DateTime onTime = application.sysLibs.GetServerDateTime(); data.baseDS.priceDataRow priceRow; data.tmpDS.portfolioListRow reportRow; decimal qty = 0, boughtAmt = 0; //Prepare data to get Alert sumary data in AlertSummaryInfo() data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); for (int idx = 0; idx < portfolioCodes.Length; idx++) { dataLibs.LoadData(tradeAlertTbl, portfolioCodes[idx], onTime.Date, onTime, (byte)application.myTypes.commonStatus.New); } DataView tradeAlertView = new DataView(tradeAlertTbl); tradeAlertView.Sort = tradeAlertTbl.stockCodeColumn.ColumnName; for (int idx1 = 0; idx1 < reportTbl.Count; idx1++) { reportRow = reportTbl[idx1]; reportRow.qty = 0; reportRow.boughtAmt = 0; for (int idx2 = 0; idx2 < portfolioCodes.Length; idx2++) { dataLibs.GetOwnStock(reportRow.stockCode, portfolioCodes[idx2], 0, onTime, out qty, out boughtAmt); reportRow.qty += qty; reportRow.boughtAmt += boughtAmt; } reportRow.boughtPrice = (reportRow.qty == 0 ? 0 : reportRow.boughtAmt / reportRow.qty) / application.Settings.sysStockPriceWeight; priceRow = application.dataLibs.GetPriceData(onTime.Date, onTime, reportRow.stockCode); reportRow.price = (priceRow == null ? 0 : priceRow.closePrice); reportRow.priceVariant = (priceRow == null ? 0 : reportRow.price - priceRow.openPrice); reportRow.volume = (priceRow == null ? 0 : priceRow.volume); reportRow.amt = reportRow.qty * reportRow.price * application.Settings.sysStockPriceWeight; reportRow.profitVariantAmt = reportRow.amt - reportRow.boughtAmt; reportRow.profitVariantPerc = (reportRow.boughtAmt == 0 ? 0 : reportRow.profitVariantAmt / reportRow.boughtAmt) * 100; //Alert summary info reportRow.notes = AlertSummaryInfo(reportRow.stockCode, tradeAlertView); } }
public static data.baseDS.tradeAlertRow UpdateData(data.baseDS.tradeAlertRow row) { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); tbl.ImportRow(row); myClient.UpdateTradeAlert(ref tbl); row.AcceptChanges(); return tbl[0]; }
protected void SetDataGrid() { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); // // onTimeColumn // this.onTimeColumn.Name = gridColumnName.OnTime.ToString(); this.onTimeColumn.DataPropertyName = tbl.onTimeColumn.ColumnName; this.onTimeColumn.HeaderText = "Thời gian"; this.onTimeColumn.ReadOnly = true; this.onTimeColumn.Width = 160; // // stockCodeColumn // this.stockCodeColumn.Name = gridColumnName.StockCode.ToString(); this.stockCodeColumn.DataPropertyName = tbl.stockCodeColumn.ColumnName; this.stockCodeColumn.HeaderText = "Mã CK"; this.stockCodeColumn.ReadOnly = true; this.stockCodeColumn.Width = 80; // // subjectColumn // this.subjectColumn.Name = gridColumnName.Subject.ToString(); this.subjectColumn.DataPropertyName = tbl.subjectColumn.ColumnName; this.subjectColumn.HeaderText = ""; this.subjectColumn.ReadOnly = true; this.subjectColumn.Width = 70; // // strategyColumn // this.strategyColumn.Name = gridColumnName.Strategy.ToString(); this.strategyColumn.DataPropertyName = tbl.strategyColumn.ColumnName; this.strategyColumn.HeaderText = "Chiến lược"; this.strategyColumn.ReadOnly = true; this.strategyColumn.Width = 100; this.strategyColumn.Visible = true; // // statusColumn // this.statusColumn.Name = gridColumnName.Status.ToString(); this.statusColumn.DataPropertyName = tbl.statusColumn.ColumnName; this.statusColumn.DisplayMember = commonStatusTbl.Columns[1].ColumnName; this.statusColumn.ValueMember = commonStatusTbl.Columns[0].ColumnName; this.statusColumn.DataSource = commonStatusSource; this.statusColumn.HeaderText = ""; this.statusColumn.ReadOnly = true; this.statusColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.statusColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.statusColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; this.statusColumn.Width = 50; // // timeScaleColumn // this.timeScaleColumn.Name = gridColumnName.TimeScale.ToString(); this.timeScaleColumn.DataPropertyName = tbl.timeScaleColumn.ColumnName; this.timeScaleColumn.DisplayMember = timeScaleTbl.Columns[1].ColumnName; this.timeScaleColumn.ValueMember = timeScaleTbl.Columns[0].ColumnName; this.timeScaleColumn.DataSource = timeScaleSource; this.timeScaleColumn.HeaderText = "Loại"; this.timeScaleColumn.ReadOnly = true; this.timeScaleColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.timeScaleColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.timeScaleColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; this.timeScaleColumn.Width = 70; // // cancelColumn // this.cancelColumn.Name = gridColumnName.Cancel.ToString(); this.cancelColumn.HeaderText = ""; this.cancelColumn.myValue = ""; this.cancelColumn.ReadOnly = true; this.cancelColumn.Width = 25; this.cancelColumn.myImageType = common.control.imageType.Cancel; // // viewColumn // this.viewColumn.Name = gridColumnName.View.ToString(); this.viewColumn.HeaderText = ""; this.viewColumn.myValue = ""; this.viewColumn.ReadOnly = true; this.viewColumn.Width = 25; this.viewColumn.myImageType = common.control.imageType.Edit; // // dataGrid // this.dataGrid.AutoGenerateColumns = false; this.dataGrid.DisableReadOnlyColumn = false; this.dataGrid.Columns.Clear(); this.dataGrid.Columns.AddRange(new DataGridViewColumn[] {this.onTimeColumn, this.stockCodeColumn, this.strategyColumn, this.timeScaleColumn, this.subjectColumn, this.statusColumn, this.viewColumn,this.cancelColumn}); AutoResize(); }
public string GetSQL() { data.baseDS.portfolioDataTable portfolioTbl = new data.baseDS.portfolioDataTable(); data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); string condCmd = ""; condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.portfolioColumn.ColumnName + " IN (" + " SELECT " + portfolioTbl.codeColumn.ColumnName + " FROM " + portfolioTbl.TableName + " WHERE " + portfolioTbl.investorCodeColumn.ColumnName + "=N'" + commonClass.SysLibs.sysLoginCode + "'))"; if (dateRangeChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.onTimeColumn.ColumnName + " BETWEEN '" + common.system.ConvertToSQLDateString(dateRange.frDate,false) + "' AND '"+ common.system.ConvertToSQLDateString(dateRange.toDate.AddDays(1).AddSeconds(-1),false) + "')"; if (statusChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.statusColumn.ColumnName + " & " + ((byte)statusCb.myValue).ToString() + ">0)"; if (portfolioChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.portfolioColumn.ColumnName + "=N'" + portfolioCb.myValue + "')"; if (strategyChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.strategyColumn.ColumnName + "=N'" + strategyCb.myValue + "')"; if (timeScaleChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.timeScaleColumn.ColumnName + "='" + timeScaleCb.myValue.Code + "')"; if (codeChk.Checked) condCmd += (condCmd == "" ? "" : " AND ") + "(" + tradeAlertTbl.stockCodeColumn.ColumnName + "=N'" + codeEd.Text.Trim() + "')"; string sqlCmd = "SELECT * FROM " + tradeAlertTbl.TableName + (condCmd == "" ? "" : " WHERE " + condCmd) + " ORDER BY " + tradeAlertTbl.onTimeColumn.ColumnName + " DESC"; return sqlCmd; }
public void UpdateTradeAlert(ref data.baseDS.tradeAlertDataTable tbl) { DbAccess.UpdateData(tbl); }
/// <summary> /// Create alerts for all stock in portfolio /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> private static void CreateTradeAlert(TradeAlert[] alertList) { decimal availabeQty; string msg; StringCollection timeScaleList; data.baseDS.tradeAlertRow tradeAlertRow; data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); data.baseDS.portfolioDetailDataTable portfolioDetailTbl = application.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList, AppTypes.PortfolioTypes.Portfolio }); DataView portfolioDetailView = new DataView(portfolioDetailTbl); //Sort by Stock code + Strategy code portfolioDetailView.Sort = portfolioDetailTbl.codeColumn.ColumnName + "," + portfolioDetailTbl.subCodeColumn.ColumnName; DataRowView[] portfolioDetailFound; data.baseDS.portfolioDetailRow portfolioDataRow; // Only alert on stock codes that were selected by user. for (int alertId = 0; alertId < alertList.Length; alertId++) { // Check if alert's strategy in user's wish list ?? portfolioDetailFound = portfolioDetailView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < portfolioDetailFound.Length; dataIdx++) { // Check if time alert's time scale in user's wish list ?? portfolioDataRow = ((data.baseDS.portfolioDetailRow)portfolioDetailFound[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDataRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) { continue; } //Ignore duplicate alerts. tradeAlertRow = application.DbAccess.GetAlert(alertList[alertId].OnDateTime, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) { continue; } //Availabe stock if (withAplicableCheckInAlert) { data.baseDS.stockExchangeRow stockExchangeRow = application.AppLibs.GetStockExchange(alertList[alertId].StockCode); int sell2BuyInterval = (stockExchangeRow == null?0:stockExchangeRow.minBuySellDay); availabeQty = application.DbAccess.GetAvailableStock(alertList[alertId].StockCode, portfolioDataRow.portfolio, sell2BuyInterval, alertList[alertId].OnDateTime); } else { availabeQty = 0; } //Aplicable to sell if ((alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.Sell || alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.ClearAll) && (availabeQty <= 0)) { 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 = commonClass.Consts.constTextMergeMarkerLEFT + "price" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + commonClass.Consts.constTextMergeMarkerLEFT + "volume" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + commonClass.Consts.constTextMergeMarkerLEFT + "marketInfo" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; if (availabeQty > 0) { msg += commonClass.Consts.constTextMergeMarkerLEFT + "ownedQty" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + availabeQty.ToString() + common.Consts.constCRLF; } CreateTradeAlert(tradeAlertTbl, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); } } application.DbAccess.UpdateData(tradeAlertTbl); }
public data.baseDS.tradeAlertDataTable GetTradeAlert_BySQL(string sql) { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); DbAccess.LoadFromSQL(tbl, sql); return tbl; }
public static void UpdateData(data.baseDS.tradeAlertDataTable tbl) { tradeAlertTA.Update(tbl); tbl.AcceptChanges(); }
public data.baseDS.tradeAlertDataTable GetTradeAlert_BySQL(string sql) { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); DbAccess.LoadFromSQL(tbl, sql); return(tbl); }
protected void SetDataGrid() { data.baseDS.tradeAlertDataTable tbl = new data.baseDS.tradeAlertDataTable(); // // onTimeColumn // this.onTimeColumn.Name = gridColumnName.OnTime.ToString(); this.onTimeColumn.DataPropertyName = tbl.onTimeColumn.ColumnName; this.onTimeColumn.HeaderText = "Thời gian"; this.onTimeColumn.ReadOnly = true; this.onTimeColumn.Width = 160; // // stockCodeColumn // this.stockCodeColumn.Name = gridColumnName.StockCode.ToString(); this.stockCodeColumn.DataPropertyName = tbl.stockCodeColumn.ColumnName; this.stockCodeColumn.HeaderText = "Mã CK"; this.stockCodeColumn.ReadOnly = true; this.stockCodeColumn.Width = 80; // // subjectColumn // this.subjectColumn.Name = gridColumnName.Subject.ToString(); this.subjectColumn.DataPropertyName = tbl.subjectColumn.ColumnName; this.subjectColumn.HeaderText = ""; this.subjectColumn.ReadOnly = true; this.subjectColumn.Width = 70; // // strategyColumn // this.strategyColumn.Name = gridColumnName.Strategy.ToString(); this.strategyColumn.DataPropertyName = tbl.strategyColumn.ColumnName; this.strategyColumn.HeaderText = "Chiến lược"; this.strategyColumn.ReadOnly = true; this.strategyColumn.Width = 100; this.strategyColumn.Visible = true; // // statusColumn // this.statusColumn.Name = gridColumnName.Status.ToString(); this.statusColumn.DataPropertyName = tbl.statusColumn.ColumnName; this.statusColumn.DisplayMember = commonStatusTbl.Columns[1].ColumnName; this.statusColumn.ValueMember = commonStatusTbl.Columns[0].ColumnName; this.statusColumn.DataSource = commonStatusSource; this.statusColumn.HeaderText = ""; this.statusColumn.ReadOnly = true; this.statusColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.statusColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.statusColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; this.statusColumn.Width = 50; // // timeScaleColumn // this.timeScaleColumn.Name = gridColumnName.TimeScale.ToString(); this.timeScaleColumn.DataPropertyName = tbl.timeScaleColumn.ColumnName; this.timeScaleColumn.DisplayMember = timeScaleTbl.Columns[1].ColumnName; this.timeScaleColumn.ValueMember = timeScaleTbl.Columns[0].ColumnName; this.timeScaleColumn.DataSource = timeScaleSource; this.timeScaleColumn.HeaderText = "Loại"; this.timeScaleColumn.ReadOnly = true; this.timeScaleColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.timeScaleColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.timeScaleColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; this.timeScaleColumn.Width = 70; // // cancelColumn // this.cancelColumn.Name = gridColumnName.Cancel.ToString(); this.cancelColumn.HeaderText = ""; this.cancelColumn.myValue = ""; this.cancelColumn.ReadOnly = true; this.cancelColumn.Width = 25; this.cancelColumn.myImageType = common.control.imageType.Cancel; // // viewColumn // this.viewColumn.Name = gridColumnName.View.ToString(); this.viewColumn.HeaderText = ""; this.viewColumn.myValue = ""; this.viewColumn.ReadOnly = true; this.viewColumn.Width = 25; this.viewColumn.myImageType = common.control.imageType.Edit; // // dataGrid // this.dataGrid.AutoGenerateColumns = false; this.dataGrid.DisableReadOnlyColumn = false; this.dataGrid.Columns.Clear(); this.dataGrid.Columns.AddRange(new DataGridViewColumn[] { this.onTimeColumn, this.stockCodeColumn, this.strategyColumn, this.timeScaleColumn, this.subjectColumn, this.statusColumn, this.viewColumn, this.cancelColumn }); AutoResize(); }
/// <summary> /// Create alerts for all stock in portfolio /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> private static void CreateTradeAlert(TradeAlert[] alertList) { decimal availabeQty; string msg; StringCollection timeScaleList; data.baseDS.tradeAlertRow tradeAlertRow; data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); data.baseDS.portfolioDetailDataTable portfolioDetailTbl = application.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList, AppTypes.PortfolioTypes.Portfolio }); DataView portfolioDetailView = new DataView(portfolioDetailTbl); //Sort by Stock code + Strategy code portfolioDetailView.Sort = portfolioDetailTbl.codeColumn.ColumnName + "," + portfolioDetailTbl.subCodeColumn.ColumnName; DataRowView[] portfolioDetailFound; data.baseDS.portfolioDetailRow portfolioDataRow; // Only alert on stock codes that were selected by user. for (int alertId = 0; alertId < alertList.Length; alertId++) { // Check if alert's strategy in user's wish list ?? portfolioDetailFound = portfolioDetailView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < portfolioDetailFound.Length; dataIdx++) { // Check if time alert's time scale in user's wish list ?? portfolioDataRow = ((data.baseDS.portfolioDetailRow)portfolioDetailFound[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDataRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) continue; //Ignore duplicate alerts. tradeAlertRow = application.DbAccess.GetAlert(alertList[alertId].OnDateTime, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, AppTypes.CommonStatus.All); if (tradeAlertRow != null) continue; //Availabe stock if (withAplicableCheckInAlert) { data.baseDS.stockExchangeRow stockExchangeRow = application.AppLibs.GetStockExchange(alertList[alertId].StockCode); int sell2BuyInterval = (stockExchangeRow==null?0:stockExchangeRow.minBuySellDay); availabeQty = application.DbAccess.GetAvailableStock(alertList[alertId].StockCode, portfolioDataRow.portfolio, sell2BuyInterval, alertList[alertId].OnDateTime); } else availabeQty = 0; //Aplicable to sell if ((alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.Sell || alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.ClearAll) && (availabeQty <= 0)) 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 = commonClass.Consts.constTextMergeMarkerLEFT + "price" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + commonClass.Consts.constTextMergeMarkerLEFT + "volume" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + commonClass.Consts.constTextMergeMarkerLEFT + "marketInfo" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + infoText + common.Consts.constCRLF; if (availabeQty >0) { msg += commonClass.Consts.constTextMergeMarkerLEFT + "ownedQty" + commonClass.Consts.constTextMergeMarkerRIGHT + " : " + availabeQty.ToString() + common.Consts.constCRLF; } CreateTradeAlert(tradeAlertTbl, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, alertList[alertId].OnDateTime, msg); } } application.DbAccess.UpdateData(tradeAlertTbl); }
public static void LoadData(data.baseDS.tradeAlertDataTable tbl, string portfolio, DateTime frDate, DateTime toDate, byte statusMask) { tradeAlertTA.ClearBeforeFill = false; tradeAlertTA.Fill(tbl, portfolio, frDate, toDate, statusMask.ToString()); }
protected void SetDataGrid() { data.baseDS.tradeAlertDataTable tbl = myDataSet.tradeAlert; // // onTimeColumn // this.onDateColumn.Name = gridColumnName.OnTime.ToString(); this.onDateColumn.DataPropertyName = tbl.onTimeColumn.ColumnName; // // stockCodeColumn // this.codeColumn.Name = gridColumnName.StockCode.ToString(); this.codeColumn.DataPropertyName = tbl.stockCodeColumn.ColumnName; // // subjectColumn // this.actionColumn.Name = gridColumnName.TradeAction.ToString(); this.actionColumn.DataPropertyName = tbl.tradeActionColumn.ColumnName; // // strategyColumn // this.strategyColumn.Name = gridColumnName.Strategy.ToString(); this.strategyColumn.DataPropertyName = tbl.strategyColumn.ColumnName; // // statusColumn // this.statusColumn.Name = gridColumnName.Status.ToString(); this.statusColumn.DataPropertyName = tbl.statusColumn.ColumnName; // // cancelColumn // this.cancelColumn.Name = gridColumnName.Cancel.ToString(); this.cancelColumn.ReadOnly = true; this.cancelColumn.Width = 25; this.cancelColumn.myImageType = common.controls.imageType.Cancel; this.cancelColumn.Visible = false; // // viewColumn // this.viewColumn.Name = gridColumnName.View.ToString(); this.viewColumn.ReadOnly = true; this.viewColumn.Width = 25; this.viewColumn.myImageType = common.controls.imageType.Edit; // // dataGrid // this.dataGrid.AutoGenerateColumns = false; this.dataGrid.DisableReadOnlyColumn = false; this.dataGrid.Columns.Clear(); this.dataGrid.Columns.AddRange(new DataGridViewColumn[] { this.onDateColumn, this.codeColumn, this.strategyColumn, this.timeScaleColumn, this.actionColumn, this.statusColumn, this.viewColumn, this.cancelColumn }); }
/// <summary> /// Create alerts for all stock in portfolio /// </summary> /// <param name="alertList"> all alert resulted from analysis </param> /// <param name="frDate">Alert will only create alert in range [frDate,toDate]. /// It also ensure that in the same day,there in ONLY one new alert of the same type</param> /// <param name="toDate"></param> private static void CreateTradeAlert(TradeAlert[] alertList, DateTime frDate, DateTime toDate) { decimal availabeQty; string msg; StringCollection timeScaleList; data.baseDS.tradeAlertRow tradeAlertRow; data.baseDS.tradeAlertDataTable tradeAlertTbl = new data.baseDS.tradeAlertDataTable(); data.baseDS.portfolioDetailDataTable portfolioDetailTbl = new data.baseDS.portfolioDetailDataTable(); DataView portfolioDetailView = new DataView(portfolioDetailTbl); //Sort by Stock code + Strategy code portfolioDetailView.Sort = portfolioDetailTbl.codeColumn.ColumnName + "," + portfolioDetailTbl.subCodeColumn.ColumnName; DataRowView[] portfolioDetailFound; data.baseDS.portfolioDetailRow portfolioDataRow; portfolioDetailTbl = data.DbAccess.GetPortfolioDetail_ByType(new AppTypes.PortfolioTypes[] { AppTypes.PortfolioTypes.WatchList, AppTypes.PortfolioTypes.Portfolio }); // Only alert on stock codes that were selected by user. for (int alertId = 0; alertId < alertList.Length; alertId++) { // Check if alert's strategy in user's wish list ?? portfolioDetailFound = portfolioDetailView.FindRows(new object[] { alertList[alertId].StockCode, alertList[alertId].Strategy.Trim() }); for (int dataIdx = 0; dataIdx < portfolioDetailFound.Length; dataIdx++) { // Check if time alert's time scale in user's wish list ?? portfolioDataRow = ((data.baseDS.portfolioDetailRow)portfolioDetailFound[dataIdx].Row); timeScaleList = common.MultiValueString.String2List(portfolioDataRow.data.Trim()); if (!timeScaleList.Contains(alertList[alertId].TimeScale.Code)) { continue; } //Do not crete alert if there is a NEW one. tradeAlertRow = data.DbAccess.GetLastAlert(frDate, toDate, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale.Code, (byte)AppTypes.CommonStatus.New); if (tradeAlertRow != null) { continue; } //Availabe stock if (withAplicableCheckInAlert) { availabeQty = data.AppLibs.GetAvailableStock(alertList[alertId].StockCode, portfolioDataRow.portfolio, Settings.sysStockSell2BuyInterval, alertList[alertId].OnDateTime); } else { availabeQty = int.MaxValue; } //Aplicable to sell if ((alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.Sell || alertList[alertId].TradePoint.TradeAction == AppTypes.TradeActions.ClearAll) && (availabeQty <= 0)) { continue; } msg = " - Giá : " + alertList[alertId].Price.ToString() + common.Consts.constCRLF + " - K/L giao dịch : " + alertList[alertId].Volume.ToString() + common.Consts.constCRLF + " - Xu hướng : (" + alertList[alertId].TradePoint.BusinessInfo.ToString() + "," + alertList[alertId].TradePoint.BusinessInfo.LongTermTrend + ")" + common.Consts.constCRLF + " - K/L sở hữu hợp lệ : " + availabeQty.ToString() + common.Consts.constCRLF; CreateTradeAlert(tradeAlertTbl, portfolioDataRow.portfolio, alertList[alertId].StockCode, alertList[alertId].Strategy, alertList[alertId].TimeScale, alertList[alertId].TradePoint, toDate, msg); } } data.DbAccess.UpdateData(tradeAlertTbl); }