Esempio n. 1
0
        /// <summary>
        /// 刷新我的持仓
        /// </summary>
        private void MyPosition()
        {
            MyPositionBll myPositionBll = new MyPositionBll();
            DataTable     dt            = new DataTable();

            dt = myPositionBll.GetUserPosition();
            dataGridViewMyPosition.DataSource = dt;
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 买入股票
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBuy_Click(object sender, EventArgs e)
        {
            if (textBoxBuyCount.Text == "" || textBoxStockId.Text == "")
            {
                return;
            }
            stockTradeBll.UpdateUserInfo();
            string stockId;
            int    buyCount;

            stockId  = textBoxStockId.Text;
            buyCount = int.Parse(textBoxBuyCount.Text);
            bool   IsValid       = stockTradeBll.StockIdValid(stockId);
            double invaliable    = stockTradeBll.GetUserInvaliableFund();
            double currentPrice  = stockTradeBll.GetCurrentStockPrice(stockId);
            int    maxInvaliable = ((int)(invaliable / currentPrice));
            int    buyStockCount = int.Parse(textBoxBuyCount.Text);

            if (IsValid && buyStockCount < maxInvaliable)
            {
                bool IsBuySuccess = stockTradeBll.BuyStock(stockId, buyCount);
                if (IsBuySuccess)
                {
                    string        available     = (LoginInfo.loginInfo.AvailableFund - currentPrice * buyStockCount).ToString();
                    MyPositionBll myPositionBll = new MyPositionBll();
                    myPositionBll.UpdateAvailableFund(available);//卖出股票后,更新总资产、可用资金
                    labMaxBuyCount.Text = (maxInvaliable - buyStockCount).ToString();
                    MessageBox.Show("股票买入成功", "信息提示", MessageBoxButtons.OK);
                    UpdateUserAssetStatus();
                    MyPosition();
                }
                else
                {
                    MessageBox.Show("股票买入失败", "信息提示", MessageBoxButtons.OK);
                }
            }
            else
            {
                MessageBox.Show("股票买入失败", "信息提示", MessageBoxButtons.OK);
            }
        }