private void BackLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            AuthorizationWindow aw = new AuthorizationWindow();

            aw.Show();
            this.Close();
        }
        private void ExitLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            AuthorizationWindow aw = new AuthorizationWindow()
            {
                WindowState = this.WindowState,
                Top         = this.Top,
                Left        = this.Left,
                Width       = this.Width,
                Height      = this.Height
            };

            aw.Show();
            this.Close();
        }
        private void ExitButton_Click(object sender, RoutedEventArgs e)
        {
            needToUpdate = true;
            AuthorizationWindow aw = new AuthorizationWindow
            {
                WindowState = this.WindowState,
                Top         = this.Top,
                Left        = this.Left,
                Width       = this.Width,
                Height      = this.Height
            };

            aw.Show();
            this.Close();
        }
        private void AlreadyHaveAnAccountLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            AuthorizationWindow aw = new AuthorizationWindow
            {
                WindowState = this.WindowState,
                Top         = this.Top,
                Left        = this.Left,
                Width       = this.Width,
                Height      = this.Height,
                users       = users
            };

            aw.Show();
            this.Close();
        }
 private void ChangeButton_Click(object sender, RoutedEventArgs e)
 {
     if (CheckPasswodsLabel.Content.ToString() == "Пароли совпадают")
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             connection.Open();
             SqlCommand command = new SqlCommand($"UPDATE Users SET Password = N'{NewPasswordBox.Password}' WHERE Login = N'{login}'", connection);
             command.ExecuteNonQuery();
         }
         MessageBox.Show("Пароль изменён");
         AuthorizationWindow aw = new AuthorizationWindow();
         aw.Show();
         this.Close();
     }
 }
        private void DeleteAccountLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (MessageBox.Show("Вы действительно хотите удалить аккаунт?", "Подтверждение", MessageBoxButton.YesNo) ==
                MessageBoxResult.Yes)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    command.Connection  = connection;
                    command.CommandText = $"SELECT Id FROM Topics WHERE UserID = {userid}";
                    List <int> idOfTopics = new List <int>();
                    reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            idOfTopics.Add(reader.GetInt32(0));
                        }
                    }
                    reader.Close();
                    if (idOfTopics.Count != 0)
                    {
                        foreach (int id in idOfTopics)
                        {
                            command.CommandText = $"DROP TABLE [{id}]";
                            command.ExecuteNonQuery();
                            command.CommandText = $"DELETE FROM [Topics] WHERE Id = {id}";
                            command.ExecuteNonQuery();
                        }
                    }
                    command.CommandText = $"DELETE FROM [UserDB] WHERE Id = {userid}";
                    command.ExecuteNonQuery();
                }

                AuthorizationWindow aw = new AuthorizationWindow
                {
                    WindowState = this.WindowState,
                    Top         = this.Top,
                    Left        = this.Left,
                    Width       = this.Width,
                    Height      = this.Height
                };
                aw.Show();
                this.Close();
            }
        }
        private void ConfirmRegistrationTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (ConfirmRegistrationTextBox.Text == randomCode)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    try
                    {
                        connection.Open();
                        command.Connection = connection;
                        string sequenceOfIndicesOfMainTopic = "";
                        command.CommandText = "SELECT * FROM MainTopic";
                        reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            int indexOfRow = 0;
                            while (reader.Read())
                            {
                                sequenceOfIndicesOfMainTopic += indexOfRow++ + "~";
                            }
                        }
                        reader.Close();

                        command.CommandText = $"INSERT INTO Users (Login, Name, Email, Password, CurrentTopicId, ChoiceOfTopicGridVisibility, DateOfRegistration, LastEntrance, TotalInTheApp, SequenceOfIndicesOfMainTopic, IndexOfMainTopic, Status)" +
                                              $" VALUES (N'{LoginTextBox.Text.Trim()}'," +
                                              $" N'{NameTextBox.Text.Trim()}', N'{EmailTextBox.Text.Trim()}', N'{PasswordBox.Password.Trim()}'," +
                                              $" 0, 'Visible', N'{DateTime.Now.ToString()}', N'', N'{DateTime.MinValue.Subtract(DateTime.MinValue).ToString()}', N'{sequenceOfIndicesOfMainTopic}', 0, N'Offline')";
                        command.ExecuteNonQuery();
                        MessageBox.Show("Вы зарегистрированы");
                        command.CommandText = $"SELECT Login FROM Users WHERE Login = N'{LoginTextBox.Text.Trim()}'";
                        reader = command.ExecuteReader();
                        reader.Read();

                        users.Add(new User
                        {
                            Login          = LoginTextBox.Text.Trim(),
                            Name           = NameTextBox.Text.Trim(),
                            Email          = EmailTextBox.Text.Trim(),
                            Password       = PasswordBox.Password,
                            CurrentTopicId = "MainWords",
                            ChoiceOfTopicGridVisibility = "Visible"
                        });
                    }
                    catch (SqlException)
                    {
                        reader.Close();
                        command.CommandText = "SELECT Id, Login, Name, Email, Password, CurrentTopicId, ChoiceOfTopicGridVisibility FROM Users" +
                                              $" WHERE Login = N'{LoginTextBox.Text}' OR Email = N'{EmailTextBox.Text}'";
                        reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            reader.Read();
                            if (LoginTextBox.Text == reader.GetString(1))
                            {
                                CheckLoginLabel.Foreground = Brushes.Red;
                                CheckLoginLabel.Content    = "✖";
                            }
                            MessageBox.Show($"Пользователь {reader.GetString(1)} уже существует");
                            users.Add(new User
                            {
                                Login    = reader.GetString(0),
                                Name     = reader.GetString(1),
                                Email    = reader.GetString(2),
                                Password = reader.GetString(3)
                            });
                        }
                    }
                }

                AuthorizationWindow aw = new AuthorizationWindow
                {
                    WindowState = this.WindowState,
                    Top         = this.Top,
                    Left        = this.Left,
                    Width       = this.Width,
                    Height      = this.Height,
                    users       = users
                };

                aw.Show();
                this.Close();
            }
        }