Advertisement
xladomaz

Ебаная практика

Jun 19th, 2020
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.84 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <msclr\marshal_cppstd.h>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <sstream>
  9. #include <atlstr.h>
  10. #include <filesystem>
  11.  
  12. namespace PracticeGraphs {
  13.  
  14. using namespace std;
  15. using namespace System;
  16. using namespace System::ComponentModel;
  17. using namespace System::Collections;
  18. using namespace System::Windows::Forms;
  19. using namespace System::Data;
  20. using namespace System::Drawing;
  21.  
  22. public ref class MyForm : public System::Windows::Forms::Form
  23. {
  24. public:
  25. MyForm(void)
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30. protected:
  31. ~MyForm()
  32. {
  33. if (components)
  34. {
  35. delete components;
  36. }
  37. }
  38.  
  39. protected:
  40.  
  41. private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
  42. private: System::Windows::Forms::Button^ button2;
  43.  
  44. private: System::Windows::Forms::TabControl^ tabControl1;
  45. private: System::Windows::Forms::TabPage^ tabPage1;
  46. private: System::Windows::Forms::TabPage^ tabPage2;
  47. private: System::Windows::Forms::WebBrowser^ webBrowser1;
  48. private: System::Windows::Forms::Label^ label1;
  49.  
  50.  
  51. private: System::Windows::Forms::Button^ button1;
  52. private: System::Windows::Forms::Button^ button3;
  53. private: System::Windows::Forms::TextBox^ second_graph;
  54. private: System::Windows::Forms::TextBox^ first_graph;
  55. private: System::Windows::Forms::Label^ label2;
  56.  
  57.  
  58. private:
  59. System::ComponentModel::Container ^components;
  60.  
  61. #pragma region Windows Form Designer generated code
  62. void InitializeComponent(void)
  63. {
  64.     this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
  65.     this->button2 = (gcnew System::Windows::Forms::Button());
  66.     this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
  67.     this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
  68.     this->second_graph = (gcnew System::Windows::Forms::TextBox());
  69.     this->first_graph = (gcnew System::Windows::Forms::TextBox());
  70.     this->label2 = (gcnew System::Windows::Forms::Label());
  71.     this->button3 = (gcnew System::Windows::Forms::Button());
  72.     this->button1 = (gcnew System::Windows::Forms::Button());
  73.     this->label1 = (gcnew System::Windows::Forms::Label());
  74.     this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
  75.     this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
  76.     this->tabControl1->SuspendLayout();
  77.     this->tabPage1->SuspendLayout();
  78.     this->tabPage2->SuspendLayout();
  79.     this->SuspendLayout();
  80.     //
  81.     // openFileDialog1
  82.     //
  83.     this->openFileDialog1->FileName = L"img.jpg";
  84.     //
  85.     // button2
  86.     //
  87.     this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  88.         static_cast<System::Byte>(204)));
  89.     this->button2->Location = System::Drawing::Point(14, 193);
  90.     this->button2->Name = L"button2";
  91.     this->button2->Size = System::Drawing::Size(184, 30);
  92.     this->button2->TabIndex = 2;
  93.     this->button2->Text = L"Из формы";
  94.     this->button2->UseVisualStyleBackColor = true;
  95.     this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  96.     //
  97.     // tabControl1
  98.     //
  99.     this->tabControl1->Controls->Add(this->tabPage1);
  100.     this->tabControl1->Controls->Add(this->tabPage2);
  101.     this->tabControl1->Location = System::Drawing::Point(7, 12);
  102.     this->tabControl1->Name = L"tabControl1";
  103.     this->tabControl1->SelectedIndex = 0;
  104.     this->tabControl1->Size = System::Drawing::Size(419, 295);
  105.     this->tabControl1->TabIndex = 4;
  106.     //
  107.     // tabPage1
  108.     //
  109.     this->tabPage1->Controls->Add(this->second_graph);
  110.     this->tabPage1->Controls->Add(this->first_graph);
  111.     this->tabPage1->Controls->Add(this->label2);
  112.     this->tabPage1->Controls->Add(this->button3);
  113.     this->tabPage1->Controls->Add(this->button1);
  114.     this->tabPage1->Controls->Add(this->label1);
  115.     this->tabPage1->Controls->Add(this->button2);
  116.     this->tabPage1->Location = System::Drawing::Point(4, 22);
  117.     this->tabPage1->Name = L"tabPage1";
  118.     this->tabPage1->Padding = System::Windows::Forms::Padding(3);
  119.     this->tabPage1->Size = System::Drawing::Size(411, 269);
  120.     this->tabPage1->TabIndex = 0;
  121.     this->tabPage1->Text = L"Ввод данных";
  122.     this->tabPage1->UseVisualStyleBackColor = true;
  123.     //
  124.     // second_graph
  125.     //
  126.     this->second_graph->Location = System::Drawing::Point(147, 45);
  127.     this->second_graph->Name = L"second_graph";
  128.     this->second_graph->Size = System::Drawing::Size(202, 20);
  129.     this->second_graph->TabIndex = 11;
  130.     //
  131.     // first_graph
  132.     //
  133.     this->first_graph->Location = System::Drawing::Point(148, 16);
  134.     this->first_graph->Name = L"first_graph";
  135.     this->first_graph->Size = System::Drawing::Size(202, 20);
  136.     this->first_graph->TabIndex = 10;
  137.     //
  138.     // label2
  139.     //
  140.     this->label2->AutoSize = true;
  141.     this->label2->Font = (gcnew System::Drawing::Font(L"Candara", 10));
  142.     this->label2->Location = System::Drawing::Point(10, 45);
  143.     this->label2->Name = L"label2";
  144.     this->label2->Size = System::Drawing::Size(131, 17);
  145.     this->label2->TabIndex = 9;
  146.     this->label2->Text = L"Ввод второго графа";
  147.     //
  148.     // button3
  149.     //
  150.     this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  151.         static_cast<System::Byte>(204)));
  152.     this->button3->Location = System::Drawing::Point(14, 229);
  153.     this->button3->Name = L"button3";
  154.     this->button3->Size = System::Drawing::Size(389, 30);
  155.     this->button3->TabIndex = 8;
  156.     this->button3->Text = L"Выход";
  157.     this->button3->UseVisualStyleBackColor = true;
  158.     this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  159.     //
  160.     // button1
  161.     //
  162.     this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  163.         static_cast<System::Byte>(204)));
  164.     this->button1->Location = System::Drawing::Point(204, 193);
  165.     this->button1->Name = L"button1";
  166.     this->button1->Size = System::Drawing::Size(199, 30);
  167.     this->button1->TabIndex = 7;
  168.     this->button1->Text = L"Из файла";
  169.     this->button1->UseVisualStyleBackColor = true;
  170.     this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click_1);
  171.     //
  172.     // label1
  173.     //
  174.     this->label1->AutoSize = true;
  175.     this->label1->Font = (gcnew System::Drawing::Font(L"Candara", 10));
  176.     this->label1->Location = System::Drawing::Point(10, 16);
  177.     this->label1->Name = L"label1";
  178.     this->label1->Size = System::Drawing::Size(131, 17);
  179.     this->label1->TabIndex = 5;
  180.     this->label1->Text = L"Ввод первого графа";
  181.     //
  182.     // tabPage2
  183.     //
  184.     this->tabPage2->Controls->Add(this->webBrowser1);
  185.     this->tabPage2->Location = System::Drawing::Point(4, 22);
  186.     this->tabPage2->Name = L"tabPage2";
  187.     this->tabPage2->Padding = System::Windows::Forms::Padding(3);
  188.     this->tabPage2->Size = System::Drawing::Size(411, 269);
  189.     this->tabPage2->TabIndex = 1;
  190.     this->tabPage2->Text = L"Веб-браузер";
  191.     this->tabPage2->UseVisualStyleBackColor = true;
  192.     //
  193.     // webBrowser1
  194.     //
  195.     this->webBrowser1->Location = System::Drawing::Point(8, 6);
  196.     this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
  197.     this->webBrowser1->Name = L"webBrowser1";
  198.     this->webBrowser1->Size = System::Drawing::Size(401, 271);
  199.     this->webBrowser1->TabIndex = 1;
  200.     //
  201.     // MyForm
  202.     //
  203.     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  204.     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  205.     this->ClientSize = System::Drawing::Size(432, 315);
  206.     this->Controls->Add(this->tabControl1);
  207.     this->Name = L"MyForm";
  208.     this->Text = L"Поиск суммы мин. элементов строки";
  209.     this->tabControl1->ResumeLayout(false);
  210.     this->tabPage1->ResumeLayout(false);
  211.     this->tabPage1->PerformLayout();
  212.     this->tabPage2->ResumeLayout(false);
  213.     this->ResumeLayout(false);
  214.  
  215. }
  216. #pragma endregion
  217. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  218.     OpenFileDialog^ opn = gcnew OpenFileDialog();
  219.     opn->Filter = "Html files (*.html)|*.html|All files (*.*)|*.*";
  220.     if (opn->ShowDialog() == Windows::Forms::DialogResult::OK) {
  221.         webBrowser1->Navigate(opn->FileName);
  222.     }
  223.  
  224. }
  225.  
  226. vector<std::string> split_by_delimiter(std::string input, char delimiter) {
  227.     size_t pos = 0;
  228.     std::string token;
  229.     std::vector<std::string> output;
  230.     while ((pos = input.find(delimiter)) != std::string::npos) {
  231.         token = input.substr(0, pos);
  232.         output.push_back(token);
  233.         input.erase(0, pos + 1);
  234.     }
  235.     output.push_back(input);
  236.     return output;
  237. }
  238.  
  239. void controller(std::string first, std::string second) {
  240.  
  241.     if (first == "" || second == "") {
  242.         MessageBox::Show("Введи данные в правильном формате!", "Ошибка ввода данных", MessageBoxButtons::OK, MessageBoxIcon::Error);
  243.         return;
  244.     }
  245.  
  246.     std::string file_name = "report.html";
  247.     auto current_path = std::filesystem::current_path().string() + (string)"\\" + file_name;
  248.  
  249.     ofstream myfile;
  250.  
  251.     myfile.open(current_path);
  252.     myfile << "<!DOCTYPE html><html><head></head><body>";
  253.     myfile << "Разность двух введенных графов:<br>";
  254.  
  255.     std::vector<string> first_graph =  split_by_delimiter(first, ' ');
  256.     std::vector<string> second_graph = split_by_delimiter(second, ' ');
  257.     std::vector<unsigned int> keys;
  258.     unsigned int ik = 0;
  259.     for (auto i : first_graph) {
  260.         for (auto j : second_graph) {
  261.             if (i == j) {
  262.                 keys.push_back(ik);
  263.                 break;
  264.             }
  265.         }
  266.         ik++;
  267.     }
  268.  
  269.     for (int i = keys.size() - 1; i >= 0; i--) {
  270.         first_graph.erase(first_graph.begin() + keys[i]);
  271.     }
  272.  
  273.     for (string graph : first_graph) {
  274.         myfile << "Узел " + graph + "<br>";
  275.     }
  276.  
  277.     myfile << "</body></html>" << std::endl;
  278.     myfile.close();
  279.  
  280.     webBrowser1->Navigate(gcnew String(current_path.c_str()));
  281.  
  282.     this->tabControl1->SelectedIndex = 1;
  283. }
  284.  
  285. public: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  286.     controller(msclr::interop::marshal_as<std::string>(first_graph->Text), msclr::interop::marshal_as<std::string>(second_graph->Text));
  287. }
  288.  
  289. private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) {
  290.     openFileDialog1->Title = "Открыть файл для заполнения";
  291.     openFileDialog1->Filter = "Text Files(*.txt)|*.txt|All files (*.*)|*.*";
  292.  
  293.     if (openFileDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) {
  294.         std::ifstream input(CString(openFileDialog1->FileName));
  295.         std::stringstream sstr;
  296.         while (input >> sstr.rdbuf());
  297.  
  298.         string file_data = sstr.str();
  299.  
  300.         vector<string> vec = split_by_delimiter(file_data, '\n');
  301.         controller(vec[0], vec[1]);
  302.  
  303.         input.close();
  304.     }
  305. }
  306.  
  307. private: System::Void linkLabel1_LinkClicked(System::Object^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e) {
  308.     MessageBox::Show("Для ввода необходимо разделять элементы через пробел, а строки через Enter!", "Помощь по вводу данных", MessageBoxButtons::OK, MessageBoxIcon::Question);
  309. }
  310.  
  311. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  312.     exit(0);
  313. }
  314. };
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement