private void bt_confirm_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Confirm that you want this date?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { selectedDate = (DateTime)datepicker_.SelectedDate; MlbInfo.mlbPerDay dayInfo = new MlbInfo.mlbPerDay(); //get the day's info foreach (var d in daysCollectionOneYear) { if (int.Parse(d.data.games.month) == selectedDate.Month && int.Parse(d.data.games.day) == selectedDate.Day) { dayInfo = d; break; } } //show the information window ScoreBoardInfo sBI = new ScoreBoardInfo(dayInfo); sBI.Show(); saveYear(); } }//end of confirm click
//combobox for year private void cb_years_SelectionChanged(object sender, SelectionChangedEventArgs e) { tb_loadingInfo.Text = "Loading..."; //clear the previous memory daysCollectionOneYear.Clear(); //you've got the year. time to enable the calendar with available date yearInfo = cb_years.SelectedIndex + START_YEAR; datepicker_.SetValue(MyPropertyProperty, new DateTime(yearInfo, 01, 01)); string filename = "mlb" + yearInfo + ".json"; //we already have json loaded bool isFound = false; //if we have year json(except for this year) if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + filename) && filename != "mlb" + CURRENT_YEAR + ".json") { using (StreamReader sr1 = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + filename)) { string stringWeLookFor = "master_scoreboard_mlb_" + yearInfo; var jsonContentThisFile = sr1.ReadToEnd(); if (jsonContentThisFile.Contains(stringWeLookFor)) { isFound = true; } ///////////////////////////////////////////////////// // Deserialize(json->object) // ///////////////////////////////////////////////////// if (isFound) { string wholeJson = sr1.ReadLine(); //make it into collection(deserialize to list) List <MlbInfo.mlbPerDay> MLBsInAYear2 = JsonConvert.DeserializeObject <List <MlbInfo.mlbPerDay> >(jsonContentThisFile); daysCollectionOneYear = MLBsInAYear2; blakcOut(); } //ifFound else //if the year is not found { if (!isYearExist) { List <string> urls = new List <string>(); //datetime container List <DateTime> datesInRangeL = getDatesInRangeL(yearInfo); foreach (DateTime dt in datesInRangeL) { urls.Add(urlMaker(dt)); } List <string> jsonsL = new List <string>(); using (WebClient client2 = new WebClient()) { foreach (string u in urls) { try { string jsonT = client2.DownloadString(u); jsonsL.Add(jsonT); } catch (Exception ex) { } } }//end of using webclient List <string> jsonExeptionCaughtWhenDeserialization = new List <string>(); foreach (var j in jsonsL) { try { MlbInfo.mlbPerDay mlbD = JsonConvert.DeserializeObject <MlbInfo.mlbPerDay>(j); daysCollectionOneYear.Add(mlbD); } catch (Exception ex) { jsonExeptionCaughtWhenDeserialization.Add(j); } } //end of foreach to add daysCollection list } } //end of else } //end of isFound } //if file exists //file not existent anyways you have to make it else { isYearExist = false; if (!isYearExist) { List <string> urls = new List <string>(); //datetime container List <DateTime> datesInRangeL = getDatesInRangeL(yearInfo); foreach (DateTime dt in datesInRangeL) { urls.Add(urlMaker(dt)); } List <string> jsonsL = new List <string>(); using (WebClient client2 = new WebClient()) { foreach (string u in urls) { try { string jsonT = client2.DownloadString(u); jsonsL.Add(jsonT); } catch (Exception ex) { } } } List <string> jsonExeptionCaughtWhenDeserialization = new List <string>(); foreach (var j in jsonsL) { try { MlbInfo.mlbPerDay mlbD = JsonConvert.DeserializeObject <MlbInfo.mlbPerDay>(j); daysCollectionOneYear.Add(mlbD); } catch (Exception ex) { jsonExeptionCaughtWhenDeserialization.Add(j); } } } }//end of else MlbInfo thisYear = new MlbInfo(); thisYear.mlbpd = daysCollectionOneYear.ToArray(); saveFile(); blakcOut(); DateTime startDate = new DateTime(yearInfo, 01, 01); datepicker_.DisplayDateStart = startDate; datepicker_.DisplayDate = startDate; datepicker_.DisplayDateEnd = new DateTime(yearInfo, 12, 31); //if (yearInfo == CURRENT_YEAR) // datepicker_.DisplayDate = DateTime.Now; //else // datepicker_.DisplayDateEnd = new DateTime(yearInfo, 12, 31); //finally make calendar available datepicker_.IsEnabled = true; tb_loadingInfo.Text = "Data for " + yearInfo + " is loaded!"; }
public ScoreBoardInfo(MlbInfo.mlbPerDay mlb) { mlbInfoOfselectedDay = mlb; InitializeComponent(); var games = mlb.data.games.game as IEnumerable <object>; //first one with general information TabItem tabG = new TabItem(); tabG.Name = "tabGeneral"; tabG.Header = "Games General Info"; ScrollViewer scrV0 = new ScrollViewer(); scrV0.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; scrV0.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; StackPanel sp = new StackPanel(); sp.Margin = new Thickness(5, 5, 5, 5); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(mlb)) { string name = descriptor.Name; object value = descriptor.GetValue(mlb); TextBlock tb = new TextBlock(); tb.TextWrapping = TextWrapping.Wrap; tb.Text = string.Format(" {0, -20} : {1}", name, value.ToString()); sp.Children.Add(tb); } scrV0.Content = sp; tabG.Content = scrV0; tabControl1.Items.Add(tabG); //each game int gameNum = 1; foreach (var game in games) { TabItem tab = new TabItem(); tab.Name = "tab" + gameNum; tab.Header = "Game " + gameNum; ScrollViewer scrV = new ScrollViewer(); scrV.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; scrV.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; StackPanel s1 = new StackPanel(); s1.Margin = new Thickness(5, 5, 5, 5); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(game)) { string name = descriptor.Name; object value = descriptor.GetValue(game); if (value != null) { TextBlock tb = new TextBlock(); tb.TextWrapping = TextWrapping.Wrap; tb.Text = string.Format(" {0, -30}: \t{1}", name, value.ToString()); s1.Children.Add(tb); } } scrV.Content = s1; tab.Content = scrV; tabControl1.Items.Add(tab); gameNum++; } }//end of ScoreBoardInfo