Untitled

 avatar
unknown
plain_text
a month ago
6.7 kB
5
Indexable
#pragma once

namespace TrafficStatisticsApp {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Podsumowanie informacji o MyForm1
	/// </summary>
	public ref class MyForm1 : public System::Windows::Forms::Form
	{
	public:
		MyForm1(void)
		{
			InitializeComponent();
			InitializeDataGridView();  // Inicjalizacja kolumn DataGridView
		}

	protected:
		/// <summary>
		/// Wyczyść wszystkie używane zasoby.
		/// </summary>
		~MyForm1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::MenuStrip^ menuStrip1;
	protected:
	private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem1;
	private: System::Windows::Forms::ToolStripMenuItem^ closeToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^ oAutorzeToolStripMenuItem;

	private: System::Windows::Forms::Button^ button1;
	private: System::Windows::Forms::DataGridView^ dataGridViewResults;

	private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
	private: System::Windows::Forms::TextBox^ speedTextBox;
	private: System::Windows::Forms::TextBox^ vehicleCountTextBox;
	private: System::Windows::Forms::TextBox^ timeTextBox;
	private: System::Windows::Forms::Label^ label1;
	private: System::Windows::Forms::Label^ label2;
	private: System::Windows::Forms::Label^ label3;

	private:
		/// <summary>
		/// Wymagana zmienna projektanta.
		/// </summary>
		System::ComponentModel::Container^ components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Metoda wymagana do obsługi projektanta — nie należy modyfikować
		/// jej zawartości w edytorze kodu.
		/// </summary>
		void InitializeComponent(void)
		{
			System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
			System::Windows::Forms::DataVisualization::Charting::Legend^ legend1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
			System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->fileToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->oAutorzeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->dataGridViewResults = (gcnew System::Windows::Forms::DataGridView());
			this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
			this->speedTextBox = (gcnew System::Windows::Forms::TextBox());
			this->vehicleCountTextBox = (gcnew System::Windows::Forms::TextBox());
			this->timeTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->menuStrip1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridViewResults))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->BeginInit();
			this->SuspendLayout();
			// 
			// dataGridViewResults
			// 
			this->dataGridViewResults->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->dataGridViewResults->Location = System::Drawing::Point(276, 221);
			this->dataGridViewResults->Name = L"dataGridViewResults";
			this->dataGridViewResults->RowHeadersWidth = 51;
			this->dataGridViewResults->Size = System::Drawing::Size(240, 150);
			this->dataGridViewResults->TabIndex = 5;
			this->dataGridViewResults->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm1::dataGridViewResults_CellContentClick);
			// 
			// MyForm1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(958, 412);
			this->Controls->Add(this->dataGridViewResults);
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"MyForm1";
			this->Text = L"MyForm1";
			this->Load += gcnew System::EventHandler(this, &MyForm1::MyForm1_Load);
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridViewResults))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();
		}
#pragma endregion

	private: System::Void dataGridViewResults_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
		String^ speedText = speedTextBox->Text;
		String^ vehicleCountText = vehicleCountTextBox->Text;
		String^ timeText = timeTextBox->Text;

		try {
			// Konwertowanie danych
			double speed = Convert::ToDouble(speedText);
			int vehicleCount = Convert::ToInt32(vehicleCountText);
			double time = Convert::ToDouble(timeText);

			// Obliczenia
			double distance = speed * time;
			double totalDistance = distance * vehicleCount;

			// Dodanie danych do DataGridView
			dataGridViewResults->Rows->Add(distance, vehicleCount, totalDistance);

			// Dodanie danych do wykresu
			chart1->Series["Series1"]->Points->Clear();
			chart1->Series["Series1"]->Points->AddXY(vehicleCount, totalDistance);
			chart1->ChartAreas[0]->AxisX->Title = "Liczba pojazdów";
			chart1->ChartAreas[0]->AxisY->Title = "Całkowity dystans (km)";
		}
		catch (FormatException^) {
			MessageBox::Show("Błąd: Wprowadź poprawne liczby.");
		}
	}

	private: System::Void InitializeDataGridView() {
		dataGridViewResults->Columns->Add("Distance", "Dystans (km)");
		dataGridViewResults->Columns->Add("VehicleCount", "Liczba pojazdów");
		dataGridViewResults->Columns->Add("TotalDistance", "Całkowity dystans (km)");
	}

	private: System::Void MyForm1_Load(System::Object^ sender, System::EventArgs^ e) {
	}
	};
};
Leave a Comment