PalletManage.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Prism.Events;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows.Controls;
  5. using TeamAAS_VP.Enums;
  6. using TeamAAS_VP.Events;
  7. using TeamAAS_VP.Interfaces;
  8. using TeamAAS_VP.Models;
  9. using TeamAAS_VP.Models.Robot;
  10. namespace TeamAAS_VP.Views.Product
  11. {
  12. /// <summary>
  13. /// Interaction logic for PalletManage
  14. /// </summary>
  15. public partial class PalletManage : UserControl
  16. {
  17. IEventAggregator _eventAggregator;
  18. public PalletManage(IEventAggregator ea)
  19. {
  20. InitializeComponent();
  21. _eventAggregator = ea;
  22. _eventAggregator.GetEvent<PalletLayoutNotification>().Subscribe(UpdateVoid);
  23. }
  24. private void UpdateVoid(Pallet pallet)
  25. {
  26. UpDatePalletLayout(pallet.Row, pallet.Column , pallet.Arrangement);
  27. }
  28. public void UpDatePalletLayout(int row,int column, PalletArrangement arrangement)
  29. {
  30. gridPalllet.RowDefinitions.Clear();
  31. gridPalllet.ColumnDefinitions.Clear();
  32. gridPalllet.Children.Clear();
  33. for (int i = 0; i < row; i++)
  34. {
  35. gridPalllet.RowDefinitions.Add(new RowDefinition());
  36. }
  37. for (int i = 0;i < column; i++)
  38. {
  39. gridPalllet.ColumnDefinitions.Add( new ColumnDefinition());
  40. }
  41. gridPalllet.ShowGridLines = true;
  42. TextBlock[] texts=new TextBlock[] {new TextBlock() { Text="P0" , HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center},
  43. new TextBlock() { Text = "P1",HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center },
  44. new TextBlock() { Text = "P2" ,HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center} };
  45. gridPalllet.Children.Add(texts[0]);
  46. gridPalllet.Children.Add(texts[1]);
  47. gridPalllet.Children.Add(texts[2]);
  48. Grid.SetRow(texts[0], row-1);
  49. Grid.SetColumn(texts[0], 0);
  50. Grid.SetRow(texts[1], row - 1);
  51. Grid.SetColumn(texts[1], column-1);
  52. Grid.SetRow(texts[2], 0);
  53. Grid.SetColumn(texts[2], 0);
  54. List<TextBlock> labels= new List<TextBlock>();
  55. for (int i = 1;i<= row* column; i++)
  56. {
  57. labels.Add(new TextBlock() { Text = $"No:{i}", HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Top,Margin=new System.Windows.Thickness(5) });
  58. gridPalllet.Children.Add(labels[labels.Count-1]);
  59. }
  60. int index = 0;
  61. if (arrangement ==PalletArrangement.Z)
  62. {
  63. for (int i = row-1;i>-1; i--)
  64. {
  65. for(int j = 0;j< column; j++)
  66. {
  67. Grid.SetRow(labels[index], i);
  68. Grid.SetColumn(labels[index], j);
  69. index++;
  70. }
  71. }
  72. }
  73. else if (arrangement == PalletArrangement.弓)
  74. {
  75. for (int i = row - 1; i > -1; i--)
  76. {
  77. if ((row-(i + 1))%2==0) //偶数
  78. {
  79. for (int j = 0; j < column; j++)
  80. {
  81. Grid.SetRow(labels[index], i);
  82. Grid.SetColumn(labels[index], j);
  83. index++;
  84. }
  85. }
  86. else //奇数
  87. {
  88. for (int j = column - 1; j > -1; j--)
  89. {
  90. Grid.SetRow(labels[index], i);
  91. Grid.SetColumn(labels[index], j);
  92. index++;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }