/// <summary> /// 卖出股票 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSellStock_Click(object sender, EventArgs e) { if (comBoxStockName.Text == "" || textBoxSellCount.Text == "" || textBoxSellPrice.Text == "" || labSellStockTip.Visible) { return; } stockTradeBll.UpdateUserInfo(); int index = comBoxStockName.SelectedIndex; int count = int.Parse(textBoxSellCount.Text); int IsSellSuccess = stockTradeBll.SellStock(index, count); if (IsSellSuccess != -1) { string stockId = ""; stockTradeBll = new StockTradeBll(); //通过重新生成对象来刷新数据库中的数据 DataTable dt = new DataTable(); dt = stockTradeBll.GetUserStockInfo(); if (dt.Rows.Count == 0) { return; } if (dt.Rows[0][1].ToString() != "null") { stockId = dt.Rows[index][1].ToString().Trim(); int stockCount = stockTradeBll.SelectStockCount(stockId); if (stockCount == 0) //当用户的某支股票持有量为0时,删除该股票在数据库中的记录 { stockTradeBll.DeleteStockInfo(stockId); } labAvailableCount.Text = stockCount.ToString(); } double invaliable = stockTradeBll.GetUserInvaliableFund(); labAvailableFund.Text = invaliable.ToString(); MessageBox.Show("股票卖出成功", "信息提示", MessageBoxButtons.OK); NowStockDataModel model = new NowStockDataModel(); model = stockTradeBll.GetNowStockData(stockId); //string totalAsset = (LoginInfo.loginInfo.TotalAssets + double.Parse(model.CurrentPrice) * count).ToString("0.00"); string available = (LoginInfo.loginInfo.AvailableFund + double.Parse(model.CurrentPrice) * count).ToString("0.00"); MyPositionBll myPositionBll = new MyPositionBll(); myPositionBll.UpdateAvailableFund(available);//卖出股票后,更新总资产、可用资金 UpdateUserAssetStatus(); MyPosition(); } else { MessageBox.Show("股票卖出失败", "信息提示", MessageBoxButtons.OK); } }
/// <summary> /// 卖出股票模块中选择卖出股票名称的组合框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comBoxStockName_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt = new DataTable(); dt = stockTradeBll.GetUserStockInfo(); if (dt.Rows.Count == 0) { return; } int index = comBoxStockName.SelectedIndex; if (dt.Rows[0][1].ToString() != "null") { string stockId = dt.Rows[index][1].ToString().Trim(); stockTradeBll = new StockTradeBll(); //通过重新生成对象来刷新数据库中的数据 int stockCount = stockTradeBll.SelectStockCount(stockId); labAvailableCount.Text = stockCount.ToString(); NowStockDataModel model = new NowStockDataModel(); model = stockTradeBll.GetNowStockData(stockId); textBoxSellPrice.Text = model.CurrentPrice; labStockNameS.Text = model.StockName; labClosePriceS.Text = double.Parse(model.YesterdayClosePrice).ToString("0.00"); labOpenPriceS.Text = double.Parse(model.TodayOpenPrice).ToString("0.00"); labHighestPriceS.Text = double.Parse(model.HighestPrice).ToString("0.00"); labLowestPriceS.Text = double.Parse(model.LowestPrice).ToString("0.00"); labCurrentPriceS.Text = double.Parse(model.CurrentPrice).ToString("0.00"); labBuyOnePriceS.Text = double.Parse(model.BuyOnePrice).ToString("0.00"); labBuyOneCountS.Text = model.BuyOneCount; labBuyTwoPriceS.Text = double.Parse(model.BuyTwoPrice).ToString("0.00"); labBuyTwoCountS.Text = model.BuyTwoCount; labBuyThreePriceS.Text = double.Parse(model.BuyThreePrice).ToString("0.00"); labBuyThreeCountS.Text = model.BuyThreeCount; labBuyFourPriceS.Text = double.Parse(model.BuyFourPrice).ToString("0.00"); labBuyFourCountS.Text = model.BuyFourCount; labBuyFivePriceS.Text = double.Parse(model.BuyFivePrice).ToString("0.00"); labBuyFiveCountS.Text = model.BuyFiveCount; labSellOnePriceS.Text = double.Parse(model.SellOnePrice).ToString("0.00"); labSellOneCountS.Text = model.SellOneCount; labSellTwoPriceS.Text = double.Parse(model.SellTwoPrice).ToString("0.00"); labSellTwoCountS.Text = model.SellTwoCount; labSellThreePriceS.Text = double.Parse(model.SellThreePrice).ToString("0.00"); labSellThreeCountS.Text = model.SellThreeCount; labSellFourPriceS.Text = double.Parse(model.SellFourPrice).ToString("0.00"); labSellFourCountS.Text = model.SellFourCount; labSellFivePriceS.Text = double.Parse(model.SellFivePrice).ToString("0.00"); labSellFiveCountS.Text = model.SellFiveCount; double growthRate = (double.Parse(model.CurrentPrice) - double.Parse(model.YesterdayClosePrice)) / double.Parse(model.YesterdayClosePrice) * 100; if (growthRate > 0) { labGrowthRateS.Text = "+" + growthRate.ToString("0.00") + "%"; labGrowthRateS.ForeColor = Color.Red; } else { labGrowthRateS.Text = growthRate.ToString("0.00") + "%"; labGrowthRateS.ForeColor = Color.Green; } double stockNum = double.Parse(stockId); if (stockNum >= 600000 && stockNum <= 603998) { stockId = "sh" + stockId; } else if (stockNum >= 000001 && stockNum <= 300489) { stockId = "sz" + stockId; } string pictureSellOne = "http://image.sinajs.cn/newchart/min/n/" + stockId + ".gif"; string pictureSellTwo = "http://image.sinajs.cn/newchart/daily/n/" + stockId + ".gif"; pictureBoxSellOne.ImageLocation = pictureSellOne; pictureBoxSellTwo.ImageLocation = pictureSellTwo; } }