123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- using comal.timesheets.CustomControls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using Plugin.Media;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using InABox.Mobile;
- using Xamarin.CommunityToolkit.Extensions;
- using Xamarin.CommunityToolkit.UI.Views;
- using Xamarin.Essentials;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- using LogType = InABox.Core.LogType;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ManufacturingScreen
- {
- List<ManufacturingPacketShell> shells = new List<ManufacturingPacketShell>();
- List<ManufacturingPacketShell> factorySearchList = new List<ManufacturingPacketShell>();
- List<String> factories = new List<string>();
- Job job = new Job();
- bool firstLoad = true;
- public ManufacturingScreen()
- {
- InitializeComponent();
- LoadPackets(Guid.Empty);
- }
- private void LoadPackets(Guid jobid)
- {
- Task.Run(() =>
- {
- shells.Clear();
- factorySearchList.Clear();
- Filter<ManufacturingPacket> filter = new Filter<ManufacturingPacket>(x => x.Completed).IsEqualTo(DateTime.MinValue).
- And(x => x.Archived).IsEqualTo(DateTime.MinValue);
- if (jobid != Guid.Empty)
- filter = filter.And(x => x.SetoutLink.JobLink.ID).IsEqualTo(jobid);
- CoreTable table = QueryPackets(filter);
- while (table == null)
- table = QueryPackets(filter);
- foreach (CoreRow row in table.Rows)
- {
- ManufacturingPacketShell shell = new ManufacturingPacketShell()
- {
- Title = row.Get<ManufacturingPacket, string>(x => x.Title),
- Quantity = row.Get<ManufacturingPacket, int>(x => x.Quantity).ToString(),
- DrawingID = row.Get<ManufacturingPacket, Guid>(x => x.Drawing.ID),
- StageLinkSection = row.Get<ManufacturingPacket, string>(x => x.StageLink.Section),
- JobNumber = row.Get<ManufacturingPacket, string>(x => x.JobLink.JobNumber),
- ITPCode = row.Get<ManufacturingPacket, string>(x => x.JobLink.JobNumber)
- + " " + row.Get<ManufacturingPacket, string>(x => x.ITP.Code),
- Created = "C: " + row.Get<ManufacturingPacket, DateTime>(x => x.Created).ToString("dd MMM yy"),
- DueDate = "D: " + row.Get<ManufacturingPacket, DateTime>(x => x.DueDate).ToString("dd MMM yy"),
- StageLinkStation = row.Get<ManufacturingPacket, int>(x => x.StageLink.Station),
- StageLinkPercentage = row.Get<ManufacturingPacket, double>(x => x.StageLink.PercentageComplete) + "%",
- FactoryName = row.Get<ManufacturingPacket, string>(x => x.ManufacturingTemplateLink.Factory.Name),
- Location = row.Get<ManufacturingPacket, string>(x => x.Location),
- SetoutID = row.Get<ManufacturingPacket, Guid>(x => x.SetoutLink.ID),
- SetoutNumber = row.Get<ManufacturingPacket, string>(x => x.SetoutLink.Number),
- ID = row.Get<ManufacturingPacket, Guid>(x => x.ID),
- TemplateLinkCode = row.Get<ManufacturingPacket, string>(x => x.ManufacturingTemplateLink.Code),
- JobName = row.Get<ManufacturingPacket, string>(x => x.SetoutLink.JobLink.Name),
- OrderID = row.Get<ManufacturingPacket, Guid>(x => x.OrderItem.ID),
- OrderRecDate = row.Get<ManufacturingPacket, DateTime>(x => x.OrderItem.ReceivedDate),
- JobID = row.Get<ManufacturingPacket, Guid>(x => x.JobLink.ID),
- };
- if (!string.IsNullOrWhiteSpace(row.Get<ManufacturingPacket, string>(x => x.WaterMark)))
- shell.Serial = "[" + row.Get<ManufacturingPacket, string>(x => x.WaterMark) + "] " + row.Get<ManufacturingPacket, string>(x => x.Serial) + ":";
- else
- shell.Serial = row.Get<ManufacturingPacket, string>(x => x.Serial);
- if (!string.IsNullOrWhiteSpace(shell.StageLinkSection))
- shell.StageLinkPercentage = shell.StageLinkPercentage + " of " + shell.StageLinkSection;
- else
- shell.StageLinkPercentage = "TBI";
- if (!string.IsNullOrWhiteSpace(row.Get<ManufacturingPacket, string>(x => x.Issues)))
- {
- 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 (row.Get<ManufacturingPacket, DateTime>(x => x.OrderItem.Consignment.EstimatedWarehouseArrival) != DateTime.MinValue)
- shell.OrderETA = "ON ORDER ETA: " + row.Get<ManufacturingPacket, DateTime>(x => x.OrderItem.Consignment.EstimatedWarehouseArrival).ToString("dd MMM yy");
- else
- shell.OrderETA = "ON ORDER";
- }
- if (!factories.Contains(row.Get<ManufacturingPacket, string>(x => x.ManufacturingTemplateLink.Factory.Name)))
- factories.Add(row.Get<ManufacturingPacket, string>(x => x.ManufacturingTemplateLink.Factory.Name));
- shells.Add(shell);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- if (firstLoad)
- {
- filterOptionsControl.Options = factories;
- filterOptionsControl.CreateRadioButtonsAndSetDefault("Fabrication");
- filterOptionsControl.OnFilterOptionChanged += FilterOptionsControl_OnFilterOptionChanged;
- firstLoad = false;
- }
- listView.ItemsSource = null;
- listView.ItemsSource = shells.Where(x => x.FactoryName.Equals("Fabrication"));
- var list = shells.Where(x => x.FactoryName.Equals("Fabrication"));
- foreach (ManufacturingPacketShell shell in list)
- {
- factorySearchList.Add(shell);
- }
- titleLbl.Text = "Packets: " + factorySearchList.Count();
- });
- });
- }
- private CoreTable QueryPackets(Filter<ManufacturingPacket> filter)
- {
- try
- {
- return new Client<ManufacturingPacket>().Query
- (
- filter,
- 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
- )
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void JobFilterBtn_Clicked(object sender, EventArgs e)
- {
- JobSelectionPage page = new JobSelectionPage(
- (job) =>
- {
- jobBtn.Text = job.Name + " (" + job.JobNumber + ")";
- LoadPackets(job.ID);
- }
- );
- Navigation.PushAsync(page);
- }
- private void FilterOptionsControl_OnFilterOptionChanged(string filterOption)
- {
- if (filterOption == filterOptionsControl.CurrentOption)
- return;
- filterOptionsControl.CurrentOption = filterOption;
- var list = shells.Where(x => x.FactoryName.Equals(filterOption));
- factorySearchList.Clear();
- foreach (ManufacturingPacketShell shell in list)
- {
- factorySearchList.Add(shell);
- }
- if (string.IsNullOrWhiteSpace(searchEnt.Text))
- {
- listView.ItemsSource = shells.Where(x => x.FactoryName.Equals(filterOption));
- titleLbl.Text = "Packets: " + factorySearchList.Count();
- }
- else
- {
- RunSearch(factorySearchList);
- }
- }
- private async void LoadPDF(Guid setoutid)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- CoreTable table = QuerySetOutDocuments(setoutid);
- while (table == null)
- table = QuerySetOutDocuments(setoutid);
- if (table.Rows.Any())
- {
- if (table.Rows.Count == 1)
- {
- List<object> list = table.Rows[0].Values;
- if (list[1] == null) list[1] = Guid.Empty;
- PDFViewer pDFViewer = new PDFViewer(Guid.Parse(list[1].ToString()));
- Device.BeginInvokeOnMainThread(() =>
- {
- Navigation.PushAsync(pDFViewer);
- });
- }
- else if (table.Rows.Count > 1)
- {
- Dictionary<string, Guid> fileNameIDs = new Dictionary<string, Guid>();
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) list[0] = "";
- if (list[1] == null) list[1] = Guid.Empty;
- fileNameIDs.Add(list[0].ToString(), Guid.Parse(list[1].ToString()));
- }
- PDFList pdfList = new PDFList(); //fileNameIDs);
- Navigation.PushAsync(pdfList);
- }
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- DisplayAlert("Alert", "No Drawings found", "OK");
- });
- }
- }
- }
- private CoreTable QuerySetOutDocuments(Guid setoutid)
- {
- try
- {
- return new Client<SetoutDocument>().Query
- (
- new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutid),
- new Columns<SetoutDocument>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID)
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private async void ListView_Tapped(object sender, EventArgs e)
- {
- ManufacturingPacketShell shell = listView.SelectedItem as ManufacturingPacketShell;
- string chosenOption = await DisplayActionSheet("Choose an Option", "Cancel", null, "View Drawing", "View Status");
- switch (chosenOption)
- {
- case "Cancel":
- break;
- default:
- break;
- case "View Drawing":
- LoadPDF(shell.SetoutID);
- break;
- case "View Status":
- ManufacturingPacketPopup popup = new ManufacturingPacketPopup(shell.ID, shell.OrderID);
- Navigation.PushAsync(popup);
- break;
- }
- }
- private void SearchEnt_Changed(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(searchEnt.Text))
- {
- listView.ItemsSource = shells.Where(x => x.FactoryName.Equals(filterOptionsControl.CurrentOption));
- }
- else
- {
- RunSearch(factorySearchList);
- }
- }
- private void RunSearch(List<ManufacturingPacketShell> packetShells)
- {
- var list = packetShells.Where(x =>
- x.Title.Contains(searchEnt.Text) || x.Title.Contains(searchEnt.Text.ToUpper()) || x.Title.Contains(UpperCaseFirst(searchEnt.Text)) || x.Title.Contains(searchEnt.Text.ToLower()) ||
- x.Quantity.Contains(searchEnt.Text) ||
- x.JobNumber.Contains(searchEnt.Text) ||
- x.DueDate.Contains(searchEnt.Text) || x.DueDate.Contains(searchEnt.Text.ToUpper()) || x.DueDate.Contains(searchEnt.Text.ToLower()) || x.DueDate.Contains(UpperCaseFirst(searchEnt.Text)) ||
- x.Created.Contains(searchEnt.Text) || x.Created.Contains(searchEnt.Text.ToUpper()) || x.Created.Contains(searchEnt.Text.ToLower()) || x.Created.Contains(UpperCaseFirst(searchEnt.Text)) ||
- x.ITPCode.Contains(searchEnt.Text) || x.ITPCode.Contains(searchEnt.Text.ToUpper()) || x.ITPCode.Contains(searchEnt.Text.ToLower()) || x.ITPCode.Contains(UpperCaseFirst(searchEnt.Text)) ||
- x.Location.Contains(searchEnt.Text) || x.Location.Contains(searchEnt.Text.ToUpper()) || x.Location.Contains(searchEnt.Text.ToLower()) || x.Location.Contains(UpperCaseFirst(searchEnt.Text)) ||
- x.SetoutNumber.Contains(searchEnt.Text) || x.SetoutNumber.Contains(searchEnt.Text.ToUpper()) || x.SetoutNumber.Contains(searchEnt.Text.ToLower()) || x.SetoutNumber.Contains(UpperCaseFirst(searchEnt.Text)) ||
- x.Serial.Contains(searchEnt.Text) || x.Serial.Contains(searchEnt.Text.ToUpper()) || x.Serial.Contains(searchEnt.Text.ToLower()) || x.Serial.Contains(UpperCaseFirst(searchEnt.Text))
- );
- listView.ItemsSource = list;
- titleLbl.Text = "Packets: " + list.Count();
- }
- static String UpperCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- }
- public class ManufacturingPacketShell
- {
- public Guid ID { get; set; }
- public string Title { get; set; }
- public string Quantity { get; set; }
- public Guid DrawingID { get; set; }
- public string StageLinkSection { get; set; }
- public string JobNumber { get; set; }
- public Guid JobID { get; set; }
- public string ITPCode { get; set; }
- public string Created { get; set; }
- public string DueDate { get; set; }
- public int StageLinkStation { get; set; }
- public string StageLinkPercentage { get; set; }
- public string FactoryName { get; set; }
- public string Location { get; set; }
- public string Serial { get; set; }
- public Guid SetoutID { get; set; }
- public string SetoutNumber { get; set; }
- public string TemplateLinkCode { get; set; }
- public string JobName { get; set; }
- public string WaterMark { get; set; }
- public string ImagePath { get; set; }
- public double ImageHeight { get; set; }
- public double ImageWidth { get; set; }
- public Color Color { get; set; }
- public Guid OrderID { get; set; }
- public DateTime OrderRecDate { get; set; }
- public double LastRowHeight { get; set; }
- public bool OnOrderVisible { get; set; }
- public String OrderETA { get; set; }
- public ManufacturingPacketShell()
- {
- ID = Guid.Empty;
- Title = "";
- Quantity = "";
- DrawingID = Guid.Empty;
- StageLinkSection = "";
- JobNumber = "";
- ITPCode = "";
- Created = "";
- DueDate = "";
- StageLinkStation = 0;
- StageLinkPercentage = "";
- FactoryName = "";
- Location = "";
- Serial = "";
- SetoutID = Guid.Empty;
- SetoutNumber = "";
- TemplateLinkCode = "";
- JobName = "";
- WaterMark = "";
- ImagePath = "";
- ImageHeight = 0.0;
- ImageWidth = 0.0;
- OrderID = Guid.Empty;
- Color = Color.Default;
- OrderRecDate = DateTime.MinValue;
- LastRowHeight = 0;
- OnOrderVisible = false;
- OrderETA = "";
- JobID = Guid.Empty;
- }
- }
- }
|