async void MainPage_Loaded(object sender, RoutedEventArgs e) { try { if (!StaticData.IsLogin && Settings.GetValueOrDefault("username", "") != "" && Settings.GetValueOrDefault("password", "") != "") { HttpHelp httpHelp = new HttpHelp(); httpHelp.parameters.Add("username", Settings.GetValueOrDefault("username", "")); httpHelp.parameters.Add("password", Settings.GetValueOrDefault("password", "")); using (var stream = await httpHelp.PostSetCookie(StaticData.login)) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(loginresult)); var result = json.ReadObject(stream) as loginresult; if (result.success) { StaticData.UserName = result.username; StaticData.UserImg = result.img; StaticData.IsLogin = true; denglu.Visibility = Visibility.Collapsed; name.Text = result.username; userlogo.Source = new BitmapImage(new Uri(StaticData.UserImg, UriKind.RelativeOrAbsolute)); zhuxiao.Visibility = Visibility.Visible; await getunRead(); } } } } catch { } }
private async void Button_Click(object sender, RoutedEventArgs e) { if (tbusername.Text == null || tbusername.Text == "") { MessageBox.Show("用户名不能为空"); return; } if (tbpassword.Password == null || tbpassword.Password == "") { MessageBox.Show("密码不能为空"); return; } indicator.IsVisible = true; HttpHelp httpHelp = new HttpHelp(); httpHelp.parameters.Add("username", tbusername.Text); httpHelp.parameters.Add("password", tbpassword.Password); using (var stream = await httpHelp.PostSetCookie("http://www.acfun.com/login.aspx")) { if (stream != null) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(loginresult)); var result = json.ReadObject(stream) as loginresult; if (result.success) { Settings.AddOrUpdateValue("username", tbusername.Text); Settings.AddOrUpdateValue("password", tbpassword.Password); StaticData.UserName = result.username; StaticData.UserImg = result.img; StaticData.IsLogin = true; if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } else if (result.result != null && result.result != "") { MessageBox.Show(result.result); } else { MessageBox.Show("未知异常"); } } else { MessageBox.Show("未知异常"); } } indicator.IsVisible = false; }