//确认添加课程 public async void btnAddConfirm_Click(object sender, RoutedEventArgs e) { var current = CoursePage.Current; if (string.IsNullOrEmpty(current.txtCourseName.Text) || current.ComboDayOfWeek.SelectedIndex == -1 || current.ComboSelectedMode.SelectedIndex == -1 || current.ComboCourseStart.SelectedIndex == -1 || current.ComboCourseEnd.SelectedIndex == -1 || current.ComboWeekStart.SelectedIndex == -1 || current.ComboWeekEnd.SelectedIndex == -1) { await new MessageDialog("亲,带 * 的都是必填选项哟,先check一下下吧(●'◡'●)").ShowAsync(); return; } Course course = new Course(); course.FullName = current.txtCourseName.Text; course.Classroom = current.txtClassroom.Text; course.Teacher = current.txtTeacher.Text; course.Credits = current.txtCredit.Text; course.Classify = current.txtClassify.Text; course.StartMark = current.ComboCourseStart.SelectedIndex; course.CourseSpan = current.ComboCourseEnd.SelectedIndex - current.ComboCourseStart.SelectedIndex + 1; //处理UI及后台逻辑 current.TipPanel.Visibility = Visibility.Visible; current.AddCourseGrid.Visibility = Visibility.Collapsed; string termlyString = await CourseDataService.ProcessCourse(course, current.ComboSelectedMode.SelectedIndex, current.ComboDayOfWeek.SelectedIndex, current.ComboWeekStart.SelectedIndex, current.ComboWeekEnd.SelectedIndex); if (!string.IsNullOrEmpty(termlyString)) { await CourseDataService.SaveTermlyJsonToIsoStoreAsync(termlyString); current.ViewModel.InitializeRootGrid(current.CourseGrid); current.TipPanel.Visibility = Visibility.Collapsed; current.btnUserControl.IsEnabled = true; } else { current.TipPanel.Visibility = Visibility.Collapsed; current.btnUserControl.IsEnabled = true; await new MessageDialog("添加课程失败了,再试一次吧~_~").ShowAsync(); } }
public async Task <int> GetTermlyJsonAsync(string id, string pwd, string code, bool rememberPwd) { if (!NetworkInterface.GetIsNetworkAvailable()) { await new MessageDialog("哦~啊~网络出故障了,检查下网络连接吧(T_T)!!").ShowAsync(); return(0); } try { HttpClientHandler handler = new HttpClientHandler(); HttpClient client = new HttpClient(handler); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("user", id); dic.Add("pwd", pwd); dic.Add("code", code); dic.Add("key", "xiaoz"); dic.Add("clientCookie", ClientCookie); dic.Add("viewState", ViewState); dic.Add("target", "course"); FormUrlEncodedContent content = new FormUrlEncodedContent(dic); HttpResponseMessage msg = await client.PostAsync(APIs.APIs.APIGetCourse + (new Random()).Next(), content); string termlyJson = await msg.Content.ReadAsStringAsync(); if (msg.StatusCode == HttpStatusCode.OK) { if (termlyJson.Contains("[")) { //存储用户信息 App.AppSettings.UserId = id; App.AppSettings.UserPassword = pwd; App.AppSettings.RememberPwd = rememberPwd; //将开学时间和总周数保存至本地设置 if (msg.Headers.Contains("termlyDate")) { App.AppSettings.TermlyDate = Convert.ToDateTime(msg.Headers.GetValues("termlyDate").ToList()[0]); } if (msg.Headers.Contains("weekNum")) { App.AppSettings.WeekNum = Convert.ToInt32(msg.Headers.GetValues("weekNum").ToList()[0]); } //将Json保存至本地 return(await CourseDataService.SaveTermlyJsonToIsoStoreAsync(termlyJson)); } else { Debug.WriteLine(termlyJson); return(2);//信息不正确 } } else { return(3);//登录超时等情况 } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(-1);//发生异常 } }