private void registr_button_Click(object sender, EventArgs e) { Judge judge = new Judge(); judge.Surname = JudgeSurname_textBox.Text; judge.Name = JudgeName_textBox.Text; judge.Patronymic = JudgePatronymic_textBox.Text; judge.JudgeClass = JudgeClass_textBox.Text; if (Path_textBox.Text != "") { SecretaryController.insertInJudges(judge, Path_textBox.Text); judge.Number = (ushort)(SecretaryController.TakeMax("Номер", "judges", Path_textBox.Text)); judge.judgeChar = (char)(64 + judge.Number); tournir.judges.Add(judge); MessageBox.Show("Новый судья: \n" + judge.Surname + "\n" + judge.Name + "\n" + judge.Patronymic + "\n" + judge.JudgeClass + "\n" + judge.Number + " " + judge.judgeChar + "\n" + "Успешно зарегистрирован!"); } else { MessageBox.Show("Необходимо выбрать базу Турнира!"); } }
public static void insertInJudges(Judge judje, string path) { connectString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={path}"; myConnection = new OleDbConnection(connectString); try { myConnection.Open(); OleDbCommand command = new OleDbCommand("", myConnection); command.CommandText = "INSERT INTO judges(ФИО, Категория_Судейства)" + "VALUES (@SNP, @Category)"; command.Parameters.AddWithValue("SNP", judje.Surname + " " + judje.Name + " " + judje.Patronymic); command.Parameters.AddWithValue("Category", judje.JudgeClass); command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show($"Упс, что-то пошло не так...\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } myConnection.Close(); }
public static List <Judge> TakeJudges(GroupClass input_group, string cn) { connectString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={cn}"; myConnection = new OleDbConnection(connectString); myConnection.Open(); Judge new_judge = new Judge(); List <Judge> judgeList = new List <Judge>(); try { string judgesString = ""; string[] judgesStringList; command = new OleDbCommand("", myConnection); command.CommandText = "SELECT Судьи FROM groups WHERE Номер_Группы = @id"; command.Parameters.AddWithValue("id", input_group.number); judgesString = command.ExecuteScalar().ToString().Replace(" ", ""); judgesStringList = judgesString.Split(new char[] { ';' }); //MessageBox.Show(judgesString); judgeList = new List <Judge>(); for (int i = 0; i < judgesStringList.Length - 1; i++) { new_judge = new Judge(); int number = Convert.ToInt32(judgesStringList[i]); //MessageBox.Show(number.ToString()); OleDbCommand command1 = new OleDbCommand("", myConnection); command1.CommandText = "SELECT ФИО FROM judges WHERE Номер = @num"; command1.Parameters.AddWithValue("num", number); string jSNP = command1.ExecuteScalar().ToString(); command1 = new OleDbCommand("", myConnection); command1.CommandText = "SELECT Категория_Судейства FROM judges WHERE Номер = @num"; command1.Parameters.AddWithValue("num", number); string jcategory = command1.ExecuteScalar().ToString().Replace(" ", ""); string[] jSNPList = jSNP.Split(new char[] { ' ' }); if (jSNPList.Length >= 3) { new_judge.Surname = jSNPList[0]; new_judge.Name = jSNPList[1]; new_judge.Patronymic = jSNPList[2]; } new_judge.JudgeClass = jcategory; new_judge.Number = (ushort)number; new_judge.judgeChar = (char)(64 + number); //MessageBox.Show(new_judge.ToString()); judgeList.Add(new_judge); } } catch (Exception ex) { MessageBox.Show("Упс, что-то пошло не так при определении списка судей\nError: " + ex.Message); } myConnection.Close(); return(judgeList); }
public static TournirClass TakeTournir(string cn) { connectString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={cn}"; myConnection = new OleDbConnection(connectString); myConnection.Open(); int Num = 1; TournirClass RetTournir = new TournirClass(); OleDbCommand command1 = new OleDbCommand("", myConnection); OleDbCommand command2 = new OleDbCommand("", myConnection); OleDbCommand command3 = new OleDbCommand("", myConnection); OleDbCommand command4 = new OleDbCommand("", myConnection); OleDbCommand command5 = new OleDbCommand("", myConnection); OleDbCommand command6 = new OleDbCommand("", myConnection); OleDbCommand command7 = new OleDbCommand("", myConnection); command1.CommandText = "SELECT Название FROM tournir WHERE ID = @Num"; command1.Parameters.AddWithValue("Num", Num); command2.CommandText = "SELECT Дата_Проведения FROM tournir WHERE ID = @Num"; command2.Parameters.AddWithValue("Num", Num); command3.CommandText = "SELECT Время_Проведения FROM tournir WHERE ID = @Num"; command3.Parameters.AddWithValue("Num", Num); command4.CommandText = "SELECT Место_Проведения FROM tournir WHERE ID = @Num"; command4.Parameters.AddWithValue("Num", Num); command5.CommandText = "SELECT Организация FROM tournir WHERE ID = @Num"; command5.Parameters.AddWithValue("Num", Num); command6.CommandText = "SELECT ФИО_Секретаря FROM tournir WHERE ID = @Num"; command6.Parameters.AddWithValue("Num", Num); command7.CommandText = "SELECT ФИО_Регистратора FROM tournir WHERE ID = @Num"; command7.Parameters.AddWithValue("Num", Num); try { RetTournir.name = command1.ExecuteScalar().ToString(); RetTournir.date.ToInt(command2.ExecuteScalar().ToString()); RetTournir.time.ToInt(command3.ExecuteScalar().ToString()); RetTournir.place = command4.ExecuteScalar().ToString(); RetTournir.organisation = command5.ExecuteScalar().ToString(); RetTournir.secretary = command6.ExecuteScalar().ToString(); RetTournir.registrator = command7.ExecuteScalar().ToString(); //MessageBox.Show($"Турнир: {RetTournir.name}\nДата: {RetTournir.date}\nВремя: {RetTournir.time}\nМесто: {RetTournir.place}\nОрганизация: {RetTournir.organisation}\nСекретарь: {RetTournir.secretary}\nРегистратор: {RetTournir.registrator}"); //myConnection.Close(); } catch (Exception ex) { MessageBox.Show("Упс, что-то пошло не так... код 1\nError: " + ex.Message); } //заполнение Турнира try { int i = 1; int k = 0; string name = ""; command = new OleDbCommand("", myConnection); command.CommandText = "SELECT COUNT(Номер_Группы) FROM groups"; k = Convert.ToInt32(command.ExecuteScalar()); //MessageBox.Show("Количество групп: " + Convert.ToString(k)); while (i <= k) { myConnection = new OleDbConnection(connectString); myConnection.Open(); command = new OleDbCommand("", myConnection); command.CommandText = "SELECT Категория FROM groups WHERE Номер_Группы = @id"; command.Parameters.AddWithValue("id", i); name = Convert.ToString(command.ExecuteScalar()); RetTournir.groups.Add(new GroupClass(i, RetTournir.name, name)); RetTournir.groups[i - 1].CategoryList = TakeCategory(RetTournir.groups[i - 1], cn); RetTournir.groups[i - 1].DancesList = TakeDances(RetTournir.groups[i - 1], cn); RetTournir.groups[i - 1].JudgeList = TakeJudges(RetTournir.groups[i - 1], cn); //MessageBox.Show(RetTournir.groups[i - 1].show()); //MessageBox.Show("Вытягивание списка пар"); RetTournir.groups[i - 1].duetList = TakeDuets(RetTournir.groups[i - 1], cn); //MessageBox.Show(RetTournir.groups[i - 1].show()); i++; } } catch (Exception ex) { MessageBox.Show("Упс, что-то пошло не так при определении списка групп\nError: " + ex.Message); } //заполнение групп try { myConnection = new OleDbConnection(connectString); myConnection.Open(); BitArray checkArray = Controller.GapCounter("Номер", "judges", myConnection); int i1 = 0; int counter = 0; int k1 = 0; int max = 0; command = new OleDbCommand("", myConnection); command.CommandText = "SELECT COUNT(Номер) FROM judges"; command3 = new OleDbCommand("", myConnection); command3.CommandText = "SELECT MAX(Номер) FROM judges"; k1 = Convert.ToInt32(command.ExecuteScalar()); //MessageBox.Show("Количество судей: " + Convert.ToString(k1)); if (k1 > 0) { max = Convert.ToInt32(command3.ExecuteScalar()); //MessageBox.Show("Максимальный номер судьи: " + Convert.ToString(max)); foreach (bool item in checkArray) { if (i1 < max) { if (checkArray[i1]) { Judge judge_new = new Judge(); command1 = new OleDbCommand("SELECT ФИО FROM judges WHERE Номер = @id", myConnection); //NSP command1.Parameters.AddWithValue("id", i1 + 1); command2 = new OleDbCommand("SELECT Категория_Судейства FROM judges WHERE Номер = @id", myConnection); //JudjeClass command2.Parameters.AddWithValue("id", i1 + 1); judge_new.ToJudge(command1.ExecuteScalar().ToString()); judge_new.JudgeClass = command2.ExecuteScalar().ToString(); judge_new.Number = (ushort)(i1 + 1); judge_new.judgeChar = (char)(64 + judge_new.Number); RetTournir.judges.Add(judge_new); //MessageBox.Show(RetTournir.judges[i1 - counter].ToNSP() + " " + RetTournir.judges[i1 - counter].JudgeClass); } else { counter++; } } i1++; } } else { //MessageBox.Show($"Не зарегистрировано ниодного судьи!"); } } catch (Exception ex) { MessageBox.Show("Упс, что-то пошло не так при определении списка судей\nError: " + ex.Message); } //заполнение судей myConnection.Close(); RetTournir.Show(); return(RetTournir); }