private async void definitionDialogPrimaryButton_Click(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (string.IsNullOrEmpty(inputCommentsOrReplies.Text) || inputCommentsOrReplies.Text.Length <= 0) { await MessageDialogTemplateUtil.showMessageDialog("请填写您的评论", "评论不能为空,请输入您的评论。", MessageDialogStyle.HAVING_BOTH).ShowAsync(); } else if (inputCommentsOrReplies.Text.Length <= 9) { await MessageDialogTemplateUtil.showMessageDialog("评论字数过少", "您发表的评论字数过少,请至少输入10个字符以上。", MessageDialogStyle.HAVING_BOTH).ShowAsync(); } else { EasClientDeviceInformation systemInfo = new EasClientDeviceInformation(); try { SingleResultEntity resultEntity = await HTTPRequestHelper <SingleResultEntity> .requestAndResponseSingleResult(MobileInterfaceFactory.PUBLISH_COMMENTS_OR_REPLIES_INFO, "{\"articleId\": " + articleId + ",\"userId\" : " + localSettings.Values["userIdentity"] + ",\"content\" : " + inputCommentsOrReplies.Text + ",\"device\" : " + systemInfo.SystemSku + ",\"system\" : " + systemInfo.OperatingSystem + " }"); if (bool.Parse(resultEntity.result.ToString()) == true) { await MessageDialogTemplateUtil.showMessageDialog("评论成功", "恭喜,您的评论/回复消息发布成功!您的评论/回复消息需要人工审核之后才能正常显示,还请您耐心等待哦~", MessageDialogStyle.HAVING_BOTH).ShowAsync(); InitMainPageDatas(true); } cOrRList.IsSwipeEnabled = true; } catch (Exception ex) { await MessageDialogTemplateUtil.showMessageDialog("评论失败", "非常抱歉,在您尝试发表评论/回复消息时发生了错误,请稍后再试。\n异常信息为:\n" + ex.Message, MessageDialogStyle.HAVING_BOTH).ShowAsync(); } } }
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; } }
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 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(); } }
/// <summary> /// “注册”按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnRegister_Click(object sender, RoutedEventArgs e) { string nullOrEmptyFormValidateResultStrings = validateIsNullOrEmptyOfForm(); //如果非空验证的验证结果不为空,则表示有表单元素没填写完整 if (!string.IsNullOrEmpty(nullOrEmptyFormValidateResultStrings) && nullOrEmptyFormValidateResultStrings.Length > 0) { await ContentDialogTemplateUtil.showContentDialog("请全部填写注册信息", "非常抱歉,您有如下信息未填写完整,请重新填写后再试。" + nullOrEmptyFormValidateResultStrings, true, false, "好的", string.Empty, ContentDialogStyle.NORMAL).ShowAsync(); } //否则去验证已填写的内容 else { string correctFormValidateResultStrings = validateIsNullOrEmptyOfForm(); //如果数据合法性验证的验证结果不为空,则表示有表单元素填入了不合法的值 if (!string.IsNullOrEmpty(correctFormValidateResultStrings) && correctFormValidateResultStrings.Length > 0) { await ContentDialogTemplateUtil.showContentDialog("填写注册信息错误", "非常抱歉,您有如下信息填写错误,请重新填写后再试。" + correctFormValidateResultStrings, true, false, "好的", string.Empty, ContentDialogStyle.NORMAL).ShowAsync(); } //否则填写正确 else { User user = new User() { userNickName = inputNickName.Text, userGender = inputGenderForBoy.IsChecked == true ? "男" : "女", userRole = "普通用户", userAge = int.Parse(inputSelectAge.SelectedValue.ToString()), userPassword = inputPassword.Password, userSecurityQuestionAnswer = inputSecurityQuestionAnswer.Text, userState = "正常", userLevel = 1, userEmail = inputEmailAddress.Text, userQQNumber = int.Parse(inputQQNumber.Text), userLocation = "浙江省杭州市江干区" }; string paramDatas = JsonConvert.SerializeObject(user); SingleResultEntity resultObj = await HTTPRequestHelper <SingleResultEntity> .requestAndResponseSingleResult(MobileInterfaceFactory.USER_REGISTER, paramDatas); if (Boolean.Parse(resultObj.result.ToString()) == true) { await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, SystemMessage.RegisterSuccessMsg, true, false, SystemMessage.DialogButtonByOkValueMsg, String.Empty, ContentDialogStyle.NORMAL).ShowAsync(); Frame.Navigate(typeof(UserLogin)); } else { await ContentDialogTemplateUtil.showContentDialog(SystemMessage.DialogCommonTitleMsg, SystemMessage.RegisterFailedMsg, true, false, SystemMessage.DialogButtonByOkValueMsg, string.Empty, ContentDialogStyle.NORMAL).ShowAsync(); } } } }
/// <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; } }
/// <summary> /// 获取文章详情,载入数据的方法 /// </summary> /// <returns></returns> private async System.Threading.Tasks.Task getArticleDetailInfo() { SingleResultEntity resultEntity = await HTTPRequestHelper <SingleResultEntity> .requestAndResponseSingleResult(MobileInterfaceFactory.GET_AN_ARTCILE_TITLE_INFO, "{\"articleId\":" + articleId + "}"); articleTitle.Text = resultEntity.result.ToString(); //showArticleName.Text = articleDetail[0].articleName; //showArticleCreateDate.Text = articleDetail[0].articleCreateDate; //showArticleAuthor.Text = articleDetail[0].articleAuthor; //showArticleType.Text = articleDetail[0].articleType; //webBrowser.NavigateToString(articleDetail[0].articleContent); //HtmlDocument document = new HtmlDocument(); //document.LoadHtml(articleDetail[0].articleContent); //HtmlNode node = document.DocumentNode; //showArticleContent.Text = document.DocumentNode.InnerText.Replace(" ", "").Trim(); //showArticleContent.Text = HttpUtility.HtmlDecode(node.InnerText); var themeValue = localSettings.Values["theme"] as string; String theme = String.Empty; if (!String.IsNullOrEmpty(themeValue) && themeValue.Equals("White")) { theme = "false"; } else { theme = "true"; } GetAnArticleDetailInfoRespEntity articleDetailEntity = new GetAnArticleDetailInfoRespEntity() { articleId = articleId.ToString(), enableNightMode = theme }; Uri uri = new Uri(MobileInterfaceFactory.GET_AN_ARTCILE_DETAIL_INFO + "?paramJsonDatas=" + JsonUtil.convertObjectToJsonFmt(articleDetailEntity)); webBrowser.Navigate(uri); }
/// <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(); } }