Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace LB23_1_2 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::IO;
- /// <summary>
- /// Сводка для Form1
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::DataGridView^ dataGridView1;
- private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column1;
- private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column2;
- private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column3;
- private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column4;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::Button^ button3;
- protected:
- private:
- /// <summary>
- /// Требуется переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Обязательный метод для поддержки конструктора - не изменяйте
- /// содержимое данного метода при помощи редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
- this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
- this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
- this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
- this->Column4 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->button3 = (gcnew System::Windows::Forms::Button());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit();
- this->SuspendLayout();
- //
- // dataGridView1
- //
- this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
- this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(4) {this->Column1,
- this->Column2, this->Column3, this->Column4});
- this->dataGridView1->Location = System::Drawing::Point(12, 12);
- this->dataGridView1->Name = L"dataGridView1";
- this->dataGridView1->Size = System::Drawing::Size(444, 150);
- this->dataGridView1->TabIndex = 0;
- //
- // Column1
- //
- this->Column1->HeaderText = L"Тип";
- this->Column1->Name = L"Column1";
- //
- // Column2
- //
- this->Column2->HeaderText = L"Фирма";
- this->Column2->Name = L"Column2";
- //
- // Column3
- //
- this->Column3->HeaderText = L"Скорость (стр/мин)";
- this->Column3->Name = L"Column3";
- //
- // Column4
- //
- this->Column4->HeaderText = L"Цена";
- this->Column4->Name = L"Column4";
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(12, 168);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(91, 23);
- this->button1->TabIndex = 1;
- this->button1->Text = L"Запись в файл";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // button2
- //
- this->button2->Location = System::Drawing::Point(109, 168);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(103, 23);
- this->button2->TabIndex = 2;
- this->button2->Text = L"Чтение из файла";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(218, 168);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(238, 23);
- this->button3->TabIndex = 3;
- this->button3->Text = L"Ведомость (принтеры HP, >10 стр/мин)";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(469, 202);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->dataGridView1);
- this->Name = L"Form1";
- this->Text = L"Form1";
- this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit();
- this->ResumeLayout(false);
- }
- #pragma endregion
- String ^fname;
- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
- fname = "Belyaev.bin";
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- BinaryWriter ^f = gcnew BinaryWriter(File::Open(fname, FileMode::OpenOrCreate));
- f->Seek(0, SeekOrigin::End);
- try {
- int k = dataGridView1->Rows->GetRowCount(DataGridViewElementStates::Visible);
- for( int i = 0; i < k-1; i++ )
- {
- String ^type = dataGridView1[0, i]->Value->ToString();
- String ^firm = dataGridView1[1, i]->Value->ToString();
- int speed = Convert::ToInt32(dataGridView1[2, i]->Value);
- double price = Convert::ToDouble(dataGridView1[3, i]->Value);
- f->Write(type); f->Write(firm); f->Write(speed); f->Write(price);
- }
- dataGridView1->Rows->Clear();
- dataGridView1->Rows->Add();
- } finally {f->Close();}
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- if(!File::Exists(fname))
- {
- MessageBox::Show("Файл не найден!"); return;
- }
- BinaryReader ^fb = gcnew BinaryReader(File::OpenRead(fname));
- try {
- int k = 0;
- dataGridView1->Rows->Clear();
- while(fb->BaseStream->Position < fb->BaseStream->Length)
- {
- String ^type = fb->ReadString();
- String ^firm = fb->ReadString();
- int speed = fb->ReadInt32();
- double price = fb->ReadDouble();
- dataGridView1->Rows->Add();
- dataGridView1[0, k]->Value = type;
- dataGridView1[1, k]->Value = firm;
- dataGridView1[2, k]->Value = speed.ToString();
- dataGridView1[3, k]->Value = price.ToString();
- k++;
- }
- } finally {fb->Close();}
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- if(!File::Exists(fname))
- {
- MessageBox::Show("Файл не найден!"); return;
- }
- BinaryReader ^fb = gcnew BinaryReader(File::OpenRead(fname));
- try {
- int k = 0;
- dataGridView1->Rows->Clear();
- while(fb->BaseStream->Position < fb->BaseStream->Length)
- {
- String ^type = fb->ReadString();
- String ^firm = fb->ReadString();
- int speed = fb->ReadInt32();
- double price = fb->ReadDouble();
- if( firm == "HP" && speed > 10 )
- {
- dataGridView1[0, k]->Value = type;
- dataGridView1[1, k]->Value = firm;
- dataGridView1[2, k]->Value = speed.ToString();
- dataGridView1[3, k]->Value = price.ToString();
- }
- k++;
- }
- } finally {fb->Close();}
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment