Пример #1
0
        private void printInFile(TPR table)
        {
            int[,] Rank  = new int[RowIndex, ColumnIndex];
            int[,] Value = new int[RowIndex, ColumnIndex];
            table.CopyRank(ref Rank);
            table.CopyValue(ref Value);
            using (StreamWriter output = new StreamWriter(@"C:\Users\Lera\source\repos\CW5\Part2\result.txt", false, System.Text.Encoding.Default)) {
                for (int i = 0; i < RowIndex; i++)
                {
                    for (int j = 0; j < ColumnIndex; j++)
                    {
                        output.Write($"оценка:{Value[i, j]} ранг:{Rank[i, j]} ");
                    }
                    output.WriteLine();
                }
            }

            /*    using (StreamWriter output = new StreamWriter(@"C:\Users\Lera\source\repos\CW5\Part2\resultSort.txt", false, System.Text.Encoding.Default))
             *
             *  {
             *      for (int rank = 1; rank <= RowIndex; rank++)
             *          for (int j = 0; j < RowIndex; j++)
             *          {
             *              if (Rank[j, ColumnIndex - 1] == rank)
             *
             *              {
             *                  int res = j + 1;
             *                  output.WriteLine($"{res}");
             *              }
             *          }
             *  }*/
        }
Пример #2
0
        private void printRank(TPR table)
        {
            int[,] Rank = new int[RowIndex, ColumnIndex];
            table.CopyRank(ref Rank);
            Form2 f2 = new Form2();

            f2.dataGridView1.ColumnCount = ColumnIndex + 1;
            f2.dataGridView1.RowCount    = RowIndex + 1;

            for (int i = 0; i < ColumnIndex; i++)
            {
                f2.dataGridView1.Columns[i].HeaderText = $"P{i}";
                for (int j = 0; j < RowIndex; j++)
                {
                    f2.dataGridView1.Rows[j].HeaderCell.Value = $"{j + 1}";
                    f2.dataGridView1.Rows[j].Cells[i].Value   = Rank[j, i];
                }
            }
            f2.dataGridView2.RowCount = RowIndex + 1;
            f2.dataGridView2.Columns[0].HeaderText = "ранжировка";

            for (int rank = 1; rank <= RowIndex; rank++)
            {
                for (int j = 0; j < RowIndex; j++)
                {
                    if (Rank[j, ColumnIndex - 1] == rank)
                    {
                        f2.dataGridView2.Rows[rank - 1].Cells[0].Value = j + 1;
                    }
                }
            }

            f2.ShowDialog();
            printInFile(table);
        }
Пример #3
0
        static void Main(string[] args)
        {
            TPR obj = new TPR(6, 4);

            obj.PriorityAlgorythm();
            obj.PrintRank();
            Console.ReadKey();
        }
Пример #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (check)
            {
                try
                {
                    label4.Text = " ";
                    int[,] MA   = new int[RowIndex, ColumnIndex];
                    for (int i = 0; i < ColumnIndex; i++)
                    {
                        for (int j = 0; j < RowIndex; j++)
                        {
                            MA[j, i] = Convert.ToInt32(dataGridView1.Rows[j].Cells[i].Value);
                        }
                    }

                    string[] str = textBox3.Text.Split(' ');
                    int[]    RA  = new int[str.Length];
                    for (int i = 0; i < str.Length; i++)
                    {
                        RA[i] = Convert.ToInt32(str[i]);
                    }
                    TPR table = new TPR(RowIndex, ColumnIndex, MA, RA);
                    table.PriorityAlgorythm();
                    printRank(table);
                }
                catch (Exception ex)
                {
                    label4.Text = "Неправильно заданные приоритеты";
                }
            }
            else
            {
                label4.Text = "Создайте таблицу!";
            }
        }