private async Task KissingAsync() { if (IsKissing) { return; } else { IsKissing = true; KissingBar.Background = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColor"]); // show ShowKissingBar.Begin(); string result = null; ContentDialog ErrorContentDialog = new ContentDialog(); // refresh try { result = await StudentData.Refresh(); } catch (Exception e) { try { ErrorContentDialog.Title = LocalizedResources.GetString("unknownError/Text"); ErrorContentDialog.Content = LocalizedResources.GetString("bad/Text") + "\r\n\r\n" + e.ToString(); ErrorContentDialog.CloseButtonText = LocalizedResources.GetString("yesNet/Text"); } catch (Exception) { } } // hide HideKissingBar.Begin(); await Task.Delay(100); HideKissingBarRow.Begin(); switch (result) { case "okey dokey": StatusTextBlock.Text = "Updated!"; break; case "error": StatusTextBlock.Text = LocalizedResources.GetString("cannotConnect/Text"); // Tawny KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 202, 81, 0)); // await ErrorContentDialog.ShowAsync(); break; case null: StatusTextBlock.Text = LocalizedResources.GetString("unknownError/Text"); // Tawny KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 202, 81, 0)); // await ErrorContentDialog.ShowAsync(); break; } ProcesR.Visibility = Visibility.Collapsed; ShowKissingBar.Begin(); await Task.Delay(1500); HideKissingBar.Begin(); await Task.Delay(200); HideKissingBarRow.Begin(); StatusTextBlock.Text = "Purr ..."; ProcesR.Visibility = Visibility.Visible; KissingBar.Background = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColor"]); Initialize(); IsKissing = false; } }
private async void Sumbission(object sender, RoutedEventArgs e) { Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; HttpClient client = new HttpClient(); var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "studentID", (string)localSettings.Values["UsrName"] }, { "studentName", StudentData.info.LastName + " " + StudentData.info.FirstName }, { "stayInSchool", StayInSchool.IsOn.ToString() }, { "schoolBus", Bus.IsOn.ToString() }, { "friN", friN.IsChecked.ToString() }, { "sat", sat.IsChecked.ToString() }, { "sun", sun.IsChecked.ToString() }, { "DateOutsideFri", DateOutsideFri.IsChecked.ToString() }, { "DateOutsideSat", DateOutsideSat.IsChecked.ToString() }, { "DateOutsideSun", DateOutsideSun.IsChecked.ToString() }, { "SubmissionTime", System.DateTime.Now.ToString("h:mm:ss tt yyyy-MM-dd") } } ); // show ShowKissingBar.Begin(); StatusTextBlock.Text = "Updating ..."; txtIcn.Visibility = Visibility.Collapsed; txtIcn.Glyph = ""; ProcesR.Visibility = Visibility.Visible; KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 99, 177)); // kiss result = ""; try { var v = await client.PostAsync("http://35.187.217.44:4567/student/", content); // var v = await client.PostAsync("http://127.0.0.1:8000/student/", content); result = await v.Content.ReadAsStringAsync(); } catch (Exception) { } // hide HideKissingBar.Begin(); await Task.Delay(300); HideKissingBarRow.Begin(); switch (result) { case "okey dokey": StatusTextBlock.Text = "留校信息更新成功。"; txtIcn.Visibility = Visibility.Visible; txtIcn.Glyph = "\uE73E"; ProcesR.Visibility = Visibility.Collapsed; KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 99, 177)); break; case "human is dead": StatusTextBlock.Text = "坏死。"; txtIcn.Visibility = Visibility.Visible; txtIcn.Glyph = "\uEA6A"; ProcesR.Visibility = Visibility.Collapsed; KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 202, 81, 0)); break; default: StatusTextBlock.Text = "生死去来,棚头傀儡。一线断时,落落磊磊。"; txtIcn.Visibility = Visibility.Visible; txtIcn.Glyph = "\uEA6A"; ProcesR.Visibility = Visibility.Collapsed; KissingBar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 202, 81, 0)); break; } ShowKissingBar.Begin(); }