Exemple #1
0
        private void button_Test_eps_Click(object sender, EventArgs e)
        {
            CompanyProfilePage cpp = new CompanyProfilePage();

            db_manager.DBConnect();
            //cpp.DownloadEpsAll(db_manager.getConnection(), "2379");
        }
Exemple #2
0
        private void button_monthly_revenue_Click(object sender, EventArgs e)
        {
            CompanyProfilePage cpp = new CompanyProfilePage();

            db_manager.DBConnect();
            //cpp.DownloadMonthRevenueAll(db_manager.getConnection(), "2379");
        }
Exemple #3
0
        private void listView_weighting_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection selected_stocks = listView_weighting.SelectedItems;

            if (selected_stocks.Count > 0)
            {
                CompanyProfilePage cpp          = new CompanyProfilePage();
                ListViewItem       select_stock = selected_stocks[0];
                juristic_stock_idx        = select_stock.Text;
                label_StockName.Text      = cpp.GetStockChineseName(db_manager.getConnection(), juristic_stock_idx);
                match_juristic_trade_info = new ArrayList();
                juristic_max_vol          = 0;
                juristic_min_vol          = 0;
                foreach (JuristicTradeInfo trade_info in jti)
                {
                    if (trade_info.stock_index.Equals(juristic_stock_idx))
                    {
                        match_juristic_trade_info.Add(trade_info);
                        if (trade_info.total_volume > juristic_max_vol)
                        {
                            juristic_max_vol = trade_info.total_volume;
                        }
                        if (trade_info.total_volume < juristic_min_vol)
                        {
                            juristic_min_vol = trade_info.total_volume;
                        }
                    }
                }
                y_height             = Math.Max(juristic_max_vol, Math.Abs(juristic_min_vol));
                label_StockName.Text = cpp.GetStockChineseName(db_manager.getConnection(), juristic_stock_idx);

                UpdateJuristicGraph = true;
                panel_juristic.Invalidate();
            }
        }
Exemple #4
0
        private void button_QueryProfile_Click(object sender, EventArgs e)
        {
            db_manager.DBConnect();
            CompanyProfilePage cpp = new CompanyProfilePage();
            String             res = cpp.GetStockChineseName(db_manager.getConnection(), "1101");

            label_company_profile_result.Text = res;
        }
Exemple #5
0
        private void button_GetEarning_Click(object sender, EventArgs e)
        {
            db_manager.DBConnect();
            CompanyProfilePage cpp = new CompanyProfilePage();
            int year;
            int season;

            for (year = 98; year < 102; year++)
            {
                for (season = 1; season <= 4; season++)
                {
                    cpp.DownloadMonthRevenue(db_manager.getConnection(), "2379", year, season);
                }
            }
        }
Exemple #6
0
        private void backgroundWorker_check_download_EPS_DoWork(object sender, DoWorkEventArgs e)
        {
            db_manager.DBConnect();
            MySqlConnection    conn = db_manager.getConnection();
            CompanyProfilePage cpp  = new CompanyProfilePage();

            while (true)
            {
                List <stockSeason> nulleps = new List <stockSeason>();
                string             qstr    = "SELECT * FROM company_earning WHERE eps is NULL order by stock_index;";
                MySqlCommand       cmd     = new MySqlCommand(qstr, conn);
                MySqlDataReader    rdr     = null;
                try
                {
                    rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        string idx    = (string)rdr["stock_index"];
                        int    year   = (int)rdr["year"];
                        int    season = (int)rdr["season"];
                        nulleps.Add(new stockSeason(idx, year, season));
                    }
                }
                catch (Exception ex)
                {
                    //Logger.e("isEPS_Null:" + stock_index + "(" + year + "," + season + ")  failed");
                }
                finally
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }

                Logger.v("total " + nulleps.Count + " eps items are null!");
                backgroundWorker_downloadrevenue_inprogress = true;
                foreach (stockSeason stkseason in nulleps)
                {
                    cpp.DownloadEpsInfo(db_manager.getConnection(), stkseason.stock_index, stkseason.year, stkseason.season);
                    downloadrevenue_index++;
                    //Thread.Sleep(3);
                }
            }
        }
Exemple #7
0
        private void button_DownloadEarning_Click(object sender, EventArgs e)
        {
            db_manager.DBConnect();
            CompanyProfilePage cpp = new CompanyProfilePage();

            // cpp.DownloadEarningInfoAll(db_manager.getConnection(), "2379");             //from 98-102. profit margin
            cpp.DownloadEpsInfo(db_manager.getConnection(), "2379", 100, 1);      //eps
            cpp.DownloadMonthRevenue(db_manager.getConnection(), "2379", 100, 1); //revenue

            cpp.DownloadEpsInfo(db_manager.getConnection(), "2379", 102, 1);      //eps
            cpp.DownloadMonthRevenue(db_manager.getConnection(), "2379", 102, 1); //revenue
            int         rev = cpp.GetMonthRevenue(db_manager.getConnection(), "2379", 102, 1);
            EarningInfo ei  = cpp.GetSeasonEarning(db_manager.getConnection(), "2379", 102, 1);

            YearSeasonMonth ysm = cpp.GetLatestRevenueInfoDate(db_manager.getConnection(), "2379");

            ysm = cpp.GetLatestEarningInfoDate(db_manager.getConnection(), "2379");
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        private void backgroundWorker_downloadrevenue_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker downloadrevenue_worker = sender as BackgroundWorker;

            List <String>   stocks     = GetAllStocks();
            DateTime        current    = DateTime.Now;
            YearSeasonMonth currentYSM = new YearSeasonMonth(current, true);

            CompanyProfilePage cpp = new CompanyProfilePage();

            backgroundWorker_downloadrevenue_inprogress = true;

            foreach (String stock_idx in stocks)
            {
                if (downloadrevenue_worker.CancellationPending)
                {
                    Logger.v("cancelling databases update");
                    backgroundWorker_downloadrevenue_inprogress = false;
                    break;
                }

                //earning
                YearSeasonMonth        latestEarning = cpp.GetLatestEarningInfoDate(db_manager.getConnection(), stock_idx);
                List <YearSeasonMonth> EPS2download  = new List <YearSeasonMonth>();
                YearSeasonMonth        nextEarning;
                if ((latestEarning == null) || (latestEarning.year < 102))
                {
                    cpp.DownloadEarningInfo_beforeIFRS(db_manager.getConnection(), stock_idx, EPS2download);
                    nextEarning = IfrsStart;
                }
                else
                {
                    nextEarning = latestEarning.NextSeason();
                }

                downloadrevenue_index++;
                for (int y = nextEarning.year; y <= (current.Year - 1911); y++)
                {
                    cpp.DownloadEarningInfo(db_manager.getConnection(), stock_idx, y, EPS2download);
                    downloadrevenue_index++;
                }

                //eps info is from another page
                foreach (YearSeasonMonth season in EPS2download)
                {
                    cpp.DownloadEpsInfo(db_manager.getConnection(), stock_idx, season.year, season.season);
                    downloadrevenue_index++;
                    int loop;
                    for (loop = 0; loop < 10; loop++)
                    {
                        if (cpp.isEPS_Null(db_manager.getConnection(), stock_idx, season.year, season.season))
                        {
                            cpp.DownloadEpsInfo(db_manager.getConnection(), stock_idx, season.year, season.season);
                            downloadrevenue_index++;
                        }
                    }
                }

                YearSeasonMonth latestRevenue = cpp.GetLatestRevenueInfoDate(db_manager.getConnection(), stock_idx);
                if (latestRevenue == null)
                {
                    latestRevenue = EarningStart;
                }
                for (YearSeasonMonth month = latestRevenue; month < currentYSM; month.NextMonth())
                {
                    cpp.DownloadMonthRevenue(db_manager.getConnection(), stock_idx, month.year, month.month);
                    downloadrevenue_index++;
                }
            }
        }
Exemple #10
0
        //public void UpdateCompanyInfo()
        private void backgroundWorker_companyProf_DoWork(object sender, DoWorkEventArgs e)
        {
            List <String> stock_ary = new List <String>();

            companyProf_inprogress = true;

            try
            {
                String          qstr = "SELECT Distinct(stock_index) from tw_stock order by stock_index";
                MySqlCommand    cmd  = new MySqlCommand(qstr, db_manager.getConnection());
                MySqlDataReader rdr  = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    String idx = (String)rdr["stock_index"];
                    if (idx.StartsWith("0") == false)
                    {
                        stock_ary.Add(idx);
                    }
                }
                rdr.Close();

                CompanyProfilePage cpp = new CompanyProfilePage();
                //foreach(object obj in stock_ary)
                while (stock_ary.Count > 0)
                {
                    String idx = stock_ary.ElementAt(0);
                    stock_ary.RemoveAt(0);
                    Thread.Sleep(10 * 1000);
                    CompanyData company_data = cpp.DownloadInfo(idx);
                    if (company_data.capital.Equals(""))
                    {
                        Logger.v("company profile " + idx + "download fail");
                        stock_ary.Add(idx);
                        continue;
                    }

                    String capital_str   = company_data.capital.Replace(",", "").Replace("元", "");
                    float  capital_float = float.Parse(capital_str);
                    int    capital       = (int)(capital_float / 100000000);
                    if (cpp.isExistCompanyProfile(db_manager.getConnection(), idx))
                    {
                        cpp.UpdateCompanyProfile(db_manager.getConnection(), idx, company_data.FullName, capital);
                        Logger.v("company profile " + idx + ", update to " + String.Format("{0}", capital));
                    }
                    else
                    {
                        cpp.AddCompanyProfile(db_manager.getConnection(), idx, company_data.FullName, capital);
                        Logger.v("company profile " + idx + "added: " + String.Format("{0}", capital));
                    }

                    if (backgroundWorker_companyProf.CancellationPending)
                    {
                        break;
                    }
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                //MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
                //    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #11
0
        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);
            }
        }