Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            NowStockDataDal   nowStockDataDal = new NowStockDataDal();
            NowStockDataModel model           = nowStockDataDal.GetNowStockData(textBox1.Text);

            if (model != null)
            {
                label1.Text  = "";
                label1.Text += model.StockId + " " + model.StockName + " " + model.TodayOpenPrice + " " + model.YesterdayClosePrice + " " + model.CurrentPrice + " " + model.HighestPrice + " " + model.LowestPrice + model.BuyOneCount + " " + model.BuyOnePrice + " " + model.SellOneCount + " " + model.SellOnePrice;
            }
        }
        /// <summary>
        /// 获取当前用户持仓信息
        /// </summary>
        /// <returns>返回当前用户持仓信息</returns>
        public DataTable GetUserPosition()
        {
            DataTable dt = myPosition.GetUserPositon();

            if (dt == null)
            {
                return(null);
            }
            DataTable dtPositon = new DataTable();

            dtPositon.Columns.Add("number", typeof(int));
            dtPositon.Columns.Add("stockId", typeof(string));
            dtPositon.Columns.Add("stockName", typeof(string));
            dtPositon.Columns.Add("growthRate", typeof(string));
            dtPositon.Columns.Add("totalEarn", typeof(string));
            dtPositon.Columns.Add("buyPrice", typeof(string));
            dtPositon.Columns.Add("buyCount", typeof(string));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NowStockDataModel model       = new NowStockDataModel();
                NowStockDataDal   nowStockDal = new NowStockDataDal();
                string            stockId     = dt.Rows[i][1].ToString().Trim();
                model = nowStockDal.GetNowStockData(stockId);
                double growthRate = (double.Parse(model.CurrentPrice) - double.Parse(dt.Rows[i][3].ToString())) / double.Parse(dt.Rows[i][3].ToString()) * 100;
                double totalEarn  = (double.Parse(model.CurrentPrice) - double.Parse(dt.Rows[i][3].ToString())) * int.Parse(dt.Rows[i][4].ToString());
                string growthRateStr;
                if (growthRate > 0)
                {
                    growthRateStr = "+" + growthRate.ToString("0.00") + "%";
                }
                else
                {
                    growthRateStr = growthRate.ToString("0.00") + "%";
                }
                DataRow row = dtPositon.NewRow();
                row[0] = i + 1;
                row[1] = stockId;
                row[2] = dt.Rows[i][2].ToString().Trim();
                row[3] = growthRateStr;
                row[4] = totalEarn.ToString("0.00");
                row[5] = dt.Rows[i][3].ToString().Trim();
                row[6] = dt.Rows[i][4].ToString().Trim();
                dtPositon.Rows.Add(row);
            }
            return(dtPositon);
        }