GraphByMatrix.xaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace GraphDrawer
  15. {
  16. /// <summary>
  17. /// Interaction logic for GraphByMatrix.xaml
  18. /// </summary>
  19. public partial class GraphByMatrix : Window
  20. {
  21. T[,] ResizeArray<T>(T[,] original, int rows, int cols)
  22. {
  23. var newArray = new T[rows, cols];
  24. int minRows = Math.Min(rows, original.GetLength(0));
  25. int minCols = Math.Min(cols, original.GetLength(1));
  26. for (int i = 0; i < minRows; i++)
  27. for (int j = 0; j < minCols; j++)
  28. newArray[i, j] = original[i, j];
  29. return newArray;
  30. }
  31. public GraphByMatrix()
  32. {
  33. InitializeComponent();
  34. }
  35. private void submitBtn_Click(object sender, RoutedEventArgs e)
  36. {
  37. try
  38. {
  39. var row = MatrixTextBox.GetLineText(0);
  40. row = row.Replace(" ", "");
  41. var elements = row.Split(',');
  42. int rows = elements.Length;
  43. int cols = 0;
  44. while (true)
  45. {
  46. var String = MatrixTextBox.GetLineText(cols);
  47. if (!(String.Length > 0))
  48. cols++;
  49. else
  50. break;
  51. }
  52. int[,] matrix = new int[rows, cols];
  53. for(int i = 0; i < rows; i++)
  54. {
  55. row = MatrixTextBox.GetLineText(i);
  56. row = row.Replace(" ", "");
  57. var rowArray = row.Split(',');
  58. for(int j = 0; j < cols; j++)
  59. {
  60. matrix[i, j] = int.Parse(rowArray[j]);
  61. }
  62. }
  63. GraphByClick graphByClick = new GraphByClick(matrix, true);
  64. }
  65. catch(Exception ex)
  66. {
  67. MessageBox.Show("Разделитель - запятая\nПопробуйте еще раз", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  68. MessageBox.Show(ex.Message);
  69. }
  70. }
  71. private void backBtn_Click(object sender, RoutedEventArgs e)
  72. {
  73. ChoiseRegime choice = new ChoiseRegime();
  74. choice.Show();
  75. Close();
  76. }
  77. }
  78. }