Advertisement
VictoriaLodochkina

contr

Apr 23rd, 2020
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.01 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <ctime>
  9. #include <msclr\marshal_cppstd.h>
  10. #include <Windows.h>
  11. int manual_filling = 0;
  12. //std::string path = "text_new.dat";
  13. struct Information
  14. {
  15.     std::string Name;
  16.     std::string Date;
  17.     std::string Problem;
  18.     std::string Status;
  19.     Information(std::string = "", std::string = "", std::string = "", std::string = "");
  20. };
  21. //--------------------------
  22. Information::Information(std::string Name, std::string Date, std::string Problem, std::string Status) {
  23.     this->Name = Name;
  24.     this->Date = Date;
  25.     this->Problem = Problem;
  26.     this->Status = Status;
  27. }
  28.  
  29. std::string randName() {
  30.     size_t size = rand() % 7 + 2;
  31.     std::string s(size, ' ');
  32.     s[0] = static_cast<char>(rand() % ('2' - 'A') + 'A');
  33.     for (size_t i = 1; i < size; i++)
  34.     {
  35.         s[i] = static_cast<char>(rand() % ('z' - 'a') + 'a');
  36.     }
  37.     return s;
  38. }
  39. std::string randDate() {
  40.     size_t size = rand() % 7 + 2;
  41.     std::string s(size, ' ');
  42.     s[0] = static_cast<char>(rand() % ('2' - 'A') + 'A');
  43.     for (size_t i = 1; i < size; i++)
  44.     {
  45.         s[i] = static_cast<char>(rand() % ('z' - 'a') + 'a');
  46.     }
  47.     return s;
  48. }
  49. std::string randProblem() {
  50.     size_t size = rand() % 7 + 2;
  51.     std::string s(size, ' ');
  52.     s[0] = static_cast<char>(rand() % ('2' - 'A') + 'A');
  53.     for (size_t i = 1; i < size; i++)
  54.     {
  55.         s[i] = static_cast<char>(rand() % ('z' - 'a') + 'a');
  56.     }
  57.     return s;
  58. }
  59. std::string randStatus() {
  60.     size_t size = rand() % 7 + 2;
  61.     std::string s(size, ' ');
  62.     s[0] = static_cast<char>(rand() % ('2' - 'A') + 'A');
  63.     for (size_t i = 1; i < size; i++)
  64.     {
  65.         s[i] = static_cast<char>(rand() % ('z' - 'a') + 'a');
  66.     }
  67.     return s;
  68. }
  69.  
  70. void randFill(std::vector<Information>& list) {
  71.     srand(static_cast<unsigned int>(time(nullptr)));
  72.     for (size_t i = 0; i < list.size(); i++) {
  73.         list[i].Name = randName();
  74.         list[i].Date = randDate();
  75.         list[i].Problem = randProblem();
  76.         list[i].Status = randStatus();
  77.     }
  78. }
  79.  
  80. void del_from_vector(std::vector<Information> & list, int in) {
  81.     for (size_t k = 0; k < list.size(); k++)
  82.     {
  83.         if (k==in)
  84.         {
  85.             list.erase(list.begin() + k);
  86.         }
  87.     }
  88. }
  89.  
  90. bool save_list_to_file(std::string path, std::vector<Information> list) {
  91.     std::ofstream file;
  92.     file.open(path.c_str(), std::ios_base::binary | std::ios::out | std::ios::trunc);
  93.     if (file) {
  94.         for (size_t i = 0; i < list.size(); i++) {
  95.             size_t lnlen = list[i].Name.length();
  96.             file.write(reinterpret_cast<char*>(&lnlen), sizeof(lnlen));
  97.             file.write(list[i].Name.c_str(), static_cast<long long>(lnlen));
  98.             size_t lnlen1 = list[i].Date.length();
  99.             file.write(reinterpret_cast<char*>(&lnlen1), sizeof(lnlen1));
  100.             file.write(list[i].Date.c_str(), static_cast<long long>(lnlen1));
  101.             size_t lnlen2 = list[i].Problem.length();
  102.             file.write(reinterpret_cast<char*>(&lnlen2), sizeof(lnlen2));
  103.             file.write(list[i].Problem.c_str(), static_cast<long long>(lnlen2));
  104.             size_t lnlen3 = list[i].Status.length();
  105.             file.write(reinterpret_cast<char*>(&lnlen3), sizeof(lnlen3));
  106.             file.write(list[i].Status.c_str(), static_cast<long long>(lnlen3));
  107.         }
  108.         file.close();
  109.         return true;
  110.     }
  111.     return false;
  112. }
  113. bool load_list_from_file(std::string path, std::vector<Information>& list) {
  114.     std::ifstream file;
  115.     list.clear();
  116.     file.open(path.c_str(), std::ios::binary | std::ios::in);
  117.     if (file) {
  118.         while (!file.eof()) {
  119.             std::string Name;
  120.             size_t lnlen;
  121.             file.read(reinterpret_cast<char*>(&lnlen), sizeof(lnlen));
  122.  
  123.             /*std::string Date;
  124.             size_t lnlen1;
  125.             //file.read(reinterpret_cast<char*>(&lnlen1), sizeof(lnlen1));*/
  126.  
  127.             /*std::string Problem;
  128.             size_t lnlen2;
  129.             //file.read(reinterpret_cast<char*>(&lnlen2), sizeof(lnlen2));*/
  130.  
  131.             /*std::string Status;
  132.             size_t lnlen3;
  133.             //file.read(reinterpret_cast<char*>(&lnlen3), sizeof(lnlen3));*/
  134.  
  135.             if (!file.fail()) {
  136.                 Name.resize(lnlen);
  137.                 file.read(&Name[0], static_cast<long long>(lnlen));
  138.  
  139.                 std::string Date;
  140.                 size_t lnlen1;
  141.                 file.read(reinterpret_cast<char*>(&lnlen1), sizeof(lnlen1));
  142.                 Date.resize(lnlen1);
  143.                 file.read(&Date[0], static_cast<long long>(lnlen1));
  144.  
  145.                 std::string Problem;
  146.                 size_t lnlen2;
  147.                 file.read(reinterpret_cast<char*>(&lnlen2), sizeof(lnlen2));
  148.                 Problem.resize(lnlen2);
  149.                 file.read(&Problem[0], static_cast<long long>(lnlen2));
  150.  
  151.                 std::string Status;
  152.                 size_t lnlen3;
  153.                 file.read(reinterpret_cast<char*>(&lnlen3), sizeof(lnlen3));
  154.                 Status.resize(lnlen3);
  155.                 file.read(&Status[0], static_cast<long long>(lnlen3));
  156.                 list.push_back(Information(Name, Date, Problem, Status));
  157.             }
  158.         }
  159.         file.close();
  160.         return true;
  161.     }
  162.     return false;
  163. }
  164.  
  165. /*bool load_list_from_file(std::string path, std::vector<Information>& list) {
  166.     std::ifstream file;
  167.     list.clear();
  168.     file.open(path.c_str(), std::ios::ios_base::binary | std::ios::in);
  169.     if (file) {
  170.         while (!file.eof()) {
  171.             std::string Name;
  172.             size_t lnlen;
  173.             file.read(reinterpret_cast<char*>(&lnlen), sizeof(lnlen));
  174.             std::string Date;
  175.             size_t lnlen1;
  176.             file.read(reinterpret_cast<char*>(&lnlen1), sizeof(lnlen1));
  177.             std::string Problem;
  178.             size_t lnlen2;
  179.             file.read(reinterpret_cast<char*>(&lnlen2), sizeof(lnlen2));
  180.             std::string Status;
  181.             size_t lnlen3;
  182.             file.read(reinterpret_cast<char*>(&lnlen3), sizeof(lnlen3));
  183.             if (!file.fail()) {
  184.                 Name.resize(lnlen);
  185.                 file.read(&Name[0], static_cast<long long>(lnlen));
  186.                 Name.resize(lnlen1);
  187.                 file.read(&Date[0], static_cast<long long>(lnlen1));
  188.                 Name.resize(lnlen2);
  189.                 file.read(&Problem[0], static_cast<long long>(lnlen2));
  190.                 Name.resize(lnlen3);
  191.                 file.read(&Status[0], static_cast<long long>(lnlen3));
  192.                 list.push_back(Information(Name, Date, Problem, Status));
  193.             }
  194.         }
  195.         file.close();
  196.         return true;
  197.     }
  198.     return false;
  199. }*/
  200.  
  201. namespace mypain {
  202.  
  203.     using namespace System;
  204.     using namespace System::ComponentModel;
  205.     using namespace System::Collections;
  206.     using namespace System::Windows::Forms;
  207.     using namespace System::Data;
  208.     using namespace System::Drawing;
  209.  
  210.     /// <summary>
  211.     /// Сводка для MyForm
  212.     /// </summary>
  213.     public ref class MyForm : public System::Windows::Forms::Form
  214.     {
  215.     public:
  216.         MyForm(void)
  217.         {
  218.             InitializeComponent();
  219.             //
  220.             //TODO: добавьте код конструктора
  221.             //
  222.         }
  223.  
  224.     protected:
  225.         /// <summary>
  226.         /// Освободить все используемые ресурсы.
  227.         /// </summary>
  228.         ~MyForm()
  229.         {
  230.             if (components)
  231.             {
  232.                 delete components;
  233.             }
  234.         }
  235.     private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip1;
  236.     protected:
  237.  
  238.  
  239.     private: System::Windows::Forms::ToolStrip^ toolStrip1;
  240.     private: System::Windows::Forms::MenuStrip^ menuStrip1;
  241.     private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem1;
  242.     private: System::Windows::Forms::ToolStripMenuItem^ saveToolStripMenuItem1;
  243.  
  244.  
  245.  
  246.     private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
  247.     private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
  248.     private: System::Windows::Forms::DataGridView^ dataGridView1;
  249.     private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column1;
  250.     private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column2;
  251.     private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column3;
  252.     private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column4;
  253.     private: System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
  254.  
  255.  
  256.  
  257.  
  258.  
  259.     private: System::Windows::Forms::ToolStripButton^ toolStripButton1;
  260.     private: System::Windows::Forms::ToolStripButton^ toolStripButton2;
  261.     private: System::Windows::Forms::ToolStripButton^ toolStripButton3;
  262.     private: System::Windows::Forms::ToolStripMenuItem^ actionsToolStripMenuItem;
  263.     private: System::Windows::Forms::ToolStripMenuItem^ increaseRowCountToolStripMenuItem;
  264.     private: System::Windows::Forms::ToolStripMenuItem^ randomToolStripMenuItem;
  265.     private: System::Windows::Forms::ToolStripMenuItem^ reduceRowCountToolStripMenuItem;
  266.     private: System::Windows::Forms::ToolStripMenuItem^ currentRowToolStripMenuItem;
  267.     private: System::Windows::Forms::ToolStripMenuItem^ processedPositionsToolStripMenuItem;
  268.     private: System::Windows::Forms::ToolStripMenuItem^ manualFillToolStripMenuItem;
  269.  
  270.     private: System::Windows::Forms::ToolStripMenuItem^ deleteToolStripMenuItem;
  271.     private: System::Windows::Forms::ToolStripMenuItem^ clearAllToolStripMenuItem1;
  272.     private: System::Windows::Forms::ToolStripMenuItem^ findProcessedPositionToolStripMenuItem;
  273.     private: System::Windows::Forms::ToolStripMenuItem^ highlightNotProcessedToolStripMenuItem;
  274.  
  275.  
  276.     private: System::ComponentModel::IContainer^ components;
  277.  
  278.     private:
  279.         /// <summary>
  280.         /// Обязательная переменная конструктора.
  281.         /// </summary>
  282.  
  283.  
  284. #pragma region Windows Form Designer generated code
  285.         /// <summary>
  286.         /// Требуемый метод для поддержки конструктора — не изменяйте
  287.         /// содержимое этого метода с помощью редактора кода.
  288.         /// </summary>
  289.         void InitializeComponent(void)
  290.         {
  291.             this->components = (gcnew System::ComponentModel::Container());
  292.             System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
  293.             this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
  294.             this->findProcessedPositionToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  295.             this->highlightNotProcessedToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  296.             this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
  297.             this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
  298.             this->toolStripButton2 = (gcnew System::Windows::Forms::ToolStripButton());
  299.             this->toolStripButton3 = (gcnew System::Windows::Forms::ToolStripButton());
  300.             this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  301.             this->fileToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
  302.             this->saveToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
  303.             this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  304.             this->clearAllToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
  305.             this->actionsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  306.             this->increaseRowCountToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  307.             this->randomToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  308.             this->reduceRowCountToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  309.             this->currentRowToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  310.             this->processedPositionsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  311.             this->deleteToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  312.             this->manualFillToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  313.             this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
  314.             this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
  315.             this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
  316.             this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  317.             this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  318.             this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  319.             this->Column4 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  320.             this->contextMenuStrip1->SuspendLayout();
  321.             this->toolStrip1->SuspendLayout();
  322.             this->menuStrip1->SuspendLayout();
  323.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
  324.             this->SuspendLayout();
  325.             //
  326.             // contextMenuStrip1
  327.             //
  328.             this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
  329.                 this->findProcessedPositionToolStripMenuItem,
  330.                     this->highlightNotProcessedToolStripMenuItem
  331.             });
  332.             this->contextMenuStrip1->Name = L"contextMenuStrip1";
  333.             this->contextMenuStrip1->Size = System::Drawing::Size(205, 48);
  334.             //
  335.             // findProcessedPositionToolStripMenuItem
  336.             //
  337.             this->findProcessedPositionToolStripMenuItem->Name = L"findProcessedPositionToolStripMenuItem";
  338.             this->findProcessedPositionToolStripMenuItem->Size = System::Drawing::Size(204, 22);
  339.             this->findProcessedPositionToolStripMenuItem->Text = L"Find Processed Positions";
  340.             //
  341.             // highlightNotProcessedToolStripMenuItem
  342.             //
  343.             this->highlightNotProcessedToolStripMenuItem->Name = L"highlightNotProcessedToolStripMenuItem";
  344.             this->highlightNotProcessedToolStripMenuItem->Size = System::Drawing::Size(204, 22);
  345.             this->highlightNotProcessedToolStripMenuItem->Text = L"Highlight Not Processed";
  346.             //
  347.             // toolStrip1
  348.             //
  349.             this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
  350.                 this->toolStripButton1,
  351.                     this->toolStripButton2, this->toolStripButton3
  352.             });
  353.             this->toolStrip1->Location = System::Drawing::Point(0, 24);
  354.             this->toolStrip1->Name = L"toolStrip1";
  355.             this->toolStrip1->Size = System::Drawing::Size(636, 25);
  356.             this->toolStrip1->TabIndex = 1;
  357.             this->toolStrip1->Text = L"toolStrip1";
  358.             //
  359.             // toolStripButton1
  360.             //
  361.             this->toolStripButton1->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
  362.             this->toolStripButton1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"toolStripButton1.Image")));
  363.             this->toolStripButton1->ImageTransparentColor = System::Drawing::Color::Magenta;
  364.             this->toolStripButton1->Name = L"toolStripButton1";
  365.             this->toolStripButton1->Size = System::Drawing::Size(23, 22);
  366.             this->toolStripButton1->Text = L"toolStripButton1";
  367.             this->toolStripButton1->Click += gcnew System::EventHandler(this, &MyForm::saveToolStripMenuItem1_Click);
  368.             //
  369.             // toolStripButton2
  370.             //
  371.             this->toolStripButton2->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
  372.             this->toolStripButton2->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"toolStripButton2.Image")));
  373.             this->toolStripButton2->ImageTransparentColor = System::Drawing::Color::Magenta;
  374.             this->toolStripButton2->Name = L"toolStripButton2";
  375.             this->toolStripButton2->Size = System::Drawing::Size(23, 22);
  376.             this->toolStripButton2->Text = L"toolStripButton2";
  377.             this->toolStripButton2->Click += gcnew System::EventHandler(this, &MyForm::manualFillToolStripMenuItem_Click);
  378.             //
  379.             // toolStripButton3
  380.             //
  381.             this->toolStripButton3->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
  382.             this->toolStripButton3->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"toolStripButton3.Image")));
  383.             this->toolStripButton3->ImageTransparentColor = System::Drawing::Color::Magenta;
  384.             this->toolStripButton3->Name = L"toolStripButton3";
  385.             this->toolStripButton3->Size = System::Drawing::Size(23, 22);
  386.             this->toolStripButton3->Text = L"toolStripButton3";
  387.             this->toolStripButton3->Click += gcnew System::EventHandler(this, &MyForm::openToolStripMenuItem_Click);
  388.             //
  389.             // menuStrip1
  390.             //
  391.             this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
  392.                 this->fileToolStripMenuItem1,
  393.                     this->actionsToolStripMenuItem
  394.             });
  395.             this->menuStrip1->Location = System::Drawing::Point(0, 0);
  396.             this->menuStrip1->Name = L"menuStrip1";
  397.             this->menuStrip1->Size = System::Drawing::Size(636, 24);
  398.             this->menuStrip1->TabIndex = 2;
  399.             this->menuStrip1->Text = L"menuStrip1";
  400.             //
  401.             // fileToolStripMenuItem1
  402.             //
  403.             this->fileToolStripMenuItem1->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
  404.                 this->saveToolStripMenuItem1,
  405.                     this->openToolStripMenuItem, this->clearAllToolStripMenuItem1
  406.             });
  407.             this->fileToolStripMenuItem1->Name = L"fileToolStripMenuItem1";
  408.             this->fileToolStripMenuItem1->Size = System::Drawing::Size(37, 20);
  409.             this->fileToolStripMenuItem1->Text = L"File";
  410.             //
  411.             // saveToolStripMenuItem1
  412.             //
  413.             this->saveToolStripMenuItem1->Name = L"saveToolStripMenuItem1";
  414.             this->saveToolStripMenuItem1->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::S));
  415.             this->saveToolStripMenuItem1->Size = System::Drawing::Size(180, 22);
  416.             this->saveToolStripMenuItem1->Text = L"Save";
  417.             this->saveToolStripMenuItem1->Click += gcnew System::EventHandler(this, &MyForm::saveToolStripMenuItem1_Click);
  418.             //
  419.             // openToolStripMenuItem
  420.             //
  421.             this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
  422.             this->openToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::O));
  423.             this->openToolStripMenuItem->Size = System::Drawing::Size(180, 22);
  424.             this->openToolStripMenuItem->Text = L"Open";
  425.             this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::openToolStripMenuItem_Click);
  426.             //
  427.             // clearAllToolStripMenuItem1
  428.             //
  429.             this->clearAllToolStripMenuItem1->Name = L"clearAllToolStripMenuItem1";
  430.             this->clearAllToolStripMenuItem1->Size = System::Drawing::Size(180, 22);
  431.             this->clearAllToolStripMenuItem1->Text = L"Clear all";
  432.             //
  433.             // actionsToolStripMenuItem
  434.             //
  435.             this->actionsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(4) {
  436.                 this->increaseRowCountToolStripMenuItem,
  437.                     this->randomToolStripMenuItem, this->reduceRowCountToolStripMenuItem, this->manualFillToolStripMenuItem
  438.             });
  439.             this->actionsToolStripMenuItem->Name = L"actionsToolStripMenuItem";
  440.             this->actionsToolStripMenuItem->Size = System::Drawing::Size(59, 20);
  441.             this->actionsToolStripMenuItem->Text = L"Actions";
  442.             //
  443.             // increaseRowCountToolStripMenuItem
  444.             //
  445.             this->increaseRowCountToolStripMenuItem->Name = L"increaseRowCountToolStripMenuItem";
  446.             this->increaseRowCountToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::I));
  447.             this->increaseRowCountToolStripMenuItem->Size = System::Drawing::Size(216, 22);
  448.             this->increaseRowCountToolStripMenuItem->Text = L"Increase Row Count";
  449.             this->increaseRowCountToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::increaseRowCountToolStripMenuItem_Click);
  450.             //
  451.             // randomToolStripMenuItem
  452.             //
  453.             this->randomToolStripMenuItem->Name = L"randomToolStripMenuItem";
  454.             this->randomToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::R));
  455.             this->randomToolStripMenuItem->Size = System::Drawing::Size(216, 22);
  456.             this->randomToolStripMenuItem->Text = L"Random Fill";
  457.             this->randomToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::randomToolStripMenuItem_Click);
  458.             //
  459.             // reduceRowCountToolStripMenuItem
  460.             //
  461.             this->reduceRowCountToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
  462.                 this->currentRowToolStripMenuItem,
  463.                     this->processedPositionsToolStripMenuItem, this->deleteToolStripMenuItem
  464.             });
  465.             this->reduceRowCountToolStripMenuItem->Name = L"reduceRowCountToolStripMenuItem";
  466.             this->reduceRowCountToolStripMenuItem->Size = System::Drawing::Size(216, 22);
  467.             this->reduceRowCountToolStripMenuItem->Text = L"Reduce Row Count";
  468.             this->reduceRowCountToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::reduceRowCountToolStripMenuItem_Click);
  469.             //
  470.             // currentRowToolStripMenuItem
  471.             //
  472.             this->currentRowToolStripMenuItem->Name = L"currentRowToolStripMenuItem";
  473.             this->currentRowToolStripMenuItem->Size = System::Drawing::Size(180, 22);
  474.             this->currentRowToolStripMenuItem->Text = L"Current Row";
  475.             this->currentRowToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::currentRowToolStripMenuItem_Click);
  476.             //
  477.             // processedPositionsToolStripMenuItem
  478.             //
  479.             this->processedPositionsToolStripMenuItem->Name = L"processedPositionsToolStripMenuItem";
  480.             this->processedPositionsToolStripMenuItem->Size = System::Drawing::Size(180, 22);
  481.             this->processedPositionsToolStripMenuItem->Text = L"Processed Positions";
  482.             //
  483.             // deleteToolStripMenuItem
  484.             //
  485.             this->deleteToolStripMenuItem->Name = L"deleteToolStripMenuItem";
  486.             this->deleteToolStripMenuItem->Size = System::Drawing::Size(180, 22);
  487.             this->deleteToolStripMenuItem->Text = L"Delete";
  488.             this->deleteToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::deleteToolStripMenuItem_Click);
  489.             //
  490.             // manualFillToolStripMenuItem
  491.             //
  492.             this->manualFillToolStripMenuItem->Name = L"manualFillToolStripMenuItem";
  493.             this->manualFillToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::M));
  494.             this->manualFillToolStripMenuItem->Size = System::Drawing::Size(216, 22);
  495.             this->manualFillToolStripMenuItem->Text = L"Manual Fill";
  496.             this->manualFillToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::manualFillToolStripMenuItem_Click);
  497.             //
  498.             // openFileDialog1
  499.             //
  500.             this->openFileDialog1->FileName = L"openFileDialog1";
  501.             //
  502.             // dataGridView1
  503.             //
  504.             this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
  505.             this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(4) {
  506.                 this->Column1,
  507.                     this->Column2, this->Column3, this->Column4
  508.             });
  509.             this->dataGridView1->ContextMenuStrip = this->contextMenuStrip1;
  510.             this->dataGridView1->Location = System::Drawing::Point(99, 69);
  511.             this->dataGridView1->Name = L"dataGridView1";
  512.             this->dataGridView1->Size = System::Drawing::Size(445, 150);
  513.             this->dataGridView1->TabIndex = 3;
  514.             //
  515.             // Column1
  516.             //
  517.             this->Column1->HeaderText = L"Name";
  518.             this->Column1->Name = L"Column1";
  519.             //
  520.             // Column2
  521.             //
  522.             this->Column2->HeaderText = L"Date";
  523.             this->Column2->Name = L"Column2";
  524.             //
  525.             // Column3
  526.             //
  527.             this->Column3->HeaderText = L"Problem";
  528.             this->Column3->Name = L"Column3";
  529.             //
  530.             // Column4
  531.             //
  532.             this->Column4->HeaderText = L"Status";
  533.             this->Column4->Name = L"Column4";
  534.             //
  535.             // MyForm
  536.             //
  537.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  538.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  539.             this->ClientSize = System::Drawing::Size(636, 287);
  540.             this->Controls->Add(this->dataGridView1);
  541.             this->Controls->Add(this->toolStrip1);
  542.             this->Controls->Add(this->menuStrip1);
  543.             this->MainMenuStrip = this->menuStrip1;
  544.             this->Name = L"MyForm";
  545.             this->Text = L"MyForm";
  546.             this->contextMenuStrip1->ResumeLayout(false);
  547.             this->toolStrip1->ResumeLayout(false);
  548.             this->toolStrip1->PerformLayout();
  549.             this->menuStrip1->ResumeLayout(false);
  550.             this->menuStrip1->PerformLayout();
  551.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
  552.             this->ResumeLayout(false);
  553.             this->PerformLayout();
  554.  
  555.         }
  556. #pragma endregion
  557.  
  558.  
  559. private: System::Void increaseRowCountToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  560.     dataGridView1->RowCount++;
  561. }
  562.  
  563.        void fill_grid(std::vector<Information>& list) {
  564.            size_t sz = list.size();
  565.            dataGridView1->RowCount = sz;
  566.            for (size_t i = 0; i < sz; i++)
  567.            {
  568.                dataGridView1->Rows[i]->Cells[0]->Value = gcnew System::String(list[i].Name.c_str());
  569.                dataGridView1->Rows[i]->Cells[1]->Value = gcnew System::String(list[i].Date.c_str());
  570.                dataGridView1->Rows[i]->Cells[2]->Value = gcnew System::String(list[i].Problem.c_str());
  571.                dataGridView1->Rows[i]->Cells[3]->Value = gcnew System::String(list[i].Status.c_str());
  572.            }
  573. }
  574. void fill_list_by_grid(std::vector<Information>& list, int& manual_filling) {
  575.     size_t sz = dataGridView1->RowCount;
  576.     sz -= manual_filling;
  577.     list.clear();
  578.     list.resize(sz);
  579.     for (size_t i = 0; i < sz; i++)
  580.            {
  581.                list[i].Name = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[0]->Value->ToString());
  582.                list[i].Date = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[1]->Value->ToString());
  583.                list[i].Problem = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[2]->Value->ToString());
  584.                list[i].Status = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[3]->Value->ToString());
  585.            }
  586. }
  587. private: System::Void randomToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  588.     manual_filling = 0;
  589.     int n = dataGridView1->RowCount;
  590.     std::vector<Information> list(n);
  591.     randFill(list);
  592.     fill_grid(list);
  593. }
  594. private: System::Void reduceRowCountToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  595.     dataGridView1->RowCount--;
  596. }
  597.  
  598. private: System::Void currentRowToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  599.     int n = dataGridView1->RowCount;
  600.     std::vector<Information> list(n);
  601.     fill_list_by_grid(list, manual_filling);
  602.     int in = dataGridView1->CurrentRow->Index;
  603.     del_from_vector(list, in);      
  604.     fill_grid(list);
  605.     //fill_list_by_grid(list, manual_filling);
  606. }
  607. private: System::Void clearAllToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  608.     dataGridView1->Rows[0]->Cells[0]->Value = L""; ////////////////////////////////////////             ЕНТО ДИЧЬ
  609. }
  610.  
  611.        void fill_list_by_grid_manual(std::vector<Information>& list, int& manual_filling) {
  612.            size_t sz = dataGridView1->RowCount;
  613.            sz--;
  614.            list.clear();
  615.            list.resize(sz);
  616.            for (size_t i = 0; i < sz; i++)
  617.            {
  618.                //if (msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[0]->Value->ToString()) !=" ")
  619.                list[i].Name = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[0]->Value->ToString());
  620.               // if (msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[1]->Value->ToString()) != " ")
  621.                list[i].Date = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[1]->Value->ToString());
  622.                //if (msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[2]->Value->ToString()) != " ")
  623.                list[i].Problem = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[2]->Value->ToString());
  624.               // if (msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[3]->Value->ToString()) != " ")
  625.                list[i].Status = msclr::interop::marshal_as<std::string>(dataGridView1->Rows[i]->Cells[3]->Value->ToString());
  626.            }
  627.        }
  628.  
  629. private: System::Void manualFillToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  630.     manual_filling = 1;
  631.     int n = dataGridView1->RowCount;
  632.     //n -= manual_filling;
  633.     std::vector<Information> list(n);
  634.     fill_list_by_grid_manual(list, manual_filling);
  635.  
  636.     del_from_vector(list, n-1);
  637.     fill_grid(list);
  638. }
  639.  
  640. private: System::Void deleteToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  641.     dataGridView1->RowCount--;
  642. }
  643.  
  644. private: System::Void saveToolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) {
  645.     int n = dataGridView1->RowCount;
  646.     n -= manual_filling;
  647.     std::vector<Information> list(n);
  648.     fill_list_by_grid(list, manual_filling); /////////////!!!!!!!!!!!!!!!!!!!!мб на одну запись меньше
  649.     saveFileDialog1->ShowDialog();
  650.     std::string path = msclr::interop::marshal_as<std::string>(saveFileDialog1->FileName);
  651.     save_list_to_file(path, list);
  652. }
  653. private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  654.     openFileDialog1->ShowDialog();
  655.     std::string path = msclr::interop::marshal_as<std::string>(openFileDialog1->FileName);
  656.     std::vector<Information> list;
  657.     load_list_from_file(path, list);
  658.     dataGridView1->RowCount = list.size();
  659.     fill_grid(list);///трабл мб с единицей
  660. }
  661.  
  662. };
  663. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement