Esempio n. 1
0
        private void loadFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form form in this.MdiChildren)
            {
                form.Close();
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\\images";
            openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    using (StreamReader streamReader = new StreamReader(openFileDialog.FileName))
                    {
                        String[] file = streamReader.ReadToEnd().Split(new Char[] { ' ', '\n' });

                        int mode;
                        Int32.TryParse(file[0], out mode);
                        size = Int32.Parse(file[1]);

                        mainMatrix = new int[size, mode == 0 ? size + 1 : size];

                        for (int i = 2; i < file.Length; i++)
                        {
                            Int32.TryParse(file[i], out mainMatrix[(i - 2) / (mode == 0 ? size + 1 : size), (i - 2) % (mode == 0 ? size + 1 : size)]);
                        }

                        if (mode == 0)
                        {
                            LinearEquationsResultForm linearEquationsResult = new LinearEquationsResultForm(this);
                            if (this.myStyle > 0)
                            {
                                linearEquationsResult.MdiParent = this;
                            }
                            linearEquationsResult.Show();
                        }
                        else
                        {
                            int   space;
                            Point dimensions;
                            Point coordinate;

                            if (myStyle > 0)
                            {
                                space      = 5;
                                dimensions = new Point((Size.Width - 40) / 3, (Size.Height - 80) / 2);
                                coordinate = new Point(space, space);
                            }
                            else
                            {
                                space      = 100;
                                dimensions = new Point((Size.Width - 40) / 3, (Size.Height - 80) / 2);
                                coordinate = new Point(this.Location.X + space, this.Location.Y + space);
                            }

                            solveStart = DateTime.Now;
                            solving    = true;
                            timer.Start();

                            ShowMatrixForm showEnteredMatrix = new ShowMatrixForm(this, this.mainMatrix);
                            showEnteredMatrix.StartPosition = FormStartPosition.Manual;
                            showEnteredMatrix.Size          = new Size(dimensions);
                            showEnteredMatrix.Location      = coordinate;
                            showEnteredMatrix.Text          = "Macierz";
                            if (this.myStyle > 0)
                            {
                                showEnteredMatrix.MdiParent = this;
                            }

                            coordinate.X += dimensions.X + space;

                            ShowMatrixForm showTransposedMatrix = new ShowMatrixForm(this, this.transposedMatrix(this.mainMatrix, size));
                            showTransposedMatrix.StartPosition = FormStartPosition.Manual;
                            showTransposedMatrix.Size          = new Size(dimensions);
                            showTransposedMatrix.Location      = coordinate;
                            showTransposedMatrix.Text          = "Macierz transponowana";
                            if (this.myStyle > 0)
                            {
                                showTransposedMatrix.MdiParent = this;
                            }

                            coordinate.X += dimensions.X + space;

                            ShowMatrixForm showAlgebraicComplementsMatrix = new ShowMatrixForm(this, this.algebraicComplementsMatrix(this.mainMatrix, size));
                            showAlgebraicComplementsMatrix.StartPosition = FormStartPosition.Manual;
                            showAlgebraicComplementsMatrix.Size          = new Size(dimensions);
                            showAlgebraicComplementsMatrix.Location      = coordinate;
                            showAlgebraicComplementsMatrix.Text          = "Macierz dopełnień algebraicznych";
                            if (this.myStyle > 0)
                            {
                                showAlgebraicComplementsMatrix.MdiParent = this;
                            }

                            coordinate.X = space;

                            coordinate.Y += space + dimensions.Y;

                            ShowMatrixForm showInvertedMatrix = new ShowMatrixForm(this, this.invertedMatrix(this.mainMatrix, size));
                            showInvertedMatrix.StartPosition = FormStartPosition.Manual;
                            showInvertedMatrix.Size          = new Size(dimensions);
                            showInvertedMatrix.Location      = coordinate;
                            showInvertedMatrix.Text          = "Macierz odwrotna";
                            if (this.myStyle > 0)
                            {
                                showInvertedMatrix.MdiParent = this;
                            }

                            coordinate.X += dimensions.X + space;

                            ShowMatrixForm showGaussianEliminationMatrix = new ShowMatrixForm(this, this.gaussianEliminationMatrix(this.mainMatrix, size));
                            showGaussianEliminationMatrix.StartPosition = FormStartPosition.Manual;
                            showGaussianEliminationMatrix.Size          = new Size(dimensions);
                            showGaussianEliminationMatrix.Location      = coordinate;
                            showGaussianEliminationMatrix.Text          = "Macierz po eliminacji gaussa";
                            if (this.myStyle > 0)
                            {
                                showGaussianEliminationMatrix.MdiParent = this;
                            }

                            coordinate.X += dimensions.X + space;

                            MatrixOtherDetailsForm showMatrixOtherDetails = new MatrixOtherDetailsForm(this);
                            showMatrixOtherDetails.StartPosition = FormStartPosition.Manual;
                            showMatrixOtherDetails.Size          = new Size(dimensions);
                            showMatrixOtherDetails.Location      = coordinate;
                            if (this.myStyle > 0)
                            {
                                showMatrixOtherDetails.MdiParent = this;
                            }

                            showEnteredMatrix.Show();
                            showTransposedMatrix.Show();
                            showAlgebraicComplementsMatrix.Show();
                            showInvertedMatrix.Show();
                            showGaussianEliminationMatrix.Show();
                            showMatrixOtherDetails.Show();

                            timer.Stop();
                            solving = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Błąd: Nie można odczytać pliku. Error: " + ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void solve_Click(object sender, EventArgs e)
        {
            this.parent.size = size;

            this.parent.mainMatrix = new int[size, size + (mode ? 1 : 0)];

            int r = 0;
            int c = 0;

            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    if (c > size - (mode ? 0 : 1))
                    {
                        c = 0;
                        r++;
                    }

                    if (!Int32.TryParse(((TextBox)ctrl).Text, out this.parent.mainMatrix[r, c]))
                    {
                        this.parent.mainMatrix[r, c] = 0;
                    }

                    c++;
                }
            }

            if (mode)
            {
                LinearEquationsResultForm linearEquationsResult = new LinearEquationsResultForm(this.parent);
                if (this.parent.myStyle > 0)
                {
                    linearEquationsResult.MdiParent = this.parent;
                }
                linearEquationsResult.Closed += (s, args) => this.Close();
                this.Hide();
                linearEquationsResult.Show();
            }
            else
            {
                int   space;
                Point dimensions;
                Point coordinate;

                if (parent.myStyle > 0)
                {
                    space      = 5;
                    dimensions = new Point((parent.Size.Width - 40) / 3, (parent.Size.Height - 80) / 2);
                    coordinate = new Point(space, space);
                }
                else
                {
                    space      = 100;
                    dimensions = new Point((parent.Size.Width - 40) / 3, (parent.Size.Height - 80) / 2);
                    coordinate = new Point(this.parent.Location.X + space, this.parent.Location.Y + space);
                }



                ShowMatrixForm showEnteredMatrix = new ShowMatrixForm(this.parent, this.parent.mainMatrix);
                showEnteredMatrix.StartPosition = FormStartPosition.Manual;
                showEnteredMatrix.Size          = new Size(dimensions);
                showEnteredMatrix.Location      = coordinate;
                showEnteredMatrix.Text          = "Macierz";
                if (this.parent.myStyle > 0)
                {
                    showEnteredMatrix.MdiParent = this.parent;
                }
                showEnteredMatrix.Closed += (s, args) => this.Close();

                coordinate.X += dimensions.X + space;

                ShowMatrixForm showTransposedMatrix = new ShowMatrixForm(this.parent, this.parent.transposedMatrix(this.parent.mainMatrix, size));
                showTransposedMatrix.StartPosition = FormStartPosition.Manual;
                showTransposedMatrix.Size          = new Size(dimensions);
                showTransposedMatrix.Location      = coordinate;
                showTransposedMatrix.Text          = "Macierz transponowana";
                if (this.parent.myStyle > 0)
                {
                    showTransposedMatrix.MdiParent = this.parent;
                }
                showTransposedMatrix.Closed += (s, args) => this.Close();

                coordinate.X += dimensions.X + space;

                ShowMatrixForm showAlgebraicComplementsMatrix = new ShowMatrixForm(this.parent, this.parent.algebraicComplementsMatrix(this.parent.mainMatrix, size));
                showAlgebraicComplementsMatrix.StartPosition = FormStartPosition.Manual;
                showAlgebraicComplementsMatrix.Size          = new Size(dimensions);
                showAlgebraicComplementsMatrix.Location      = coordinate;
                showAlgebraicComplementsMatrix.Text          = "Macierz dopełnień algebraicznych";
                if (this.parent.myStyle > 0)
                {
                    showAlgebraicComplementsMatrix.MdiParent = this.parent;
                }
                showAlgebraicComplementsMatrix.Closed += (s, args) => this.Close();

                coordinate.X = space;

                coordinate.Y += space + dimensions.Y;

                ShowMatrixForm showInvertedMatrix = new ShowMatrixForm(this.parent, this.parent.invertedMatrix(this.parent.mainMatrix, size));
                showInvertedMatrix.StartPosition = FormStartPosition.Manual;
                showInvertedMatrix.Size          = new Size(dimensions);
                showInvertedMatrix.Location      = coordinate;
                showInvertedMatrix.Text          = "Macierz odwrotna";
                if (this.parent.myStyle > 0)
                {
                    showInvertedMatrix.MdiParent = this.parent;
                }
                showInvertedMatrix.Closed += (s, args) => this.Close();

                coordinate.X += dimensions.X + space;

                ShowMatrixForm showGaussianEliminationMatrix = new ShowMatrixForm(this.parent, this.parent.gaussianEliminationMatrix(this.parent.mainMatrix, size));
                showGaussianEliminationMatrix.StartPosition = FormStartPosition.Manual;
                showGaussianEliminationMatrix.Size          = new Size(dimensions);
                showGaussianEliminationMatrix.Location      = coordinate;
                showGaussianEliminationMatrix.Text          = "Macierz po eliminacji gaussa";
                if (this.parent.myStyle > 0)
                {
                    showGaussianEliminationMatrix.MdiParent = this.parent;
                }
                showGaussianEliminationMatrix.Closed += (s, args) => this.Close();

                coordinate.X += dimensions.X + space;

                MatrixOtherDetailsForm showMatrixOtherDetails = new MatrixOtherDetailsForm(this.parent);
                showMatrixOtherDetails.StartPosition = FormStartPosition.Manual;
                showMatrixOtherDetails.Size          = new Size(dimensions);
                showMatrixOtherDetails.Location      = coordinate;
                if (this.parent.myStyle > 0)
                {
                    showMatrixOtherDetails.MdiParent = this.parent;
                }
                showMatrixOtherDetails.Closed += (s, args) => this.Close();

                this.Hide();
                showEnteredMatrix.Show();
                showTransposedMatrix.Show();
                showAlgebraicComplementsMatrix.Show();
                showInvertedMatrix.Show();
                showGaussianEliminationMatrix.Show();
                showMatrixOtherDetails.Show();
            }
        }