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 savewz_Click(object sender, EventArgs e) { try { if (!StaticData.IsLogin) { MessageBox.Show("请先登录"); return; } if (isCollection) { MessageBox.Show("已经收藏,可以到我的收藏中删除"); return; } HttpHelp httpHelp = new HttpHelp(); httpHelp.parameters.Add("cId", StaticData.acitem.href.Remove(0, 5)); httpHelp.parameters.Add("operate", "1"); using (var stream = await httpHelp.Post(StaticData.tocollection)) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(tocollectionresult)); var result = json.ReadObject(stream) as tocollectionresult; if (result.success) { MessageBox.Show("收藏成功"); isCollection = true; } else { MessageBox.Show("收藏失败"); } } } 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; }
private async void delcolbt_Click(object sender, RoutedEventArgs e) { try { if (MessageBox.Show("若确信继续当前操作,请点击[确定]按钮,反之则请点击[取消]按钮", "取消收藏", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } ButtonEx lb = sender as ButtonEx; HttpHelp httpHelp = new HttpHelp(); httpHelp.parameters.Add("cId", lb.Tag.ToString().Remove(0, 5)); httpHelp.parameters.Add("operate", "0"); using (var stream = await httpHelp.Post(StaticData.tocollection)) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(tocollectionresult)); var result = json.ReadObject(stream) as tocollectionresult; if (result.success) { int tag = -1; for (int i = 0; i < collectionlist.Count; i++) { if (lb.Tag.ToString() == collectionlist[i].href) { tag = i; } } if (tag != -1) { collectionlist.RemoveAt(tag); } } else { MessageBox.Show("删除收藏失败"); } } } catch { } }
private async void send_Click(object sender, RoutedEventArgs e) { try { if (!StaticData.IsLogin) { MessageBox.Show("请先登录"); return; } if (content.Text != null && content.Text != "") { if (noemoji(content.Text).Length < 5) { MessageBox.Show("字数这么少~!"); return; } indicator.IsVisible = true; HttpHelp httpHelp = new HttpHelp(); httpHelp.parameters.Add("name", StaticData.postname); httpHelp.parameters.Add("token", StaticData.posttoken); httpHelp.parameters.Add("text", content.Text + Environment.NewLine + "---发送自WP文章区客户端"); httpHelp.parameters.Add("quoteId", replayid > 0 ? (replayid + "") : ""); httpHelp.parameters.Add("contentId", StaticData.acitem.href.Substring(5, StaticData.acitem.href.Length - 5)); httpHelp.parameters.Add("cooldown", StaticData.postcooldown); httpHelp.parameters.Add("quoteName", ""); using (var stream = await httpHelp.Post("http://www.acfun.com/comment.aspx")) { if (stream != null) { //StreamReader sr = new StreamReader(stream); //Debug.WriteLine(sr.ReadToEnd()); //stream.Position = 0; DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(commentuploadresult)); var result = json.ReadObject(stream) as commentuploadresult; if (result.success) { content.Text = ""; replayid = 0; floor.Text = "无引用"; flush(); } else if (result.info != null && result.info != "") { MessageBox.Show(result.info); } else { MessageBox.Show("回复失败"); } } else { MessageBox.Show("未知异常,多半是网络问题啦~"); } } indicator.IsVisible = false; } } catch { } }