#using <mscorlib.dll>
#include "threadExample.h"
using namespace System;
using namespace System::Threading;
#pragma once
namespace ProgettoStageReal
{
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 System::Threading;
using namespace System::IO;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
ProgettoStageReal::ThreadExample^ tws;
private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
public:
String^ tmp;
Form1(void)
{
InitializeComponent();
}
protected:
/// <summary>
/// Liberare le risorse in uso.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
public:
System::Windows::Forms::NotifyIcon^ ZeroStage;
System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ToolStripMenuItem^ calcolaTempoTotaleToolStripMenuItem;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::ToolStripMenuItem^ salvaToolStripMenuItem;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label3;
public:
System::Windows::Forms::Label^ label4;
System::Windows::Forms::Label^ label2;
protected:
private: System::ComponentModel::IContainer^ components;
protected:
private:
//Label *p;
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->ZeroStage = (gcnew System::Windows::Forms::NotifyIcon(this->components));
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->salvaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->calcolaTempoTotaleToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// ZeroStage
//
this->ZeroStage->BalloonTipIcon = System::Windows::Forms::ToolTipIcon::Info;
this->ZeroStage->BalloonTipText = L"Programma x Stage";
this->ZeroStage->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"ZeroStage.Icon")));
this->ZeroStage->Text = L"ZeroStage";
this->ZeroStage->MouseDoubleClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::notifyIcon1_MouseDoubleClick);
//
// label1
//
this->label1->AutoSize = true;
this->label1->BackColor = System::Drawing::SystemColors::Desktop;
this->label1->ForeColor = System::Drawing::SystemColors::Info;
this->label1->Location = System::Drawing::Point(12, 33);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(139, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"ORA INIZIO PROGRAMMA";
//
// label2
//
this->label2->AutoSize = true;
this->label2->BackColor = System::Drawing::SystemColors::Desktop;
this->label2->ForeColor = System::Drawing::SystemColors::Info;
this->label2->Location = System::Drawing::Point(235, 33);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(16, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"...";
//
// label3
//
this->label3->AutoSize = true;
this->label3->BackColor = System::Drawing::SystemColors::Desktop;
this->label3->ForeColor = System::Drawing::SystemColors::Info;
this->label3->Location = System::Drawing::Point(12, 66);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(133, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"GIORNO / MESE / ANNO";
//
// label4
//
this->label4->AutoSize = true;
this->label4->BackColor = System::Drawing::SystemColors::Desktop;
this->label4->ForeColor = System::Drawing::SystemColors::Info;
this->label4->Location = System::Drawing::Point(202, 66);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(16, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"...";
//
// textBox1
//
this->textBox1->BackColor = System::Drawing::SystemColors::Info;
this->textBox1->Location = System::Drawing::Point(26, 117);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox1->Size = System::Drawing::Size(235, 105);
this->textBox1->TabIndex = 4;
//
// label5
//
this->label5->AutoSize = true;
this->label5->BackColor = System::Drawing::SystemColors::ControlText;
this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 7.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label5->ForeColor = System::Drawing::SystemColors::Info;
this->label5->Location = System::Drawing::Point(93, 101);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(98, 13);
this->label5->TabIndex = 5;
this->label5->Text = L"Risultato Raggiunto";
//
// button1
//
this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button1.BackgroundImage")));
this->button1->Location = System::Drawing::Point(58, 239);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(35, 35);
this->button1->TabIndex = 6;
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button2.BackgroundImage")));
this->button2->Location = System::Drawing::Point(193, 239);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(35, 35);
this->button2->TabIndex = 7;
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button3.BackgroundImage")));
this->button3->Location = System::Drawing::Point(126, 239);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(35, 35);
this->button3->TabIndex = 8;
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// menuStrip1
//
this->menuStrip1->BackColor = System::Drawing::SystemColors::Highlight;
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->fileToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(292, 24);
this->menuStrip1->TabIndex = 9;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->salvaToolStripMenuItem,
this->calcolaTempoTotaleToolStripMenuItem, this->exitToolStripMenuItem});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(35, 20);
this->fileToolStripMenuItem->Text = L"File";
//
// salvaToolStripMenuItem
//
this->salvaToolStripMenuItem->Name = L"salvaToolStripMenuItem";
this->salvaToolStripMenuItem->Size = System::Drawing::Size(183, 22);
this->salvaToolStripMenuItem->Text = L"Salva";
this->salvaToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::salvaToolStripMenuItem_Click);
//
// calcolaTempoTotaleToolStripMenuItem
//
this->calcolaTempoTotaleToolStripMenuItem->Name = L"calcolaTempoTotaleToolStripMenuItem";
this->calcolaTempoTotaleToolStripMenuItem->Size = System::Drawing::Size(183, 22);
this->calcolaTempoTotaleToolStripMenuItem->Text = L"Calcola tempo totale";
this->calcolaTempoTotaleToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::calcolaTempoTotaleToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
this->exitToolStripMenuItem->Size = System::Drawing::Size(183, 22);
this->exitToolStripMenuItem->Text = L"Exit";
this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::exitToolStripMenuItem_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(58, 295);
this->textBox2->Multiline = true;
this->textBox2->Name = L"textBox2";
this->textBox2->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox2->Size = System::Drawing::Size(170, 20);
this->textBox2->TabIndex = 10;
this->textBox2->Text = L"TEMPO TOTALE :\r\nPAUSE TOTALI :";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));
this->ClientSize = System::Drawing::Size(292, 334);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label5);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->menuStrip1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->Location = System::Drawing::Point(10, 10);
this->MainMenuStrip = this->menuStrip1;
this->MaximizeBox = false;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Stage";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
DateTime d1 = DateTime::Now;
tmp=d1.Hour.ToString();
String^ tmp2(d1.Minute.ToString());
tmp=System::String::Concat(tmp,":",tmp2);
this->label2->Text=tmp;
tmp=d1.Day.ToString();
tmp2=d1.Month.ToString();
String^ tmp3(d1.Year.ToString());
tmp=System::String::Concat(tmp,"/",tmp2,"/",tmp3);
this->label4->Text=tmp;
// ProgettoStageReal::ThreadExample^ tws=gcnew ProgettoStageReal::ThreadExample(this->label2);
// Thread^ t = gcnew Thread(gcnew ThreadStart(tws, &ThreadExample::DoWork));
// t->Start();
//ale2^ prova;
//prova->setta(this->label2);
//prova->go();
}
private: System::Void notifyIcon1_MouseDoubleClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->Show();
//this->ZeroStage->Visible = true;
}
//PLAY
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
this->Hide();
if (this->ZeroStage->Visible)
{
tws->settapausa(0);
}
else
{
this->ZeroStage->Visible = true;
tws=gcnew ProgettoStageReal::ThreadExample(this->textBox2);
Thread^ t = gcnew Thread(gcnew ThreadStart(tws, &ThreadExample::DoWork));
t->Start();
}
}
//STOP
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
if (this->ZeroStage->Visible)
{
this->ZeroStage->Visible = false;
tws->settavai(0);
}
}
//PAUSE
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
if (this->ZeroStage->Visible)
{
tws->settapausa(1);
}
}
private: System::Void salvaToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
try {
Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "4x4 files (*.4x4)|*.4x4";
saveFileDialog1->FilterIndex = 1;
saveFileDialog1->RestoreDirectory = true;
saveFileDialog1->ShowDialog();
if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
{
StreamWriter^ scr=gcnew StreamWriter(myStream);
scr->WriteLine(Definizioni::intro+"\r\n\r\n\r\n"+Definizioni::intro2+" "+tmp+"\r\n");
scr->WriteLine(Definizioni::asterisco+"\r\n\r\n"+this->textBox1->Text+"\r\n\r\n"+Definizioni::asterisco+"\r\n");
String^ liz=this->textBox2->Text;
int m=liz->LastIndexOf("\r\n");
liz=liz->Remove(m);
//MessageBox::Show(liz);
scr->WriteLine(liz);
scr->Close();
// Code to write the stream goes here.
myStream->Close();
}
}
catch (Exception^ e)
{
MessageBox::Show("Problema nel salvataggio");
}
}
private: System::Void calcolaTempoTotaleToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
try {
OpenFileDialog^ openfile= gcnew OpenFileDialog;
openfile->Filter ="4x4'files (*.4x4)|*.4x4;";
openfile->Multiselect = true;
openfile->ShowDialog();
array<String^>^ nomifile=openfile->FileNames;
int totale_ore=0;
int totale_min=0;
for(int i=0; i<nomifile->Length;i++)
{
StreamReader^ sr = gcnew StreamReader((String^)nomifile->GetValue(i) );
try
{
String^ line;
int count=0;
int temp_ora,temp_min;
// Read and display lines from the file until the end of
// the file is reached.
while ( line = sr->ReadLine() )
{
if (count==2)
{
String^ ora,^minuti;
line=sr->ReadLine();
int pr=line->IndexOf(":");
line=line->Substring(pr+1);
pr=line->IndexOf(",");
ora=line->Remove(pr-1);
line=line->Substring(pr+1);
pr=line->IndexOf("m");
minuti=line->Remove(pr-1);
temp_ora=System::Convert::ToInt32(ora);
temp_min=System::Convert::ToInt32(minuti);
totale_ore += temp_ora;
totale_min += temp_min;
//MessageBox::Show(totale_ore.ToString()+" "+totale_min.ToString());
}
if ((line->CompareTo(Definizioni::asterisco))==0)
{
count++;
}
}
}
catch ( Exception^ e )
{
// Let the user know what went wrong.
Console::WriteLine( "The file could not be read:" );
Console::WriteLine( e->Message );
}
finally
{
if ( sr )
delete (IDisposable^)sr;
}
//MessageBox::Show((String^)nomifile->GetValue(i));
}
while(totale_min>=60)
{
totale_ore++;
totale_min -= 60;
}
String^ finisco=this->textBox2->Text;
//calcolo tempo rimanente prima della fine dello stage
int min_mancanti=Definizioni::ore_mancanti*60;
int min_fatti=(totale_ore*60)+totale_min;
int diff,ore_restanti,min_restanti,gg_restanti,ggo_restanti;
diff=ore_restanti=min_restanti=gg_restanti=ggo_restanti=0;
if (min_mancanti<min_fatti)
MessageBox::Show("ComplimenTi, hai raggiunto il tuo obbiettivo");
else
{
diff=min_mancanti-min_fatti;
ore_restanti=diff/60;
min_restanti=diff%60;
gg_restanti=ore_restanti/24;
ggo_restanti=ore_restanti%24;
}
finisco=String::Concat(finisco,"\r\n","ORE TOTALI STAGE :","\r\n",totale_ore.ToString()," ore e ",totale_min.ToString()," min","\r\n",
"TEMPO RIMASTO ALLA FINE\r\n",ore_restanti," ore e ",min_restanti," min\r\nOssia\r\n",gg_restanti," giorni e ",ggo_restanti," ore");
this->textBox2->Text=finisco;
}
catch (...)
{
MessageBox::Show("Problema nel calcolo del totale");
}
}
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
if (this->ZeroStage->Visible)
{
this->ZeroStage->Visible = false;
tws->settavai(0);
Thread::Sleep(501);
}
this->Close();
}
};
}