| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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;
- using TeamAAS_VP.Models.Robot;
- namespace TeamAAS_VP.Views.Product
- {
- /// <summary>
- /// Interaction logic for PalletManage
- /// </summary>
- public partial class PalletManage : UserControl
- {
- IEventAggregator _eventAggregator;
- public PalletManage(IEventAggregator ea)
- {
- InitializeComponent();
- _eventAggregator = ea;
- _eventAggregator.GetEvent<PalletLayoutNotification>().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<TextBlock> labels= new List<TextBlock>();
- 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++;
- }
- }
-
- }
- }
- }
- }
- }
|