Ejemplo n.º 1
0
        private void LoadSecondMatrix(object sender, EventArgs e)
        {
            Stream         stream         = null;
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                InitialDirectory = "c:\\",
                Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try{
                    if ((stream = openFileDialog.OpenFile()) != null)
                    {
                        using ( stream ){
                            var matrix = MatrixTxT.FromTxtToMatrix(stream);
                            matrixSecond = matrix;
                            FillViewMatrix(matrixViewSecond, matrix);
                        }
                    }
                } catch (IOException ex) {
                    MessageBox.Show("Error: File Exeption:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } catch (Exception ex) {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        //===============================================
        //Methods
        private async void Resulter(Func <Matrix, Matrix, Matrix> operationFirst, Func <Matrix, Matrix, Matrix> operationSecond)
        {
            if (resultView == null)
            {
                resultView = new DataGridView()
                {
                    ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                    Location            = new Point((Width - (Width / 2)) - 175, (Height - (Height / 2))),
                    Name                = "matrixViewSecond",
                    AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                    Size                = new Size(270, 150),
                    TabIndex            = 2
                };
                Controls.Add(resultView);
            }

            var result = await Task.Run(() => operationFirst(matrixFirst, matrixSecond));

            await Task.Run(() => MatrixTxT.FromMatrixToTxt(operationSecond(matrixFirst, matrixSecond)));

            FillViewMatrix(resultView, result);
        }