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); }
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; } }