private void button8_Click(object sender, System.EventArgs e)
        {
            if (attacksListBox.SelectedItems.Count > 1)
            {
                MessageBox.Show("Выбирите одну атаку");
                return;
            }
            Attack oldAttack = attacksListBox.SelectedItem as Attack;
            if (oldAttack == null)
            {
                return;
            }

            List<Category> categories = new List<Category>();
            Attack newAttack = new Attack()
            {
                AttackName = attackNameTextBox.Text,
                AttackClass = 1//int.Parse(attackClassTextBox.Text)
            };
            foreach (Category category in categoryesListBox.SelectedItems)
            {
                categories.Add(category);
            }

            _baseWorker.ChangeAttack(oldAttack, newAttack, categories);
            RefreshAttacks();
        }
        private void button9_Click(object sender, System.EventArgs e)
        {
            List<Category> categories = new List<Category>();

            Attack attack = new Attack()
            {
                AttackName =  newAttackNametextBox.Text,
                AttackClass = 1//int.Parse(newAttackClassTextBox.Text)
            };
            foreach (Category category in categoryesListBox.SelectedItems)
            {
                categories.Add(category);
            }
            if (categories.Count == 0)
            {
                MessageBox.Show("Выбирите категорию/категории");
            }
            else
            {
                _baseWorker.AddNewAttack(attack, categories);
                RefreshAttacks();
            }
        }
        public void AddNewAttack(Attack attack, List<Category> categories)
        {
            using (SqlCommand sqlCommand = new SqlCommand(InsertAttack, _sqlConnection))
            {
                sqlCommand.Parameters.AddWithValue("@attackName", attack.AttackName);
                sqlCommand.Parameters.AddWithValue("@attackClass", attack.AttackClass);

                if (sqlCommand.ExecuteNonQuery() > 0)
                {
                    foreach (Category category in categories)
                    {
                        using (SqlCommand command = new SqlCommand(InsertAttackCategory, _sqlConnection))
                        {
                            command.Parameters.AddWithValue("@categoryId", category.Id);
                            command.ExecuteNonQuery();
                        }
                    }
                    //   MessageBox.Show("Добвленно");
                }
                else
                {
                    MessageBox.Show("Ошибка при добавлении");
                }
            }
        }
        public List<Sign> Signs(Attack attack)
        {
            List<Sign> signs = new List<Sign>();
            using (SqlCommand sqlCommand = new SqlCommand(SelectSignAttack, _sqlConnection))
            {
                sqlCommand.Parameters.AddWithValue("@id", attack.Id);
                using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                {
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            signs.Add(new Sign()
                            {
                                Id = int.Parse(sqlDataReader["Id"].ToString()),
                                SingText = sqlDataReader["Sign_Text"].ToString(),
                                SignImage = sqlDataReader["Sign_Image"] as byte[]
                            });
                        }

                        foreach (Sign sign in signs)
                        {
                            byte[] nullBytes = new byte[0];
                            if (sign.SignImage.SequenceEqual(nullBytes))
                            {
                                sign.SignImage = null;
                            }
                        }

                        return signs;
                    }
                    return signs;
                }
            }
        }
 public Recommendation Recommendation(Attack attack)
 {
     using (SqlCommand sqlCommand = new SqlCommand(SelectRecomendation, _sqlConnection))
     {
         sqlCommand.Parameters.Add("id", attack.Id);
         using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
         {
             if (sqlDataReader.HasRows)
             {
                 sqlDataReader.Read();
                 return new Recommendation()
                 {
                     Id = int.Parse(sqlDataReader["Id"].ToString()),
                     RecommendationText = sqlDataReader["Recommendation_Text"].ToString(),
                     AttackId = int.Parse(sqlDataReader["Attack_Id"].ToString()),
                     ClassId = int.Parse(sqlDataReader["Class_Id"].ToString())
                 };
             }
             return null;
         }
     }
 }
        public void DeleteAttack(Attack attack)
        {
            using (SqlCommand sqlCommand = new SqlCommand(RemoveAttack, _sqlConnection))
            {
                sqlCommand.Parameters.AddWithValue("@attackId", attack.Id);

                if (sqlCommand.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Атака удалена");
                }
                else
                {
                    MessageBox.Show("Ошибка при удалении");
                }
            }
        }
        public void ChangeAttack(Attack oldAttack, Attack newAttack, List<Category> categories)
        {
            using (SqlCommand sqlCommand = new SqlCommand(UpdateAttack, _sqlConnection))
            {
                sqlCommand.Parameters.AddWithValue("@attackName", newAttack.AttackName);
                sqlCommand.Parameters.AddWithValue("@attackClass", newAttack.AttackClass);
                sqlCommand.Parameters.AddWithValue("@attackId", oldAttack.Id);

                if (sqlCommand.ExecuteNonQuery() > 0)
                {
                    using (SqlCommand command = new SqlCommand(RemoveAttackCategory, _sqlConnection))
                    {
                        command.Parameters.AddWithValue("@attackId", oldAttack.Id);
                        int c = sqlCommand.ExecuteNonQuery();
                    }
                    foreach (Category category in categories)
                    {
                        using (SqlCommand command = new SqlCommand(UpdateAttackCategory, _sqlConnection))
                        {

                            command.Parameters.AddWithValue("@attackId", oldAttack.Id);
                            command.Parameters.AddWithValue("@categoryId", category.Id);
                            command.ExecuteNonQuery();
                        }
                    }

                    MessageBox.Show("Атака изменена");
                }
                else
                {
                    MessageBox.Show("Ошибка при изменении");
                }
            }
        }
 public List<int> AttackSign(Attack attack)
 {
     List<int> ints = new List<int>();
     using (SqlCommand sqlCommand = new SqlCommand(SelectAttackSign, _sqlConnection))
     {
         sqlCommand.Parameters.AddWithValue("attackId", attack.Id);
         using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
         {
             if (sqlDataReader.HasRows)
             {
                 while (sqlDataReader.Read())
                 {
                     ints.Add(int.Parse(sqlDataReader["Sign_Id"].ToString()));
                 }
                 return ints;
             }
             return ints;
         }
     }
 }
        public Attack Attack(int id)
        {
            Attack attack = new Attack();

            using (SqlCommand sqlCommand = new SqlCommand(SelectAttack, _sqlConnection))
            {
                sqlCommand.Parameters.AddWithValue("@id", id);
                using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                {
                    while (sqlDataReader.Read())
                    {
                        attack.Id = int.Parse(sqlDataReader["Id"].ToString());
                        attack.AttackName = sqlDataReader["Attack_Name"].ToString();
                        attack.AttackClass = int.Parse(sqlDataReader["Attack_Class"].ToString());
                    }
                }
            }
            return attack;
        }