public RegularVM() { this.SearchText = ""; this.BeginDate = ""; this.EndDate = ""; DataGrabber.Connect(); }
private void UpdateStock() { try { if (_searchText == "") { this.ChartPoints = null; } else { DataTable[] dt = new DataTable[5]; string beginDate = this.BeginDate; string endDate = this.EndDate; if (this.BeginDate == null || this.EndDate == null || this.BeginDate.CompareTo("") == 0 || this.EndDate.CompareTo("") == 0) { beginDate = DateTime.Today.Subtract(new TimeSpan(365, 0, 0, 0)).ToString(); endDate = DateTime.Today.ToString(); } dt[0] = DataGrabber.GetStockCloseInfo(_searchText, beginDate, endDate); List <Chart.ChartPoint>[] pts = new List <Chart.ChartPoint> [5]; pts[0] = new List <Chart.ChartPoint>(); pts[1] = new List <Chart.ChartPoint>(); pts[2] = new List <Chart.ChartPoint>(); pts[3] = new List <Chart.ChartPoint>(); pts[4] = new List <Chart.ChartPoint>(); Parallel.For(0, 5, i => { if (i == 1) { dt[1] = DataGrabber.GetStockConversionLine(_searchText, beginDate, endDate, 9); } else if (i == 2) { dt[2] = DataGrabber.GetStockConversionLine(_searchText, beginDate, endDate, 26); } else if (i == 3) { dt[3] = DataGrabber.GetStockLeadingSpanALine(_searchText, beginDate, endDate, 9, 26); } else if (i == 4) { dt[4] = DataGrabber.GetStockConversionLine(_searchText, beginDate, endDate, 52); } foreach (DataRow row in dt[i].Rows) { pts[i].Add(new Chart.ChartPoint((DateTime)row[0], Math.Round((double)row[1], 2))); } }); this.ChartPoints = pts; } } catch (Exception ex) { Console.WriteLine("EXCEPTION: " + ex.Message); } }