private async void BTNsaveCustomCourse_Click(object sender, RoutedEventArgs e) { PRGRSadd.ProgressStart(); List <Parameters> l = new List <Parameters>(); l.Add(new Parameters("token", Constants.token)); l.Add(new Parameters("operation", "set")); l.Add(new Parameters("content", CourseUtil.ToStandardJsonStr(CourseUtil.CustomCourses))); Parameters parameter = await WebConnection.Connect(Constants.domain + "/services/course.php", l); if (!parameter.name.Equals("200")) { Util.DealWithDisconnect(parameter); PRGRSadd.ProgressEnd(); return; } try { JsonObject json = JsonObject.Parse(parameter.value); int code; try { code = (int)json.GetNamedNumber("code"); } catch { code = int.Parse(json.GetNamedString("code")); } if (!(code == 0)) { return; } CourseUtil.SaveCourses("CustomCourses", CourseUtil.CustomCourses); CourseUtil.currentCoursePage.RefreshCourse(); PRGRSadd.ProgressEnd(); STRBDpopout.Begin(); } catch (Exception ex) { Debug.WriteLine("fail to update custom courses! at" + ex.StackTrace); } }
private async void GetCustomCourses() { PRGRSadd.ProgressStart(); CourseUtil.CustomCourses.Clear(); Parameters parameter = await WebConnection.Connect(Constants.domain + "/services/pkuhelper/course.php?token=" + Constants.token + "&?=" + DateTime.Now.Millisecond, null); if (!"200".Equals(parameter.name)) { Util.DealWithDisconnect(parameter); PRGRSadd.ProgressEnd(); return; } CourseUtil.ParseCourseJson(parameter.value, ref CourseUtil.CustomCourses); CourseUtil.SaveCourses("CustomCourses", CourseUtil.CustomCourses); CourseUtil.SimpleCustomInfo.Clear(); foreach (var info in CourseUtil.CustomCourses) { CourseUtil.SimpleCustomInfo.Add(new SimpleCustomCourseInfo(info.Key)); } LSTVWcustomCourse.ItemsSource = CourseUtil.SimpleCustomInfo; PRGRSadd.ProgressEnd(); }