using Prism.Events; using System; using System.Collections.Generic; using System.Windows.Controls; using TeamAAS_VP.Enums; using TeamAAS_VP.Events; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Models; namespace TeamAAS_VP.Views.Product { /// /// Interaction logic for PalletManage /// public partial class PalletManage : UserControl { IEventAggregator _eventAggregator; public PalletManage(IEventAggregator ea) { InitializeComponent(); _eventAggregator = ea; _eventAggregator.GetEvent().Subscribe(UpdateVoid); } private void UpdateVoid(Pallet pallet) { UpDatePalletLayout(pallet.Row, pallet.Column , pallet.Arrangement); } public void UpDatePalletLayout(int row,int column, PalletArrangement arrangement) { gridPalllet.RowDefinitions.Clear(); gridPalllet.ColumnDefinitions.Clear(); gridPalllet.Children.Clear(); for (int i = 0; i < row; i++) { gridPalllet.RowDefinitions.Add(new RowDefinition()); } for (int i = 0;i < column; i++) { gridPalllet.ColumnDefinitions.Add( new ColumnDefinition()); } gridPalllet.ShowGridLines = true; TextBlock[] texts=new TextBlock[] {new TextBlock() { Text="P0" , HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center}, new TextBlock() { Text = "P1",HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center }, new TextBlock() { Text = "P2" ,HorizontalAlignment=System.Windows.HorizontalAlignment.Center,VerticalAlignment=System.Windows.VerticalAlignment.Center} }; gridPalllet.Children.Add(texts[0]); gridPalllet.Children.Add(texts[1]); gridPalllet.Children.Add(texts[2]); Grid.SetRow(texts[0], row-1); Grid.SetColumn(texts[0], 0); Grid.SetRow(texts[1], row - 1); Grid.SetColumn(texts[1], column-1); Grid.SetRow(texts[2], 0); Grid.SetColumn(texts[2], 0); List labels= new List(); for (int i = 1;i<= row* column; i++) { labels.Add(new TextBlock() { Text = $"No:{i}", HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Top,Margin=new System.Windows.Thickness(5) }); gridPalllet.Children.Add(labels[labels.Count-1]); } int index = 0; if (arrangement ==PalletArrangement.Z) { for (int i = row-1;i>-1; i--) { for(int j = 0;j< column; j++) { Grid.SetRow(labels[index], i); Grid.SetColumn(labels[index], j); index++; } } } else if (arrangement == PalletArrangement.弓) { for (int i = row - 1; i > -1; i--) { if ((row-(i + 1))%2==0) //偶数 { for (int j = 0; j < column; j++) { Grid.SetRow(labels[index], i); Grid.SetColumn(labels[index], j); index++; } } else //奇数 { for (int j = column - 1; j > -1; j--) { Grid.SetRow(labels[index], i); Grid.SetColumn(labels[index], j); index++; } } } } } } }