Skip to content

Commit e25e331

Browse files
Guardar/recuperar delegado (ficheiro txt)
1 parent d084698 commit e25e331

File tree

2 files changed

+83
-29
lines changed

2 files changed

+83
-29
lines changed

07_TheAlphaProject/ProjCLR/Form1.h

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ namespace ProjCLR {
251251
/// </summary>
252252
void InitializeComponent(void)
253253
{
254-
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle2 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
254+
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
255255
this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
256256
this->Nome = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
257257
this->Localidade = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
@@ -268,6 +268,8 @@ namespace ProjCLR {
268268
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
269269
this->delegadoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
270270
this->novoDelegadoSortearToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
271+
this->guardarDelegadoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
272+
this->toolStripComboBox1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
271273
this->estatísticasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
272274
this->identificarOMaisVelhoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
273275
this->médiaDeIdadesToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
@@ -289,8 +291,6 @@ namespace ProjCLR {
289291
this->btn_feminino = (gcnew System::Windows::Forms::Button());
290292
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
291293
this->lbl_status = (gcnew System::Windows::Forms::ToolStripStatusLabel());
292-
this->guardarDelegadoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
293-
this->toolStripComboBox1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
294294
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
295295
this->groupBox1->SuspendLayout();
296296
this->menuStrip1->SuspendLayout();
@@ -306,15 +306,15 @@ namespace ProjCLR {
306306
| System::Windows::Forms::AnchorStyles::Left)
307307
| System::Windows::Forms::AnchorStyles::Right));
308308
this->dataGridView1->BorderStyle = System::Windows::Forms::BorderStyle::None;
309-
dataGridViewCellStyle2->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
310-
dataGridViewCellStyle2->BackColor = System::Drawing::SystemColors::Control;
311-
dataGridViewCellStyle2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular,
309+
dataGridViewCellStyle1->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
310+
dataGridViewCellStyle1->BackColor = System::Drawing::SystemColors::Control;
311+
dataGridViewCellStyle1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular,
312312
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
313-
dataGridViewCellStyle2->ForeColor = System::Drawing::SystemColors::WindowText;
314-
dataGridViewCellStyle2->SelectionBackColor = System::Drawing::SystemColors::Highlight;
315-
dataGridViewCellStyle2->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
316-
dataGridViewCellStyle2->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
317-
this->dataGridView1->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
313+
dataGridViewCellStyle1->ForeColor = System::Drawing::SystemColors::WindowText;
314+
dataGridViewCellStyle1->SelectionBackColor = System::Drawing::SystemColors::Highlight;
315+
dataGridViewCellStyle1->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
316+
dataGridViewCellStyle1->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
317+
this->dataGridView1->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
318318
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
319319
this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(5) {
320320
this->Nome, this->Localidade,
@@ -470,6 +470,20 @@ namespace ProjCLR {
470470
this->novoDelegadoSortearToolStripMenuItem->Text = L"Novo Delegado (Sortear)";
471471
this->novoDelegadoSortearToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::NovoDelegadoSortearToolStripMenuItem_Click);
472472
//
473+
// guardarDelegadoToolStripMenuItem
474+
//
475+
this->guardarDelegadoToolStripMenuItem->Name = L"guardarDelegadoToolStripMenuItem";
476+
this->guardarDelegadoToolStripMenuItem->Size = System::Drawing::Size(204, 22);
477+
this->guardarDelegadoToolStripMenuItem->Text = L"Guardar Delegado";
478+
this->guardarDelegadoToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::GuardarDelegadoToolStripMenuItem_Click);
479+
//
480+
// toolStripComboBox1
481+
//
482+
this->toolStripComboBox1->Name = L"toolStripComboBox1";
483+
this->toolStripComboBox1->Size = System::Drawing::Size(204, 22);
484+
this->toolStripComboBox1->Text = L"Recuperar Delegado";
485+
this->toolStripComboBox1->Click += gcnew System::EventHandler(this, &Form1::ToolStripComboBox1_Click);
486+
//
473487
// estatísticasToolStripMenuItem
474488
//
475489
this->estatísticasToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
@@ -637,19 +651,6 @@ namespace ProjCLR {
637651
this->lbl_status->Name = L"lbl_status";
638652
this->lbl_status->Size = System::Drawing::Size(0, 17);
639653
//
640-
// guardarDelegadoToolStripMenuItem
641-
//
642-
this->guardarDelegadoToolStripMenuItem->Name = L"guardarDelegadoToolStripMenuItem";
643-
this->guardarDelegadoToolStripMenuItem->Size = System::Drawing::Size(204, 22);
644-
this->guardarDelegadoToolStripMenuItem->Text = L"Guardar Delegado";
645-
//
646-
// toolStripComboBox1
647-
//
648-
this->toolStripComboBox1->Name = L"toolStripComboBox1";
649-
this->toolStripComboBox1->Size = System::Drawing::Size(204, 22);
650-
this->toolStripComboBox1->Text = L"Recuperar Delegado";
651-
this->toolStripComboBox1->Click += gcnew System::EventHandler(this, &Form1::ToolStripComboBox1_Click);
652-
//
653654
// Form1
654655
//
655656
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
@@ -665,7 +666,7 @@ namespace ProjCLR {
665666
this->MainMenuStrip = this->menuStrip1;
666667
this->MinimumSize = System::Drawing::Size(1000, 640);
667668
this->Name = L"Form1";
668-
this->Text = L"Projecto Alpha";
669+
this->Text = L"Projeto Alpha";
669670
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
670671
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
671672
this->groupBox1->ResumeLayout(false);
@@ -1089,12 +1090,13 @@ private: void gerar_colunas()
10891090
{
10901091
dataGridView1->Columns[i]->Name = "media";
10911092
dataGridView1->Columns[i]->Width = 50;
1092-
1093+
dataGridView1->Columns[i]->DefaultCellStyle->ForeColor = Color::Blue;
10931094
}
10941095
else if (novas_colunas[i - cur_n] == "Negativas")
10951096
{
10961097
dataGridView1->Columns[i]->Name = "negativas";
10971098
dataGridView1->Columns[i]->Width = 60;
1099+
dataGridView1->Columns[i]->DefaultCellStyle->ForeColor = Color::Blue;
10981100
}
10991101
else if (novas_colunas[i - cur_n] == "Estado")
11001102
{
@@ -1106,7 +1108,6 @@ private: void gerar_colunas()
11061108
{
11071109
dataGridView1->Columns[i]->Name = "d" + (i - cur_n);
11081110
dataGridView1->Columns[i]->Width = 38;
1109-
11101111
}
11111112
}
11121113
}
@@ -1241,14 +1242,66 @@ private: void atualizar_estado()
12411242
// Guardar o nome do delegado num ficheiro de texto
12421243
private: void guardar_delegado()
12431244
{
1245+
String^ filename = "_Projeto_Alpha__delegado.txt";
1246+
StreamWriter^ fp = gcnew StreamWriter(filename);
1247+
String^ delegado = "";
1248+
int n_formandos;
1249+
1250+
bool linha_intro = dataGridView1->AllowUserToAddRows;
1251+
dataGridView1->AllowUserToAddRows = false;
1252+
n_formandos = dataGridView1->Rows->Count;
1253+
dataGridView1->AllowUserToAddRows = linha_intro;
1254+
1255+
for (int i = 0; i < n_formandos && delegado==""; i++)
1256+
{
1257+
if (dataGridView1->Rows[i]->Cells["Delegado"]->Value == "X")
1258+
delegado = dataGridView1->Rows[i]->Cells["Nome"]->Value->ToString();
1259+
}
12441260

1261+
fp->WriteLine(delegado);
1262+
fp->Close();
12451263
}
12461264

12471265

12481266
// Recuperar o nome do delegado a partir de um ficheiro de texto
12491267
private: void recuperar_delegado()
12501268
{
12511269

1270+
String^ filename = "_Projeto_Alpha__delegado.txt";
1271+
StreamReader^ fp;
1272+
String^ delegado;
1273+
int n_formandos;
1274+
1275+
bool linha_intro = dataGridView1->AllowUserToAddRows;
1276+
dataGridView1->AllowUserToAddRows = false;
1277+
n_formandos = dataGridView1->Rows->Count;
1278+
dataGridView1->AllowUserToAddRows = linha_intro;
1279+
1280+
try
1281+
{
1282+
fp = gcnew StreamReader(filename);
1283+
}
1284+
catch (FileNotFoundException^)
1285+
{
1286+
MessageBox::Show("Não há nenhum delegado guardado.");
1287+
return;
1288+
}
1289+
delegado = fp->ReadLine();
1290+
1291+
1292+
if (delegado == "" || delegado == nullptr)
1293+
MessageBox::Show("Não há nenhum delegado guardado.");
1294+
1295+
for (int i = 0; i < n_formandos; i++)
1296+
{
1297+
if (dataGridView1->Rows[i]->Cells["Nome"]->Value->ToString() == delegado)
1298+
dataGridView1->Rows[i]->Cells["Delegado"]->Value = "X";
1299+
else
1300+
dataGridView1->Rows[i]->Cells["Delegado"]->Value = "";
1301+
}
1302+
1303+
fp->Close();
1304+
dataGridView1->Columns["Delegado"]->Visible = true;
12521305
}
12531306

12541307
private: void status_formando()
@@ -1302,7 +1355,7 @@ private: System::Void MostrarOcultarPainelLateralToolStripMenuItem_Click(System:
13021355
private: System::Void Btn_painel_Click(System::Object^ sender, System::EventArgs^ e) { alternar_painel_lateral();}
13031356
private: System::Void GerarNotasToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { gerar_notas();}
13041357
private: System::Void NotasToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { stats_notas(); }
1305-
private: System::Void ToolStripComboBox1_Click(System::Object^ sender, System::EventArgs^ e) {
1306-
}
1358+
private: System::Void ToolStripComboBox1_Click(System::Object^ sender, System::EventArgs^ e) { recuperar_delegado(); }
1359+
private: System::Void GuardarDelegadoToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { guardar_delegado();}
13071360
};
13081361
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hilda Fonseca Silva

0 commit comments

Comments
 (0)