コード例 #1
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridView1.Rows.Count > 1)
     {
         Expert exp = new Expert(dataGridView1.Rows[e.RowIndex]);
         richTextBox1.Text = exp.getExplanation();
     }
 }
コード例 #2
0
 //Открываем и считываем файл с текущими состояниями, чтобы их мониторить
 private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
 {
     int rowIndex = 0;
     string[] arrayOfStrings, stringArray; ;
     string fileName;
     OpenFileDialog openfiledialog = new OpenFileDialog();
     openfiledialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
     openfiledialog.ShowDialog();
     fileName = openfiledialog.FileName;
     try
     {
         using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.GetEncoding(1251)))
         {
             String line = sr.ReadToEnd();
             line = line.Replace("\r", "");
             arrayOfStrings = line.Split('\n');
             foreach (var x in arrayOfStrings)
             {
                 dataGridView1.Rows.Add();
                 stringArray = x.Split(' ');
                 foreach (var y in stringArray)
                 {
                     var ident = identifyAnAttribute(y);
                     if (ident == 0)
                         dataGridView1.Rows[rowIndex].Cells[0].Value = y.Replace("obj_t:", "");
                     else
                     {
                         if (ident == 1)
                             dataGridView1.Rows[rowIndex].Cells[0].Value += y.Replace("obj_n", "");
                         else
                         {
                             if (ident == 2)
                                 dataGridView1.Rows[rowIndex].Cells[1].Value = y.Replace("obj_l:", "");
                             else
                             {
                                 if (ident == 3)
                                     dataGridView1.Rows[rowIndex].Cells[2].Value = y.Replace("obj_d:", "");
                                 else
                                 {
                                     if (ident == 4)
                                         dataGridView1.Rows[rowIndex].Cells[3].Value = y.Replace("obj_h:", "");
                                 }
                             }
                         }
                     }
                 }
                 //Прочитали и добавили строку в таблицу, теперь пора заполнить поле ответа, какое текущее состояние объекта
                 Expert exp = new Expert(dataGridView1.Rows[rowIndex]);
                 dataGridView1.Rows[rowIndex].Cells[4].Value = exp.getAnswer();
                 rowIndex += 1;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("The file could not be read:");
         Console.WriteLine(ex.Message);
     }
     cellsValidating(dataGridView1);
 }