private void loadDataButton_Click(object sender, EventArgs e) { StreamReader reader = new StreamReader(File.Open("input.dat", FileMode.Open)); List <int[]> col = new List <int[]>(); int i = 0; while (!reader.EndOfStream) { string[] str = reader.ReadLine().Split(' '); col.Add(new int[str.Length]); for (int j = 0; j < str.Length; j++) { col[i][j] = Convert.ToInt32(str[j]); } i++; } reader.Close(); if (!EqualLenthes(col)) { MessageBox.Show("Столбцы имееют разное количество элементов"); return; } columns = col.ToArray(); newColumns = new int[columns.Length][]; downtimes = new int[columns.Length][]; newDowntimes = new int[columns.Length][]; for (i = 0; i < columns.Length; i++) { newColumns[i] = Algorithm.copyMassive(columns[i]); downtimes[i] = new int[columns[0].Length]; newDowntimes[i] = new int[columns[0].Length]; for (int j = 0; j < columns[0].Length; j++) { downtimes[i][j] = 0; newDowntimes[i][j] = 0; } } AddToList1(); if (columns.Length == 2) { Algorithm.JohnsonsAlgorithm(newColumns[0], newColumns[1]); } if (columns.Length == 3) { Algorithm.JohnsonsAlgorithm(newColumns[0], newColumns[1], newColumns[2]); } AddToList2(); Algorithm.CountDowntimes(columns, downtimes); Algorithm.CountDowntimes(newColumns, newDowntimes); answerLabel1.Text = "Время: " + (Algorithm.summ(columns[columns.Length - 1]) + Algorithm.summ(downtimes[downtimes.Length - 1])).ToString(); answerLabel2.Text = "Время: " + (Algorithm.summ(newColumns[newColumns.Length - 1]) + Algorithm.summ(newDowntimes[newDowntimes.Length - 1])).ToString(); }
private void canvas_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Black); Pen dottedPen = new Pen(Color.Black); float[] dash = { 5, 5 }; dottedPen.DashPattern = dash; float stepw = ((float)canvas.Size.Width - 50) / (Algorithm.summ(columns[columns.Length - 1]) + Algorithm.summ(downtimes[downtimes.Length - 1])), steph = ((float)canvas.Size.Height - 20) / (columns.Length + 1); e.Graphics.DrawLine(pen, 30, 10, 30, canvas.Size.Height - 10); float curw, curh = 10 + steph; Char S = 'S', x = 'x', s = 's'; int Si = 0, xi = 0, si = 0; for (int i = 0; i < columns.Length; i++) { curw = 30; e.Graphics.DrawString(S.ToString() + Si.ToString(), new Font("Arial", 12), new SolidBrush(Color.Black), new PointF(0, curh - 8), StringFormat.GenericDefault); Si++; e.Graphics.DrawLine(pen, 30, curh, (float)canvas.Size.Width - 10, curh); for (int j = 0; j < columns[0].Length; j++) { if (downtimes[i][j] > 0) { curw += downtimes[i][j] * stepw; e.Graphics.DrawLine(pen, curw, curh - 5, curw, curh + 5); e.Graphics.DrawString(x.ToString() + xi.ToString() + j.ToString(), new Font("Arial", 9), new SolidBrush(Color.Black), new PointF(curw - ((stepw * downtimes[i][j]) / 2) - 10, curh - 15), StringFormat.GenericDefault); e.Graphics.DrawString(downtimes[i][j].ToString(), new Font("Arial", 9), new SolidBrush(Color.Black), new PointF(curw - ((stepw * downtimes[i][j]) / 2) - 10, curh + 2), StringFormat.GenericDefault); } curw += columns[i][j] * stepw; e.Graphics.DrawLine(pen, curw, curh - 5, curw, curh + 5); e.Graphics.DrawString(s.ToString() + si + j.ToString(), new Font("Arial", 9), new SolidBrush(Color.Black), new PointF(curw - ((stepw * columns[i][j]) / 2) - 10, curh - 15), StringFormat.GenericDefault); e.Graphics.DrawString(columns[i][j].ToString(), new Font("Arial", 9), new SolidBrush(Color.Black), new PointF(curw - ((stepw * columns[i][j]) / 2) - 10, curh + 2), StringFormat.GenericDefault); if (i < columns.Length - 1 && downtimes[i + 1][j] != 0) { e.Graphics.DrawLine(dottedPen, curw, curh, curw, curh + steph); } } xi++; si++; curh += steph; } }