/// <summary> /// SplitView中ListItem选中项事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void splitViewListItems_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (null != svModel && svModel.Count > 0) { var selectItem = svModel[0]; //如果当前显示“退 出”,则表示已经登录,要清除用户信息 if (selectItem.SplitViewTitle.Contains("退 出")) { localSettings.Values["userIdentity"] = null; MainPageSplitViewItemEntity svItemLoginOrLogOff = new MainPageSplitViewItemEntity(); //判断用户是否登录过 string userIdentity = localSettings.Values["userIdentity"] as string; //不为空则表示登录过 if (!string.IsNullOrEmpty(userIdentity)) { svItemLoginOrLogOff.IconFont = "\ue603"; svItemLoginOrLogOff.SplitViewTitle = "退 出"; svItemLoginOrLogOff.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; } else { svItemLoginOrLogOff.IconFont = "\ue604"; svItemLoginOrLogOff.SplitViewTitle = "登 录"; svItemLoginOrLogOff.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; } MainPageSplitViewItemEntity svItemRegister = new MainPageSplitViewItemEntity(); svItemRegister.IconFont = "\ue605"; svItemRegister.SplitViewTitle = "注 册"; svItemRegister.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; if (null != svModel) { svModel.Clear(); } svModel.Add(svItemLoginOrLogOff); svModel.Add(svItemRegister); splitViewListItems.ItemsSource = svModel; } else if (splitViewListItems.SelectedIndex == 1) { //导航到“注册”页 this.Frame.Navigate(typeof(UserRegister)); }//如果当前显示“登录”,则表示未登录,要转向登录页面 else if (selectItem.SplitViewTitle.Contains("登 录")) { //导航到“登录”页 this.Frame.Navigate(typeof(UserLogin)); } } }
/// <summary> /// 初始化主页数据的方法 /// </summary> public async void InitMainPageDatas() { //使用导航缓存 NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Disabled; MainPageSplitViewItemEntity svItemLoginOrLogOff = new MainPageSplitViewItemEntity(); //判断用户是否登录过 string userIdentity = localSettings.Values["userIdentity"] as string; //不为空则表示登录过 if (!string.IsNullOrEmpty(userIdentity)) { svItemLoginOrLogOff.IconFont = "\ue603"; svItemLoginOrLogOff.SplitViewTitle = "退 出"; svItemLoginOrLogOff.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; } else { svItemLoginOrLogOff.IconFont = "\ue604"; svItemLoginOrLogOff.SplitViewTitle = "登 录"; svItemLoginOrLogOff.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; } MainPageSplitViewItemEntity svItemRegister = new MainPageSplitViewItemEntity(); svItemRegister.IconFont = "\ue605"; svItemRegister.SplitViewTitle = "注 册"; svItemRegister.FontFamilyProperty = "ms-appx:///Assets/Resources/iconfont.ttf#iconfont"; splitViewListItems.ItemsSource = null; svModel.Add(svItemLoginOrLogOff); svModel.Add(svItemRegister); splitViewListItems.ItemsSource = svModel; try { LoadInitData = true; articlesModel = await HTTPRequestHelper <ArticlesEntity> .requestAndResponseCollections(MobileInterfaceFactory.GET_ALL_ARTICLES_INFO, "{\"paramJsonDatas\":" + pageIndex + "}"); mainPageList.ItemsSource = articlesModel; progressOfInitFirstDatas.Visibility = Visibility.Collapsed; } catch (HttpRequestException requestEx) { //初始化失败计数+1 initDataFailedCount += 1; //异常之后再次请求 InitMainPageDatas(); //如果请求次数超出2次,说明不是MySQL超时自动关闭连接的问题而是其他问题,弹出消息框 if (initDataFailedCount > 2) { await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg + "HttpRequestException", requestEx.Message, true, false, SystemMessage.DialogButtonByOkValueMsg, String.Empty, ContentDialogStyle.NORMAL).ShowAsync(); } } catch (Exception ex) { //异常之后再次请求 InitMainPageDatas(); await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg + "Exception", ex.Message, true, false, SystemMessage.DialogButtonByOkValueMsg, String.Empty, ContentDialogStyle.NORMAL).ShowAsync(); } }