/*public String StockDbName(String stock_index) * { * return "s" + stock_index; * }*/ public void StockData_Save(ArrayList data) { foreach (Object obj in data) { StockTradeInfo stock_info = (StockTradeInfo)obj; String stock_db_name = stock_info.stock_index; if (stock_db_name.StartsWith("237") == false) //debug { continue; } string sql_ins = "INSERT INTO " + StockPage.StockDbName(stock_db_name) + "( trans_date, trans_volume, trans_count, trans_value, open, high, low ," + "close, diff, close_buy_price, close_buy_volume, close_sell_price, close_sell_volume) VALUE(" + "'" + Util.convertDate2mysql(stock_info.trans_date) + "'" + "," + stock_info.trans_volume.ToString() + "," + stock_info.trans_count.ToString() + "," + stock_info.trans_value.ToString() + "," + Util.double2dec(stock_info.open, 6, 2) + "," + Util.double2dec(stock_info.high, 6, 2) + "," + Util.double2dec(stock_info.low, 5, 2) + "," + Util.double2dec(stock_info.close, 5, 2) + "," + Util.double2dec(stock_info.diff, 5, 2) + "," + Util.double2dec(stock_info.close_buy_price, 5, 2) + "," + stock_info.close_buy_volume.ToString() + "," + Util.double2dec(stock_info.close_sell_price, 5, 2) + "," + stock_info.close_sell_volume.ToString() + ");"; MySqlCommand cmd_insert = new MySqlCommand(sql_ins, conn); try { cmd_insert.ExecuteNonQuery(); } catch (MySql.Data.MySqlClient.MySqlException ex) { //MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message, // "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button_LastPrice_Click(object sender, EventArgs e) { db_manager.DBConnect(); StockPage sp = new StockPage(); //float close_price = sp.getLastClosePrice(db_manager.getConnection(), "1101"); Hashtable last_price = sp.getLastClosePriceTable(db_manager.getConnection()); float sss = (float)last_price["1101"]; label_LastClosePrice.Text = String.Format("{0}", (float)last_price["1101"]); }
private void button_BuildTable_Click(object sender, EventArgs e) { StockPage stk = new StockPage(); db_manager.DBConnect(); //DateTime last_date = stk.getLastDBDate(db_manager); int period = (int)long.Parse(textBox_period.Text); sti = stk.GetStockTradeHistory(db_manager.getConnection(), textBox_stock_number.Text, period); Update_STI = true; panel1.Invalidate(); }
public DateTime getLastUpdateDate() { StockPage stk = new StockPage(); DateTime stk_date = stk.getLastDBDate(this, "2379"); Logger.v("Stock database last date:" + String.Format("{0}", stk_date)); PageJuristic foreign = new PageJuristic("foreign_"); DateTime foreign_date = foreign.getLastDBDate(this); Logger.v("Foreign database last date:" + String.Format("{0}", foreign_date)); DateTime res = foreign_date.CompareTo(stk_date) > 0 ? stk_date : foreign_date; Debug.WriteLine("Last DB date : " + res.ToShortDateString()); return(res); }
public void DBConnect() { string myConnectionString = "server=localhost;uid=shang;" + "pwd=king3697;database=twstock;"; try { conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); } catch (MySql.Data.MySqlClient.MySqlException ex) { try { setupUser(); SetupDatabase(); conn.Open(); } catch (MySql.Data.MySqlClient.MySqlException ex_in) { } } StockPage sp = new StockPage(); PageJuristic jp = new PageJuristic("foreign_"); sp.SetupDatebase(conn); jp.SetupDatebase(conn); CompanyProfilePage cpp = new CompanyProfilePage(); cpp.SetupDatebase(conn); cpp.SetupEarningDatebase(conn); UserManager userManager = new UserManager(); userManager.SetupDatebase(conn); }
private void button_new_juristic_Click(object sender, EventArgs e) { StockPage stk = new StockPage(); DateTime date = new DateTime(2015, 5, 28); String res = stk.download_page(stk.getPageUrl(date), date); using (StreamWriter sw = new StreamWriter(@"c:\temp\test.html", false, Encoding.GetEncoding("utf-8"))) { sw.Write(res); sw.Close(); } db_manager.DBConnect(); stk.ParseHtml(db_manager.getConnection(), res, date); /*PageJuristic p_juristic = new PageJuristic("foreign_"); * * using (StreamReader sr = new StreamReader(@"c:\temp\TWSE 臺灣證券交易所 _ 外資及陸資買賣超彙總表.html", Encoding.GetEncoding("big5"))) * { * p_juristic.ParseHtmlNew(db_manager.getConnection(), sr.ReadToEnd(), new DateTime()); * } * */ }
public void StockData_SaveForeign(ArrayList data) { foreach (Object obj in data) { JuristicTradeInfo stock_info = (JuristicTradeInfo)obj; String stock_db_name = stock_info.stock_index; if (stock_db_name.StartsWith("237") == false) //debug { continue; } /*string sql_update = "UPDATE @stock_db_name " + * " SET foreign_buy=@buy_volume, foreign_sell=@sell_volume, foreign_total=@total_volume " + * " WHERE trans_date =@trans_date;";*/ string sql_update = "UPDATE " + StockPage.StockDbName(stock_db_name) + " SET foreign_buy=@buy_volume, foreign_sell=@sell_volume, foreign_total=@total_volume " + " WHERE trans_date =@trans_date;"; MySqlCommand cmd_insert = new MySqlCommand(sql_update, conn); cmd_insert.Parameters.AddWithValue("@stock_db_name", StockPage.StockDbName(stock_db_name)); cmd_insert.Parameters.AddWithValue("@buy_volume", stock_info.buy_volume); cmd_insert.Parameters.AddWithValue("@sell_volume", stock_info.sell_volume); cmd_insert.Parameters.AddWithValue("@total_volume", stock_info.total_volume); cmd_insert.Parameters.AddWithValue("@trans_date", Util.convertDate2mysql(stock_info.trans_date)); try { cmd_insert.ExecuteNonQuery(); } catch (MySql.Data.MySqlClient.MySqlException ex) { //MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message, // "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void AnaLyzeJuristic(JuristicTradeInfo[] jti, int days2analyse) { Hashtable weight = new Hashtable(); CompanyProfilePage cpp = new CompanyProfilePage(); StockPage sp = new StockPage(); int view_days = getViewDays(days2analyse); //int days2analyse = int.Parse(textBox_jur_period.Text); Hashtable last_price = sp.getLastClosePriceTable(db_manager.getConnection()); foreach (JuristicTradeInfo ji in jti) { if (weight.ContainsKey(ji.stock_index) == false) { //query stock info int cap = cpp.GetStockCapital(db_manager.getConnection(), ji.stock_index); //float last_price = sp.getLastClosePrice(db_manager.getConnection(), ji.stock_index); float lp = 0; if (last_price.ContainsKey(ji.stock_index)) { lp = (float)last_price[ji.stock_index]; } StockRatingInfo sr = new StockRatingInfo(ji.stock_index, cap, lp, 0); weight.Add(ji.stock_index, sr); } DateTime ref_date = DateTime.Now.AddDays(-1 * days2analyse); if (ji.trans_date.CompareTo(ref_date) >= 0) { ((StockRatingInfo)weight[ji.stock_index]).weighting += (float)(ji.total_volume / 1000.0); } } StockRatingInfo[] juristic_stocks = new StockRatingInfo[weight.Count]; weight.Values.CopyTo(juristic_stocks, 0); foreach (StockRatingInfo sri in juristic_stocks) { if (comboBox_WightingFunc.SelectedIndex == 1) { sri.weighting *= sri.price_close; } else if (comboBox_WightingFunc.SelectedIndex == 2) { if (sri.capital != 0) { sri.weighting /= sri.capital; } } } Array.Sort(juristic_stocks, new StockRatingComparer()); listView_weighting.Items.Clear(); int i; for (i = 0; i < juristic_stocks.Length; i++) { ListViewItem lvi = new ListViewItem(juristic_stocks[i].stock_index); lvi.SubItems.Add(String.Format("{0}", juristic_stocks[i].capital)); lvi.SubItems.Add(String.Format("{0}", juristic_stocks[i].price_close)); lvi.SubItems.Add(String.Format("{0}", juristic_stocks[i].weighting)); listView_weighting.Items.Add(lvi); } }