// save to database
        public static void UpdateQGQPData(string stockCode, StockCommentList report)
        {
            string sql = $"insert or replace into qgqpData (_id, TRADECODE, STOCKNAME, TRADEDATE, PCTBUYXL, PCTBUYL, ZB, " +
                         $"ZB3RAVG, ZB50RAVG, JGCYD, FLOWINXL, FLOWOUTXL, FLOWINL, FLOWOUTL, ZLJLR) values " +
                         $"((select _id from qgqpData where TRADECODE == {SQLString(stockCode)} and TRADEDATE == {SQLString(report.Tradedate.ToString())}), " +
                         $"{SQLString(stockCode)}, {SQLString(report.Stockname)}, {SQLString(report.Tradedate.ToString())}, {SQLString(report.Pctbuyxl.ToString())}, {SQLString(report.Pctbuyl.ToString())}, {SQLString(report.Zb.ToString())}" +
                         $", {SQLString(report.Zb3Ravg.ToString())}, {SQLString(report.Zb50Ravg.ToString())}, {SQLString(report.Jgcyd.ToString())}, {SQLString(report.Flowinxl.ToString())}, {SQLString(report.Flowoutxl.ToString())}, {SQLString(report.Flowinl.ToString())}" +
                         $", {SQLString(report.Flowoutl.ToString())}, {SQLString(report.Zljlr.ToString())})";
            SQLiteCommand cmd = new SQLiteCommand(sql, SystemSetting.sqliteConnection);

            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        private void QueryQgqpData(double proMin, double proMax)
        {
            var reader = DatabaseHelper.QueryQGQPDataByMainControl(proMin, proMax);

            if (reader.HasRows)
            {
                var commentList = new List <StockCommentList>();
                while (reader.Read())
                {
                    try
                    {
                        var record = new StockCommentList()
                        {
                            Tradecode = reader["TRADECODE"].ToString(),
                            Tradedate = Convert.ToDateTime(reader["TRADEDATE"].ToString()),
                            Stockname = reader["STOCKNAME"].ToString(),
                            Jgcyd     = Convert.ToDouble(reader["JGCYD"].ToString()) * 100,
                            Zljlr     = Convert.ToInt64(reader["ZLJLR"].ToString()),
                        };
                        commentList.Add(record);
                    }
                    catch (Exception ex)
                    {
                        SystemSetting.LogAndDisplayError(ex, "MainForm.cs, line 114");
                    }
                }
                if (commentList.Count > 0)
                {
                    var ui = new Views.UI_QgqpData(proMin * 100, proMax * 100, commentList.Count);
                    ui.FillData(commentList);
                    int heightIntend = (commentList.Count + 2) * 23 + 38;
                    ui.Height = heightIntend < ui.minimumHeight ? ui.minimumHeight : heightIntend;
                    ui.Dock   = DockStyle.Top;
                    this.panel_main.Controls.Add(ui);
                }
            }
            else
            {
                MessageBox.Show("未找到记录值!");
            }
        }
Ejemplo n.º 3
0
        public void FetchQGQP(IProgress <double> progress)
        {
            lock (lockObject)
            {
                try
                {
                    var fileDir   = SystemSetting.downloadJsonDir + "qgqp.tmp";
                    int dataCount = DatabaseHelper.Get006030StockRecordCount("stockList");

                    var stockCommentList = new Dictionary <string, List <StockCommentList> >();
                    var jsonCollection   = new StringBuilder(dataCount);
                    var stockCodeTemp    = "";

                    // DatabaseHelper.ClearTable("qgqpData");
                    int i = 0;
                    if (File.Exists(fileDir))
                    {
                        var rawJsonList = File.ReadAllLines(fileDir);
                        foreach (var record in rawJsonList)
                        {
                            i++;
                            var line                 = record.Split(new string[] { "|||" }, StringSplitOptions.None);
                            var stockCode            = line[0];
                            var rawTopTenShareHolder = line[1];
                            var package              = StockCommentList.FromJson(rawTopTenShareHolder);
                            stockCommentList.Add(stockCode, package);
                            progress.Report(50.0 * i / dataCount);
                            Console.WriteLine($"{i}:{stockCode} --- {rawTopTenShareHolder}");
                        }
                    }
                    else
                    {
                        var reader        = DatabaseHelper.GetAll006030StockRecords("stockList");
                        var stockCodeList = new List <string>();
                        while (reader.Read())
                        {
                            string stockCode = reader[1].ToString().ToLower().Replace("sz", "").Replace("sh", "");
                            stockCodeList.Add(stockCode);
                        }

                        try
                        {
                            if (stockCodeList.Any())
                            {
                                foreach (var stockCode in stockCodeList)
                                {
                                    i++;
                                    stockCodeTemp = stockCode;
                                    var qgqpData = HttpRequestWithRetryTimes(SystemSetting.stockQGQPURL.Replace("{code}", stockCode), 3);
                                    if (qgqpData != "!!error!!")
                                    {
                                        jsonCollection.AppendLine(qgqpData);

                                        var package = StockCommentList.FromJson(qgqpData);
                                        stockCommentList.Add(stockCode, package);
                                        Console.WriteLine($"{i}:{stockCode} --- {qgqpData}");
                                    }
                                    progress.Report(50.0 * i / dataCount);
                                }
                                File.WriteAllText(fileDir, jsonCollection.ToString());
                            }
                            i = 0;
                            DatabaseHelper.OptimizationBegin();
                            foreach (var record in stockCommentList)
                            {
                                i++;
                                var stockCode   = record.Key;
                                var commentList = record.Value;
                                foreach (StockCommentList comment in commentList)
                                {
                                    DatabaseHelper.UpdateQGQPData(stockCode, comment);
                                }
                                progress.Report(50.0 * i / dataCount + 50);
                            }
                            DatabaseHelper.OptimizationEnd();
                        }
                        catch (Exception ex0)
                        {
                            SystemSetting.LogAndDisplayError(ex0, $"{stockCodeTemp} MainForm.cs, line 169");
                        }
                    }

                    if (File.Exists(fileDir))
                    {
                        File.Delete(fileDir);
                    }
                }
                catch (Exception ex)
                {
                    SystemSetting.LogAndDisplayError(ex, "MainForm.cs, line 178");
                }
            }
        }