Пример #1
0
        public List <TickerBase> GetAllTicker(string tickerbase)
        {
            var listTickerLoad = new List <TickerBase>();
            //check db da tao chua
            var dao           = new TickerDAO(connstring, tickerbase);
            var isexistticker = dao.IsTableExisted(tickerbase);

            if (isexistticker)
            {
                listTickerLoad.AddRange(dao.SelectALL(tickerbase));
            }
            return(listTickerLoad);
        }
Пример #2
0
        public bool InsertTicker(string tickerbase, List <TickerBase> listdata)
        {
            try
            {
                var dao            = new TickerDAO(connstring, tickerbase);
                var listTickerLoad = new List <TickerBase>();
                //check db da tao chua
                var isexistticker = dao.IsTableExisted(tickerbase);
                if (isexistticker)
                {
                    listTickerLoad.AddRange(dao.SelectALL(tickerbase));
                }
                else
                {
                    //taoj moi tabke
                    dao.CreateTable(tickerbase);
                    dao.SetOwner(tickerbase);
                }
                //get all data check trung

                //insert to db
                foreach (var entity in listdata)
                {
                    if (listTickerLoad.Contains(entity))
                    {
                        continue;
                    }
                    dao.Insert(entity);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(true);
        }
        //Load data Ticker
        private void Button1_Click(object sender, EventArgs e)
        {
            //load dl ticker
            string connstring = String.Format("Server={0};Port={1};" +
                                              "User Id={2};Password={3};Database={4};",
                                              "127.0.0.1", "5433", "lemon",
                                              "admin", "DailyTrading");

            var tickerbase = txtTicker.Text;
            var dao        = new TickerDAO(connstring, tickerbase);

            listPredicInput.Clear();
            _maxDate = new DateTime(2000, 01, 01);
            _minDate = DateTime.Now.Date;
            //check db da tao chua
            var isexistticker = dao.IsTableExisted(tickerbase);

            if (isexistticker)
            {
                var listdata = dao.SelectALL(tickerbase);
                foreach (var data in listdata)
                {
                    var predicInput = new PredicInput();

                    predicInput.Date = data.Day;

                    predicInput.SetValue((int)PredicInputIndexe.OpenIndex, data.Open);
                    predicInput.SetValue((int)PredicInputIndexe.HighIndex, data.Hight);
                    predicInput.SetValue((int)PredicInputIndexe.LowIndex, data.Low);
                    predicInput.SetValue((int)PredicInputIndexe.CloseIndex, data.Close);
                    predicInput.SetValue((int)PredicInputIndexe.VolumeIndex, data.Volume);

                    predicInput.SetValue((int)PredicInputIndexe.VNIndex, 0);
                    listPredicInput.Add(predicInput);

                    if (_maxDate.Date < data.Day)
                    {
                        _maxDate = data.Day;
                    }
                    if (_minDate.Date > data.Day)
                    {
                        _minDate = data.Day;
                    }
                }
            }
            else
            {
                MessageBox.Show("Load dl ticker khong thanh cong"); return;
            }
            dao.Dispose();
            //load dl vnindex
            var daoindex = new TickerDAO(connstring, txtVNIndex.Text);

            isexistticker = daoindex.IsTableExisted(txtVNIndex.Text);
            if (isexistticker)
            {
                var listdata = daoindex.SelectALL(txtVNIndex.Text);
                foreach (var data in listPredicInput)
                {
                    foreach (TickerBase index in from index in listdata
                             where index.Day == data.Date
                             select index)
                    {
                        data.SetValue((int)PredicInputIndexe.VNIndex, index.Close);
                    }
                }
            }
            else
            {
                MessageBox.Show("Load dl ticker VNIndex khong thanh cong"); return;
            }

            daoindex.Dispose();

            //set value to txtbox
            txtstartDate.Text   = _minDate.Date.ToShortDateString();
            _dtpTrainFrom.Value = _minDate.Date;

            txtEndDate.Text      = _maxDate.Date.ToShortDateString();
            _dtpTrainUntil.Value = _maxDate.Date.AddDays(-10);

            _dtpPredictFrom.Value = _maxDate.Date.AddDays(-9);
            _dtpPredictTo.Value   = _maxDate.Date;
        }
Пример #4
0
        private void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                var listdata   = new List <TickerBase>();
                var fileName   = textBox2.Text;
                var tickerbase = textBox1.Text;
                var lines      = File.ReadAllLines(fileName);
                foreach (var line in lines)
                {
                    if (line.Length < 2)
                    {
                        continue;
                    }
                    //tach value/
                    var listvalues = line.Split(',');
                    if (listvalues[0].Contains("DATE"))
                    {
                        continue;
                    }

                    var ticker = new TickerBase();
                    ticker.Day    = DateTime.ParseExact(listvalues[0], "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                    ticker.Close  = float.Parse(listvalues[1]);
                    ticker.Open   = float.Parse(listvalues[3]);
                    ticker.Hight  = float.Parse(listvalues[4]);
                    ticker.Low    = float.Parse(listvalues[5]);
                    ticker.Volume = float.Parse(listvalues[6]);

                    listdata.Add(ticker);
                }
                string connstring = String.Format("Server={0};Port={1};" +
                                                  "User Id={2};Password={3};Database={4};",
                                                  "127.0.0.1", "5433", "lemon",
                                                  "admin", "DailyTrading");

                var dao            = new TickerDAO(connstring, tickerbase);
                var listTickerLoad = new List <TickerBase>();
                //check db da tao chua
                var isexistticker = dao.IsTableExisted(tickerbase);
                if (isexistticker)
                {
                    listTickerLoad.AddRange(dao.SelectALL(tickerbase));
                }
                else
                {
                    //taoj moi tabke
                    dao.CreateTable(tickerbase);
                    dao.SetOwner(tickerbase);
                }
                //get all data check trung

                //insert to db
                foreach (var entity in listdata)
                {
                    if (listTickerLoad.Contains(entity))
                    {
                        continue;
                    }
                    dao.Insert(entity);
                }
            }
            catch (Exception msg)
            {
                // something went wrong, and you wanna know why
                MessageBox.Show(msg.ToString());
                throw;
            }
        }