数据访问类:StockDAL
예제 #1
0
        //搜索是否存在代码名
        public bool SearchStCode(string stokename)
        {
            string str = string.Format("select count(1) from T_STOCK where STOCK_CODE like '%{0}%'", stokename);

            D.StockDAL dsi = new D.StockDAL();
            return(dsi.ExistsName(str));
        }
예제 #2
0
        //分析融券卖出量
        public decimal SELLQUANTITYrate(string StockCode)
        {
            decimal[]  Remining = new decimal[5];
            D.StockDAL dsd      = new D.StockDAL();
            M.Stock    ms       = new M.Stock();
            DataSet    ds       = new DataSet();

            ds = dsd.Get5List(StockCode);
            for (int i = 0; i < 5; i++)
            {
                Remining[i] = decimal.Parse(ds.Tables[0].Rows[4 - i][10].ToString());
            }

            decimal[] ReminingCha = new decimal[4];

            for (int i = 0; i < 4; i++)
            {
                ReminingCha[i] = (Remining[i + 1] - Remining[i]) / Remining[i];
            }
            decimal dec;

            dec = (ReminingCha[0] + ReminingCha[1] + ReminingCha[2] + ReminingCha[3]) / 4;

            return(dec);
        }
예제 #3
0
        //数组获取数据库融券余量
        public int[] GETREMAINQUILITY(string StockCode)
        {
            int[] REMAINQUILITY = new int[20];
            D.StockDAL dsd = new D.StockDAL();
            M.Stock ms = new M.Stock();
            DataSet ds = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                REMAINQUILITY[i] = int.Parse(ds.Tables[0].Rows[19 - i][9].ToString());
            }
            return REMAINQUILITY;
        }
예제 #4
0
        //数组获取数据库融资余额
        public decimal[] GETREMAINING(string StockCode)
        {
            decimal[] REMAINING = new decimal[20];
            D.StockDAL dsd = new D.StockDAL();
            M.Stock ms = new M.Stock();
            DataSet ds = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                REMAINING[i] = decimal.Parse(ds.Tables[0].Rows[19 - i][5].ToString());
            }
            return REMAINING;
        }
예제 #5
0
        //数组获取数据库融资买入额
        public decimal[] GETPURCHASES(string StockCode)
        {
            decimal[] PURCHASES = new decimal[20];
            D.StockDAL dsd = new D.StockDAL();
            M.Stock ms = new M.Stock();
            DataSet ds = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                PURCHASES[i] = decimal.Parse(ds.Tables[0].Rows[19 - i][6].ToString());
            }
            return PURCHASES;
        }
예제 #6
0
        //数组获取数据库日期
        public DateTime[] GETDATE(string StockCode)
        {
            DateTime[] DATE = new DateTime[20];
            D.StockDAL dsd = new D.StockDAL();
            M.Stock ms = new M.Stock();
            DataSet ds = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                DATE[i] = DateTime.Parse(ds.Tables[0].Rows[19 - i][2].ToString());
            }
            return DATE;
        }
예제 #7
0
        //数组获取数据库日期
        public DateTime[] GETDATE(string StockCode)
        {
            DateTime[] DATE = new DateTime[20];
            D.StockDAL dsd  = new D.StockDAL();
            M.Stock    ms   = new M.Stock();
            DataSet    ds   = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                DATE[i] = DateTime.Parse(ds.Tables[0].Rows[19 - i][2].ToString());
            }
            return(DATE);
        }
예제 #8
0
        //数组获取数据库融券卖出量
        public int[] GETSELLQUANTITY(string StockCode)
        {
            int[]      SELLQUANTITY = new int[20];
            D.StockDAL dsd          = new D.StockDAL();
            M.Stock    ms           = new M.Stock();
            DataSet    ds           = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                SELLQUANTITY[i] = int.Parse(ds.Tables[0].Rows[19 - i][10].ToString());
            }
            return(SELLQUANTITY);
        }
예제 #9
0
        //数组获取数据库融资买入额
        public decimal[] GETPURCHASES(string StockCode)
        {
            decimal[]  PURCHASES = new decimal[20];
            D.StockDAL dsd       = new D.StockDAL();
            M.Stock    ms        = new M.Stock();
            DataSet    ds        = new DataSet();

            ds = dsd.GetREMAININGList(StockCode);

            for (int i = 0; i < 20; i++)
            {
                PURCHASES[i] = decimal.Parse(ds.Tables[0].Rows[19 - i][6].ToString());
            }
            return(PURCHASES);
        }
예제 #10
0
        //分析融券余量
        public decimal REAMINQUANTITYrate(string StockCode)
        {
            decimal[] Remining = new decimal[5];
               D.StockDAL dsd = new D.StockDAL();
               M.Stock ms = new M.Stock();
               DataSet ds = new DataSet();

               ds = dsd.Get5List(StockCode);
               for (int i = 0; i < 5; i++)
               {
               Remining[i] = decimal.Parse(ds.Tables[0].Rows[4 - i][9].ToString());
               }

               decimal[] ReminingCha = new decimal[4];

               for (int i = 0; i < 4; i++)
               {
               ReminingCha[i] = (Remining[i + 1] - Remining[i]) / Remining[i];
               }
               decimal dec;
               dec = (ReminingCha[0] + ReminingCha[1] + ReminingCha[2] + ReminingCha[3]) / 4;

               return dec;
        }
예제 #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    int flat = 3;//默认数据是最新的
                    Label1.Text = "正在自动爬取中 ,请稍候!";
                    //自动获取最近30天的数据,并存到数据库里

                    D.StockDAL dsd = new D.StockDAL();
                    DateTime tradeDateFlat = DateTime.Now;
                    tradeDateFlat = tradeDateFlat.Date;

                    //判断是否为最新数据
                    if (!dsd.ExistsDate(tradeDateFlat))
                    {
                        try
                        {
                            DateTime tradeDate = DateTime.Now.AddDays(-29);
                            tradeDate = tradeDate.Date;
                            //判断30天的数据是否完整
                            for (int i = 0; i < 30; i++)
                            {
                                //首先从数据库里检索当天的数据,如果没有则到新浪融资融券网爬取当天的数据,并存储到数据库里
                                if (!dsd.ExistsDate(tradeDate))
                                {
                                    //获取当天的数据,并存到数据库里
                                    StockManager.BeginFunction(tradeDate);
                                }
                                tradeDate = tradeDate.AddDays(1);
                            }
                            flat = 1;
                        }
                        catch
                        {
                            flat = 0;
                        }

                    }
                    else
                    {
                        flat = 3;
                    }
                    if (flat == 3)
                    {
                        Label1.Text = "数据已经是最新的啦";

                    }
                    else
                    {
                        if (flat == 1)
                        {
                            Label1.Text = "爬取成功";
                        }
                        else
                        { Label1.Text = "爬取失败,当天数据不存在或者你未联网!"; }
                    }
                }
                catch
                {
                    Label1.Text = "爬取失败,当天数据不存在或者你未联网!";
                }
            }
        }
예제 #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    int flat = 3;//默认数据是最新的
                    Label1.Text = "正在自动爬取中 ,请稍候!";
                    //自动获取最近30天的数据,并存到数据库里

                    D.StockDAL dsd           = new D.StockDAL();
                    DateTime   tradeDateFlat = DateTime.Now;
                    tradeDateFlat = tradeDateFlat.Date;

                    //判断是否为最新数据
                    if (!dsd.ExistsDate(tradeDateFlat))
                    {
                        try
                        {
                            DateTime tradeDate = DateTime.Now.AddDays(-29);
                            tradeDate = tradeDate.Date;
                            //判断30天的数据是否完整
                            for (int i = 0; i < 30; i++)
                            {
                                //首先从数据库里检索当天的数据,如果没有则到新浪融资融券网爬取当天的数据,并存储到数据库里
                                if (!dsd.ExistsDate(tradeDate))
                                {
                                    //获取当天的数据,并存到数据库里
                                    StockManager.BeginFunction(tradeDate);
                                }
                                tradeDate = tradeDate.AddDays(1);
                            }
                            flat = 1;
                        }
                        catch
                        {
                            flat = 0;
                        }
                    }
                    else
                    {
                        flat = 3;
                    }
                    if (flat == 3)
                    {
                        Label1.Text = "数据已经是最新的啦";
                    }
                    else
                    {
                        if (flat == 1)
                        {
                            Label1.Text = "爬取成功";
                        }
                        else
                        {
                            Label1.Text = "爬取失败,当天数据不存在或者你未联网!";
                        }
                    }
                }
                catch
                {
                    Label1.Text = "爬取失败,当天数据不存在或者你未联网!";
                }
            }
        }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string StockCode;
                    StockCode = Request.QueryString["STOCK_CODE"].ToString();
                    //定义一个数组
                    ShowChart(StockCode);
                    D.StockDAL dsd = new D.StockDAL();
                    M.Stock    MS  = new M.Stock();
                    MS = dsd.GetModelName(StockCode);
                    string StockName = MS.STOCK_NAME;

                    B.StockAnalyse bsa                = new B.StockAnalyse();
                    decimal        REMININGrate       = bsa.REMININGrate(StockCode);
                    decimal        URCHASESrate       = bsa.PURCHASESrate(StockCode);
                    decimal        REAMINQUANTITYrate = bsa.REAMINQUANTITYrate(StockCode);
                    decimal        SELLQUANTITYrate   = bsa.SELLQUANTITYrate(StockCode);
                    decimal        Conclusion         = bsa.Conclusion(StockCode);

                    lbl1.Text = (REMININGrate * 100).ToString("0.00") + "%";
                    lbl2.Text = (URCHASESrate * 100).ToString("0.00") + "%";
                    lbl3.Text = (REAMINQUANTITYrate * 100).ToString("0.00") + "%";
                    lbl4.Text = (SELLQUANTITYrate * 100).ToString("0.00") + "%";
                    lbl5.Text = (Conclusion * 100).ToString("0.00") + "%";
                    #region//分析数据
                    StringBuilder strconclusion = new StringBuilder();
                    strconclusion.Append(StockName);
                    if (REMININGrate > 0)
                    {
                        strconclusion.Append("股票的融资余额在一周内同比增长了" + lbl1.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("股票的融资余额在一周内同比减少了" + lbl1.Text + ",");
                    }
                    if (URCHASESrate > 0)
                    {
                        strconclusion.Append("融资买入额在一周内同比增长了" + lbl2.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融资买入额在一周内同比减少了" + lbl2.Text + ",");
                    }
                    if (REAMINQUANTITYrate > 0)
                    {
                        strconclusion.Append("融券余量在一周内同比增长了" + lbl3.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融券余量在一周内同比减少了" + lbl3.Text + ",");
                    }
                    if (SELLQUANTITYrate > 0)
                    {
                        strconclusion.Append("融券卖出量在一周内同比增长了" + lbl4.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融券卖出量在一周内同比减少了" + lbl4.Text + ",");
                    }
                    if (Conclusion > 0)
                    {
                        strconclusion.Append("平均在一周内同比增长了" + lbl5.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("平均在一周内同比减少了" + lbl5.Text + ",");
                    }

                    if (Conclusion < 0.05M)
                    {
                        strconclusion.Append("变现低落,建议持股即可,必要时可适当卖出.");
                    }
                    else
                    {
                        if (0.05M <= Conclusion || Conclusion < 0.1M)
                        {
                            strconclusion.Append("低开高走,表现平淡,投资者对未来本股的行情出现分歧、结合其一周以来的涨幅,走强势头尚未结束,建议继续持股.");
                        }
                        else
                        {
                            if (0.1M <= Conclusion || Conclusion < 0.12M)
                            {
                                strconclusion.Append("表现强势,相应股票表现不俗,适当关注这一现象.");
                            }
                            else
                            {
                                if (0.12M <= Conclusion || Conclusion < 0.15M)
                                {
                                    strconclusion.Append("强势整理,强支撑,而且成交量也保持良好水平,技术指标亦多有配合。建议密切关注.");
                                }
                                else
                                {
                                    strconclusion.Append("表现强势,属于强力股,资金大头,个人可适当跟盘操作,公司可考虑强力入股.");
                                }
                            }
                        }
                    }
                    #endregion
                    string strconclusion2 = strconclusion.ToString();
                    lbl6.Text = strconclusion2;
                }
                catch
                {
                    Server.Transfer("404error.aspx", true);
                }
            }
        }
예제 #14
0
 //搜索是否存在股票名
 public bool SearchStName(string stokename)
 {
     string str = string.Format("select count(1) from T_STOCK where STOCK_NAME like '%{0}%'", stokename);
     D.StockDAL dsi = new D.StockDAL();
     return dsi.ExistsName(str);
 }
예제 #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string StockCode;
                    StockCode = Request.QueryString["STOCK_CODE"].ToString();
                    //定义一个数组
                    ShowChart(StockCode);
                    D.StockDAL dsd=new D.StockDAL ();
                    M.Stock MS=new M.Stock ();
                    MS=dsd.GetModelName(StockCode);
                    string StockName=MS.STOCK_NAME;

                     B.StockAnalyse bsa = new B.StockAnalyse();
                    decimal REMININGrate=bsa.REMININGrate(StockCode);
                    decimal URCHASESrate=bsa.PURCHASESrate(StockCode);
                    decimal REAMINQUANTITYrate=bsa.REAMINQUANTITYrate(StockCode);
                    decimal SELLQUANTITYrate=bsa.SELLQUANTITYrate(StockCode);
                    decimal Conclusion=bsa.Conclusion(StockCode);

                    lbl1.Text = ( REMININGrate* 100).ToString("0.00") + "%";
                    lbl2.Text = (URCHASESrate * 100).ToString("0.00") + "%";
                    lbl3.Text = (REAMINQUANTITYrate * 100).ToString("0.00") + "%";
                    lbl4.Text = (SELLQUANTITYrate * 100).ToString("0.00") + "%";
                    lbl5.Text = ( Conclusion* 100).ToString("0.00") + "%";
                    #region//分析数据
                    StringBuilder strconclusion = new StringBuilder();
                    strconclusion.Append(StockName);
                    if (REMININGrate > 0)
                    {
                        strconclusion.Append("股票的融资余额在一周内同比增长了" + lbl1.Text+",");
                    }
                    else
                    {
                        strconclusion.Append("股票的融资余额在一周内同比减少了" + lbl1.Text + ",");
                    }
                    if (URCHASESrate > 0)
                    {
                        strconclusion.Append("融资买入额在一周内同比增长了" + lbl2.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融资买入额在一周内同比减少了" + lbl2.Text + ",");
                    }
                    if (REAMINQUANTITYrate > 0)
                    {
                        strconclusion.Append("融券余量在一周内同比增长了" + lbl3.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融券余量在一周内同比减少了" + lbl3.Text + ",");
                    }
                    if (SELLQUANTITYrate > 0)
                    {
                        strconclusion.Append("融券卖出量在一周内同比增长了" + lbl4.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("融券卖出量在一周内同比减少了" + lbl4.Text + ",");
                    }
                    if (Conclusion > 0)
                    {
                        strconclusion.Append("平均在一周内同比增长了" + lbl5.Text + ",");
                    }
                    else
                    {
                        strconclusion.Append("平均在一周内同比减少了" + lbl5.Text + ",");
                    }

                    if (Conclusion < 0.05M)
                    {
                        strconclusion.Append("变现低落,建议持股即可,必要时可适当卖出.");
                    }
                    else
                    {
                        if (0.05M <= Conclusion || Conclusion <0.1M)
                        {
                            strconclusion.Append("低开高走,表现平淡,投资者对未来本股的行情出现分歧、结合其一周以来的涨幅,走强势头尚未结束,建议继续持股.");
                        }
                        else
                        {
                            if (0.1M <= Conclusion || Conclusion <0.12M)
                            {
                                strconclusion.Append("表现强势,相应股票表现不俗,适当关注这一现象.");
                            }
                            else
                            {
                                if (0.12M <= Conclusion || Conclusion < 0.15M)
                                {
                                    strconclusion.Append("强势整理,强支撑,而且成交量也保持良好水平,技术指标亦多有配合。建议密切关注.");
                                }
                                else
                                {
                                    strconclusion.Append("表现强势,属于强力股,资金大头,个人可适当跟盘操作,公司可考虑强力入股.");
                                }
                            }
                        }
                    }
            #endregion
                    string strconclusion2 = strconclusion.ToString();
                    lbl6.Text = strconclusion2;
                }
                catch
                {
                    Server.Transfer("404error.aspx", true);
                }

             }
        }
예제 #16
0
        /// <summary>
        /// 爬取新浪融资融券网当天的交易信息,并存储到数据库里
        /// </summary>
        /// <param name="tradeDate"></param>
        /// <returns></returns>
        public static int BeginFunction(DateTime tradeDate)
        {
            int flat = 0;
            string url = "http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/rzrq/index.phtml?tradedate=" + tradeDate.Date.ToString("yyyy-MM-dd");
            //得到指定Url的源码
            string strWebContent = GetWebContent(url);

                #region//取出和数据有关的那段源码
                int iStart = strWebContent.IndexOf("融资融券交易明细");
                if (iStart > 0)
                {
                    string strTableStart = strWebContent.Substring(0, iStart);
                    string strTableEnd = strWebContent.Substring(iStart);
                    strTableStart = strTableStart.Substring(strTableStart.LastIndexOf("<table"));
                    strTableEnd = strTableEnd.Substring(0, strTableEnd.IndexOf("</table>") + 8);
                    string strWeb = strTableStart + strTableEnd;
                    string[] trArray = Regex.Split(strWeb, @"<tr class=""head"">", RegexOptions.IgnoreCase);
                    for (int i = 0; i < trArray.Length; i++)
                    {
                        string[] tdArray = Regex.Split(trArray[i], @"<td style=""background-color:#ffffff"">", RegexOptions.IgnoreCase);
                        if (tdArray.Length == 12)
                        {
                            string stockCode = string.Empty;
                            string stockName = string.Empty;
                            decimal remaining = 0;
                            decimal purchases = 0;
                            decimal payments = 0;
                            decimal remainSum = 0;
                            int remainQuantity = 0;
                            int sellQuantity = 0;
                            int reimbursedFloat = 0;
                            decimal securitiesBalances = 0;

                            stockCode = tdArray[2];
                            stockCode = stockCode.Substring(0, stockCode.IndexOf("</a>"));
                            stockCode = stockCode.Substring(stockCode.LastIndexOf(">") + 1);

                            stockName = tdArray[3];
                            stockName = stockName.Substring(0, stockName.IndexOf("</a>"));
                            stockName = stockName.Substring(stockName.LastIndexOf(">") + 1);

                            string strRemaining = tdArray[4].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Trim();
                            if (strRemaining != string.Empty)
                                remaining = decimal.Parse(strRemaining);

                            string strPurchases = tdArray[5].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Trim();
                            if (strPurchases != string.Empty)
                                purchases = decimal.Parse(strPurchases);

                            string strPayments = tdArray[6].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Trim();
                            if (strPayments != string.Empty)
                                payments = decimal.Parse(strPayments);

                            string strRemainSum = tdArray[7].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Trim();
                            if (strRemainSum != string.Empty)
                                remainSum = decimal.Parse(strRemainSum);

                            string strRemainQuantity = tdArray[8].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Replace(",", "").Trim();
                            if (strRemainQuantity != string.Empty)
                                remainQuantity = int.Parse(strRemainQuantity);

                            string strSellQuantity = tdArray[9].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Replace(",", "").Trim();
                            if (strSellQuantity != string.Empty)
                                sellQuantity = int.Parse(strSellQuantity);

                            string strReimbursedFloat = tdArray[10].Replace("</td>", "").Replace("\n>", "").Replace("--", "").Replace(",", "").Trim();
                            if (strReimbursedFloat != string.Empty)
                                reimbursedFloat = int.Parse(strReimbursedFloat);

                            try
                            {
                                string strSecuritiesBalances = tdArray[11].Replace("</td>", "").Replace("</tr>", "").Replace("</table>", "").Replace("\n>", "").Replace("--", "").Trim();
                                if (strSecuritiesBalances != string.Empty)
                                    securitiesBalances = decimal.Parse(strSecuritiesBalances);
                            }
                            catch (Exception e)
                            {
                                string message = e.Message;
                            }

                            StockWebApp.Model.Stock swm = new Stock();
                            StockWebApp.DAL.StockDAL swd = new StockDAL();

                            swm.STOCK_CODE = stockCode;
                            swm.STOCK_NAME = stockName;
                            swm.REMAINING = remaining;
                            swm.PURCHASES = purchases;
                            swm.PAYMENTS = payments;
                            swm.REMAIN_SUM = remainSum;
                            swm.REMAIN_QUANTITY = remainQuantity;
                            swm.SELL_QUANTITY = sellQuantity;
                            swm.REIMBURSED_FLOAT = reimbursedFloat;
                            swm.SECURITIES_BALANCES = securitiesBalances;
                            swm.TRADE_DATE = tradeDate;
                            swm.CREATED = DateTime.Now;
                            flat = swd.Add(swm);
                        }
                    }
                }
                if (flat != 0)
                {
                    return 1;//爬取成功
                }
                else return 0;//爬取失败
                #endregion
        }