VXP

LB23_1_1

VXP
Nov 15th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.93 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace LB23_1_2 {
  4.  
  5.     using namespace System;
  6.     using namespace System::ComponentModel;
  7.     using namespace System::Collections;
  8.     using namespace System::Windows::Forms;
  9.     using namespace System::Data;
  10.     using namespace System::Drawing;
  11.  
  12.     using namespace System::IO;
  13.  
  14.     /// <summary>
  15.     /// Сводка для Form1
  16.     /// </summary>
  17.     public ref class Form1 : public System::Windows::Forms::Form
  18.     {
  19.     public:
  20.         Form1(void)
  21.         {
  22.             InitializeComponent();
  23.             //
  24.             //TODO: добавьте код конструктора
  25.             //
  26.         }
  27.  
  28.     protected:
  29.         /// <summary>
  30.         /// Освободить все используемые ресурсы.
  31.         /// </summary>
  32.         ~Form1()
  33.         {
  34.             if (components)
  35.             {
  36.                 delete components;
  37.             }
  38.         }
  39.     private: System::Windows::Forms::DataGridView^  dataGridView1;
  40.     private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column1;
  41.     private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column2;
  42.     private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column3;
  43.     private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column4;
  44.     private: System::Windows::Forms::Button^  button1;
  45.     private: System::Windows::Forms::Button^  button2;
  46.     private: System::Windows::Forms::Button^  button3;
  47.     protected:
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     private:
  54.         /// <summary>
  55.         /// Требуется переменная конструктора.
  56.         /// </summary>
  57.         System::ComponentModel::Container ^components;
  58.  
  59. #pragma region Windows Form Designer generated code
  60.         /// <summary>
  61.         /// Обязательный метод для поддержки конструктора - не изменяйте
  62.         /// содержимое данного метода при помощи редактора кода.
  63.         /// </summary>
  64.         void InitializeComponent(void)
  65.         {
  66.             this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
  67.             this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  68.             this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  69.             this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  70.             this->Column4 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
  71.             this->button1 = (gcnew System::Windows::Forms::Button());
  72.             this->button2 = (gcnew System::Windows::Forms::Button());
  73.             this->button3 = (gcnew System::Windows::Forms::Button());
  74.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->BeginInit();
  75.             this->SuspendLayout();
  76.             //
  77.             // dataGridView1
  78.             //
  79.             this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
  80.             this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(4) {this->Column1,
  81.                 this->Column2, this->Column3, this->Column4});
  82.             this->dataGridView1->Location = System::Drawing::Point(12, 12);
  83.             this->dataGridView1->Name = L"dataGridView1";
  84.             this->dataGridView1->Size = System::Drawing::Size(444, 150);
  85.             this->dataGridView1->TabIndex = 0;
  86.             //
  87.             // Column1
  88.             //
  89.             this->Column1->HeaderText = L"Тип";
  90.             this->Column1->Name = L"Column1";
  91.             //
  92.             // Column2
  93.             //
  94.             this->Column2->HeaderText = L"Фирма";
  95.             this->Column2->Name = L"Column2";
  96.             //
  97.             // Column3
  98.             //
  99.             this->Column3->HeaderText = L"Скорость (стр/мин)";
  100.             this->Column3->Name = L"Column3";
  101.             //
  102.             // Column4
  103.             //
  104.             this->Column4->HeaderText = L"Цена";
  105.             this->Column4->Name = L"Column4";
  106.             //
  107.             // button1
  108.             //
  109.             this->button1->Location = System::Drawing::Point(12, 168);
  110.             this->button1->Name = L"button1";
  111.             this->button1->Size = System::Drawing::Size(91, 23);
  112.             this->button1->TabIndex = 1;
  113.             this->button1->Text = L"Запись в файл";
  114.             this->button1->UseVisualStyleBackColor = true;
  115.             this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  116.             //
  117.             // button2
  118.             //
  119.             this->button2->Location = System::Drawing::Point(109, 168);
  120.             this->button2->Name = L"button2";
  121.             this->button2->Size = System::Drawing::Size(103, 23);
  122.             this->button2->TabIndex = 2;
  123.             this->button2->Text = L"Чтение из файла";
  124.             this->button2->UseVisualStyleBackColor = true;
  125.             this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
  126.             //
  127.             // button3
  128.             //
  129.             this->button3->Location = System::Drawing::Point(218, 168);
  130.             this->button3->Name = L"button3";
  131.             this->button3->Size = System::Drawing::Size(238, 23);
  132.             this->button3->TabIndex = 3;
  133.             this->button3->Text = L"Ведомость (принтеры HP, >10 стр/мин)";
  134.             this->button3->UseVisualStyleBackColor = true;
  135.             this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
  136.             //
  137.             // Form1
  138.             //
  139.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  140.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  141.             this->ClientSize = System::Drawing::Size(469, 202);
  142.             this->Controls->Add(this->button3);
  143.             this->Controls->Add(this->button2);
  144.             this->Controls->Add(this->button1);
  145.             this->Controls->Add(this->dataGridView1);
  146.             this->Name = L"Form1";
  147.             this->Text = L"Form1";
  148.             this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  149.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->EndInit();
  150.             this->ResumeLayout(false);
  151.  
  152.         }
  153. #pragma endregion
  154.         String ^fname;
  155.     private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
  156.                  fname = "Belyaev.bin";
  157.              }
  158. private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  159.              BinaryWriter ^f = gcnew BinaryWriter(File::Open(fname, FileMode::OpenOrCreate));
  160.              f->Seek(0, SeekOrigin::End);
  161.              try {
  162.                  int k = dataGridView1->Rows->GetRowCount(DataGridViewElementStates::Visible);
  163.                  for( int i = 0; i < k-1; i++ )
  164.                  {
  165.                      String ^type = dataGridView1[0, i]->Value->ToString();
  166.                      String ^firm = dataGridView1[1, i]->Value->ToString();
  167.                      int speed = Convert::ToInt32(dataGridView1[2, i]->Value);
  168.                      double price = Convert::ToDouble(dataGridView1[3, i]->Value);
  169.                      f->Write(type); f->Write(firm); f->Write(speed); f->Write(price);
  170.                  }
  171.                  dataGridView1->Rows->Clear();
  172.                  dataGridView1->Rows->Add();
  173.              } finally {f->Close();}
  174.          }
  175. private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
  176.             if(!File::Exists(fname))
  177.             {
  178.                 MessageBox::Show("Файл не найден!"); return;
  179.             }
  180.             BinaryReader ^fb = gcnew BinaryReader(File::OpenRead(fname));
  181.             try {
  182.                 int k = 0;
  183.                 dataGridView1->Rows->Clear();
  184.                 while(fb->BaseStream->Position < fb->BaseStream->Length)
  185.                 {
  186.                     String ^type = fb->ReadString();
  187.                     String ^firm = fb->ReadString();
  188.                     int speed = fb->ReadInt32();
  189.                     double price = fb->ReadDouble();
  190.                     dataGridView1->Rows->Add();
  191.                     dataGridView1[0, k]->Value = type;
  192.                     dataGridView1[1, k]->Value = firm;
  193.                     dataGridView1[2, k]->Value = speed.ToString();
  194.                     dataGridView1[3, k]->Value = price.ToString();
  195.                     k++;
  196.                 }
  197.             } finally {fb->Close();}
  198.          }
  199. private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
  200.              if(!File::Exists(fname))
  201.             {
  202.                 MessageBox::Show("Файл не найден!"); return;
  203.             }
  204.             BinaryReader ^fb = gcnew BinaryReader(File::OpenRead(fname));
  205.             try {
  206.                 int k = 0;
  207.                 dataGridView1->Rows->Clear();
  208.                 while(fb->BaseStream->Position < fb->BaseStream->Length)
  209.                 {
  210.                     String ^type = fb->ReadString();
  211.                     String ^firm = fb->ReadString();
  212.                     int speed = fb->ReadInt32();
  213.                     double price = fb->ReadDouble();
  214.                     if( firm == "HP" && speed > 10 )
  215.                     {
  216.                         dataGridView1[0, k]->Value = type;
  217.                         dataGridView1[1, k]->Value = firm;
  218.                         dataGridView1[2, k]->Value = speed.ToString();
  219.                         dataGridView1[3, k]->Value = price.ToString();
  220.                     }
  221.                     k++;
  222.                 }
  223.             } finally {fb->Close();}
  224.          }
  225. };
  226. }
Advertisement
Add Comment
Please, Sign In to add comment