예제 #1
0
 private void buttonClearB_Click(object sender, EventArgs e)
 {
     try
     {
         MatrixName = "B";
         Delete_Matrix();
         GlobalsMatrix.setRowMatrixB(0);
         GlobalsMatrix.setColMatrixB(0);
         textBoxColB.Text = "";
         textBoxRowB.Text = "";
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
예제 #2
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonGetRandomB_Click(object sender, EventArgs e)
 {
     try
     {
         if (int.Parse(textBoxRowB.Text) <= 50 && int.Parse(textBoxColB.Text) <= 50)
         {
             //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
             if (RowB == 0 && ColB == 0)
             {
                 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_Matrix();
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (GlobalsMatrix.RowB == int.Parse(textBoxRowB.Text) && GlobalsMatrix.ColB == int.Parse(textBoxColB.Text))
             {
                 MatrixName = "B";
                 Refresh_Matrix();
             }
             //Trường hợp còn lại
             else
             {
                 MatrixName = "B";
                 Delete_Matrix();
                 GlobalsMatrix.setRowMatrixB(int.Parse(textBoxRowB.Text));
                 GlobalsMatrix.setColMatrixB(int.Parse(textBoxColB.Text));
                 RowB = int.Parse(textBoxRowB.Text);
                 ColB = int.Parse(textBoxColB.Text);
                 Add_Matrix();
             }
         }
         else
         {
             MyMessageBox.Show("Dòng hoặc cột lớn hơn 50, vui lòng sử dụng chức năng Matrix's bigger than 50x50");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
예제 #3
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);
     }
 }
예제 #4
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");
            }
        }
예제 #5
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);
     }
 }