Beispiel #1
0
        // Удаление выбранного поста
        private async void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            RequesterVK.deletePost(button.Tag.ToString());
            postsGrid.Children.Clear();
            getPosts();
        }
Beispiel #2
0
        // Получение постов
        private void getPosts()
        {
            JsonDocument posts = JsonDocument.Parse(RequesterVK.getPosts().Result);
            var          items = posts.RootElement.GetProperty("response").GetProperty("items");

            for (int i = 0; i < items.GetArrayLength(); i++)
            {
                string postText = items[i].GetProperty("text").ToString();

                if (!postText.Contains("#dist_apps"))
                {
                    continue;
                }

                string finalText = "";
                foreach (string substr in postText.Split(new[] { "#dist_apps" }, StringSplitOptions.None))
                {
                    finalText += substr;
                }

                string id = items[i].GetProperty("id").ToString();

                TextBox textBox = new TextBox();
                textBox.Name              = "post" + id;
                textBox.Width             = 400;
                textBox.Height            = 100;
                textBox.VerticalAlignment = VerticalAlignment.Top;
                textBox.Margin            = new Thickness(0, 50 + i * 200, 0, 0);
                textBox.Text              = finalText;
                textBox.TextWrapping      = TextWrapping.Wrap;
                postsGrid.Children.Add(textBox);

                Button updateButton = new Button();
                updateButton.Content           = "Сохранить";
                updateButton.VerticalAlignment = VerticalAlignment.Top;
                updateButton.Width             = 150;
                updateButton.Height            = 50;
                updateButton.Margin            = new Thickness(0, 170 + i * 200, 250, 0);
                updateButton.Tag    = id;
                updateButton.Click += updateButton_Click;
                postsGrid.Children.Add(updateButton);

                Button deleteButton = new Button();
                deleteButton.Content           = "Удалить";
                deleteButton.VerticalAlignment = VerticalAlignment.Top;
                deleteButton.Width             = 150;
                deleteButton.Height            = 50;
                deleteButton.Margin            = new Thickness(250, 170 + i * 200, 0, 0);
                deleteButton.Tag    = id;
                deleteButton.Click += deleteButton_Click;
                postsGrid.Children.Add(deleteButton);
            }
        }
Beispiel #3
0
        // Отправка поста
        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            Regex regex = new Regex(@"[#&]");

            if (regex.Matches(messageText.Text).Count > 0)
            {
                MessageBox.Show("Недопустимые символы: # и &");
                return;
            }

            string postString = messageText.Text + "\n\n%23dist_apps";

            RequesterVK.createPost(postString);

            MessageBox.Show("Пост опубликован!");
        }
Beispiel #4
0
        // Редактирование выбранного поста
        private void updateButton_Click(object sender, RoutedEventArgs e)
        {
            Button  button  = (Button)sender;
            TextBox textBox = (TextBox)LogicalTreeHelper.FindLogicalNode(postsGrid, "post" + button.Tag.ToString());
            Regex   regex   = new Regex(@"[#&]");

            if (regex.Matches(textBox.Text).Count > 0)
            {
                MessageBox.Show("Недопустимые символы: # и &");
                return;
            }
            string temp = RequesterVK.updatePost(button.Tag.ToString(), textBox.Text + "\n\n%23dist_apps").Result;

            postsGrid.Children.Clear();
            getPosts();
        }