private async void post_click(object sender, EventArgs e) { if (_popuppost.contentTextBox.Text == string.Empty) { MessageBox.Show("请输入内容"); return; } if (_popuppost.titleTextBox.Text == string.Empty) { MessageBox.Show("请输入标题"); return; } pgbar.Visibility = Visibility.Visible; bool bl = await BuAPI.PostThread(_fid, _popuppost.titleTextBox.Text, _popuppost.contentTextBox.Text); pgbar.Visibility = Visibility.Collapsed; if (bl) { MessageBox.Show("发布成功"); _popuppost.CloseMeAsPopup(); } else { MessageBox.Show("发布失败"); } }
private async void post_click(object sender, EventArgs e) { if (_popupreply.contentTextBox.Text == string.Empty) { MessageBox.Show("请输入内容"); return; } _popupreply.CloseMeAsPopup(); pgbar.Visibility = Visibility.Visible; (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false; bool bl = await BuAPI.ReplyPost(_tid, _popupreply.contentTextBox.Text); pgbar.Visibility = Visibility.Collapsed; (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; if (bl) { _popupreply.contentTextBox.Text = string.Empty; MessageBox.Show("回复成功"); //此处其实还需修改版面上该帖的相关数据,懒得弄了╮(╯_╰)╭ if (Convert.ToUInt16(_replies) == _maxpage * BuSetting.PageThreadCount) { _maxpage++; } _pagecache.Remove(_maxpage); ShowViewModel(_maxpage); } else { MessageBox.Show("回复失败"); } }
//异步加载论坛列表 private async void LoadForumList() { if (_mainvm.ForumItems.Count() != 0) { return; } if (isloadingforumlist) { return; } isloadingforumlist = true; pgBar.Visibility = Visibility.Visible; List <BuGroupForum> bl = await BuAPI.QueryForumList(); pgBar.Visibility = Visibility.Collapsed; if (bl == null) { isloadingforumlist = false; return; } foreach (BuGroupForum bt in bl) { if (bt.main == null) { continue; } if (bt.main.Count != 1) { continue; } //添加主论坛 _mainvm.ForumItems.Add(new ForumViewModel(bt.main[0])); if (bt.sub == null) { continue; } DictFourm[bt.main[0].fid] = new List <BuForum>(); foreach (var subforum in bt.sub) { DictFourm[bt.main[0].fid].Add(subforum); } } isloadingforumlist = false; }
private async void ShowViewModel(uint pageno) { _currentpage = pageno; ThreadName.Text = string.Format(_pagetemplate, pageno.ToString(), _maxpage.ToString()) + _subject; //清除界面数据 _threadview.PostItems.Clear(); //先从缓存中获取 List <BuPost> postlist = null; if (!_pagecache.TryGetValue(pageno, out postlist))//尾页刷新&设置页码后刷新 { togglePgBar(); //载入期间禁用菜单栏 (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = false; (ApplicationBar.Buttons[2] as ApplicationBarIconButton).IsEnabled = false; (ApplicationBar.MenuItems[0] as ApplicationBarMenuItem).IsEnabled = false; (ApplicationBar.MenuItems[1] as ApplicationBarMenuItem).IsEnabled = false; postlist = await BuAPI.QueryPost(_tid, ((pageno - 1) * BuSetting.PageThreadCount).ToString(), (pageno *BuSetting.PageThreadCount).ToString()); togglePgBar(); if (postlist == null || postlist.Count == 0) { //控制菜单显示 CheckBtnEnable(); return; } _pagecache[pageno] = postlist; } //修改标题的所在页码 ThreadName.Text = string.Format(_pagetemplate, pageno.ToString(), _maxpage.ToString()) + _subject; //控制菜单显示 CheckBtnEnable(); uint floorno = (pageno - 1) * BuSetting.PageThreadCount; //填写视图模型 foreach (BuPost post in postlist) { _threadview.PostItems.Add(new PostViewModel(post, ++floorno)); } }
//点击登陆事件 private async void login_click(object sender, EventArgs e) { if (ID.Text == string.Empty || Password.Password == string.Empty) { return; } SwitchLoading(); bool bl = await BuAPI.Login(ID.Text, Password.Password); if (bl) { SaveConfig(); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } else { SwitchLoading(false); } }
//异步加载帖子列表 private async void LoadThreadList() { //清除界面数据 _forumpageviewmodel.ThreadItems.Clear(); //先从缓存中获取 List <BuThread> threadlist; if (!_pagecache.TryGetValue(_pageno, out threadlist)) { togglePgBar(); //载入期间禁用菜单栏 (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = false; (ApplicationBar.Buttons[2] as ApplicationBarIconButton).IsEnabled = false; (ApplicationBar.Buttons[3] as ApplicationBarIconButton).IsEnabled = false; threadlist = await BuAPI.QueryThreadList(_fid, ((_pageno - 1) * 20).ToString(), (_pageno * 20 - 1).ToString()); (ApplicationBar.Buttons[3] as ApplicationBarIconButton).IsEnabled = true; togglePgBar(); if (threadlist == null || threadlist.Count == 0) { //控制菜单显示 CheckBtnEnable(); return; } _pagecache[_pageno] = threadlist; } //控制菜单显示 CheckBtnEnable(); //填写视图模型 foreach (BuThread bt in threadlist) { _forumpageviewmodel.ThreadItems.Add(new ThreadViewModel(bt)); } }
//异步加载最新帖子列表 private async void LoadLatestThreadList() { if (_mainvm.LatestThreadItems.Count != 0) { return; } pgBar.Visibility = Visibility.Visible; (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false; List <BuLatestThread> btl = await BuAPI.QueryLatestThreadList(); (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; pgBar.Visibility = Visibility.Collapsed; if (btl == null) { return; } foreach (BuLatestThread bt in btl) { _mainvm.LatestThreadItems.Add(new ThreadViewModel(bt)); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { bool bl = true; PgBar.Visibility = Visibility.Collapsed; //可能的登出判断 string type; NavigationContext.QueryString.TryGetValue("type", out type); if (type == "logout") { NavigationService.RemoveBackEntry(); SwitchLoading(); bl = await BuAPI.Logout(); SwitchLoading(false); } if (bl == false) { MessageBox.Show("登出失败,可能与服务器连接已断开"); } //填写记录的默认信息 ID.Text = BuSetting.ID; Password.Password = BuSetting.Password; isRemPassword.IsChecked = BuSetting.RemPassWord; isAutoLogin.IsChecked = BuSetting.AutoLogin; tsNetWork.IsChecked = (BuSetting.URL == "http://out.bitunion.org/open_api/"); if (BuSetting.RemPassWord) { isRemPassword_Checked(null, null); } else { isRemPassword_Unchecked(null, null); } if (BuSetting.AutoLogin) { isAutoLogin_Checked(null, null); } else { isAutoLogin_Unchecked(null, null); } if (BuSetting.URL == "http://out.bitunion.org/open_api/") { NetWork_Checked(null, null); } else { NetWork_Unchecked(null, null); } //自动登录 if (BuSetting.AutoLogin && BuSetting.RemPassWord && type != "logout" && e.NavigationMode == NavigationMode.New) { login_click(null, null); } }