private void FindLike(string execcomm) // Обновление вывода { MainWindow.playerinf.Clear(); // очищаем всё, если там что-то будет string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=cubercock;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(); command.CommandText = execcomm; command.Connection = connection; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) // если есть данные { while (reader.Read()) // построчно считываем данные { MainWindow.Plauerinf playerinfo = new MainWindow.Plauerinf(); playerinfo.Id_plauer = Convert.ToInt32(reader.GetValue(0)); playerinfo.Nickname_plauer = Convert.ToString(reader.GetValue(1)); playerinfo.KillDeath = Convert.ToDouble(reader.GetValue(2)); playerinfo.WinLose = Convert.ToDouble(reader.GetValue(3)); FileInfoView.ItemsSource = MainWindow.playerinf; MainWindow.playerinf.Add(playerinfo); } } reader.Close(); } }
private void AddUserBtn(object sender, RoutedEventArgs e) { try { string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=cubercock;Integrated Security=True"; int uniqueID = 0; if (MainWindow.playerinf.Count > 0) { uniqueID = MainWindow.playerinf[MainWindow.playerinf.Count - 1].Id_plauer + 1; } string name = txname.Text; double surname = Convert.ToDouble(txsurname.Text); double dadname = Convert.ToDouble(txdadname.Text); string sqlExpression = "INSERT INTO player_inf(id_player, nickname_player, Kill_death, Win_Lose) VALUES(" + uniqueID + ",'" + name + "', " + surname + ", " + dadname + ")"; MessageBox.Show(sqlExpression); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); int number = command.ExecuteNonQuery(); MessageBox.Show("Добавлено объектов: " + Convert.ToString(number)); MainWindow.Plauerinf fileInfo = new MainWindow.Plauerinf(); fileInfo.Id_plauer = uniqueID; fileInfo.Nickname_plauer = name; fileInfo.KillDeath = Convert.ToDouble(surname); fileInfo.WinLose = Convert.ToDouble(dadname); MainWindow.playerinf.Add(fileInfo); Page3 phonePage = new Page3 { frame = this.frame }; //Открываем добавление номерков Page3.Id_plauer = uniqueID; // студентик if (MainWindow.organizationinf.Count > 0) { } else { Page3.uniqueID = uniqueID; } frame.Content = phonePage; //открываем мобилку страничную добавку } } catch (FormatException) { MessageBox.Show("Неверный ввод", "ОШИБКА"); } }