private void buttonClearA_Click(object sender, EventArgs e) { try { MatrixName = "A"; Delete_Matrix(); GlobalsMatrix.setRowMatrixA(0); GlobalsMatrix.setColMatrixA(0); textBoxColA.Text = ""; textBoxRowA.Text = ""; } catch (Exception ex) { MyMessageBox.Show(ex.Message); } }
private void buttonGetRandomA_Click(object sender, EventArgs e) { try { if (int.Parse(textBoxRowA.Text) <= 50 && int.Parse(textBoxColA.Text) <= 50) { //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận if (RowA == 0 && ColA == 0) { RowA = int.Parse(textBoxRowA.Text); ColA = int.Parse(textBoxColA.Text); GlobalsMatrix.setRowMatrixA(int.Parse(textBoxRowA.Text)); GlobalsMatrix.setColMatrixA(int.Parse(textBoxColA.Text)); MatrixName = "A"; Add_Matrix(); } //Nếu muốn tạo ra ma trận ngẫu nhiên khác else if (GlobalsMatrix.RowA == int.Parse(textBoxRowA.Text) && GlobalsMatrix.ColA == int.Parse(textBoxColA.Text)) { MatrixName = "A"; Refresh_Matrix(); } //Trường hợp còn lại else { MatrixName = "A"; Delete_Matrix(); GlobalsMatrix.setRowMatrixA(int.Parse(textBoxRowA.Text)); GlobalsMatrix.setColMatrixA(int.Parse(textBoxColA.Text)); RowA = int.Parse(textBoxRowA.Text); ColA = int.Parse(textBoxColA.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); } }
private void buttonGetRandomA_Click(object sender, EventArgs e) { try { if (int.Parse(textBoxRowA.Text) > 50 || int.Parse(textBoxColA.Text) > 50) { RowA = int.Parse(textBoxRowA.Text); ColA = int.Parse(textBoxColA.Text); GlobalsMatrix.setRowMatrixA(int.Parse(textBoxRowA.Text)); GlobalsMatrix.setColMatrixA(int.Parse(textBoxColA.Text)); MatrixName = "A"; Add_MatrixBig(); MyMessageBox.Show("Đã tạo ma trận A 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); } }
///////////////////////////////////////////////////////////////////// ///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"); } }
/// <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); } }