private void txtCode_KeyUp(object sender, KeyEventArgs e) { string code = txtCode.Text.Trim(); if (code.Length == 6) { StockModel model = GetInfo.Get(code); txtName.Text = model.Name; txtBuyPrice.Text = model.CurrentPrice.ToString(); } }
/// <summary> /// 根据策略得到购买价格 /// </summary> /// <param name="config"></param> /// <param name="stock"></param> /// <returns></returns> private decimal GetBuyPriceByTactics(StockConfigModel config, StockList stock) { if (config.UseGapLowerTactics) { StockModel model = GetInfo.Get(stock.StockCode); if (model.YesterdayEndPrice / model.TodayBeginPrice >= 1.01M) { return(Math.Round(stock.BuyPrice * (1 - (model.TodayBeginPrice / model.YesterdayEndPrice)), 2)); } } return(stock.BuyPrice); }
private void BindData(StockConfigModel configModel) { int Cnt = 0; foreach (StockList ll in configModel.StockList) { StockModel infoModel = GetInfo.Get(ll.StockCode); if (infoModel != null) { ll.CurrentPrice = infoModel.CurrentPrice; } else { ll.CurrentPrice = 0; } ll.BuyStrategy = string.Format("{0}{1}元", ((BuyVariableTrendEnum)ll.BuyVariableTrend).GetEnumDescription(), ll.BuyVariableAmount); ll.SaleStrategy = string.Format("{0}{1}元", ((SaleVariableTrendEnum)ll.SaleVariableTrend).GetEnumDescription(), ll.SaleVariableAmount); if (ll.Monitor == "监控中") { Cnt++; } } configModel.StockList.Add(new StockList { StockCode = "", StockName = "", BuyPrice = 0, BuyAmount = 0, CurrentPrice = 0, SalePrice = 0, SaleAmount = 0, Monitor = "" }); dataGrid.DataSource = configModel.StockList; txtBalance.Text = configModel.AvailableBalance.ToString(); chkLimitBuyTime.Checked = configModel.LimitBuyTime; chkLimitSaleTime.Checked = configModel.LimitSaleTime; dtBuyBeginTime.Value = configModel.BuyBeginTime; dtBuyEndTime.Value = configModel.BuyEndTime; dtSaleBeginTime.Value = configModel.SaleBeginTime; dtSaleEndTime.Value = configModel.SaleEndTime; btnStop.Visible = true; lblMonitor.Visible = true; cbxSoft.SelectedIndex = configModel.TradeSoftWare; btnStop.Text = Cnt > 0 ? "停止监控" : "开始监控"; lblMonitor.Text = Cnt > 0 ? "正在监控..." : "监控已停止..."; btnCloseComputer.Text = configModel.CloseComputerTime == DateTime.MinValue ? "关闭电脑" : "取消关闭"; chkGapLower.Checked = configModel.UseGapLowerTactics; }
private void BindData(StockConfigModel configModel) { if (configModel != null) { int Cnt = 0; foreach (StockList ll in configModel.StockList) { StockModel smodel = GetInfo.Get(ll.StockCode); ll.CurrentPrice = smodel.CurrentPrice; ll.BuyStrategy = string.Format("{0}{1}元", ((BuyVariableTrendEnum)ll.BuyVariableTrend).GetEnumDescription(), ll.BuyVariableAmount); ll.SaleStrategy = string.Format("{0}{1}元", ((SaleVariableTrendEnum)ll.SaleVariableTrend).GetEnumDescription(), ll.SaleVariableAmount); if (ll.CurrentPrice >= smodel.YesterdayEndPrice) { ll.IncreaseAmt = string.Format("{0}", Math.Round((ll.CurrentPrice / smodel.YesterdayEndPrice - 1) * 100, 2)); } else { ll.IncreaseAmt = string.Format("-{0}", Math.Round((1 - ll.CurrentPrice / smodel.YesterdayEndPrice) * 100, 2)); } if (ll.Monitor == "监控中") { Cnt++; } } dataGrid.DataSource = configModel.StockList; dataGrid.Refresh(); txtBalance.Text = configModel.AvailableBalance.ToString(); chkLimitBuyTime.Checked = configModel.LimitBuyTime; chkLimitSaleTime.Checked = configModel.LimitSaleTime; dtBuyBeginTime.Value = configModel.BuyBeginTime; dtBuyEndTime.Value = configModel.BuyEndTime; dtSaleBeginTime.Value = configModel.SaleBeginTime; dtSaleEndTime.Value = configModel.SaleEndTime; lblMonitor.Visible = true; lblMonitor.Text = Cnt > 0 ? "正在监控..." : "监控已停止..."; cbxSoft.SelectedIndex = configModel.TradeSoftWare; chkGapLower.Checked = configModel.UseGapLowerTactics; } }
private void dataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { var cell = dataGrid.Rows[e.RowIndex].Cells[0].Value; if (cell == null) { return; } string code = cell.ToString(); if (code.Length == 6) { StockModel model = GetInfo.Get(code); if (model != null) { bool flag = false; for (int j = 0; j < dataGrid.Rows.Count; j++) { if (j != e.RowIndex) { if (dataGrid.Rows[j].Cells[txtStockCode].Value != null) { if (dataGrid.Rows[j].Cells[txtStockCode].Value.ToString() == dataGrid.Rows[e.RowIndex].Cells[txtStockCode].Value.ToString()) { flag = true; break; } } } } if (flag) { MessageBox.Show("证券信息重复!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning); ClearRow(e.RowIndex); } else { dataGrid.Rows[e.RowIndex].Cells[txtStockName].Value = model.Name; dataGrid.Rows[e.RowIndex].Cells[txtBuyPrice].Value = model.CurrentPrice; SetFull_Stock(); dataGrid.Rows[e.RowIndex].Cells[txtMonitor].Value = "已停止";//默认值 dataGrid.Rows[e.RowIndex].Cells[txtBuyVariableTrend].Value = (int)BuyVariableTrendEnum.ReachOrDown; dataGrid.Rows[e.RowIndex].Cells[txtBuyVariableAmount].Value = 0.00M; dataGrid.Rows[e.RowIndex].Cells[txtBuyStrategy].Value = string.Format("{0}{1}元", BuyVariableTrendEnum.ReachOrDown.GetEnumDescription(), 0); dataGrid.Rows[e.RowIndex].Cells[txtSalePrice].Value = Math.Round(model.CurrentPrice * 1.04M, 2); dataGrid.Rows[e.RowIndex].Cells[txtSaleAmount].Value = 0;//默认值 dataGrid.Rows[e.RowIndex].Cells[txtSaleVariableTrend].Value = (int)SaleVariableTrendEnum.ReachOrUp; dataGrid.Rows[e.RowIndex].Cells[txtSaleVariableAmount].Value = 0.00M; dataGrid.Rows[e.RowIndex].Cells[txtSaleStrategy].Value = string.Format("{0}{1}元", SaleVariableTrendEnum.ReachOrUp.GetEnumDescription(), 0); } } else { MessageBox.Show("获取信息失败!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); ClearRow(e.RowIndex); } } else { ClearRow(e.RowIndex); StockConfigModel model = GetModelFromDataContainer(); BindData(model); } } if (e.RowIndex == dataGrid.Rows.Count - 1) { DataGridViewCellCollection cells = dataGrid.Rows[e.RowIndex].Cells; if (cells[txtStockCode].Value != null && cells[txtStockCode].Value.ToString() != "" && cells[txtStockName].Value.ToString() != "") { StockConfigModel model = GetModelFromDataContainer(); BindData(model); } } }