123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- using comal.timesheets.CustomControls;
- using comal.timesheets.Data_Classes;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SetoutsScreen : ContentPage
- {
- #region Constructor / navigation
- Guid JobID = new Guid();
- List<SetoutShell> Setouts = new List<SetoutShell>();
- List<ManufacturingPacketShell> packets = new List<ManufacturingPacketShell>();
- Dictionary<string, Guid> fileNameIDS = new Dictionary<string, Guid>();
- public SetoutsScreen()
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- if (Device.RuntimePlatform == Device.iOS)
- {
- closeImg.HeightRequest = 45;
- closeImg.WidthRequest = 45;
- }
- }
- private void ExitBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- #endregion
- #region Loading Setouts
- private async void LoadSetouts()
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- AddSetoutsToList(DoSetoutsQuery());
- DisplayList();
- }
- }
- catch { }
- }
- private CoreTable DoSetoutsQuery()
- {
- CoreTable table = new Client<Setout>().Query
- (
- new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(JobID),
- new Columns<Setout>(
- x => x.ID,
- x => x.Number,
- x => x.Description
- )
- );
- return table;
- }
- private void AddSetoutsToList(CoreTable table)
- {
- foreach (CoreRow row in table.Rows)
- Setouts.Add(CreateSetoutShell(row));
- }
- private SetoutShell CreateSetoutShell(CoreRow row)
- {
- List<object> list = row.Values;
- if (list[0] == null) list[0] = Guid.Empty;
- if (list[1] == null) list[1] = "";
- if (list[2] == null) list[2] = "";
- SetoutShell shell = new SetoutShell();
- shell.ID = Guid.Parse(list[0].ToString());
- shell.Number = list[1].ToString();
- shell.Description = list[2].ToString();
- return shell;
- }
- private void DisplayList()
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- setoutsListView.ItemsSource = Setouts;
- });
- }
- #endregion
- #region Button Presses
- private void JobsBtn_Clicked(object sender, EventArgs e)
- {
- JobSelectionPage page = new JobSelectionPage();
- page.OnItemSelected += () =>
- {
- JobID = page.Job.ID;
- jobBtn.Text = page.Job.JobNumber + " " + page.Job.Name;
- LoadSetouts();
- };
- Navigation.PushAsync(page);
- }
- private void SetoutsListView_Tapped(object sender, EventArgs e)
- {
- try
- {
- SetoutShell shell = setoutsListView.SelectedItem as SetoutShell;
- QueryPDFsAndPackets(shell.ID);
- DisplayPackets();
- }
- catch { }
- }
- private async void ClosePackets_Clicked(object sender, EventArgs e)
- {
- await packetsFrame.TranslateTo(0, 900, 500);
- packetsFrame.IsVisible = false;
- packetsFrame.TranslateTo(0, 0, 500);
- packetsFrame.IsVisible = false;
- packetRow.Height = 0;
- }
- private void PDFs_Tapped(object sender, EventArgs e)
- {
- PDFList list = new PDFList(fileNameIDS);
- Navigation.PushAsync(list);
- }
- private void PacketListView_Tapped(object sender, EventArgs e)
- {
- ManufacturingPacketShell shell = packetListView.SelectedItem as ManufacturingPacketShell;
- ManufacturingPacketPopup popup = new ManufacturingPacketPopup(shell.ID, shell.OrderID);
- Navigation.PushAsync(popup);
- }
- #endregion
- #region Loading Setout Details (Packets and PDFs)
- private async void DisplayPackets()
- {
- packetsFrame.IsVisible = false;
- int height = 60 + (packets.Count * 150);
- if (height > 600)
- height = 600;
- packetRow.Height = height;
- packetListView.ItemsSource = null;
- packetListView.ItemsSource = packets;
- packetsLbl.Text = "Packets (" + packets.Count + ")";
- await packetsFrame.TranslateTo(0, 900, 0);
- packetsFrame.IsVisible = true;
- await packetsFrame.TranslateTo(0, 0, 500);
- }
- private void QueryPDFsAndPackets(Guid setoutID)
- {
- QueryPackets(setoutID);
- Task.Run(() => { QueryPDFs(setoutID); });
- }
- private void AddPacketsToList(CoreTable table)
- {
- packets.Clear();
- foreach (CoreRow row in table.Rows)
- packets.Add(CreatePacket(row));
- }
- private ManufacturingPacketShell CreatePacket(CoreRow row)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = ""; } //0
- if (list[1] == null) { list[1] = 0; } //1
- if (list[2] == null) { list[2] = Guid.Empty; } //2
- if (list[3] == null) { list[3] = ""; } //3
- if (list[4] == null) { list[4] = ""; } //4
- if (list[5] == null) { list[5] = ""; } //5
- if (list[6] == null) { list[6] = DateTime.MinValue; } //6
- if (list[7] == null) { list[7] = DateTime.MinValue; } //7
- if (list[8] == null) { list[8] = 0; } //8
- if (list[9] == null) { list[9] = 0.0; } //9
- if (list[10] == null) { list[10] = ""; } //10
- if (list[11] == null) { list[11] = ""; } //11
- if (list[12] == null) { list[12] = ""; } //12
- if (list[13] == null) { list[13] = Guid.Empty; } //13
- if (list[14] == null) { list[14] = ""; } //14
- if (list[15] == null) { list[15] = Guid.Empty; } //15
- if (list[16] == null) { list[16] = ""; } //16
- if (list[17] == null) { list[17] = ""; } //17
- if (list[18] == null) { list[18] = ""; } //18
- if (list[19] == null) { list[19] = ""; } //19
- if (list[20] == null) { list[20] = Guid.Empty; } //20
- if (list[21] == null) { list[21] = DateTime.MinValue; } //21
- if (list[22] == null) { list[22] = DateTime.MinValue; } //22
- if (list[23] == null) { list[23] = Guid.Empty; } //23
- ManufacturingPacketShell shell = new ManufacturingPacketShell()
- {
- Title = list[0].ToString(),
- Quantity = list[1].ToString(),
- DrawingID = Guid.Parse(list[2].ToString()),
- StageLinkSection = list[3].ToString(),
- JobNumber = list[4].ToString(),
- ITPCode = list[4].ToString() + " " + list[5].ToString(),
- Created = "C: " + DateTime.Parse(list[6].ToString()).ToString("dd MMM yy"),
- DueDate = "D: " + DateTime.Parse(list[7].ToString()).ToString("dd MMM yy"),
- StageLinkStation = int.Parse(list[8].ToString()),
- StageLinkPercentage = list[9].ToString() + "%",
- FactoryName = list[10].ToString(),
- Location = list[11].ToString(),
- SetoutID = Guid.Parse(list[13].ToString()),
- SetoutNumber = list[14].ToString(),
- ID = Guid.Parse(list[15].ToString()),
- TemplateLinkCode = list[16].ToString(),
- JobName = list[17].ToString(),
- OrderID = Guid.Parse(list[20].ToString()),
- OrderRecDate = DateTime.Parse(list[21].ToString()),
- JobID = Guid.Parse(list[23].ToString()),
- };
- if (!string.IsNullOrWhiteSpace(list[18].ToString()))
- {
- shell.Serial = "[" + list[18].ToString() + "] " + list[12].ToString() + ":";
- }
- else
- {
- shell.Serial = list[12].ToString();
- }
- if (!string.IsNullOrWhiteSpace(shell.StageLinkSection))
- shell.StageLinkPercentage = shell.StageLinkPercentage + " of " + shell.StageLinkSection;
- else
- shell.StageLinkPercentage = "TBI";
- if (!string.IsNullOrWhiteSpace(list[19].ToString()))
- {
- shell.ImagePath = "notifications.png";
- shell.ImageHeight = 25.0;
- shell.ImageWidth = 25.0;
- if (Device.RuntimePlatform.Equals(Device.iOS))
- {
- shell.ImageHeight = 35.0;
- shell.ImageWidth = 35.0;
- }
- }
- if (shell.OrderID != Guid.Empty && shell.OrderRecDate == DateTime.MinValue)
- {
- shell.OnOrderVisible = true;
- shell.LastRowHeight = 30;
- if (DateTime.TryParse(list[22].ToString(), out DateTime ETA))
- {
- shell.OrderETA = "ON ORDER ETA: " + ETA.ToString("dd MMM yy");
- }
- else
- {
- shell.OrderETA = "ON ORDER";
- }
- }
- return shell;
- }
- private void QueryPDFs(Guid setoutID)
- {
- fileNameIDS.Clear();
- CoreTable table = new Client<SetoutDocument>().Query
- (
- new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutID),
- new Columns<SetoutDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
- );
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- fileNameIDS.Add(row.Get<string>("DocumentLink.FileName"), row.Get<Guid>("DocumentLink.ID"));
- }
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- numberOfDocsLbl.Text = fileNameIDS.Count.ToString();
- });
- }
- private void QueryPackets(Guid setoutID)
- {
- AddPacketsToList(new Client<ManufacturingPacket>().Query
- (
- new Filter<ManufacturingPacket>(x => x.SetoutLink.ID).IsEqualTo(setoutID),
- Columns
- ));
- }
- Columns<ManufacturingPacket> Columns = new Columns<ManufacturingPacket>(
- x => x.Title, //0
- x => x.Quantity, //1
- x => x.Drawing.ID, //2
- x => x.StageLink.Section, //3
- x => x.SetoutLink.JobLink.JobNumber, //4
- x => x.ITP.Code, //5
- x => x.Created, //6
- x => x.DueDate, //7
- x => x.StageLink.Station, //8
- x => x.StageLink.PercentageComplete, //9
- x => x.ManufacturingTemplateLink.Factory.Name, //10
- x => x.Location, //11
- x => x.Serial, //12
- x => x.SetoutLink.ID, //13
- x => x.SetoutLink.Number, //14
- x => x.ID, //15
- x => x.ManufacturingTemplateLink.Code, //16
- x => x.SetoutLink.JobLink.Name, //17
- x => x.WaterMark, //18
- x => x.Issues, //19
- x => x.OrderItem.ID, //20
- x => x.OrderItem.ReceivedDate, //21
- x => x.OrderItem.Consignment.EstimatedWarehouseArrival, //22
- x => x.SetoutLink.JobLink.ID //23
- );
- #endregion
- #region Searching
- private void SearchEnt_Changed(object sender, EventArgs e)
- {
- if (!string.IsNullOrWhiteSpace(searchEnt.Text))
- setoutsListView.ItemsSource = Setouts.Where(x => x.Number.Contains(searchEnt.Text)
- || x.Description.Contains(searchEnt.Text) || x.Description.Contains(SearchUtils.UpperCaseFirst(searchEnt.Text))
- || x.Description.Contains(searchEnt.Text.ToLower()) || x.Description.Contains(searchEnt.Text.ToUpper()));
- else
- setoutsListView.ItemsSource = Setouts;
- }
- #endregion
- }
- public class SetoutShell
- {
- public Guid ID { get; set; }
- public string Number { get; set; }
- public string Description { get; set; }
- public SetoutShell()
- {
- ID = Guid.Empty;
- Number = "";
- Description = "";
- }
- }
- }
|