using Comal.Classes; using InABox.Clients; using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Xamarin.Forms; namespace comal.timesheets { public class SetoutPacketGrid : Frame { public SetoutShell Shell; Dictionary fileNameIDS = new Dictionary(); public SetoutPacketGrid(SetoutShell shell) { Margin = new Thickness(1, 1, 2, 1); Padding = 0; BorderColor = Color.Gray; HasShadow = false; Shell = shell; Grid mainGrid = new Grid(); mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }); mainGrid.Children.Add(SetupSetoutColumn(shell)); mainGrid.Children.Add(SetupPacketsColumn(shell)); Content = mainGrid; GestureRecognizers.Add(OpenPDFCommand(shell)); } private View SetupPacketsColumn(SetoutShell shell) { StackLayout layout = new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 0 }; layout.SetValue(Grid.ColumnProperty, 1); foreach (var packet in shell.Packets) { ViewPosition position = ViewPosition.Middle; if (packet == shell.Packets.First()) position = ViewPosition.First; else if (packet == shell.Packets.Last()) position = ViewPosition.Last; layout.Children.Add(CreatePacketView(packet, position)); } return layout; } private View CreatePacketView(MiniManufacturingPacket packet, ViewPosition position) { Frame frame = new Frame(); frame.Margin = new Thickness(0, 1.5, 0, 1.5); if(position == ViewPosition.First) frame.Margin = new Thickness(0, 0, 0, 1.5); else if (position == ViewPosition.Last) frame.Margin = new Thickness(0, 1.5, 0, 0); frame.Padding = 0; frame.BorderColor = Color.Gray; frame.HasShadow = false; frame.Content = new Label { Text = packet.Serial + " / " + packet.Location, Margin = new Thickness(5, 0, 0, 0) }; frame.GestureRecognizers.Add(OpenPacketCommand(packet)); return frame; } private IGestureRecognizer OpenPacketCommand(MiniManufacturingPacket packet) { var tapped = new TapGestureRecognizer(); tapped.Tapped += async (s, e) => { ManufacturingPacketPopup popup = new ManufacturingPacketPopup(packet.ID, packet.OrderID); Navigation.PushAsync(popup); }; return tapped; } private IGestureRecognizer OpenPDFCommand(SetoutShell shell) { var tapped = new TapGestureRecognizer(); tapped.Tapped += async (s, e) => { fileNameIDS.Clear(); CoreTable table = new Client().Query ( new Filter(x => x.EntityLink.ID).IsEqualTo(shell.ID), new Columns(x => x.DocumentLink.ID, x => x.DocumentLink.FileName) ); if (table.Rows.Any()) { foreach (CoreRow row in table.Rows) { if (!fileNameIDS.ContainsKey(row.Get("DocumentLink.FileName"))) fileNameIDS.Add(row.Get("DocumentLink.FileName"), row.Get("DocumentLink.ID")); } PDFList list = new PDFList(fileNameIDS); Navigation.PushAsync(list); } }; return tapped; } #region Setup Setout column private Grid SetupSetoutColumn(SetoutShell shell) { Grid grid = new Grid(); grid.SetValue(Grid.ColumnProperty, 0); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); Label label = new Label { Text = shell.Number, LineBreakMode = LineBreakMode.WordWrap, Margin = new Thickness(5, 0, 0, 0) }; label.SetValue(Grid.RowProperty, 0); Label label1 = new Label { Text = shell.Description, LineBreakMode = LineBreakMode.WordWrap, Margin = new Thickness(5, 0, 0, 0) }; label1.SetValue(Grid.RowProperty, 1); grid.Children.Add(label); grid.Children.Add(label1); return grid; } private View CreateLabel(string text, double rownumber) { Label label = new Label { Text = text, LineBreakMode = LineBreakMode.WordWrap }; label.SetValue(Grid.RowProperty, rownumber); return label; } enum ViewPosition { First, Middle, Last } #endregion } }