Exemplo n.º 1
0
        private void btnReport_Click(object sender, EventArgs e)
        {
            var rptName     = $"Report[{txtName.Text}][{DateTime.Now.ToString("yyyy-MM-dd HHmmss")}].html";
            var outPath     = Path.Combine(Application.StartupPath, "Report");
            var outFileName = Path.Combine(outPath, rptName);

            Task.Run(() =>
            {
                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }
                var fileName = StockHelper.MakeReport(txtId.Text, outFileName);
                if (DialogResult.Yes == MsgBox.ShowQuestion(
                        message: "消息内容",                                // 消息摘要
                        attach: "",                                     // 详细信息
                        caption: "消息",                                  // 窗口标题
                        buttons: MessageBoxButtons.YesNo,               // 按钮样式
                        defaultButton: MessageBoxDefaultButton.Button1, // 默认按钮
                        expand: false,                                  // 是否展开详细
                        buttonsText: new[] { "Yes", "No" } // 按钮文字
                        ))
                {
                    try
                    {
                        Process.Start($"{outFileName}");
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }
                //MsgBox.ShowInfo(
                //    message: "OK", // 消息摘要
                //    attach: fileName,  // 详细信息
                //    caption: "消息", // 窗口标题
                //    expand: false, // 是否展开详细信息
                //    buttonText: "OK" // 确定按钮文字
                //);
            });
        }
Exemplo n.º 2
0
        private void btnRiskNDay_Click(object sender, EventArgs e)
        {
            Task.Run(() => {
                List <RowData> lst    = new List <RowData>();
                List <Codes> codeList = new List <Codes>();

                var riskDays = 3;
                var frm      = new FrmSetRiskDay();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    riskDays = frm.RiskDays;
                }

                var outPath = Path.Combine(Application.StartupPath, "Report");
                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }
                var fileName = Path.Combine(outPath, $"RiskNDaysStock[{DateTime.Now.ToString("yyyyMMddhhmmss")}].html");

                var swReport       = new StreamWriter(fileName, false, Encoding.UTF8);
                var reportDateTime = $"{DateTime.Now.Year}{DateTime.Now.Month.ToString().PadLeft(2, '0')}{DateTime.Now.Day.ToString().PadLeft(2, '0')}-{DateTime.Now.Hour.ToString().PadLeft(2, '0')}{DateTime.Now.Minute.ToString().PadLeft(2, '0')}";
                swReport.WriteLine($"<!DOCTYPE html>");
                swReport.WriteLine($"<html>");
                swReport.WriteLine($"<head>");
                swReport.WriteLine($"<meta charset=\"UTF-8\">");
                swReport.WriteLine($"<link rel='stylesheet' href='https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>  ");
                swReport.WriteLine($"<script src='https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>");
                swReport.WriteLine($"<script src='https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js'></script>");
                swReport.WriteLine($"<title>Rising Stocks Report</title>");
                swReport.WriteLine($"</head>");
                swReport.WriteLine($"<body>");

                var sz   = "sh000001"; // 上证指数
                var sc   = "sz399001"; // 深证成指
                var cy   = "sz399006"; // 创业板指
                var kc50 = "sh000688"; // 科创50指数
                var risingDetailBuilder = new StringBuilder();
                risingDetailBuilder.Append($"<table class='table table-striped table-bordered table-hover'>");
                risingDetailBuilder.Append($"<tr><td>&nbsp;</td><td><a target='_blank' href='http://quote.eastmoney.com/{sz}.html'>上证指数</a><br>{sz}</td><td><image src='data:image/png;base64,{StockHelper.GetFenShiImageBase64(sz)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetRiKXianImageBase64(sz)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetZhouKXianImageBase64(sz)}' /></td></tr>");
                risingDetailBuilder.Append($"<tr><td>&nbsp;</td><td><a target='_blank' href='http://quote.eastmoney.com/{sc}.html'>深证成指</a><br>{sc}</td><td><image src='data:image/png;base64,{StockHelper.GetFenShiImageBase64(sc)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetRiKXianImageBase64(sc)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetZhouKXianImageBase64(sc)}' /></td></tr>");
                risingDetailBuilder.Append($"<tr><td>&nbsp;</td><td><a target='_blank' href='http://quote.eastmoney.com/{cy}.html'>创业板指</a><br>{cy}</td><td><image src='data:image/png;base64,{StockHelper.GetFenShiImageBase64(cy)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetRiKXianImageBase64(cy)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetZhouKXianImageBase64(cy)}' /></td></tr>");
                risingDetailBuilder.Append($"<tr><td>&nbsp;</td><td><a target='_blank' href='http://quote.eastmoney.com/{kc50}.html'>科创50指数</a><br>{kc50}</td><td><image src='data:image/png;base64,{StockHelper.GetFenShiImageBase64(kc50)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetRiKXianImageBase64(kc50)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetZhouKXianImageBase64(kc50)}' /></td></tr>");
                int posYang = 0;

                var dt = SqlServer.Instance.GetDataTable($"SELECT a.code, a.Exchange, b.name FROM CODES as a left join StockStatus as b on a.code = b.code");
                foreach (DataRow dr in dt.Rows)
                {
                    codeList.Add(new Codes {
                        Code = dr["Code"].ToString(), Exchange = dr["Exchange"].ToString(), Name = dr["Name"].ToString()
                    });
                }
                foreach (var code in codeList)
                {
                    var name = code.Name;
                    if (name.StartsWith("ST") ||
                        name.StartsWith("*ST") ||
                        name.StartsWith("N") ||
                        name.Contains("退")
                        )
                    {
                        continue;
                    }
                    var hisDateStart = DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd");
                    var hisDateEnd   = DateTime.Now.ToString("yyyy-MM-dd");

                    var dtR  = SqlServer.Instance.GetDataTable($"select * from StockHistory where Code='{code.Code}'");
                    var rank = string.Empty;

                    #region 计算连续阳线天数
                    if (dtR.Rows.Count >= riskDays)
                    {
                        var cnt = 0;
                        foreach (DataRow dr in dtR.Rows)
                        {
                            if ((decimal)dr["ShouPan"] > (decimal)dr["JinKai"])
                            {
                                cnt++;
                            }
                            else
                            {
                                cnt = 0;
                                break;
                            }
                        }
                        if (cnt > 0 && cnt == dtR.Rows.Count) // 所有天都是阳线收盘
                        {
                            ++posYang;
                            var industry     = string.Empty;
                            var industryHref = "#";

                            var __dt = SqlServer.Instance.GetDataTable($"select * from StockIndustry where Code='{code.Code}'");
                            if (__dt.Rows.Count > 0)
                            {
                                industry     = __dt.Rows[0]["Industry"].ToString();
                                industryHref = __dt.Rows[0]["Href"].ToString();
                            }
                            risingDetailBuilder.Append($"<tr><td style='color:red;'>R{riskDays}-{posYang}</td><td><a target='_blank' href='http://quote.eastmoney.com/{code.Code}.html'>{name}</a><br />{code.Exchange}{code.Code}<br /><a target='_blank' href='{industryHref}'>{industry}</a>{rank}</td><td><image src='data:image/png;base64,{StockHelper.GetFenShiImageBase64(code.Exchange + code.Code)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetRiKXianImageBase64(code.Exchange + code.Code)}' /></td><td><image src='data:image/png;base64,{StockHelper.GetZhouKXianImageBase64(code.Exchange + code.Code)}' /></td></tr>");
                        }
                    }
                    #endregion
                }

                risingDetailBuilder.Append($"</table>");
                swReport.WriteLine(risingDetailBuilder);
                swReport.WriteLine($"<div style='margin:0;padding:0;text-align:center'>");
                swReport.WriteLine($"<h5>生成时间:{reportDateTime}</h5>");
                swReport.WriteLine($"<h5>软件版本:{2.1}</h5>");
                swReport.WriteLine($"</div>");
                swReport.WriteLine($"</body>");
                swReport.WriteLine($"<html>");
                swReport.Close();

                Invoke(new Action(() => {
                    MsgBox.ShowInfo(
                        message: "OK",    // 消息摘要
                        attach: fileName, // 详细信息
                        caption: "消息",    // 窗口标题
                        expand: false,    // 是否展开详细信息
                        buttonText: "OK"  // 确定按钮文字
                        );
                }));
            });
        }
Exemplo n.º 3
0
        private void btnGetData_Click(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                List <Codes> codeList = new List <Codes>();
                var startDate         = txtStartDate.Text;
                var endDate           = txtEndDate.Text;
                var dt = SqlServer.Instance.GetDataTable($"SELECT * FROM CODES");
                foreach (DataRow dr in dt.Rows)
                {
                    codeList.Add(new Codes {
                        Code = dr["Code"].ToString(), Exchange = dr["Exchange"].ToString()
                    });
                }
                SqlServer.Instance.ExcuteSQL($"delete from StockHistory");

                foreach (var stockCode in codeList)
                {
                    var q        = $"https://q.stock.sohu.com/hisHq?code=cn_{stockCode.Code}&start={startDate}&end={endDate}&stat=1&order=D&period=d&callback=historySearchHandler&rt=jsonp";
                    var ___s     = StockHelper.GetHtmltxt(q);
                    var jsonData = ___s.Replace("historySearchHandler(", string.Empty).Replace("\n", string.Empty).TrimEnd(')');
                    if (jsonData == "{}")
                    {
                        continue;
                    }
                    var jArr   = JsonConvert.DeserializeObject(jsonData) as JArray;
                    var status = jArr[0]["status"].ToString();
                    if (status != "0")
                    {
                        continue;
                    }
                    var _arrJsonData = jArr[0]["hq"] as JArray;
                    foreach (var data in _arrJsonData)
                    {
                        var row      = new RowData();
                        row.Code     = stockCode.Code;
                        row.Exchange = stockCode.Exchange;
                        row.HisDate  = Convert.ToDateTime(data[0], new DateTimeFormatInfo {
                            ShortDatePattern = "yyyy-MM-dd"
                        });
                        decimal.TryParse(data[1].ToString(), out decimal jinKai);                      // 今开
                        decimal.TryParse(data[2].ToString(), out decimal shouPan);                     // 收盘
                        decimal.TryParse(data[3].ToString(), out decimal shangZhangJinE);              // 上涨金额
                        decimal.TryParse(data[4].ToString().TrimEnd('%'), out decimal shangZhangFuDu); // 上涨幅度
                        decimal.TryParse(data[5].ToString(), out decimal zuiDi);                       // 最低
                        decimal.TryParse(data[6].ToString(), out decimal zuiGao);                      // 最高
                        decimal.TryParse(data[7].ToString(), out decimal chengJiaoLiang);              // 成交量
                        decimal.TryParse(data[8].ToString(), out decimal chengJiaoE);                  // 成交额
                        decimal.TryParse(data[9].ToString().TrimEnd('%'), out decimal huanShouLv);     // 换手率
                        row.JinKai         = jinKai;
                        row.ZuiGao         = zuiGao;
                        row.ShangZhangJinE = shangZhangJinE;
                        row.ShangZhangFuDu = shangZhangFuDu;
                        row.ZuiDi          = zuiDi;
                        row.ShouPan        = shouPan;
                        row.ChengJiaoLiang = chengJiaoLiang;
                        row.ChengJiaoE     = chengJiaoE;
                        row.HuanShouLv     = huanShouLv;

                        var cmd = new SqlCommand($"INSERT INTO StockHistory(Code, Exchange, HisDate, JinKai, ZuiGao, ShangZhangJinE, ShangZhangFuDu, ZuiDi, ShouPan, ChengJiaoLiang, ChengJiaoE, HuanShouLv) VALUES (@Code, @Exchange, @HisDate, @JinKai, @ZuiGao, @ShangZhangJinE, @ShangZhangFuDu, @ZuiDi, @ShouPan, @ChengJiaoLiang, @ChengJiaoE, @HuanShouLv)");
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqlParameter("@Code", row.Code));
                        cmd.Parameters.Add(new SqlParameter("@Exchange", row.Exchange));
                        cmd.Parameters.Add(new SqlParameter("@HisDate", row.HisDate));
                        cmd.Parameters.Add(new SqlParameter("@JinKai", row.JinKai));
                        cmd.Parameters.Add(new SqlParameter("@ZuiGao", row.ZuiGao));
                        cmd.Parameters.Add(new SqlParameter("@ShangZhangJinE", row.ShangZhangJinE));
                        cmd.Parameters.Add(new SqlParameter("@ShangZhangFuDu", row.ShangZhangFuDu));
                        cmd.Parameters.Add(new SqlParameter("@ZuiDi", row.ZuiDi));
                        cmd.Parameters.Add(new SqlParameter("@ShouPan", row.ShouPan));
                        cmd.Parameters.Add(new SqlParameter("@ChengJiaoLiang", row.ChengJiaoLiang));
                        cmd.Parameters.Add(new SqlParameter("@ChengJiaoE", row.ChengJiaoE));
                        cmd.Parameters.Add(new SqlParameter("@HuanShouLv", row.HuanShouLv));
                        SqlServer.Instance.ExcuteSQL(new[] { cmd });
                    }
                }
                Invoke(new Action(() => {
                    MsgBox.ShowInfo(
                        message: "执行成功。", // 消息摘要
                        attach: "",       // 详细信息
                        caption: "消息",    // 窗口标题
                        expand: false,    // 是否展开详细信息
                        buttonText: "OK"  // 确定按钮文字
                        );
                }));
            });
        }