Example #1
0
        private void buttonFillMatrixes_Click(object sender, EventArgs e)
        {
            if (int.TryParse(textBoxARows.Text, out int result) && int.TryParse(textBoxAColumns.Text, out result) &&
                int.TryParse(textBoxBRows.Text, out result) && int.TryParse(textBoxBColumns.Text, out result) &&
                int.Parse(textBoxARows.Text) > 0 && int.Parse(textBoxAColumns.Text) > 0 &&
                int.Parse(textBoxBRows.Text) > 0 && int.Parse(textBoxBColumns.Text) > 0)
            {
                this.MatrixARowsCount    = int.Parse(textBoxARows.Text);
                this.MatrixAColumnsCount = int.Parse(textBoxAColumns.Text);

                this.MatrixBRowsCount    = int.Parse(textBoxBRows.Text);
                this.MatrixBColumnsCount = int.Parse(textBoxBColumns.Text);

                dataGridViewA.Enabled      = true;
                dataGridViewB.Enabled      = true;
                dataGridViewResult.Enabled = true;

                checkBoxParallel.Enabled = true;
                buttonFillRandom.Enabled = true;
                buttonCalculate.Enabled  = true;

                MatrixClientHelper.SetColumnsAndRowsForDatagridView(dataGridViewA, this.MatrixARowsCount, this.MatrixAColumnsCount, (i, j) => { return(0); });
                MatrixClientHelper.SetColumnsAndRowsForDatagridView(dataGridViewB, this.MatrixBRowsCount, this.MatrixBColumnsCount, (i, j) => { return(0); });
            }
            else
            {
                MessageBox.Show("Параметры матрицы заданы некорректно!");
            }
        }
Example #2
0
        private void buttonSaveCSV_Click(object sender, EventArgs e)
        {
            string delimiter = ",";

            StringBuilder stringBuilder = new StringBuilder();

            double[][] output = MatrixClientHelper.ToJagged <double>(this.Result.Elements);

            int length = output.GetLength(0);

            for (int index = 0; index < length; index++)
            {
                stringBuilder.AppendLine(string.Join(delimiter, output[index]));
            }

            Stream stream;

            saveFileDialogCSV.Filter           = "csv files (*.csv)|*.csv";
            saveFileDialogCSV.FilterIndex      = 0;
            saveFileDialogCSV.RestoreDirectory = true;

            if (saveFileDialogCSV.ShowDialog() == DialogResult.OK)
            {
                if ((stream = saveFileDialogCSV.OpenFile()) != null)
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(stringBuilder.ToString());
                    }

                    stream.Close();
                }
            }
        }
Example #3
0
        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            if (!this.IsOperationApproved)
            {
                MessageBox.Show("Операция не может быть выполнена так как параметры матриц заданы не верно!");
                return;
            }

            if (MatrixClientHelper.VerifyMatrixParameters(dataGridViewA, dataGridViewB))
            {
                double[,] matrixA = MatrixClientHelper.GetArrayFromGrid(dataGridViewA);
                double[,] matrixB = MatrixClientHelper.GetArrayFromGrid(dataGridViewB);

                if (checkBoxParallel.Checked)
                {
                    MatrixT <double> .Paral = true;
                }

                MatrixT <double> A = new MatrixT <double>(matrixA);
                MatrixT <double> B = new MatrixT <double>(matrixB);

                Operations operation = (Operations)comboBoxOperation.SelectedIndex;

                Stopwatch stopwatch = new Stopwatch();

                switch (operation)
                {
                case Operations.Sum:
                {
                    stopwatch.Start();
                    this.Result = A + B;
                    stopwatch.Stop();

                    break;
                }

                case Operations.Multiply:
                {
                    stopwatch.Start();
                    this.Result = A * B;
                    stopwatch.Stop();

                    break;
                }

                default:
                {
                    throw new Exception("Операция не установлена");
                }
                }

                double calcTime = stopwatch.ElapsedMilliseconds / 1000.0;

                labelTime.Text = "Время: " + calcTime.ToString();

                this.SetResultGrid(this.Result);

                buttonSaveCSV.Enabled = true;
            }
            else
            {
                MessageBox.Show("Значения матрицы установлены не верно!");
            }
        }
Example #4
0
 private void buttonFillRandom_Click(object sender, EventArgs e)
 {
     MatrixClientHelper.SetRandomValuesForGrid(dataGridViewA, dataGridViewB);
 }