Untitled
#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(); // // menuStrip1 // this->menuStrip1->ImageScalingSize = System::Drawing::Size(20, 20); 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->Padding = System::Windows::Forms::Padding(5, 2, 0, 2); this->menuStrip1->Size = System::Drawing::Size(958, 28); this->menuStrip1->TabIndex = 0; this->menuStrip1->Text = L"menuStrip1"; this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &MyForm1::menuStrip1_ItemClicked); // // fileToolStripMenuItem // this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) { this->fileToolStripMenuItem1, this->helpToolStripMenuItem }); this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem"; this->fileToolStripMenuItem->Size = System::Drawing::Size(60, 24); this->fileToolStripMenuItem->Text = L"menu"; this->fileToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm1::fileToolStripMenuItem_Click); // // fileToolStripMenuItem1 // this->fileToolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->closeToolStripMenuItem }); this->fileToolStripMenuItem1->Name = L"fileToolStripMenuItem1"; this->fileToolStripMenuItem1->Size = System::Drawing::Size(156, 26); this->fileToolStripMenuItem1->Text = L"narzedzia"; // // closeToolStripMenuItem // this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem"; this->closeToolStripMenuItem->Size = System::Drawing::Size(143, 26); this->closeToolStripMenuItem->Text = L"zamknij"; // // helpToolStripMenuItem // this->helpToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->oAutorzeToolStripMenuItem }); this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem"; this->helpToolStripMenuItem->Size = System::Drawing::Size(156, 26); this->helpToolStripMenuItem->Text = L"pomoc"; this->helpToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm1::helpToolStripMenuItem_Click); // // oAutorzeToolStripMenuItem // this->oAutorzeToolStripMenuItem->Name = L"oAutorzeToolStripMenuItem"; this->oAutorzeToolStripMenuItem->Size = System::Drawing::Size(157, 26); this->oAutorzeToolStripMenuItem->Text = L"O autorze"; this->oAutorzeToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm1::oAutorzeToolStripMenuItem_Click); // // button1 // this->button1->Location = System::Drawing::Point(116, 172); this->button1->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 4; this->button1->Text = L"Oblicz"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click); // // dataGridViewResults // this->dataGridViewResults->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize; this->dataGridViewResults->Location = System::Drawing::Point(276, 221); this->dataGridViewResults->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); 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); // // chart1 // chartArea1->Name = L"ChartArea1"; this->chart1->ChartAreas->Add(chartArea1); legend1->Name = L"Legend1"; this->chart1->Legends->Add(legend1); this->chart1->Location = System::Drawing::Point(595, 71); this->chart1->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->chart1->Name = L"chart1"; series1->ChartArea = L"ChartArea1"; series1->Legend = L"Legend1"; series1->Name = L"Series1"; this->chart1->Series->Add(series1); this->chart1->Size = System::Drawing::Size(300, 300); this->chart1->TabIndex = 6; this->chart1->Text = L"chart1"; this->chart1->Click += gcnew System::EventHandler(this, &MyForm1::chart1_Click); // // speedTextBox // this->speedTextBox->Location = System::Drawing::Point(51, 41); this->speedTextBox->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->speedTextBox->Name = L"speedTextBox"; this->speedTextBox->Size = System::Drawing::Size(100, 22); this->speedTextBox->TabIndex = 7; // // vehicleCountTextBox // this->vehicleCountTextBox->Location = System::Drawing::Point(51, 81); this->vehicleCountTextBox->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->vehicleCountTextBox->Name = L"vehicleCountTextBox"; this->vehicleCountTextBox->Size = System::Drawing::Size(100, 22); this->vehicleCountTextBox->TabIndex = 8; // // timeTextBox // this->timeTextBox->Location = System::Drawing::Point(51, 123); this->timeTextBox->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->timeTextBox->Name = L"timeTextBox"; this->timeTextBox->Size = System::Drawing::Size(100, 22); this->timeTextBox->TabIndex = 9; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(183, 46); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(166, 16); this->label1->TabIndex = 10; this->label1->Text = L"Prędkość pojazdów (km/h)"; // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(187, 86); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(107, 16); this->label2->TabIndex = 11; this->label2->Text = L"Liczba pojazdów"; this->label2->Click += gcnew System::EventHandler(this, &MyForm1::label2_Click); // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(187, 128); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(122, 16); this->label3->TabIndex = 12; this->label3->Text = L"Czas (w godzinach)"; // // 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->label3); this->Controls->Add(this->label2); this->Controls->Add(this->label1); this->Controls->Add(this->timeTextBox); this->Controls->Add(this->vehicleCountTextBox); this->Controls->Add(this->speedTextBox); this->Controls->Add(this->chart1); this->Controls->Add(this->dataGridViewResults); this->Controls->Add(this->button1); this->Controls->Add(this->menuStrip1); this->MainMenuStrip = this->menuStrip1; this->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); 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 menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) { } private: System::Void fileToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void closeToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { this->Close(); } private: System::Void oAutorzeToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ text = speedTextBox->Text; String^ text1 = vehicleCountTextBox->Text; String^ text2 = timeTextBox->Text; String^ speedText = speedTextBox->Text; String^ vehicleCountText = vehicleCountTextBox->Text; String^ timeText = timeTextBox->Text; double speed = Convert::ToDouble(speedTextBox->Text); int vehicleCount = Convert::ToInt32(vehicleCountTextBox->Text); double time = Convert::ToDouble(timeTextBox->Text); try { double speed = Convert::ToDouble(speedTextBox->Text); int vehicleCount = Convert::ToInt32(vehicleCountTextBox->Text); double time = Convert::ToDouble(timeTextBox->Text); // Teraz możesz używać zmiennych: speed, vehicleCount, time } catch (FormatException^) { MessageBox::Show("Błąd: Wprowadź poprawne liczby."); } // Konwertuj wprowadzone teksty na liczby (jeśli to możliwe) //double speed = Convert::ToDouble(speedText); // Prędkość (km/h) //int vehicleCount = Convert::ToInt32(vehicleCountText); // Liczba pojazdów //double time = Convert::ToDouble(timeText); // Czas (godziny) tutaj zmienne zdefiniowane były wcześniej // Wykonaj obliczenia (np. liczba przejechanych kilometrów) double distance = speed * time; // Dystans = prędkość * czas double totalDistance = distance * vehicleCount; // Całkowity dystans = dystans * liczba pojazdów // Dodanie danych do DataGridView dataGridViewResults->Rows->Add(distance, vehicleCount, totalDistance); // Wyświetl wynik MessageBox::Show("Całkowity dystans przejechany przez wszystkie pojazdy: " + totalDistance.ToString() + " km"); }; private: System::Void dataGridViewResults_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) { dataGridViewResults->Columns->Add("Distance", "Dystans (km)"); dataGridViewResults->Columns->Add("VehicleCount", "Liczba pojazdów"); dataGridViewResults->Columns->Add("TotalDistance", "Całkowity dystans (km)"); } 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(); // Wyczyść poprzednie dane na wykresie chart1->Series["Series1"]->Points->AddXY(vehicleCount, totalDistance); // Dodaj nowe dane // Opcjonalnie: Ustawienia osi wykresu 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) { } private: System::Void chart1_Click(System::Object^ sender, System::EventArgs^ e) { // Inicjalizacja wykresu System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea(); chartArea1->Name = L"ChartArea1"; chart1->ChartAreas->Add(chartArea1); // Dodanie legendy System::Windows::Forms::DataVisualization::Charting::Legend^ legend1 = gcnew System::Windows::Forms::DataVisualization::Charting::Legend(); legend1->Name = L"Legend1"; chart1->Legends->Add(legend1); // Dodanie serii danych System::Windows::Forms::DataVisualization::Charting::Series^ series1 = gcnew System::Windows::Forms::DataVisualization::Charting::Series(); series1->ChartArea = L"ChartArea1"; series1->Legend = L"Legend1"; series1->Name = L"Series1"; chart1->Series->Add(series1); // Ustawienie rozmiaru wykresu chart1->Size = System::Drawing::Size(400, 300); chart1->Location = System::Drawing::Point(250, 50); } private: System::Void helpToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { } }; };
Leave a Comment