Exemple #1
0
 /// <summary>
 /// 更新DataGrid的市场信息
 /// </summary>
 /// <param name="listUrlStock"></param>
 /// <param name="dgv"></param>
 /// <param name="stockNoColName"></param>
 /// <param name="priceColName"></param>
 /// <param name="updateTimeColName"></param>
 /// <param name="riseColName"></param>
 /// <param name="riseRateColName"></param>
 /// <param name="backTable"></param>
 public static void ShowDataGridViewMarket(List <M_UrlStock> listUrlStock, DataGridView dgv, string stockNoColName, string priceColName, string updateTimeColName, string riseColName, string riseRateColName, DataTable backTable)
 {
     if (dgv.Rows.Count == backTable.Rows.Count)
     {
         for (int i = 0; i < dgv.Rows.Count; i++)
         {
             for (int j = 0; j < backTable.Rows.Count; j++)
             {
                 if (dgv.Rows[i].Cells[stockNoColName].Value.ToString() == backTable.Rows[j]["StockNo"].ToString())
                 {
                     dgv.Rows[i].Cells[priceColName].Value      = backTable.Rows[j][priceColName].ToString();
                     dgv.Rows[i].Cells[updateTimeColName].Value =
                         backTable.Rows[j][updateTimeColName].ToString();
                     M_UrlStock stock =
                         CommonFunction.Ger_M_UrlStockFromList(
                             dgv.Rows[i].Cells[stockNoColName].Value.ToString(),
                             listUrlStock);
                     decimal riseNum =
                         decimal.Parse(
                             Math.Round(stock.Price - stock.YesterDayPrice, 2, MidpointRounding.AwayFromZero)
                             .ToString());
                     decimal riseNumRate =
                         decimal.Parse(
                             Math.Round((stock.Price - stock.YesterDayPrice) / stock.YesterDayPrice * 100, 2,
                                        MidpointRounding.AwayFromZero)
                             .ToString());
                     if (Math.Abs(riseNumRate) > 50)
                     {
                         riseNumRate = 0;
                         riseNum     = 0;
                     }
                     dgv.Rows[i].Cells[riseColName].Value     = riseNum;
                     dgv.Rows[i].Cells[riseRateColName].Value = string.Format("{0}%", riseNumRate);
                     Color color;
                     if (riseNum >= 0)
                     {
                         color = Color.Red;
                     }
                     else
                     {
                         color = Color.Green;
                     }
                     dgv.Rows[i].Cells[riseColName].Style.ForeColor     = color;
                     dgv.Rows[i].Cells[riseRateColName].Style.ForeColor = color;
                     dgv.Rows[i].Cells[priceColName].Style.ForeColor    = color;
                 }
             }
         }
     }
     else
     {
         dgv.DataSource = backTable;
     }
 }
Exemple #2
0
        /// <summary>
        /// 下载新浪服务器的股票信息 单只
        /// </summary>
        /// <param name="stockNo">股票代码</param>
        /// <returns></returns>
        public static M_UrlStock GetNowStockInfo(string stockNo)
        {
            M_UrlStock    stockInfo   = new M_UrlStock();
            List <string> listStockNo = new List <string>()
            {
                stockNo
            };
            string            urlContent   = GetUrlStockContent(listStockNo);
            List <M_UrlStock> listUrlStock = new List <M_UrlStock>();

            GetUrlInfo(urlContent, ref listUrlStock);
            if (listUrlStock.Count > 0)
            {
                stockInfo = listUrlStock[0];
            }
            return(stockInfo);
        }
Exemple #3
0
        /// <summary>
        /// 分解Url反回的信息(递归思想)
        /// </summary>
        public static void GetUrlInfo(string strUrlValue, ref List <M_UrlStock> listUrlStock)
        {
            M_UrlStock urlstock = new M_UrlStock();
            int        index1   = strUrlValue.IndexOf("=");

            if (index1 == -1)
            {
                return;
            }
            string stockNo = strUrlValue.Substring(index1 - 6, 6);

            urlstock.StockNo = stockNo;
            string str1   = strUrlValue.Substring(index1 + 2, strUrlValue.Length - index1 - 2);
            int    index2 = str1.IndexOf(";");

            if (index2 == -1)
            {
                return;
            }
            string        info = str1.Substring(0, index2 - 1);
            List <string> list = new List <string>(info.Split(','));

            if (list.Count < 30)
            {
                return;
            }
            urlstock.Price = Convert.ToDouble(list[3]);
            //如果当前价为0,当前价为昨天股价
            if (urlstock.Price <= 0.0)
            {
                urlstock.Price = Convert.ToDouble(list[2]);
            }
            urlstock.UpdateTime     = Convert.ToDateTime(list[30] + " " + list[31]);
            urlstock.YesterDayPrice = Convert.ToDouble(list[2]);
            urlstock.StockName      = list[0];
            if (urlstock.Price > 0)
            {
                listUrlStock.Add(urlstock);
            }
            //listUrlInfo.Add(info);
            string otherStr = str1.Substring(index2 + 1, str1.Length - index2 - 1);

            GetUrlInfo(otherStr, ref listUrlStock);
        }
Exemple #4
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            int InitNo = 600000;
            List <M_UrlStock> listStock = new List <M_UrlStock>();

            while (InitNo < 610000)
            {
                M_UrlStock stock = CommonFunction.GetNowStockInfo(InitNo.ToString());
                if (stock != null && !string.IsNullOrEmpty(stock.StockName))
                {
                    listStock.Add(stock);
                }
                InitNo++;
            }
            InitNo = 0;
            while (InitNo < 10000)
            {
                M_UrlStock stock = CommonFunction.GetNowStockInfo(string.Format("00{0}", InitNo.ToString()));
                if (stock != null && !string.IsNullOrEmpty(stock.StockName))
                {
                    listStock.Add(stock);
                }
                InitNo++;
            }
            InitNo = 300000;
            while (InitNo < 310000)
            {
                M_UrlStock stock = CommonFunction.GetNowStockInfo(InitNo.ToString());
                if (stock != null && !string.IsNullOrEmpty(stock.StockName))
                {
                    listStock.Add(stock);
                }
                InitNo++;
            }
            //MessageBox.Show("共找到上证股票数" + listStock.Count + "只");
            SqliteDBUtility.DbHelperSQLite.ExecuteSql("delete from StockInfo");
            foreach (var item in listStock)
            {
                string insertSql = string.Format("insert into StockInfo (StockNo,StockName) values ('{0}','{1}')",
                                                 item.StockNo, item.StockName);
                SqliteDBUtility.DbHelperSQLite.ExecuteSql(insertSql);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string     stockNo  = txtStockNo.Text.Trim();
            M_UrlStock urlStock = CommonFunction.GetNowStockInfo(stockNo);

            if (ExpectStock.Exists(stockNo))
            {
                MessageBox.Show("此股票已存在!");
                return;
            }
            if (urlStock == null || string.IsNullOrEmpty(urlStock.StockNo))
            {
                return;
            }
            M_ExpectStock expectStock = new M_ExpectStock();

            expectStock.StockNo     = urlStock.StockNo;
            expectStock.StockName   = urlStock.StockName;
            expectStock.Price       = urlStock.Price;
            expectStock.ExpectPrice = double.Parse(numExpectPrice.Value.ToString());
            expectStock.UpdateTime  = urlStock.UpdateTime;
            ExpectStock.Add(expectStock);
        }