Листинг исходных кодов
If (MessageBox:Show («Вы точно хотите удалить сессию со всеми предметами и оценками?», «Подтверждение удаления», MessageBoxButtons: YesNo) == System: Windows: Forms:DialogResult:Yes){. TreeView1→SelectedNode→Parent→Nodes→Add («Сессия «+ Convert: ToString (treeView1→SelectedNode→Parent→Nodes→Count — 5)); Array^ RTD = treeView1→Nodes→Nodes→Nodes→Text→Split (gcnew array {Convert:ToChar… Читать ещё >
Листинг исходных кодов (реферат, курсовая, диплом, контрольная)
#pragma once.
namespace filesystem {.
using namespace System;
using namespace System: ComponentModel;
using namespace System: Collections;
using namespace System: Windows:Forms;
using namespace System: Data;
using namespace System: Drawing;
using namespace std;
/// Сводка для Form1.
public ref class Form1: public System: Windows:Forms:Form.
{.
public:
Form1(void).
{.
InitializeComponent ();
//TODO: добавьте код конструктора.
}.
protected:
/// Освободить все используемые ресурсы.
~Form1().
{.
if (components).
{.
delete components;
}.
}.
protected:
private: System: Windows:Forms:Button^ button2;
private: System: Windows:Forms:Button^ button5;
private: System: Windows:Forms:Button^ button6;
private: System: Windows:Forms:Button^ button9;
private: System: Windows:Forms:Button^ button1;
private: System: String^ filename;
private: System: Windows:Forms:TreeView^ treeView1;
private: System: Windows:Forms:TextBox^ textBox1;
private: System: Windows:Forms:TextBox^ textBox2;
private:
/// Требуется переменная конструктора.
System:ComponentModel:Container ^components;
#pragma region Windows Form Designer generated code.
/// Обязательный метод для поддержки конструктора — не изменяйте.
/// содержимое данного метода при помощи редактора кода.
void InitializeComponent (void).
{.
this->button2 = (gcnew System: Windows:Forms:Button ());
this->button5 = (gcnew System: Windows:Forms:Button ());
this->button6 = (gcnew System: Windows:Forms:Button ());
this->button9 = (gcnew System: Windows:Forms:Button ());
this->button1 = (gcnew System: Windows:Forms:Button ());
this->treeView1 = (gcnew System: Windows:Forms:TreeView ());
this->textBox1 = (gcnew System: Windows:Forms:TextBox ());
this->textBox2 = (gcnew System: Windows:Forms:TextBox ());
this->SuspendLayout ();
// button2.
this->button2->Enabled = false;
this->button2->Location = System: Drawing:Point (111, 12);
this->button2->Name = L" button2″ ;
this->button2->Size = System: Drawing:Size (86, 23);
this->button2->TabIndex = 7;
this->button2->Text = L" Новая сессия" ;
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System: EventHandler (this, &Form1:button2_Click);
// button5.
this->button5->Enabled = false;
this->button5->Location = System: Drawing:Point (203, 12);
this->button5->Name = L" button5″ ;
this->button5->Size = System: Drawing:Size (95, 23);
this->button5->TabIndex = 10;
this->button5->Text = L" Новый предмет" ;
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System: EventHandler (this, &Form1:button5_Click);
// button6.
this->button6->Location = System: Drawing:Point (12, 12);
this->button6->Name = L" button6″ ;
this->button6->Size = System: Drawing:Size (93, 23);
this->button6->TabIndex = 12;
this->button6->Text = L" Новый студент" ;
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System: EventHandler (this, &Form1:button6_Click);
// button9.
this->button9->Location = System: Drawing:Point (368, 12);
this->button9->Name = L" button9″ ;
this->button9->Size = System: Drawing:Size (109, 23);
this->button9->TabIndex = 15;
this->button9->Text = L" Вывести список" ;
this->button9->UseVisualStyleBackColor = true;
this->button9->Click += gcnew System: EventHandler (this, &Form1:button9_Click);
// button1.
this->button1->Enabled = false;
this->button1->Location = System: Drawing:Point (304, 12);
this->button1->Name = L" button1″ ;
this->button1->Size = System: Drawing:Size (58, 23);
this->button1->TabIndex = 18;
this->button1->Text = L" Удалить" ;
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System: EventHandler (this, &Form1:button1_Click2);
// treeView1.
this->treeView1->Anchor = static_cast ((((System:Windows:Forms:AnchorStyles:Top | System: Windows:Forms:AnchorStyles:Bottom).
| System: Windows:Forms:AnchorStyles:Left).
| System: Windows:Forms:AnchorStyles:Right));
this->treeView1->HideSelection = false;
this->treeView1->LabelEdit = true;
this->treeView1->Location = System: Drawing:Point (12, 41);
this->treeView1->Name = L" treeView1″ ;
this->treeView1->PathSeparator = L" :" ;
this->treeView1->Size = System: Drawing:Size (465, 125);
this->treeView1->TabIndex = 19;
this->treeView1->BeforeLabelEdit += gcnew System: Windows:Forms:NodeLabelEditEventHandler (this, &Form1:treeView1_BeforeLabelEdit);
this->treeView1->AfterLabelEdit += gcnew System: Windows:Forms:NodeLabelEditEventHandler (this, &Form1:treeView1_AfterLabelEdit);
this->treeView1->AfterSelect += gcnew System: Windows:Forms:TreeViewEventHandler (this, &Form1:treeView1_AfterSelect);
// textBox1.
this->textBox1->Anchor = static_cast (((System:Windows:Forms:AnchorStyles:Bottom | System: Windows:Forms:AnchorStyles:Left).
| System: Windows:Forms:AnchorStyles:Right));
this->textBox1->Location = System: Drawing:Point (12, 198);
this->textBox1->Multiline = true;
this->textBox1->Name = L" textBox1″ ;
this->textBox1->Size = System: Drawing:Size (465, 87);
this->textBox1->TabIndex = 20;
// textBox2.
this->textBox2->Anchor = static_cast (((System:Windows:Forms:AnchorStyles:Bottom | System: Windows:Forms:AnchorStyles:Left).
| System: Windows:Forms:AnchorStyles:Right));
this->textBox2->Location = System: Drawing:Point (12, 172);
this->textBox2->Name = L" textBox2″ ;
this->textBox2->Size = System: Drawing:Size (465, 20);
this->textBox2->TabIndex = 21;
// Form1.
this->AutoScaleDimensions = System: Drawing:SizeF (6, 13);
this->AutoScaleMode = System: Windows:Forms:AutoScaleMode:Font;
this->ClientSize = System: Drawing:Size (489, 297);
this->Controls->Add (this->textBox2);
this->Controls->Add (this->textBox1);
this->Controls->Add (this->treeView1);
this->Controls->Add (this->button1);
this->Controls->Add (this->button9);
this->Controls->Add (this->button6);
this->Controls->Add (this->button5);
this->Controls->Add (this->button2);
this->MinimumSize = System: Drawing:Size (505, 336);
this->Name = L" Form1″ ;
this->Text = L" Карточка студента" ;
this->FormClosing += gcnew System: Windows:Forms:FormClosingEventHandler (this, &Form1:Form1_FormClosing);
this->Load += gcnew System: EventHandler (this, &Form1:Form1_Load);
this->ResumeLayout (false);
this->PerformLayout ();
}.
#pragma endregion.
private: System: Void Form1_Load (System:Object^ sender, System: EventArgs^ e) {.
OpenFileDialog^ ofd= gcnew OpenFileDialog;
ofd->Filter = «*.xml|*.xml|*.txt|*.txt|*.*|*.*» ;
if (ofd->ShowDialog ()==System:Windows:Forms:DialogResult:OK){.
filename = ofd->FileName;
String^ StrIn = System: IO:File:ReadAllText (filename, System: Text:Encoding:Default);
array ^ rty = StrIn->Split (gcnew array{ Convert: ToChar («;») }, StringSplitOptions: RemoveEmptyEntries);
for (int a = 0; a Length; a++){.
array^Data = rty[a]->Split (gcnew array{ Convert: ToChar («,») }, StringSplitOptions: RemoveEmptyEntries);
treeView1->Nodes->Add (««);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[0]->Trim ());
treeView1->Nodes[treeView1->Nodes->Count — 1]->Text = Data[0]->Trim ();
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[1]->Trim ());
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[2]->Trim ());
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[3]->Trim ());
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[4]->Trim ());
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add (Data[5]->Trim ());
if (Data->Length>6){.
array^ Sessions = Data[6]->Split (gcnew array{Convert:ToChar («.»)}, StringSplitOptions: RemoveEmptyEntries);
for (int b = 0; b Length; b++){.
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («Сессия «+ Convert: ToString (treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Count — 5));
array^ Tasks = Sessions[b]->Split (gcnew array{Convert:ToChar («!»)}, StringSplitOptions: RemoveEmptyEntries);
for (int c = 0; c Length; c++){.
array^RTD = Tasks[c]->Split (gcnew array{Convert:ToChar («:»)}, StringSplitOptions: RemoveEmptyEntries);
TreeNodett = treeView1->Nodes[treeView1->Nodes->Count — 1];
TreeNodets = tt->Nodes[tt->Nodes->Count — 1];
ts->Nodes->Add (««);
TreeNodetk = ts->Nodes[ts->Nodes->Count — 1];
tk->Text = RTD[0] + «, «+ RTD[1];
tk->Nodes->Add (RTD[0]);
tk->Nodes->Add (RTD[1]);
}.
}.
}.
}.
BringToFront ();
if (treeView1->Nodes->Count > 0){ button1->Enabled = true; button2->Enabled = true; }.
}.
else{.
SaveFileDialog^ sfd;
sfd = gcnew SaveFileDialog;
sfd->Filter = «*.xml|*.xml» ;
if (sfd->ShowDialog () == System: Windows:Forms:DialogResult:OK){.
filename = sfd->FileName;
BringToFront ();
}.
else{.
MessageBox:Show («Не предъявлен файл с базой данных! Подключение провалено!»);
Close ();
}.
}.
}.
private: System: Void button6_Click (System:Object^ sender, System: EventArgs^ e) {.
button2->Enabled = true;
button1->Enabled = true;
treeView1->Nodes->Add («Иванов Иван Иванович»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («Иванов Иван Иванович»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («КБ-3»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («09.05.2015»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («2015»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («КБ-3з2014»);
treeView1->Nodes[treeView1->Nodes->Count — 1]->Nodes->Add («ИТ6з142 000»);
treeView1->SelectedNode = treeView1->Nodes[treeView1->Nodes->Count — 1];
}.
private: System: Void button2_Click (System:Object^ sender, System: EventArgs^ e) {.
if (treeView1->SelectedNode->Level == 0){.
if (treeView1->SelectedNode->Nodes->Count < 15){.
treeView1->SelectedNode->Nodes->Add («Сессия «+ Convert: ToString (treeView1->SelectedNode->Nodes->Count — 5));
}.
}.
else if (treeView1->SelectedNode->Level == 1){.
if (treeView1->SelectedNode->Parent->Nodes->Count < 15){.
treeView1->SelectedNode->Parent->Nodes->Add («Сессия «+ Convert: ToString (treeView1->SelectedNode->Parent->Nodes->Count — 5));
}.
}.
}.
private: System: Void Form1_FormClosing (System:Object^ sender, System: Windows:Forms:FormClosingEventArgs^ e) {.
String^ strout="" ;
for (int a = 0; aNodes->Count; a++){.
strout = strout + treeView1->Nodes[a]->Nodes[0]->Text+" ," ;
strout = strout + treeView1->Nodes[a]->Nodes[1]->Text + «,» ;
strout = strout + treeView1->Nodes[a]->Nodes[2]->Text + «,» ;
strout = strout + treeView1->Nodes[a]->Nodes[3]->Text + «,» ;
strout = strout + treeView1->Nodes[a]->Nodes[4]->Text + «,» ;
strout = strout + treeView1->Nodes[a]->Nodes[5]->Text + «,» ;
for (int b = 6; b Nodes[a]->Nodes->Count; b++){.
for (int c = 0; c Nodes[a]->Nodes[b]->Nodes->Count; c++){.
strout = strout + treeView1->Nodes[a]->Nodes[b]->Nodes[c]->Nodes[0]->Text + «:» + treeView1->Nodes[a]->Nodes[b]->Nodes[c]->Nodes[1]->Text+" !" ;
}.
strout = strout + «.» ;
}.
strout = strout + «;» ;
}.
System:IO:File:WriteAllText (filename, strout, System: Text:Encoding:Default);
}.
private: System: Void treeView1_BeforeLabelEdit (System:Object^ sender, System: Windows:Forms:NodeLabelEditEventArgs^ e) {.
if (e->Node->Level==0||e->Node->Level==2||(e->Node->Level==1&&e->Node->Index>5)){.
e->CancelEdit = true;
}.
}.
private: System: Void button1_Click2(System:Object^ sender, System: EventArgs^ e) {.
if (treeView1->SelectedNode->Level == 3){.
treeView1->SelectedNode->Parent->Remove ();
treeView1->SelectedNode = treeView1->Nodes[0];
}.
else if (treeView1->SelectedNode->Level == 2){.
treeView1->SelectedNode->Remove ();
treeView1->SelectedNode = treeView1->Nodes[0];
}.
else if (treeView1->SelectedNode->Level == 1&&treeView1->SelectedNode->Index>5){.
if (MessageBox:Show («Вы точно хотите удалить сессию со всеми предметами и оценками?», «Подтверждение удаления», MessageBoxButtons: YesNo) == System: Windows:Forms:DialogResult:Yes){.
treeView1->SelectedNode->Remove ();
treeView1->SelectedNode = treeView1->Nodes[0];
}.
}.
else if (treeView1->SelectedNode->Level == 1 && treeView1->SelectedNode->Index<6){.
if (MessageBox:Show («Вы точно хотите удалить студента со всеми данными, сессиями, предметами и оценками?», «Подтверждение удаления», MessageBoxButtons: YesNo) == System: Windows:Forms:DialogResult:Yes){.
treeView1->SelectedNode->Parent->Remove ();
if (treeView1->Nodes->Count>0){.
treeView1->SelectedNode = treeView1->Nodes[0];
}.
else{ button1->Enabled = false; button2->Enabled = false; }.
}.
}.
else if (treeView1->SelectedNode->Level == 0){.
if (MessageBox:Show («Вы точно хотите удалить студента со всеми данными, сессиями, предметами и оценками?», «Подтверждение удаления», MessageBoxButtons: YesNo) == System: Windows:Forms:DialogResult:Yes){.
treeView1->SelectedNode->Remove ();
if (treeView1->Nodes->Count>0){.
treeView1->SelectedNode = treeView1->Nodes[0];
}.
else{ button1->Enabled = false; button2->Enabled = false; }.
}.
}.
}.
private: System: Void treeView1_AfterSelect (System:Object^ sender, System: Windows:Forms:TreeViewEventArgs^ e) {.
try{.
if ((treeView1->SelectedNode->Level == 1 && treeView1->SelectedNode->Index>5) || treeView1->SelectedNode->Level > 1){.
button5->Enabled = true;
}.
else{.
button5->Enabled = false;
}.
}.
catch (Exception^ ex){.
}.
}.
private: System: Void button5_Click (System:Object^ sender, System: EventArgs^ e) {.
if (treeView1->SelectedNode->Level == 1){.
treeView1->SelectedNode->Nodes->Add («Новый предмет, 5»);
treeView1->SelectedNode->Nodes[treeView1->SelectedNode->Nodes->Count-1]->Nodes->Add («Новый предмет»);
treeView1->SelectedNode->Nodes[treeView1->SelectedNode->Nodes->Count — 1]->Nodes->Add («5»);
}.
else if (treeView1->SelectedNode->Level == 2){.
treeView1->SelectedNode->Parent->Nodes->Add («Новый предмет, 5»);
treeView1->SelectedNode->Parent->Nodes[treeView1->SelectedNode->Parent->Nodes->Count — 1]->Nodes->Add («Новый предмет»);
treeView1->SelectedNode->Parent->Nodes[treeView1->SelectedNode->Parent->Nodes->Count — 1]->Nodes->Add («5»);
}.
else if (treeView1->SelectedNode->Level == 3){.
treeView1->SelectedNode->Parent->Parent->Nodes->Add («Новый предмет, 5»);
treeView1->SelectedNode->Parent->Parent->Nodes[treeView1->SelectedNode->Parent->Parent->Nodes->Count — 1]->Nodes->Add («Новый предмет»);
treeView1->SelectedNode->Parent->Parent->Nodes[treeView1->SelectedNode->Parent->Parent->Nodes->Count — 1]->Nodes->Add («5»);
}.
}.
private: System: Void treeView1_AfterLabelEdit (System:Object^ sender, System: Windows:Forms:NodeLabelEditEventArgs^ e) {.
if (e->Node->Level == 3 && e->Node->Index == 0){.
e->Node->Parent->Text = e->Label + «, «+ e->Node->Parent->Nodes[1]->Text;
}.
else if (e->Node->Level == 3 && e->Node->Index == 1){.
try{.
e->Node->Parent->Text = e->Node->Parent->Nodes[0]->Text + «, «+Convert:ToString (Convert:ToInt32(e->Label));
}.
catch (Exception^ exc){.
MessageBox:Show (exc->Message);
e->CancelEdit = true;
}.
}.
else if (e->Node->Level == 1&&e->Node->Index==2){.
try{.
DateTime^ Dummy = Convert: ToDateTime (e->Label);
}.
catch (Exception^ exc){.
MessageBox:Show (exc->Message);
e->CancelEdit = true;
}.
}.
else if (e->Node->Level == 1 && e->Node->Index == 3){.
try{.
Int32^ Dummy = Convert: ToInt32(e->Label);
}.
catch (Exception^ exc){.
MessageBox:Show (exc->Message);
e->CancelEdit = true;
}.
}.
}.
private: System: Void button9_Click (System:Object^ sender, System: EventArgs^ e) {.
int sdd = 0;
try{.
textBox1->Text = «» ;
sdd = Convert: ToInt32(textBox2->Text);
array^ mark_students = gcnew array (200);
int mark_students_L = 0;
for (int x = 0; x Nodes->Count; x++){.
if (treeView1->Nodes[x]->Nodes->Count>=sdd+6){.
int marks = 0;
int marks_L = 0;
for (int y = 0; y Nodes[x]->Nodes[sdd + 5]->Nodes->Count; y++){.
array^ RTD = treeView1->Nodes[x]->Nodes[sdd + 5]->Nodes[y]->Text->Split (gcnew array {Convert:ToChar («,»)}, StringSplitOptions: RemoveEmptyEntries);
marks += Convert: ToInt32(RTD[1]->Trim ());
marks_L++;
}.
marks = marks / marks_L;
mark_students[mark_students_L] = treeView1->Nodes[x]->Nodes[0]->Text+" ," +marks;
mark_students_L++;
}.
}.
int maximum = 0;
String^ Max = «» ;
int i, j, pos;
String^ tmp;
for (i = 0; i < mark_students_L; ++i).
{.
pos = i;
tmp = mark_students[i];
for (j = i + 1; j < mark_students_L; ++j).
{.
array^ RTD = mark_students[j]->Split (gcnew array {Convert:ToChar («,»)});
array^ RTDr = tmp->Split (gcnew array {Convert:ToChar («,»)});
if (Convert:ToInt32(RTD[1]) > Convert: ToInt32(RTDr[1])).
{.
pos = j;
tmp = mark_students[j];
}.
}.
mark_students[pos] = mark_students[i];
mark_students[i] = tmp;
textBox1->Text += mark_students[i] + ««;
}.
}.
catch (Exception^ ex){.
MessageBox:Show (ex->Message);
}.
}.
};
}.