Пример #1
0
        private void saveAsBtn_Click(object sender, EventArgs e)
        {
            double[,] A;
            double[,] B;
            DialogResult Result;

            DGV1.EndEdit();
            DGV2.EndEdit();
            A      = ReadFromDGV(ref DGV1);
            B      = ReadFromDGV(ref DGV2);
            Result = SFD.ShowDialog();
            try
            {
                if (Result == DialogResult.OK)
                {
                    File.Delete(SFD.FileName);
                    StreamWriter FileFromTable = new StreamWriter(SFD.FileName);
                    SaveFileStream(A, B, FileFromTable);
                    CurrentOpenFileName      = SFD.FileName;
                    this.saveBtn.Enabled     = true;
                    MatrixUnsavedChangesDone = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Cursor = Cursors.Arrow;
            }
        }
Пример #2
0
 private void triangular_Click(object sender, EventArgs e)
 {
     double[,] A;
     double[,] B;
     if (((Button)sender).Name == "triangularA")
     {
         DGV1.EndEdit();
         A = ReadFromDGV(ref DGV1);
         B = MatrixTriangularForm(A);
         if (B != null)
         {
             OutputWindow otpWin = new OutputWindow();
             otpWin.Show();
             WriteToDGV(ref otpWin.otpDGV, B);
         }
     }
     else if (((Button)sender).Name == "triangularB")
     {
         DGV2.EndEdit();
         A = ReadFromDGV(ref DGV2);
         B = MatrixTriangularForm(A);
         if (B != null)
         {
             OutputWindow otpWin = new OutputWindow();
             otpWin.Show();
             WriteToDGV(ref otpWin.otpDGV, B);
         }
     }
 }
Пример #3
0
 private void saveBtn_Click(object sender, EventArgs e)
 {
     double[,] A, B;
     DGV1.EndEdit();
     DGV2.EndEdit();
     A = ReadFromDGV(ref DGV1);
     B = ReadFromDGV(ref DGV2);
     if (CurrentOpenFileName == "")
     {
         SFD.ShowDialog();
         CurrentOpenFileName = SFD.FileName;
     }
     try
     {
         File.Delete(CurrentOpenFileName);
         StreamWriter FileFromTable = new StreamWriter(CurrentOpenFileName);
         SaveFileStream(A, B, FileFromTable);
         MatrixUnsavedChangesDone = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         this.Cursor = Cursors.Arrow;
     } // : DGV1.BackgroundColor = Color.LightGreen
 }
Пример #4
0
        private void openBtn_Click(object sender, EventArgs e)
        {
            DialogResult Result;

            DGV1.EndEdit();
            try
            {
                Result = OFD.ShowDialog();
                if (Result == DialogResult.OK)
                {
                    StreamReader FileToOpen = new StreamReader(OFD.FileName);
                    OpenFileStream(FileToOpen);
                    CurrentOpenFileName    = OFD.FileName;
                    txtRowCount1.Text      = DGV1.RowCount.ToString();
                    txtColumnCount1.Text   = DGV1.ColumnCount.ToString();
                    this.saveAsBtn.Enabled = true;
                    this.saveBtn.Enabled   = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Cursor = Cursors.Arrow;
            }
        }
Пример #5
0
        private void reverse_Click(object sender, EventArgs e)
        {
            double[,] A;
            double[,] B;

            if (((Button)sender).Name == "reverseA")
            {
                DGV1.EndEdit();
                A = ReadFromDGV(ref DGV1);
                B = InverseMatrix(A);
                if (B != null)
                {
                    OutputWindow otpWin = new OutputWindow();
                    otpWin.Show();
                    WriteToDGV(ref otpWin.otpDGV, B);
                }
            }
            else if (((Button)sender).Name == "reverseB")
            {
                DGV2.EndEdit();
                A = ReadFromDGV(ref DGV2);
                B = InverseMatrix(A);
                if (B != null)
                {
                    OutputWindow otpWin = new OutputWindow();
                    otpWin.Show();
                    WriteToDGV(ref otpWin.otpDGV, B);
                }
            }
        }
Пример #6
0
 private void swapBtn_Click(object sender, EventArgs e)
 {
     double[,] A;
     DGV1.EndEdit();
     DGV2.EndEdit();
     A = ReadFromDGV(ref this.DGV1);
     CopyDGV(ref DGV2, ref DGV1);
     WriteToDGV(ref DGV2, A);
     MatrixUnsavedChangesDone = true;
 }
Пример #7
0
        private void btnMultiply_Click(object sender, EventArgs e)
        {
            double x;

            double[,] A;
            double[,] B;


            if (((Button)sender).Name == "btnMultiplyA")
            {
                DGV1.EndEdit();
                A = ReadFromDGV(ref DGV1);
                if (txtMultiplyA.Text == "")
                {
                    MessageBox.Show("Enter the value for the number 'x'.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (txtMultiplyA.Text == "-")
                {
                    MessageBox.Show("Incorrect value. Field 'x' contains an invalid character.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    x = Convert.ToDouble(txtMultiplyA.Text);
                    B = MultiplicationByNumber(A, x);
                    OutputWindow otpWin = new OutputWindow();
                    otpWin.Show();
                    WriteToDGV(ref otpWin.otpDGV, B);
                }
            }
            else if (((Button)sender).Name == "btnMultiplyB")
            {
                DGV2.EndEdit();
                A = ReadFromDGV(ref DGV2);
                if (txtMultiplyA.Text == "")
                {
                    MessageBox.Show("Enter the value for the number 'x'.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (txtMultiplyA.Text == "-")
                {
                    MessageBox.Show("Incorrect value. Field 'x' contains an invalid character.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    x = Convert.ToDouble(txtMultiplyB.Text);
                    B = MultiplicationByNumber(A, x);
                    OutputWindow otpWin = new OutputWindow();
                    otpWin.Show();
                    WriteToDGV(ref otpWin.otpDGV, B);
                }
            }
        }
Пример #8
0
 private void multiplyBtn_Click(object sender, EventArgs e)
 {
     double[,] A;
     double[,] B;
     double[,] C;
     DGV1.EndEdit();
     DGV2.EndEdit();
     A = ReadFromDGV(ref DGV1);
     B = ReadFromDGV(ref DGV2);
     C = MatrixMultiplication(A, B);
     if (C != null)
     {
         OutputWindow otpWin = new OutputWindow();
         otpWin.Show();
         WriteToDGV(ref otpWin.otpDGV, C);
     }
 }
Пример #9
0
 private void transposed_Click(object sender, EventArgs e)
 {
     double[,] A;
     double[,] B;
     if (((Button)sender).Name == "transposedA")
     {
         DGV1.EndEdit();
         A = ReadFromDGV(ref DGV1);
         B = MatrixTransposition(A);
         WriteToDGV(ref DGV1, B);
     }
     else if (((Button)sender).Name == "transposedB")
     {
         DGV2.EndEdit();
         A = ReadFromDGV(ref DGV2);
         B = MatrixTransposition(A);
         WriteToDGV(ref DGV2, B);
     }
     MatrixUnsavedChangesDone = true;
 }
Пример #10
0
        private void substractBtn_Click(object sender, EventArgs e)
        {
            int m;
            int n;
            int k;
            int l;

            double[,] A;
            double[,] B;
            double[,] C;
            DGV1.EndEdit();
            DGV2.EndEdit();
            m = DGV1.RowCount;
            n = DGV1.ColumnCount;
            k = DGV2.RowCount;
            l = DGV2.ColumnCount;

            if (m != k & n != l)
            {
                MessageBox.Show("The dimensions of the matrices do not match. ", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (m == k & n == l)
            {
                A = new double[m, n];
                B = new double[m, n];
                C = new double[m, n];

                A = ReadFromDGV(ref DGV1);
                B = ReadFromDGV(ref DGV2);
                for (int i = 0; i <= m - 1; i++)
                {
                    for (int j = 0; j <= n - 1; j++)
                    {
                        C[i, j] = A[i, j] - B[i, j];
                    }
                }
                OutputWindow otpWin = new OutputWindow();
                otpWin.Show();
                WriteToDGV(ref otpWin.otpDGV, C);
            }
        }
Пример #11
0
        private void detBtn_Click(object sender, EventArgs e)
        {
            double[,] A;
            DGV1.EndEdit();

            if (((Button)sender).Name == "detABtn")
            {
                A = ReadFromDGV(ref DGV1);
                if (A != null)
                {
                    txtDetA.Text = ((int)MatrixDeterminant(A)).ToString();
                }
            }
            else if (((Button)sender).Name == "detBBtn")
            {
                A = ReadFromDGV(ref DGV2);
                if (A != null)
                {
                    txtDetB.Text = ((int)MatrixDeterminant(A)).ToString();
                }
            }
        }