this->write_button->Location = System::Drawing::Point(356, 116);
this->write_button->Name = L"write_button";
this->write_button->Size = System::Drawing::Size(75, 52);
this->write_button->TabIndex = 3;
this->write_button->Text = L"Прочитать из файла";
this->write_button->UseVisualStyleBackColor = true;
this->write_button->Click += gcnew System::EventHandler(this, &Form1::write_button_Click);
//
// save2_button
//
this->save2_button->Location = System::Drawing::Point(541, 369);
this->save2_button->Name = L"save2_button";
this->save2_button->Size = System::Drawing::Size(75, 49);
this->save2_button->TabIndex = 4;
this->save2_button->Text = L"Сохранить в файл";
this->save2_button->UseVisualStyleBackColor = true;
this->save2_button->Click += gcnew System::EventHandler(this, &Form1::save2_button_Click);
//
// read_button
//
this->read_button->Location = System::Drawing::Point(12, 365);
this->read_button->Name = L"read_button";
this->read_button->Size = System::Drawing::Size(122, 50);
this->read_button->TabIndex = 5;
this->read_button->Text = L"Вывести учащихся проживающих в Москве";
this->read_button->UseVisualStyleBackColor = true;
this->read_button->Click += gcnew System::EventHandler(this, &Form1::read_button_Click);
//
// surname_tb
//
this->surname_tb->Location = System::Drawing::Point(149, 17);
this->surname_tb->Name = L"surname_tb";
this->surname_tb->Size = System::Drawing::Size(139, 20);
this->surname_tb->TabIndex = 6;
//
// city_tb
//
this->city_tb->Location = System::Drawing::Point(149, 43);
this->city_tb->Name = L"city_tb";
this->city_tb->Size = System::Drawing::Size(139, 20);
this->city_tb->TabIndex = 7;
//
// city2_tb
//
this->city2_tb->Location = System::Drawing::Point(149, 69);
this->city2_tb->Name = L"city2_tb";
this->city2_tb->Size = System::Drawing::Size(139, 20);
this->city2_tb->TabIndex = 8;
//
// gender_cb
//
this->gender_cb->FormattingEnabled = true;
this->gender_cb->Items->AddRange(gcnew cli::array< System::Object^ >(2) { L"Мужской (М)", L"Женский (Ж)" });
this->gender_cb->Location = System::Drawing::Point(149, 95);
this->gender_cb->Name = L"gender_cb";
this->gender_cb->Size = System::Drawing::Size(139, 21);
this->gender_cb->TabIndex = 9;
//
// birthday_num
//
this->birthday_num->Location = System::Drawing::Point(149, 122);
this->birthday_num->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 2002, 0, 0, 0 });
this->birthday_num->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1945, 0, 0, 0 });
this->birthday_num->Name = L"birthday_num";
this->birthday_num->Size = System::Drawing::Size(139, 20);
this->birthday_num->TabIndex = 10;
this->birthday_num->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 2002, 0, 0, 0 });
//
// number_num
//
this->number_num->Location = System::Drawing::Point(149, 148);
this->number_num->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 5000, 0, 0, 0 });
this->number_num->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
this->number_num->Name = L"number_num";
this->number_num->Size = System::Drawing::Size(139, 20);
this->number_num->TabIndex = 11;
this->number_num->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
//
// add_stud_num
//
this->add_stud_num->Location = System::Drawing::Point(476, 17);
this->add_stud_num->Name = L"add_stud_num";
this->add_stud_num->ReadOnly = true;
this->add_stud_num->Size = System::Drawing::Size(139, 20);
this->add_stud_num->TabIndex = 12;
//
// stud_num
//
this->stud_num->Location = System::Drawing::Point(476, 43);
this->stud_num->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
this->stud_num->Name = L"stud_num";
this->stud_num->Size = System::Drawing::Size(139, 20);
this->stud_num->TabIndex = 13;
this->stud_num->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(100, 20);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(43, 13);
this->label1->TabIndex = 14;
this->label1->Text = L"Ф.И.О:";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(50, 46);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(93, 13);
this->label2->TabIndex = 15;
this->label2->Text = L"Город рождения:";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(38, 72);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(105, 13);
this->label3->TabIndex = 16;
this->label3->Text = L"Город проживания:";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(113, 98);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(30, 13);
this->label4->TabIndex = 17;
this->label4->Text = L"Пол:";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(62, 124);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(81, 13);
this->label5->TabIndex = 18;
this->label5->Text = L"Год рождения:";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(9, 150);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(134, 13);
this->label6->TabIndex = 19;
this->label6->Text = L"Номер зачетной книжки:";
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(412, 45);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(58, 13);
this->label7->TabIndex = 20;
this->label7->Text = L"Студенты:";
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(322, 19);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(148, 13);
this->label8->TabIndex = 21;
this->label8->Text = L"Студентов было добавлено:";
//
// student_list
//
this->student_list->FormattingEnabled = true;
this->student_list->Location = System::Drawing::Point(13, 200);
this->student_list->Name = L"student_list";
this->student_list->Size = System::Drawing::Size(603, 160);
this->student_list->TabIndex = 22;
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::Point(10, 184);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(101, 13);
this->label9->TabIndex = 23;
this->label9->Text = L"Список студентов:";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(627, 430);
this->Controls->Add(this->label9);
this->Controls->Add(this->student_list);
this->Controls->Add(this->label8);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->stud_num);
this->Controls->Add(this->add_stud_num);
this->Controls->Add(this->number_num);
this->Controls->Add(this->birthday_num);
this->Controls->Add(this->gender_cb);
this->Controls->Add(this->city2_tb);
this->Controls->Add(this->city_tb);
this->Controls->Add(this->surname_tb);
this->Controls->Add(this->read_button);
this->Controls->Add(this->save2_button);
this->Controls->Add(this->write_button);
this->Controls->Add(this->save1_button);
this->Controls->Add(this->start_button);
this->Controls->Add(this->add_student_button);
this->Name = L"Form1";
this->Text = L"Лабораторная работа 6";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->birthday_num))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->number_num))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->add_stud_num))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->stud_num))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// Кнопка "Добавить студента в группу"
private: System::Void add_student_button_Click(System::Object^ sender, System::EventArgs^ e)
{
// Обработка ошибок ввода
if (String::IsNullOrEmpty(surname_tb->Text))
{
MessageBox::Show("Совершен некорректный ввод,введите Ф.И.О");
}
else if (String::IsNullOrEmpty(city_tb->Text))
{
MessageBox::Show("Совершен некорректный ввод,введите город рождения");
}
else if (String::IsNullOrEmpty(city2_tb->Text))
{
MessageBox::Show("Совершен некорректный ввод,введите город проживания");
}
else if (add < stud_count) // Если группа не заполнена
{
Student^ stud = gcnew Student; // создать объект класса студента
stud->surname = surname_tb->Text; // Ф.И.О
stud->city = city_tb->Text; // Город рождения
stud->city_2 = city2_tb->Text; // Город проживания
stud->gender = gender_cb->Text; // Пол
stud->birthday = (int)birthday_num->Value; // Год рождения
stud->number = (int)number_num->Value; // Номер зачетной книжки
arr_stud[add] = stud; // Добавить студента в группу
add++; // Увеличить число "добавленных студентов"
student_list->Items->Add(stud->surname + ", Пол: " + stud->gender + ", Город рождения: " + stud->city + ", Город проживания: " + stud->city_2 + ", Год рождения: " + stud->birthday + ", Номер зачетки: " + stud->number);
add_stud_num->Value = (int)add_stud_num->Value + 1; // Увеличить число добавленных студентов на форме
}
if (add >= stud_count) // Если группа уже заполнена
{
student_list->Items->Clear();
Array::Sort(arr_stud);
for (unsigned int i = 0; i < add; i++)
{
// Добавить полученные значения в список на форме:
student_list->Items->Add(arr_stud[i]->surname + ", Пол: " + arr_stud[i]->gender + " , Город рождения: " + arr_stud[i]->city + ", Город проживания: " + arr_stud[i]->city_2 + ", Год рождения: " + arr_stud[i]->birthday + ", Номер зачетки: " + arr_stud[i]->number);
}
// Деактивация кнопок:
add_student_button->Enabled = false;
save1_button->Enabled = false;
// Активация кнопки сохранения
save2_button->Enabled = true;
// Активация кнопка вывода
start_button->Enabled = true;
}
}
// Кнопка "СТАРТ"
private: System::Void start_button_Click(System::Object^ sender, System::EventArgs^ e)
{
stud_count = (int)stud_num->Value; // Общее число студентов в группе
arr_stud = gcnew array<Student^>(stud_count); // Новый массив для студентов
add = 0; // Число добавленных студентов
stud_num->ReadOnly = true; // Активация окна добавленных студентов
// Активация кнопки добавления:
add_student_button->Enabled = true;
save1_button->Enabled = true;
write_button->Enabled = false; // Активация кнопки "СТАРТ"
}
// Кнопка "Прочитать из файла"
private: System::Void write_button_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ filename;
OpenFileDialog^ ofd = gcnew OpenFileDialog();
if (ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
filename = ofd->FileName;
try
{
StreamReader^ din = File::OpenText(filename); // Открытие файла
String^ delimStr = ";"; // Разделитель
array<Char>^ delimiter = delimStr->ToCharArray(); // Преобразовать строку разделителей в символьный массив
String^ str;
while ((str = din->ReadLine()) != nullptr && add < stud_count) // Если файл не пустой & группа не заполнена
{
// Разбиваем строку по разделителям:
array<String^>^ words;
words = str->Split(delimiter);
Student^ st = gcnew Student;
st->surname = words[0]; // Ф.И.О
st->city = words[1]; // Город рождения
st->city_2 = words[2]; // Город проживания
st->gender = words[3]; // Пол
st->birthday = Convert::ToInt32(words[4]); // Год рождения
st->number = Convert::ToInt32(words[5]); // Номер зачетной книжки
System::Diagnostics::Debug::WriteLine(str);
arr_stud[add] = st; // Добавить студента в группу
add++; // Увеличить число добавленных студентов
student_list->Items->Add(st->surname + ", Пол: " + st->gender + ", Город рождения: " + st->city + ", Город проживания: " + st->city_2 + ", Год рождения: " + st->birthday + ", Номер зачетки: " + st->number);
add_stud_num->Value = (int)add_stud_num->Value + 1;
if (add >= stud_count)
{
student_list->Items->Clear();
Array::Sort(arr_stud);
for (unsigned int i = 0; i < add; i++)
// Вывод:
student_list->Items->Add(arr_stud[i]->surname + ", Пол: " + arr_stud[i]->gender + " , Город рождения: " + arr_stud[i]->city + ", Город проживания: " + arr_stud[i]->city_2 + ", Год рождения: " + arr_stud[i]->birthday + ", Номер зачетки: " + arr_stud[i]->number);
add_student_button->Enabled = false;
start_button->Enabled = true;
save2_button->Enabled = true;
}
}
save1_button->Enabled = false;
}
// Обработчик если открыть файл не удалось
catch (Exception^ e)
{
if (dynamic_cast<FileNotFoundException^>(e))
{
MessageBox::Show("Файл " + filename + " был не найден");
}
else
{