示例#1
0
 private async void scrollViewer_ViewerChanged(object sender, ScrollViewerViewChangedEventArgs e)
 {
     if (!e.IsIntermediate)
     {
         IsPullRefresh = true;
         //将服务器返回的JSON反序列化为对象集合
         foreach (CommentsOrRepliesEntity item in await HTTPRequestHelper <CommentsOrRepliesEntity> .requestAndResponseCollections(MobileInterfaceFactory.GET_AN_ARTICLE_COMMENTS_OR_REPLIES_INFO, "{\"pageIndex\":" + (pageIndex += 1).ToString() + ",\"articleId\":" + articleId + "}"))
         {
             commentsOrRepliesModel.Add(item);
         }
         cOrRList.ItemsSource = commentsOrRepliesModel;
         IsPullRefresh        = false;
     }
 }
 private async void scrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
 {
     if (!e.IsIntermediate)
     {
         IsPullRefresh = true;
         //将服务器返回的JSON反序列化为对象集合
         foreach (ArticlesEntity item in await HTTPRequestHelper <ArticlesEntity> .requestAndResponseCollections(MobileInterfaceFactory.GET_ALL_ARTICLES_INFO, "{\"paramJsonDatas\":" + (pageIndex += 1).ToString() + "}"))
         {
             articlesModel.Add(item);
         }
         mainPageList.ItemsSource = articlesModel;
         IsPullRefresh            = false;
     }
 }
示例#3
0
        private async void PraiseCountButton_Click(object sender, RoutedEventArgs e)
        {
            string dialogTitle = "", dialogContent = "";

            var selectItem = cOrRList.SelectedItem;

            //如果没有选中项,则给出提示
            if (null == selectItem)
            {
                await ContentDialogTemplateUtil.showContentDialog("操作错误", "请选中一项评论/回复消息后再点赞。", true, false, "好的", null, ContentDialogStyle.NORMAL).ShowAsync();
            }
            else
            {
                string prepareParam = "{\"paramJsonDatas\":" + ((CommentsOrRepliesEntity)selectItem).id + "}";
                ObservableCollection <DoPraiseRespEntity> resultEntity = await HTTPRequestHelper <DoPraiseRespEntity> .requestAndResponseCollections(MobileInterfaceFactory.DO_PRAISE_FOR_COMMENTS_OR_REPLIES_INFO, prepareParam);

                //最终结果属性
                var resultFlag = bool.Parse(resultEntity[0].result.ToString());
                //是否点赞过属性
                var isPraisedFlag = bool.Parse(resultEntity[0].isParised.ToString());

                //如果最终结果为true,是否点赞为false,则表示点赞成功
                if (resultFlag == true && isPraisedFlag == false)
                {
                    dialogTitle   = "点赞成功";
                    dialogContent = "恭喜,点赞成功!";
                    InitMainPageDatas(true);
                }
                //如果最终结果为false,是否点赞为true,则表示已点过赞
                else if (resultFlag == false && isPraisedFlag == true)
                {
                    dialogTitle   = "点赞失败";
                    dialogContent = "请勿重复点赞!";
                }
                //如果最终结果和是否点赞都为false,则表示点赞失败
                else if (resultFlag == false && isPraisedFlag == false)
                {
                    dialogTitle   = "点赞失败";
                    dialogContent = "非常抱歉,在您尝试点赞时发生错误,请稍候再试。";
                }

                await ContentDialogTemplateUtil.showContentDialog(dialogTitle, dialogContent, true, false, "好的", null, ContentDialogStyle.NORMAL).ShowAsync();
            }
        }
示例#4
0
        /// <summary>
        /// 初始化主页数据的方法
        /// </summary>

        public async void InitMainPageDatas(bool refreshButtonClicked)
        {
            noDataPicArea.Visibility = Visibility.Collapsed;
            scrollViewer.Visibility  = Visibility.Visible;
            try
            {
                LoadInitData           = true;
                commentsOrRepliesModel = await HTTPRequestHelper <CommentsOrRepliesEntity> .requestAndResponseCollections(MobileInterfaceFactory.GET_AN_ARTICLE_COMMENTS_OR_REPLIES_INFO, "{\"pageIndex\":" + (refreshButtonClicked == true ? 1 : pageIndex) + ",\"articleId\":" + articleId + "}");

                //为0则表示没有数据,给出提示
                if (commentsOrRepliesModel.Count == 0)
                {
                    noDataPicArea.Visibility = Visibility.Visible;
                    scrollViewer.Visibility  = Visibility.Collapsed;
                }
                else
                {
                    noDataPicArea.Visibility = Visibility.Collapsed;
                    scrollViewer.Visibility  = Visibility.Visible;

                    cOrRList.ItemsSource = commentsOrRepliesModel;
                }

                progressOfInitFirstCOrRDatas.Visibility = Visibility.Collapsed;
            }
            catch (HttpRequestException requestEx)
            {
                await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, requestEx.Message, true, false, SystemMessage.DialogButtonByOkValueMsg, String.Empty, ContentDialogStyle.NORMAL).ShowAsync();
            }
            catch (Exception ex)
            {
                await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, ex.Message, true, false, SystemMessage.DialogButtonByOkValueMsg, String.Empty, ContentDialogStyle.NORMAL).ShowAsync();
            }
            finally
            {
                LoadInitData = false;
            }
        }
示例#5
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(this.inputAccount.Text) || this.inputAccount.Text.Length <= 0)
            {
                await new MessageDialog("请填写您的账户信息。", SystemMessage.DialogCommonTitleMsg).ShowAsync();
                return;
            }
            else if (String.IsNullOrEmpty(this.inputPassword.Password) || this.inputPassword.Password.Length <= 0)
            {
                await new MessageDialog("请填写您的账户密码。", SystemMessage.DialogCommonTitleMsg).ShowAsync();
                return;
            }

            User u = new User()
            {
                userNickName = this.inputAccount.Text, userPassword = this.inputPassword.Password
            };

            //对象序列化为JSON字符串
            string serializeResult = JsonConvert.SerializeObject(u);

            ObservableCollection <UserLoginRespEntity> result = await HTTPRequestHelper <UserLoginRespEntity> .requestAndResponseCollections(MobileInterfaceFactory.USER_LOGIN, serializeResult);

            if (result[0].result == true)
            {
                //await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, SystemMessage.LoginSuccessMsg, true, false, SystemMessage.DialogButtonByOkValueMsg, string.Empty, ContentDialogStyle.NORMAL).ShowAsync();

                //登录成功后放入用户信息
                localSettings.Values["userIdentity"] = result[0].userId;

                Frame.Navigate(typeof(MainPage));
            }
            else
            {
                await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, SystemMessage.LoginFailedMsg, true, false, SystemMessage.DialogButtonByOkValueMsg, string.Empty, ContentDialogStyle.NORMAL).ShowAsync();
            }
        }
        /// <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();
            }
        }