distributed-computing/tasks/dunaev-oi/lab_5/RVIP_Lab5/Form1.cs

121 lines
3.2 KiB
C#
Raw Permalink Normal View History

2023-12-18 17:38:52 +04:00
using System.Diagnostics;
namespace RVIP_Lab5
{
public partial class Form1 : Form
{
public Controller service;
public Alg1 Alg1;
public Alg2 Alg2;
public Stopwatch stopwatch;
public int[,] matrixA;
public int[,] matrixB;
public Form1()
{
InitializeComponent();
this.service = new Controller();
this.Alg1 = new Alg1();
this.Alg2 = new Alg2();
this.stopwatch = new Stopwatch();
}
private void buttonAlg1_Click(object sender, EventArgs e)
{
try
{
stopwatch.Start();
int[,] matrixResult = Alg1.Begin(matrixA, matrixB);
stopwatch.Stop();
labelResultTime.Text = "" + stopwatch.Elapsed;
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
stopwatch.Reset();
}
private void buttonAlg2_Click(object sender, EventArgs e)
{
try
{
stopwatch.Start();
int[,] matrixResult = Alg2.Begin(matrixA, matrixB, (int)countStream.Value);
stopwatch.Stop();
labelResultTime.Text = "" + stopwatch.Elapsed;
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
stopwatch.Reset();
}
private void buttonLoadMatrix1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string filePath = openFileDialog1.FileName;
string result = service.GetTextFromFile(filePath);
textBoxMatrix1.Text = result;
matrixA = service.GetMatrixFromTextbox(result);
}
private void buttonLoadMatrix2_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string filePath = openFileDialog1.FileName;
string result = service.GetTextFromFile(filePath);
textBoxMatrix2.Text = result;
matrixB = service.GetMatrixFromTextbox(result);
}
private void buttonGenerateMatrix1_Click(object sender, EventArgs e)
{
matrixA = service.GenerateNewMatrix((int)genCountRowCol.Value);
textBoxMatrix1.Text = service.PrintResultMatrix(matrixA);
}
private void buttonGenerateMatrix2_Click(object sender, EventArgs e)
{
matrixB = service.GenerateNewMatrix((int)genCountRowCol.Value);
textBoxMatrix2.Text = service.PrintResultMatrix(matrixB);
}
private void button1_Click(object sender, EventArgs e)
{
textBoxMatrix1.Text = "";
textBoxMatrix2.Text = "";
textBoxResult.Text = "";
matrixA = null;
matrixB = null;
}
}
}