private void DowanloadButton_Click(object sender, EventArgs e)//чтение из файла информации { OpenFileDialog openFileDialog1 = new OpenFileDialog(); DataBaseInfo.Rows.Add(); if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string path = openFileDialog1.FileName; BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)); int counter = 0; for (int i = 0; i < DataBaseInfo.RowCount; i++) { if (reader.PeekChar() != -1) { counter += 1; for (int j = 0; j < DataBaseInfo.ColumnCount; j++) { DataBaseInfo.Rows[i].Cells[j].Value = reader.ReadString(); } DataBaseInfo.Rows.Add(); } } for (int i = 0; i < DataBaseInfo.RowCount - 1; i++) { string[] tmpsurname = Convert.ToString(DataBaseInfo.Rows[i].Cells[1].Value).Split(' '); Base.Add(new Sportsman(Convert.ToInt32(DataBaseInfo.Rows[i].Cells[0].Value), Convert.ToString(tmpsurname[0]), Convert.ToString(tmpsurname[1]), Convert.ToString(tmpsurname[2]), Convert.ToString(DataBaseInfo.Rows[i].Cells[2].Value), Convert.ToString(DataBaseInfo.Rows[i].Cells[3].Value), Convert.ToInt32(DataBaseInfo.Rows[i].Cells[4].Value))); } DataBaseInfo.Rows.RemoveAt(counter); DataBaseInfo.Refresh(); }
private void PrizeListButton_Click(object sender, EventArgs e)//выдает список призеров всех стран мира { int prize; for (int i = 0; i < DataBaseInfo.RowCount; i++) { prize = Convert.ToInt32(DataBaseInfo.Rows[i].Cells[4].Value); if (prize > 3) { DataBaseInfo.Rows.RemoveAt(i); i -= 1; } } DataBaseInfo.Refresh(); }
private void DelButton_Click(object sender, EventArgs e)//кнопка удаления спортсмена из базы данных по фамилии { string surname = ""; surname = InputBox.Show("Фамилия", surname); for (int i = 0; i < DataBaseInfo.RowCount; i++) { string[] tmpsurname = Convert.ToString(DataBaseInfo.Rows[i].Cells[1].Value).Split(' '); if (tmpsurname[0] == surname) { DataBaseInfo.Rows.RemoveAt(i); } tmpsurname = null; } DataBaseInfo.Refresh(); }
private void CountryPrizeButton_Click(object sender, EventArgs e)//выдает список призеров только нужной нам страны { string country = ""; country = InputBox2.Show2(country); int prize; for (int i = 0; i < DataBaseInfo.RowCount; i++) { prize = Convert.ToInt32(DataBaseInfo.Rows[i].Cells[4].Value); if (prize > 3 || Convert.ToString(DataBaseInfo.Rows[i].Cells[2].Value) != country) { DataBaseInfo.Rows.RemoveAt(i); i -= 1; } } DataBaseInfo.Refresh(); }
private void AddButton_Click(object sender, EventArgs e)//добавление спортсмена в базу данных с всеми проверками { foreach (var element in Base) { if (NumberOfSportsmanNumericUpDown.Value == element.Regestration_Number) { MessageBox.Show("Такой номер учасника уже есть!\r\n"); return; } } foreach (var element in Base) { if (PlaceOfSportsmanNummericUpDown.Value == element.Place && CountryComboBox.Text == element.Country && KindOfSportComboBox.Text == element.Kind_OfSport) { MessageBox.Show("В этой стрнае по этому виду спорта уже есть чемпион с таким местом"); return; } } DataBaseInfo.Refresh(); if (SurnameTextBox.Text == "" || NameTextBox.Text == "" || PatronymicTextBox.Text == "" || CountryComboBox.Text == "" || KindOfSportComboBox.Text == "") { MessageBox.Show("Введите коректные данные"); } if (SurnameTextBox.Text.Length == 0 || !Slovo((String)SurnameTextBox.Text)) { MessageBox.Show("Проверьте правильность написания фамилии!"); } else if (NameTextBox.Text.Length == 0 || !Slovo((String)NameTextBox.Text)) { MessageBox.Show("Проверьте правильность написания имени"); } else if (PatronymicTextBox.Text.Length == 0 || !Slovo((String)PatronymicTextBox.Text)) { MessageBox.Show("Проверьте правильность написания Отчества"); } else { Base.Add(new Sportsman((int)NumberOfSportsmanNumericUpDown.Value, SurnameTextBox.Text, NameTextBox.Text, PatronymicTextBox.Text, CountryComboBox.Text, KindOfSportComboBox.Text, (int)PlaceOfSportsmanNummericUpDown.Value)); AddElement(); NumberOfSportsmanNumericUpDown.Value += 1; } }