Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <fstream>
- #include <msclr\marshal_cppstd.h>
- #include <algorithm>
- #include <vector>
- #include <sstream>
- #include <atlstr.h>
- #include <filesystem>
- namespace PracticeGraphs {
- using namespace std;
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- }
- protected:
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- protected:
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::TabControl^ tabControl1;
- private: System::Windows::Forms::TabPage^ tabPage1;
- private: System::Windows::Forms::TabPage^ tabPage2;
- private: System::Windows::Forms::WebBrowser^ webBrowser1;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::TextBox^ second_graph;
- private: System::Windows::Forms::TextBox^ first_graph;
- private: System::Windows::Forms::Label^ label2;
- private:
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- void InitializeComponent(void)
- {
- this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
- this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
- this->second_graph = (gcnew System::Windows::Forms::TextBox());
- this->first_graph = (gcnew System::Windows::Forms::TextBox());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
- this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
- this->tabControl1->SuspendLayout();
- this->tabPage1->SuspendLayout();
- this->tabPage2->SuspendLayout();
- this->SuspendLayout();
- //
- // openFileDialog1
- //
- this->openFileDialog1->FileName = L"img.jpg";
- //
- // button2
- //
- this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button2->Location = System::Drawing::Point(14, 193);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(184, 30);
- this->button2->TabIndex = 2;
- this->button2->Text = L"Из формы";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
- //
- // tabControl1
- //
- this->tabControl1->Controls->Add(this->tabPage1);
- this->tabControl1->Controls->Add(this->tabPage2);
- this->tabControl1->Location = System::Drawing::Point(7, 12);
- this->tabControl1->Name = L"tabControl1";
- this->tabControl1->SelectedIndex = 0;
- this->tabControl1->Size = System::Drawing::Size(419, 295);
- this->tabControl1->TabIndex = 4;
- //
- // tabPage1
- //
- this->tabPage1->Controls->Add(this->second_graph);
- this->tabPage1->Controls->Add(this->first_graph);
- this->tabPage1->Controls->Add(this->label2);
- this->tabPage1->Controls->Add(this->button3);
- this->tabPage1->Controls->Add(this->button1);
- this->tabPage1->Controls->Add(this->label1);
- this->tabPage1->Controls->Add(this->button2);
- this->tabPage1->Location = System::Drawing::Point(4, 22);
- this->tabPage1->Name = L"tabPage1";
- this->tabPage1->Padding = System::Windows::Forms::Padding(3);
- this->tabPage1->Size = System::Drawing::Size(411, 269);
- this->tabPage1->TabIndex = 0;
- this->tabPage1->Text = L"Ввод данных";
- this->tabPage1->UseVisualStyleBackColor = true;
- //
- // second_graph
- //
- this->second_graph->Location = System::Drawing::Point(147, 45);
- this->second_graph->Name = L"second_graph";
- this->second_graph->Size = System::Drawing::Size(202, 20);
- this->second_graph->TabIndex = 11;
- //
- // first_graph
- //
- this->first_graph->Location = System::Drawing::Point(148, 16);
- this->first_graph->Name = L"first_graph";
- this->first_graph->Size = System::Drawing::Size(202, 20);
- this->first_graph->TabIndex = 10;
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Font = (gcnew System::Drawing::Font(L"Candara", 10));
- this->label2->Location = System::Drawing::Point(10, 45);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(131, 17);
- this->label2->TabIndex = 9;
- this->label2->Text = L"Ввод второго графа";
- //
- // button3
- //
- this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button3->Location = System::Drawing::Point(14, 229);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(389, 30);
- this->button3->TabIndex = 8;
- this->button3->Text = L"Выход";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
- //
- // button1
- //
- this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button1->Location = System::Drawing::Point(204, 193);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(199, 30);
- this->button1->TabIndex = 7;
- this->button1->Text = L"Из файла";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click_1);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Font = (gcnew System::Drawing::Font(L"Candara", 10));
- this->label1->Location = System::Drawing::Point(10, 16);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(131, 17);
- this->label1->TabIndex = 5;
- this->label1->Text = L"Ввод первого графа";
- //
- // tabPage2
- //
- this->tabPage2->Controls->Add(this->webBrowser1);
- this->tabPage2->Location = System::Drawing::Point(4, 22);
- this->tabPage2->Name = L"tabPage2";
- this->tabPage2->Padding = System::Windows::Forms::Padding(3);
- this->tabPage2->Size = System::Drawing::Size(411, 269);
- this->tabPage2->TabIndex = 1;
- this->tabPage2->Text = L"Веб-браузер";
- this->tabPage2->UseVisualStyleBackColor = true;
- //
- // webBrowser1
- //
- this->webBrowser1->Location = System::Drawing::Point(8, 6);
- this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
- this->webBrowser1->Name = L"webBrowser1";
- this->webBrowser1->Size = System::Drawing::Size(401, 271);
- this->webBrowser1->TabIndex = 1;
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(432, 315);
- this->Controls->Add(this->tabControl1);
- this->Name = L"MyForm";
- this->Text = L"Поиск суммы мин. элементов строки";
- this->tabControl1->ResumeLayout(false);
- this->tabPage1->ResumeLayout(false);
- this->tabPage1->PerformLayout();
- this->tabPage2->ResumeLayout(false);
- this->ResumeLayout(false);
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ opn = gcnew OpenFileDialog();
- opn->Filter = "Html files (*.html)|*.html|All files (*.*)|*.*";
- if (opn->ShowDialog() == Windows::Forms::DialogResult::OK) {
- webBrowser1->Navigate(opn->FileName);
- }
- }
- vector<std::string> split_by_delimiter(std::string input, char delimiter) {
- size_t pos = 0;
- std::string token;
- std::vector<std::string> output;
- while ((pos = input.find(delimiter)) != std::string::npos) {
- token = input.substr(0, pos);
- output.push_back(token);
- input.erase(0, pos + 1);
- }
- output.push_back(input);
- return output;
- }
- void controller(std::string first, std::string second) {
- if (first == "" || second == "") {
- MessageBox::Show("Введи данные в правильном формате!", "Ошибка ввода данных", MessageBoxButtons::OK, MessageBoxIcon::Error);
- return;
- }
- std::string file_name = "report.html";
- auto current_path = std::filesystem::current_path().string() + (string)"\\" + file_name;
- ofstream myfile;
- myfile.open(current_path);
- myfile << "<!DOCTYPE html><html><head></head><body>";
- myfile << "Разность двух введенных графов:<br>";
- std::vector<string> first_graph = split_by_delimiter(first, ' ');
- std::vector<string> second_graph = split_by_delimiter(second, ' ');
- std::vector<unsigned int> keys;
- unsigned int ik = 0;
- for (auto i : first_graph) {
- for (auto j : second_graph) {
- if (i == j) {
- keys.push_back(ik);
- break;
- }
- }
- ik++;
- }
- for (int i = keys.size() - 1; i >= 0; i--) {
- first_graph.erase(first_graph.begin() + keys[i]);
- }
- for (string graph : first_graph) {
- myfile << "Узел " + graph + "<br>";
- }
- myfile << "</body></html>" << std::endl;
- myfile.close();
- webBrowser1->Navigate(gcnew String(current_path.c_str()));
- this->tabControl1->SelectedIndex = 1;
- }
- public: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- controller(msclr::interop::marshal_as<std::string>(first_graph->Text), msclr::interop::marshal_as<std::string>(second_graph->Text));
- }
- private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) {
- openFileDialog1->Title = "Открыть файл для заполнения";
- openFileDialog1->Filter = "Text Files(*.txt)|*.txt|All files (*.*)|*.*";
- if (openFileDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) {
- std::ifstream input(CString(openFileDialog1->FileName));
- std::stringstream sstr;
- while (input >> sstr.rdbuf());
- string file_data = sstr.str();
- vector<string> vec = split_by_delimiter(file_data, '\n');
- controller(vec[0], vec[1]);
- input.close();
- }
- }
- private: System::Void linkLabel1_LinkClicked(System::Object^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e) {
- MessageBox::Show("Для ввода необходимо разделять элементы через пробел, а строки через Enter!", "Помощь по вводу данных", MessageBoxButtons::OK, MessageBoxIcon::Question);
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- exit(0);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement