Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
  2.             int coords[2][4];
  3.             array<System::String^>^ lines = gcnew array<System::String^>(7);
  4.  
  5.             openFile(lines);
  6.             //if не пустой
  7.             parseFile(lines, coords);
  8.             drawLines(coords);
  9.         }
  10.  
  11.         void drawLines(int coords[][4]) {
  12.             Graphics^ g;
  13.             g = pictureBox1->CreateGraphics();
  14.             g->DrawLine(System::Drawing::Pens::Green, coords[0][0], coords[0][1], coords[0][2], coords[0][3]);
  15.             g->DrawLine(System::Drawing::Pens::Green, coords[1][0], coords[1][1], coords[1][2], coords[1][3]);
  16.         }
  17.  
  18.         void openFile(array<System::String^>^ lines) {
  19.             int i = 0;
  20.  
  21.             OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
  22.  
  23.             openFileDialog1->InitialDirectory = "c:\\";
  24.             openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
  25.             openFileDialog1->FilterIndex = 2;
  26.             openFileDialog1->RestoreDirectory = true;
  27.  
  28.             if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
  29.             {
  30.                 StreamReader^ sr = gcnew StreamReader(openFileDialog1->FileName);
  31.  
  32.                 try
  33.                 {
  34.                     String^ line;
  35.                     while (line = sr->ReadLine())
  36.                     {
  37.                         try {
  38.                             lines[i] = line;
  39.                             i++;
  40.                         }
  41.                         catch (IndexOutOfRangeException^ e) {
  42.                             textBox1->Text = "Ошибка";
  43.                         }
  44.                     }
  45.                 }  
  46.                 finally
  47.                 {
  48.                     if (sr)
  49.                         delete (IDisposable^)sr;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         int* parseFile(array<System::String^>^ lines, int coords[][4]) {
  55.             try {
  56.                 bool flag = false;
  57.                 String^ line = "Line[1-2]{1}";
  58.                 String^ coord = "[0-9]{1,5}[ ][0-9]{1,5}";
  59.  
  60.  
  61.                 if (!Regex::IsMatch(lines[0], line, RegexOptions::IgnoreCase)) {
  62.                     throw 0;
  63.                 }
  64.                 if (!Regex::IsMatch(lines[1], coord, RegexOptions::IgnoreCase)) {
  65.                     throw 1;
  66.                 }
  67.                 if (!Regex::IsMatch(lines[2], coord, RegexOptions::IgnoreCase)) {
  68.                     throw 2;
  69.                 }
  70.                 if (!Regex::IsMatch(lines[4], line, RegexOptions::IgnoreCase)) {
  71.                     throw 4;
  72.                 }
  73.                 if (!Regex::IsMatch(lines[5], coord, RegexOptions::IgnoreCase)) {
  74.                     throw 5;
  75.                 }
  76.                 if (!Regex::IsMatch(lines[6], coord, RegexOptions::IgnoreCase)) {
  77.                     throw 6;
  78.                 }
  79.  
  80.                 coords[0][0] = int::Parse(lines[1]->Split(' ')[0]);
  81.                 coords[0][1] = int::Parse(lines[1]->Split(' ')[1]);
  82.  
  83.                 coords[1][0] = int::Parse(lines[2]->Split(' ')[0]);
  84.                 coords[1][1] = int::Parse(lines[2]->Split(' ')[1]);
  85.  
  86.                 coords[2][0] = int::Parse(lines[5]->Split(' ')[0]);
  87.                 coords[2][1] = int::Parse(lines[5]->Split(' ')[1]);
  88.  
  89.                 coords[3][0] = int::Parse(lines[6]->Split(' ')[0]);
  90.                 coords[3][1] = int::Parse(lines[6]->Split(' ')[1]);
  91.                
  92.             }
  93.             catch (int i) {
  94.                 textBox1->Text = "Ошибка в строке " + (i + 1).ToString();
  95.             }
  96.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement