public override void DBSave(ArrayList stock_data)
 {
     foreach (Object obj in stock_data)
     {
         EquityInfo info = (EquityInfo)obj;
         DbSql.AddEquityInfo(info);
     }
 }
Exemple #2
0
 public void LoadAll()
 {
     array = DbSql.GetStockTradeHistory(stock_index, 10000, false);
     for (int i = 0; i < array.Length; i++)
     {
         if (!date_index.ContainsKey(array[i].trans_date))
         {
             date_index.Add(array[i].trans_date, i);
         }
     }
 }
Exemple #3
0
        private void btn_query_Click(object sender, RoutedEventArgs e)
        {
            String stock_selected = (String)combo_stock_index.SelectedItem;

            StockTradeInfo[] hist = DbSql.GetStockTradeHistory(stock_selected, 50, true);
            show_kd(kd_canvas, hist);

            DbMongo mongo = new DbMongo();

            mongo.connect();
            financial_reports = mongo.FinancialReport_FindAll(stock_selected);
            show_financial(financial_reports);
        }
Exemple #4
0
        public MainWindow()
        {
            InitializeComponent();
            combo_stock_index.SelectedIndex = 0;

            DbSql.DBConnect();
            company_infos = DbSql.LoadCompanyList();
            foreach (object obj in company_infos)
            {
                PageEquityList.EquityInfo ci = (PageEquityList.EquityInfo)obj;
                combo_stock_index.Items.Add(ci.index);
            }
        }
Exemple #5
0
        /*public void Download_PerDay(DateTime date)
         * {
         *  dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };//, new PageJuristic("selfoper_"), new PageJuristic("investtrust_"), };
         *
         *  foreach (dynamic page in equility_pages)
         *  {
         *      current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
         *      Logger.Log(current_download_status);
         *      page.download_page(page.getPageUrl(date),   date);
         *      Thread.Sleep(5000);
         *  }
         * }*/

        public void BatchDownloadStockTrading()
        {
            dynamic[] equility_pages = new dynamic[] { new PageStock(), new PageForeign() };

            //DateTime date = checkDownload ? StartDate : equility_pages[0].getLastDBDate(sql_db, "2379");
            DateTime date = DbSql.getLastDBDate("2379");

            date = date.CompareTo(StartDate) > 0 ? date : StartDate;

            while (!date.Equals(DateTime.Today))
            {
                date = date.AddDays(1);
                //Logger.v("Downloading data starting from " + String.Format("{0}", date));
                if (!TradingDays.IsTradingDay(date))
                {
                    continue;
                }
                //Download_PerDay(date);
                foreach (dynamic page in equility_pages)
                {
                    String content = String.Empty;
                    if (!File.Exists(TargetDirectory + page.getFileName(date)))
                    {
                        current_download_status = "Downloading " + page.getFilePrefix() + date.ToShortDateString();
                        Logger.Log(current_download_status);
                        content = page.download_page(page.getPageUrl(date), Encoding.GetEncoding("utf-8"));
                        Thread.Sleep(5000);
                        using (StreamWriter sw = new StreamWriter(TargetDirectory + page.getFileName(date), false, Encoding.GetEncoding("utf-8")))
                        {
                            sw.Write(content);
                            sw.Close();
                        }
                    }
                    else
                    {
                        using (StreamReader sr = new StreamReader(TargetDirectory + page.getFileName(date), Encoding.GetEncoding("utf-8")))
                        {
                            content = sr.ReadToEnd();
                        }
                    }
                    ArrayList stock_data = page.ParseHtml(content, date);
                    if (stock_data.Count > 0)
                    {
                        page.DBSave(stock_data);
                    }
                }
                //Thread.Sleep(5000);
            }
        }
Exemple #6
0
        public void DownloadEquityinfo()
        {
            DbSql.SetupEquityInfo();
            String[] pages = new String[] { "2", "4" };
            foreach (String pageidx in pages)
            {
                PageEquityList page = new PageEquityList(pageidx);

                String    content    = page.download_page(page.getPageUrl(DateTime.Now), Encoding.GetEncoding("big5"));
                ArrayList stock_data = page.ParseHtml(content, DateTime.Now);
                if (stock_data.Count > 0)
                {
                    page.DBSave(stock_data);
                }
            }
        }
Exemple #7
0
        /*public DateTime getLastDBDate(DbSql db)
         * {
         *  DateTime res = new DateTime(2004, 12, 18);        //first date
         *
         *  String qstr = "SELECT * from " + table_name + "  ORDER by trans_date DESC LIMIT 1;";
         *  MySqlCommand cmd = new MySqlCommand(qstr, db.getConnection());
         *  MySqlDataReader rdr = cmd.ExecuteReader();
         *  if (rdr.HasRows)
         *  {
         *      rdr.Read();
         *      res = (DateTime)rdr["trans_date"];
         *  }
         *  rdr.Close();
         *  return res;
         * }*/

        public override void DBSave(ArrayList stock_data)
        {
            DbSql.StockData_SaveForeign(stock_data);
        }
Exemple #8
0
 static public void Log(String message)
 {
     DbSql.Log(message);
 }
Exemple #9
0
 static public void SetupDb()
 {
     DbSql.SetupLoggerDb();
 }