private void EditSaveChangesButton_Click(object sender, EventArgs e) { string editString = null; for (int i = 0; i < registrationID; i++) { bool result = true; string[] str = new string[7]; for (int j = 1; j < RegistrationDataView.ColumnCount; j++) { /*Каждый иф проверяет одну из 7 ячеек на итерации, если проверки типа CorrectName не выполняется то происходит * вызов бокса сообщений, и так для кажого поля в таблице пока не введешь правильно значения*/ if ((j == 1 || j == 2 || j == 3) && Correct.CorrectName(EditDataView.Rows[i].Cells[j].Value.ToString(), out editString)) { result = false; MessageBox.Show($"Invalid {editString}", "Edit Info"); } if (j == 4 && Correct.CorrectCountry(EditDataView.Rows[i].Cells[j].Value.ToString(), out editString)) { result = false; MessageBox.Show($"Invalid {editString}", "Edit Info"); } if (j == 5 && Correct.CorrectCompetition(EditDataView.Rows[i].Cells[j].Value.ToString(), out editString)) { result = false; MessageBox.Show($"Invalid {editString}", "Edit Info"); } if (j == 6 && Correct.CorrectOlimpicPlace(EditDataView.Rows[i].Cells[j].Value.ToString(), out editString)) { result = false; MessageBox.Show($"Invalid {editString}", "Edit Info"); } str[j] = EditDataView.Rows[i].Cells[j].Value.ToString(); if (result) { for (int k = 1; k < 7; k++) { RegistrationDataView.Rows[i].Cells[k].Value = str[k]; } WinterOlimpic.Sporstmens.ElementAt(i).FirstName = EditDataView.Rows[i].Cells[1].Value.ToString(); WinterOlimpic.Sporstmens.ElementAt(i).LastName = EditDataView.Rows[i].Cells[2].Value.ToString(); WinterOlimpic.Sporstmens.ElementAt(i).Patronymic = EditDataView.Rows[i].Cells[3].Value.ToString(); WinterOlimpic.Sporstmens.ElementAt(i).Country = EditDataView.Rows[i].Cells[4].Value.ToString(); WinterOlimpic.Sporstmens.ElementAt(i).TypeOfCompetition = EditDataView.Rows[i].Cells[5].Value.ToString(); WinterOlimpic.Sporstmens.ElementAt(i).Place = Convert.ToInt32(EditDataView.Rows[i].Cells[6].Value.ToString()); } } } }
private void saveToDBButton_Click(object sender, EventArgs e) { string errorField = null; if (string.IsNullOrEmpty(firstNameTextBox.Text) || string.IsNullOrEmpty(lastNameTextBox.Text) || string.IsNullOrEmpty(patronymicTextBox.Text) || string.IsNullOrEmpty(countryTextBox.Text) || string.IsNullOrEmpty(competitionTextBox.Text) || string.IsNullOrEmpty(placeTextBox.Text)) { MessageBox.Show("Not all text boxes were filled"); } else if (Correct.CorrectName(firstNameTextBox.Text, out errorField) || Correct.CorrectName(lastNameTextBox.Text, out errorField) || Correct.CorrectName(patronymicTextBox.Text, out errorField) || Correct.CorrectCountry(countryTextBox.Text, out errorField) || Correct.CorrectCompetition(competitionTextBox.Text, out errorField) || Correct.CorrectOlimpicPlace(placeTextBox.Text, out errorField)) { MessageBox.Show($"Not correct {errorField}", "Validation Error"); } else { registrationID++; RegistrationDataView.Rows.Add(registrationID, firstNameTextBox.Text, lastNameTextBox.Text, patronymicTextBox.Text, countryTextBox.Text, competitionTextBox.Text, placeTextBox.Text); EditDataView.Rows.Add(registrationID, firstNameTextBox.Text, lastNameTextBox.Text, patronymicTextBox.Text, countryTextBox.Text, competitionTextBox.Text, placeTextBox.Text); WinterOlimpic.Sporstmens.Add(new Sporstman { Registration_ID = registrationID, FirstName = firstNameTextBox.Text, LastName = lastNameTextBox.Text, Patronymic = patronymicTextBox.Text, Country = countryTextBox.Text, TypeOfCompetition = competitionTextBox.Text, Place = int.Parse(placeTextBox.Text) }); } }