コード例 #1
0
        private async void Create_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string pass = null;

            passage.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out pass);
            if (pass == "")
            {
                MessageDialog dialog = new MessageDialog("帖子内容不能为空!");
                await dialog.ShowAsync();

                return;
            }
            Dictionary <string, string> info = await NetworkControl.PublishPost(username, password, title.Text, pass, media);

            if (info["code"] != "1")
            {
                MessageDialog dialog = new MessageDialog("创建帖子失败!");
                await dialog.ShowAsync();
            }
            else
            {
                string[] temp = new string[2];
                temp[0] = username;
                temp[1] = password;
                MessageDialog dialog = new MessageDialog("创建帖子成功!");
                await dialog.ShowAsync();

                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(MainPage), temp);
            }
        }
コード例 #2
0
ファイル: PostPageM.xaml.cs プロジェクト: SYSU532/Know-it
        public PostPageM()
        {
            InitializeComponent();
            NetworkControl.InitialWebSocket();

            //Control tile change time
            timer.Interval = new TimeSpan(0, 0, 3);
            timer.Tick    += ChangeTile;
            timer.Start();
        }
コード例 #3
0
        private async void InitializeUser()
        {
            usernameText.Text = username;
            Dictionary <string, string> info = await NetworkControl.QueryUserInfo(username);

            string imageUrl = info.GetValueOrDefault <string, string>("imageUrl");
            var    newSrc   = new BitmapImage(new Uri(NetworkControl.GetFullPathUrl(imageUrl), UriKind.Absolute));

            newSrc.CreateOptions     = BitmapCreateOptions.IgnoreImageCache;
            personPic.ProfilePicture = newSrc;
        }
コード例 #4
0
ファイル: PostPageM.xaml.cs プロジェクト: SYSU532/Know-it
        private async void SendMessage_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string mess = null;

            message.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out mess);
            if (mess != "")
            {
                await NetworkControl.SendChatMessage(username, password, mess);

                message.Document.SetText(Windows.UI.Text.TextSetOptions.ApplyRtfDocumentDefaults, "");
            }
        }
コード例 #5
0
ファイル: PostPageM.xaml.cs プロジェクト: SYSU532/Know-it
        private async void InitializePost()
        {
            myViewModels.allPosts.Clear();
            ObservableCollection <PostItem> posts = await NetworkControl.GetPostCollection(username, password);

            if (posts != null)
            {
                foreach (PostItem item in posts)
                {
                    string thumbs_num = item.thumbs.ToString();
                    myViewModels.AddPost(item.id, item.editor, item.title, thumbs_num, item.imageURL, item.videoURL);
                }
            }
        }
コード例 #6
0
ファイル: UserPage.xaml.cs プロジェクト: SYSU532/Know-it
        private async void Commit_Change(object sender, RoutedEventArgs e)
        {
            if (emailBlock.Text == oldEmail && phoneBlock.Text == oldPhone && CurrentPic == null)
            {
                MessageDialog dialog = new MessageDialog("请先点击电话或邮箱或头像以修改信息!");
                await dialog.ShowAsync();

                return;
            }
            StringBuilder errBuilder = new StringBuilder();

            if (!phonePattern.IsMatch(phoneBlock.Text))
            {
                errBuilder.Append("Phone Number Invalid!\n");
            }
            if (!emailPattern.IsMatch(emailBlock.Text))
            {
                errBuilder.Append("Email Address Invalid!\n");
            }
            if (errBuilder.ToString().Length != 0)
            {
                MessageDialog dialog = new MessageDialog(errBuilder.ToString(), "Error!");
                await dialog.ShowAsync();

                return;
            }

            Dictionary <string, string> info = await NetworkControl.UserInfoModify(username, password, phoneBlock.Text, emailBlock.Text, CurrentPic);

            await WebView.ClearTemporaryWebDataAsync();

            string status = info["code"];

            if (status != "1")
            {
                MessageDialog dialog = new MessageDialog("修改失败!");
                await dialog.ShowAsync();
            }
            else
            {
                string[] temp = new string[2];
                temp[0] = username;
                temp[1] = password;
                MessageDialog dialog = new MessageDialog("修改成功!");
                await dialog.ShowAsync();

                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(MainPage), temp);
            }
        }
コード例 #7
0
 protected override async void OnNavigatedFrom(NavigationEventArgs e)
 {
     if (video.Visibility == Windows.UI.Xaml.Visibility.Visible)
     {
         video.Source = null;
     }
     if (thumb_click == 1 && hasThumb != true)
     {
         Dictionary <string, string> info = await NetworkControl.GiveThumbToPost(username, password, id);
     }
     else if (thumb_click == 0 && hasThumb == true)
     {
         Dictionary <string, string> info = await NetworkControl.CancelThumbToPost(username, password, id);
     }
 }
コード例 #8
0
        private async void InitializePost()
        {
            myViewModels.allComments.Clear();
            hasThumb = await NetworkControl.CheckUserThumbOrNot(username, id);

            if (hasThumb)
            {
                thumb_click = 1;
            }
            Dictionary <string, object> post = await NetworkControl.GetPostFromID(username, password, id);

            if ((string)post["code"] != "1")
            {
                //
            }
            else
            {
                title.Text     = post["title"] as string;
                author.Text    = post["editor"] as string;
                thumb_num.Text = post["thumbs"] as string;
                List <KeyValuePair <String, String> > commentDict = post["comment"] as List <KeyValuePair <String, String> >;
                Run run = new Run
                {
                    Text = post["content"] as string
                };
                Paragraph paragraph = new Paragraph();
                paragraph.Inlines.Add(run);
                passage.Blocks.Add(paragraph);
                if ((string)post["image"] != "")
                {
                    image.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    var imageUrl = (string)post["image"];
                    var newSrc   = new BitmapImage(new Uri(NetworkControl.GetFullPathUrl(imageUrl), UriKind.Absolute));
                    newSrc.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    image.Source         = newSrc;
                }
                else if ((string)post["media"] != "")
                {
                    video.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    var videoUrl = (string)post["media"];
                    video.Source = MediaSource.CreateFromUri(new Uri(NetworkControl.GetFullPathUrl(videoUrl), UriKind.Absolute));
                }
                foreach (var comment in commentDict)
                {
                    myViewModels.AddComment(comment.Key, comment.Value);
                }
            }
        }
コード例 #9
0
        private async void AddComment_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string mess = null;

            comment.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out mess);
            if (mess == "")
            {
                MessageDialog dialog = new MessageDialog("评论不能为空!");
                await dialog.ShowAsync();
            }
            else
            {
                myViewModels.AddComment(username, mess);
                Dictionary <string, string> info = await NetworkControl.PostComment(username, password, id, mess);

                comment.Document.SetText(Windows.UI.Text.TextSetOptions.ApplyRtfDocumentDefaults, "");
            }
        }
コード例 #10
0
ファイル: UserPage.xaml.cs プロジェクト: SYSU532/Know-it
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            string[] temp = e.Parameter as string[];
            username = temp[0];
            password = temp[1];
            Dictionary <string, string> info = await NetworkControl.QueryUserInfo(username);

            string imageUrl = info.GetValueOrDefault <string, string>("imageUrl");
            string phone    = info.GetValueOrDefault <string, string>("phone");
            string email    = info.GetValueOrDefault <string, string>("email");
            var    newSrc   = new BitmapImage(new Uri(NetworkControl.GetFullPathUrl(imageUrl), UriKind.Absolute));

            newSrc.CreateOptions     = BitmapCreateOptions.IgnoreImageCache;
            personPic.ProfilePicture = newSrc;
            usernameBlock.Text       = username;
            phoneBlock.Text          = phone;
            emailBlock.Text          = email;
            oldPhone = phone;
            oldEmail = email;
        }
コード例 #11
0
ファイル: SigninPage.xaml.cs プロジェクト: SYSU532/Know-it
        private async void UserNameBox_LostFocus(object sender, RoutedEventArgs e)
        {
            if (UserNameBox.Text.Length != 0)
            {
                string name = UserNameBox.Text;
                var    res  = await NetworkControl.QueryUserInfo(name);

                UserNameMsg.Text = "";
                if (res["code"] == "0")
                {
                    UserNameMsg.Text = res["errMessage"];
                }
                else if (res["code"] == "1")
                {
                    string imgUrl = res["imageUrl"];
                    var    newSrc = new BitmapImage(new Uri(NetworkControl.GetFullPathUrl(imgUrl), UriKind.Absolute));
                    newSrc.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    Logo.Source          = newSrc;
                }
            }
        }
コード例 #12
0
ファイル: SigninPage.xaml.cs プロジェクト: SYSU532/Know-it
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            var res = await NetworkControl.AttemptSignin(UserNameBox.Text, PasswordBox.Password);

            string msg     = "";
            bool   success = false;

            if (res["code"] == "-1")
            {
                msg = "Connection to server appears to be down, please check.";
            }
            else if (res["code"] == "-2")
            {
                msg = "Ughh... The server doesn't seem to be a Know-it Server, please check again.";
            }
            else if (res["code"] == "0")
            {
                msg = res["errMessage"];
            }
            else if (res["code"] == "1")
            {
                success = true;
            }
            if (msg != "")
            {
                MessageDialog dialog = new MessageDialog(msg);
                await dialog.ShowAsync();
            }
            if (success)
            {
                string[] temp = new string[2];
                temp[0] = UserNameBox.Text;
                temp[1] = PasswordBox.Password;
                this.Frame.Navigate(typeof(MainPage), temp);
                //go to content page, passing a pair with username as key and password as value as parameter.
            }
        }
コード例 #13
0
ファイル: PostPageM.xaml.cs プロジェクト: SYSU532/Know-it
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     NetworkControl.closeWs();
 }
コード例 #14
0
ファイル: SignupPage.xaml.cs プロジェクト: SYSU532/Know-it
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder builder = new StringBuilder();

            if (!usernamePattern.IsMatch(UsernameBox.Text) || UsernameBox.Text.Contains(" "))
            {
                builder.Append("Username Invalid!\n");
            }
            if (!passwordPattern.IsMatch(PasswordBox.Password))
            {
                builder.Append("Password Invalid!\n");
            }
            if (PasswordBox.Password != SecondPasswordBox.Password)
            {
                builder.Append("The Two Passwords Don't Match!\n");
            }
            if (!emailPattern.IsMatch(EmailBox.Text))
            {
                builder.Append("Email Invalid!\n");
            }
            if (!phonePattern.IsMatch(PhoneBox.Text))
            {
                builder.Append("Phone Number Invalid!\n");
            }
            if (builder.Length != 0)
            {
                var alert = new MessageDialog(builder.ToString(), "Error!");
                await alert.ShowAsync();
            }
            else
            {
                if (thumbFile == null)
                {
                    thumbFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/jian-yang.png"));
                }
                var res = await NetworkControl.AttemptSignUp(UsernameBox.Text, PasswordBox.Password, SecondPasswordBox.Password,
                                                             PhoneBox.Text, EmailBox.Text, thumbFile);

                string msg     = "";
                bool   success = false;
                if (res["code"] == "-1")
                {
                    msg = "Connection to server appears to be down, please check.";
                }
                else if (res["code"] == "-2")
                {
                    msg = "Ughh... The server doesn't seem to be a Know-it Server, please check again.";
                }
                else if (res["code"] == "0")
                {
                    msg = res["errMessage"];
                }
                else if (res["code"] == "1")
                {
                    msg     = "Success!";
                    success = true;
                }
                MessageDialog dialog = new MessageDialog(msg);
                await dialog.ShowAsync();

                if (success)
                {
                    string[] temp = new string[2];
                    temp[0] = UsernameBox.Text;
                    temp[1] = PasswordBox.Password;
                    Frame.Navigate(typeof(MainPage), temp);
                    //go to content page, passing a pair with username as key and password as value as parameter.
                }
            }
        }