Esempio n. 1
0
 private void buttonGetRandomB_Click(object sender, EventArgs e)
 {
     try
     {
         if (int.Parse(textBoxRowB.Text) > 50 || int.Parse(textBoxColB.Text) > 50)
         {
             RowB = int.Parse(textBoxRowB.Text);
             ColB = int.Parse(textBoxColB.Text);
             GlobalsMatrix.setRowMatrixB(int.Parse(textBoxRowB.Text));
             GlobalsMatrix.setColMatrixB(int.Parse(textBoxColB.Text));
             MatrixName = "B";
             Add_MatrixBig();
             MyMessageBox.Show("Đã tạo ma trận B ngẫu nhiên, do ma trận có kích thước lớn vui lòng nhập số dòng/cột rồi nhấn nút show để xem chi tiết");
         }
         else
         {
             MyMessageBox.Show("Dòng hoặc cột nhỏ hơn hoặc bằng 50, vui lòng sử dụng chức năng Matrix's smaller than 50x50");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonTransposeB_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.chuyenvi(GlobalsMatrix.RowB, GlobalsMatrix.ColB, GlobalsMatrix.B);
         Add_MatrixRe(ColB, RowB);
         GlobalsMatrix.setRowMatrixRe(ColB);
         GlobalsMatrix.setColMatrixRe(RowB);
         RowR = GlobalsMatrix.RowRe;
         ColR = GlobalsMatrix.ColRe;
         if (RowR >= 5 && ColR >= 5)
         {
             flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
         }
         else
         {
             flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 3
0
 private void Add_Col(int Col, string MatrixName)
 {
     try
     {
         if (MatrixName == "A")
         {
             //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
             if (ColA == 0)
             {
                 //Add Matrix
                 FlowLayoutPanel pan = new FlowLayoutPanel();
                 pan.Name      = MatrixName + Col;
                 pan.BackColor = Color.Violet;
                 pan.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowA, 43);
                 for (int i = 0; i < GlobalsMatrix.RowA; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + Col;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.A[i, Col];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan.Controls.Add(btn);
                 }
                 pan.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelA.Controls.Add(pan);
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (Col == ColA)
             {
                 //Refesh()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + Col) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowA; i++)
                             {
                                 if ((MatrixName + i + "_" + Col) == btn.Name)
                                 {
                                     btn.Text = "" + GlobalsMatrix.A[i, Col];
                                 }
                             }
                         }
                     }
                 }
             }
             //Trường hợp còn lại
             else
             {
                 //Delete()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + ColA) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowA; i++)
                             {
                                 if ((MatrixName + i + "_" + ColA) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelA.Controls.Remove(pan);
                     }
                 }
                 //Add()
                 int             j    = Col;
                 FlowLayoutPanel pan1 = new FlowLayoutPanel();
                 pan1.Name      = MatrixName + j;
                 pan1.BackColor = Color.Violet;
                 pan1.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowA, 43);
                 for (int i = 0; i < GlobalsMatrix.RowA; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + j;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.A[i, j];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan1.Controls.Add(btn);
                 }
                 pan1.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelA.Controls.Add(pan1);
             }
             ColA = Col;
         }
         else
         if (MatrixName == "B")
         {
             //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
             if (ColB == 0)
             {
                 //Add Matrix
                 FlowLayoutPanel pan = new FlowLayoutPanel();
                 pan.Name      = MatrixName + Col;
                 pan.BackColor = Color.Violet;
                 pan.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowB, 43);
                 for (int i = 0; i < GlobalsMatrix.RowB; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + Col;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.B[i, Col];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan.Controls.Add(btn);
                 }
                 pan.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelB.Controls.Add(pan);
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (Col == ColB)
             {
                 //Refesh()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + Col) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowB; i++)
                             {
                                 if ((MatrixName + i + "_" + Col) == btn.Name)
                                 {
                                     btn.Text = "" + GlobalsMatrix.B[i, Col];
                                 }
                             }
                         }
                     }
                 }
             }
             //Trường hợp còn lại
             else
             {
                 //Delete()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + ColB) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowB; i++)
                             {
                                 if ((MatrixName + i + "_" + ColB) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelB.Controls.Remove(pan);
                     }
                 }
                 //Add()
                 int             j    = Col;
                 FlowLayoutPanel pan1 = new FlowLayoutPanel();
                 pan1.Name      = MatrixName + j;
                 pan1.BackColor = Color.Violet;
                 pan1.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowB, 43);
                 for (int i = 0; i < GlobalsMatrix.RowB; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + j;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.B[i, j];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan1.Controls.Add(btn);
                 }
                 pan1.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelB.Controls.Add(pan1);
             }
             ColB = Col;
         }
         else
         {
             if (ColR == 0)
             {
                 //Add Matrix
                 FlowLayoutPanel pan = new FlowLayoutPanel();
                 pan.Name      = MatrixName + Col;
                 pan.BackColor = Color.Violet;
                 pan.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowRe, 43);
                 for (int i = 0; i < GlobalsMatrix.RowRe; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + Col;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.Re[i, Col];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan.Controls.Add(btn);
                 }
                 pan.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelR.Controls.Add(pan);
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (Col == ColR)
             {
                 //Refesh()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + Col) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowRe; i++)
                             {
                                 if ((MatrixName + i + "_" + Col) == btn.Name)
                                 {
                                     btn.Text = "" + GlobalsMatrix.Re[i, Col];
                                 }
                             }
                         }
                     }
                 }
             }
             //Trường hợp còn lại
             else
             {
                 //Delete()
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + ColR) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int i = 0; i < GlobalsMatrix.RowRe; i++)
                             {
                                 if ((MatrixName + i + "_" + ColR) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelR.Controls.Remove(pan);
                     }
                 }
                 //Add()
                 int             j    = Col;
                 FlowLayoutPanel pan1 = new FlowLayoutPanel();
                 pan1.Name      = MatrixName + j;
                 pan1.BackColor = Color.Violet;
                 pan1.Size      = new System.Drawing.Size(46 * GlobalsMatrix.RowRe, 43);
                 for (int i = 0; i < GlobalsMatrix.RowRe; i++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + j;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.Re[i, j];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan1.Controls.Add(btn);
                 }
                 pan1.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelR.Controls.Add(pan1);
             }
             ColR = Col;
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 4
0
 public void Remove_Row(int Row, string MatrixName)
 {
     try
     {
         if (MatrixName == "Re")
         {
             foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
             {
                 if ((MatrixName + Row) == pan.Name)
                 {
                     foreach (Button btn in pan.Controls.OfType <Button>())
                     {
                         for (int j = 0; j < GlobalsMatrix.ColRe; j++)
                         {
                             if ((MatrixName + Row + "_" + j) == btn.Name)
                             {
                                 pan.Controls.Remove(btn);
                             }
                         }
                     }
                     flowLayoutPanelR.Controls.Remove(pan);
                 }
             }
         }
         else
         if (MatrixName == "A")
         {
             foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
             {
                 if ((MatrixName + Row) == pan.Name)
                 {
                     foreach (Button btn in pan.Controls.OfType <Button>())
                     {
                         for (int j = 0; j < GlobalsMatrix.ColA; j++)
                         {
                             if ((MatrixName + Row + "_" + j) == btn.Name)
                             {
                                 pan.Controls.Remove(btn);
                             }
                         }
                     }
                     flowLayoutPanelA.Controls.Remove(pan);
                 }
             }
         }
         else
         {
             foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
             {
                 if ((MatrixName + Row) == pan.Name)
                 {
                     foreach (Button btn in pan.Controls.OfType <Button>())
                     {
                         for (int j = 0; j < GlobalsMatrix.ColB; j++)
                         {
                             if ((MatrixName + Row + "_" + j) == btn.Name)
                             {
                                 pan.Controls.Remove(btn);
                             }
                         }
                     }
                     flowLayoutPanelB.Controls.Remove(pan);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 5
0
        /////////////////////////////////////////////////////////////////////
        ///Doc xuat file
        public static void docketqua(string MatrixName)
        {
            string         s = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "txt files (*.txt)|*.txt",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                s = openFileDialog1.FileName;
            }
            if (s != "")
            {
                if (MatrixName == "A")
                {
                    GlobalsMatrix.setRowMatrixA(0);
                    GlobalsMatrix.setColMatrixA(0);
                    String input = File.ReadAllText(s);
                    int    i = 0, j = 0;
                    foreach (var row in input.Split('\n'))
                    {
                        j = 0;
                        foreach (string col in row.Trim().Split(' '))
                        {
                            float t = float.Parse(col.Trim());
                            GlobalsMatrix.setMatrixA(i, j, t);
                            j++;
                        }
                        i++;
                    }
                    GlobalsMatrix.setRowMatrixA(i);
                    GlobalsMatrix.setColMatrixA(j);
                }
                else if (MatrixName == "B")
                {
                    GlobalsMatrix.setRowMatrixB(0);
                    GlobalsMatrix.setColMatrixB(0);
                    String input = File.ReadAllText(s);
                    int    i = 0, j = 0;
                    foreach (var row in input.Split('\n'))
                    {
                        j = 0;
                        foreach (string col in row.Trim().Split(' '))
                        {
                            float t = float.Parse(col.Trim());
                            GlobalsMatrix.setMatrixB(i, j, t);
                            j++;
                        }
                        i++;
                    }
                    GlobalsMatrix.setRowMatrixB(i);
                    GlobalsMatrix.setColMatrixB(j);
                }
                else
                {
                    MyMessageBox.Show("Ma trận không hợp lệ");
                }
            }
            else
            {
                MyMessageBox.Show("Bạn chưa chọn file");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////
        /// </summary>
        private void Add_MatrixRead()
        {
            try
            {
                if (MatrixName == "A")
                {
                    Col = GlobalsMatrix.ColA;
                    Row = GlobalsMatrix.RowA;
                    textBoxColA.Text = "" + Col;
                    textBoxRowA.Text = "" + Row;
                }
                else
                if (MatrixName == "B")
                {
                    Col = GlobalsMatrix.ColB;
                    Row = GlobalsMatrix.RowB;
                    textBoxColB.Text = "" + Col;
                    textBoxRowB.Text = "" + Row;
                }
                for (int i = 0; i < Row; i++)
                {
                    FlowLayoutPanel pan = new FlowLayoutPanel();
                    pan.Name      = MatrixName + i;
                    pan.BackColor = System.Drawing.Color.Violet;
                    pan.Size      = new System.Drawing.Size(46 * Col, 43);
                    for (int j = 0; j < Col; j++)
                    {
                        Button btn = new Button();
                        btn.Name = MatrixName + i + "_" + j;
                        if (MatrixName == "A")
                        {
                            btn.Text = "" + GlobalsMatrix.A[i, j];
                        }
                        else
                        {
                            btn.Text = "" + GlobalsMatrix.B[i, j];
                        }
                        btn.Size   = new System.Drawing.Size(40, 40);
                        btn.Click += btn_Click;
                        pan.Controls.Add(btn);
                    }
                    pan.FlowDirection = FlowDirection.LeftToRight;
                    if (MatrixName == "A")
                    {
                        flowLayoutPanelA.Controls.Add(pan);
                    }
                    else
                    if (MatrixName == "B")
                    {
                        flowLayoutPanelB.Controls.Add(pan);
                    }
                    else
                    {
                        flowLayoutPanelR.Controls.Add(pan);
                    }

                    if (GlobalsMatrix.ColA >= 5 && GlobalsMatrix.RowA >= 5)
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.TopDown;
                    }


                    if (GlobalsMatrix.ColB >= 5 && GlobalsMatrix.RowB >= 5)
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.TopDown;
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonInverseA_Click(object sender, EventArgs e)
 {
     try
     {
         if (GlobalsMatrix.RowA <= 30 && GlobalsMatrix.ColA <= 30)
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.A, GlobalsMatrix.RowA) != 0) && (GlobalsMatrix.RowA == GlobalsMatrix.ColA))
             {
                 MatrixName = "A";
                 InverseMatrix inversefrm = new InverseMatrix();
                 inversefrm.Show();
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColA, RowA);
                 GlobalsMatrix.setRowMatrixRe(ColA);
                 GlobalsMatrix.setColMatrixRe(RowA);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
                 if (RowR >= 5 && ColR >= 5)
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
                 }
                 else
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
                 }
             }
             else
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận A");
             }
         }
         else
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.A, GlobalsMatrix.RowA) != 0) && (GlobalsMatrix.RowA == GlobalsMatrix.ColA))
             {
                 MatrixName = "A";
                 InverseMatrix inversefrm = new InverseMatrix();
                 inversefrm.MergeMatrixBig(GlobalsMatrix.A, GlobalsMatrix.RowA);
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColA, RowA);
                 GlobalsMatrix.setRowMatrixRe(ColA);
                 GlobalsMatrix.setColMatrixRe(RowA);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
                 if (RowR >= 5 && ColR >= 5)
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
                 }
                 else
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
                 }
             }
             else
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận A");
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void Add_MatrixRe(int Row, int Col)
 {
     try
     {
         MatrixName = "R";
         //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
         if (RowR == 0 && ColR == 0)
         {
             //Add Matrix
             for (int i = 0; i < Row; i++)
             {
                 FlowLayoutPanel pan = new FlowLayoutPanel();
                 pan.Name      = MatrixName + i;
                 pan.BackColor = Color.Violet;
                 pan.Size      = new System.Drawing.Size(46 * Col, 43);
                 for (int j = 0; j < Col; j++)
                 {
                     Button btn = new Button();
                     btn.Name = MatrixName + i + "_" + j;
                     ///
                     ///
                     btn.Text   = "" + GlobalsMatrix.Re[i, j];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan.Controls.Add(btn);
                 }
                 pan.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelR.Controls.Add(pan);
             }
         }
         //Nếu muốn tạo ra ma trận ngẫu nhiên khác
         else
         if (Row == RowR && Col == ColR)
         {
             //Refesh()
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     btn.Text = "" + GlobalsMatrix.Re[i, j];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //Trường hợp còn lại
         else
         {
             //Delete()
             for (int i = 0; i < RowR; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < ColR; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelR.Controls.Remove(pan);
                     }
                 }
             }
             //Add()
             for (int i = 0; i < Row; i++)
             {
                 FlowLayoutPanel pan = new FlowLayoutPanel();
                 pan.Name      = MatrixName + i;
                 pan.BackColor = Color.Violet;
                 pan.Size      = new System.Drawing.Size(46 * Col, 43);
                 for (int j = 0; j < Col; j++)
                 {
                     Button btn = new Button();
                     btn.Name   = MatrixName + i + "_" + j;
                     btn.Text   = "" + GlobalsMatrix.Re[i, j];
                     btn.Size   = new System.Drawing.Size(40, 40);
                     btn.Click += btn_Click;
                     pan.Controls.Add(btn);
                 }
                 pan.FlowDirection = FlowDirection.LeftToRight;
                 flowLayoutPanelR.Controls.Add(pan);
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 9
0
        /// </summary>
        private void Add_Matrix()
        {
            try
            {
                Random rd = new Random();
                if (MatrixName == "A")
                {
                    Col = GlobalsMatrix.ColA;
                    Row = GlobalsMatrix.RowA;
                }
                else
                if (MatrixName == "B")
                {
                    Col = GlobalsMatrix.ColB;
                    Row = GlobalsMatrix.RowB;
                }
                for (int i = 0; i < Row; i++)
                {
                    FlowLayoutPanel pan = new FlowLayoutPanel();
                    pan.Name      = MatrixName + i;
                    pan.BackColor = Color.Violet;
                    pan.Size      = new System.Drawing.Size(46 * Col, 43);
                    for (int j = 0; j < Col; j++)
                    {
                        Button btn = new Button();
                        btn.Name = MatrixName + i + "_" + j;
                        float t = rd.Next(0, 100);
                        btn.Text = "" + t;

                        if (MatrixName == "A")
                        {
                            GlobalsMatrix.setMatrixA(i, j, t);
                        }
                        else
                        if (MatrixName == "B")
                        {
                            GlobalsMatrix.setMatrixB(i, j, t);
                        }
                        else
                        {
                            btn.Text = btn.Name;
                        }
                        btn.Size   = new System.Drawing.Size(40, 40);
                        btn.Click += btn_Click;
                        pan.Controls.Add(btn);
                    }
                    pan.FlowDirection = FlowDirection.LeftToRight;
                    if (MatrixName == "A")
                    {
                        flowLayoutPanelA.Controls.Add(pan);
                    }
                    else
                    if (MatrixName == "B")
                    {
                        flowLayoutPanelB.Controls.Add(pan);
                    }

                    if (GlobalsMatrix.ColA >= 5 && GlobalsMatrix.RowA >= 5)
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.TopDown;
                    }


                    if (GlobalsMatrix.ColB >= 5 && GlobalsMatrix.RowB >= 5)
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.TopDown;
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 private void Refresh_MatrixRead()
 {
     try
     {
         if (MatrixName == "A")
         {
             Col = GlobalsMatrix.ColA;
             Row = GlobalsMatrix.RowA;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = GlobalsMatrix.A[i, j];
                                     btn.Text = "" + GlobalsMatrix.A[i, j];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         if (MatrixName == "B")
         {
             Col = GlobalsMatrix.ColB;
             Row = GlobalsMatrix.RowB;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = GlobalsMatrix.B[i, j];
                                     btn.Text = "" + GlobalsMatrix.B[i, j];
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void Refresh_Matrix()
 {
     try
     {
         Random rd = new Random();
         if (MatrixName == "A")
         {
             Col = GlobalsMatrix.ColA;
             Row = GlobalsMatrix.RowA;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = rd.Next(0, 100);
                                     btn.Text = "" + t;
                                     if (MatrixName == "A")
                                     {
                                         GlobalsMatrix.setMatrixA(i, j, t);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         if (MatrixName == "B")
         {
             Col = GlobalsMatrix.ColB;
             Row = GlobalsMatrix.RowB;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = rd.Next(0, 100);
                                     btn.Text = "" + t;
                                     if (MatrixName == "B")
                                     {
                                         GlobalsMatrix.setMatrixB(i, j, t);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Esempio n. 12
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void Delete_Matrix()
 {
     try
     {
         if (MatrixName == "A")
         {
             Col = GlobalsMatrix.ColA;
             Row = GlobalsMatrix.RowA;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelA.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixA(0);
             GlobalsMatrix.setRowMatrixA(0);
         }
         else
         if (MatrixName == "B")
         {
             Col = GlobalsMatrix.ColB;
             Row = GlobalsMatrix.RowB;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelB.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixB(0);
             GlobalsMatrix.setRowMatrixB(0);
         }
         else
         if (MatrixName == "Re")
         {
             Col = GlobalsMatrix.ColRe;
             Row = GlobalsMatrix.RowRe;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelR.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixRe(0);
             GlobalsMatrix.setRowMatrixRe(0);
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }