PalletManage.xaml.cs 4.0 KB

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