123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using Xamarin.Forms;
- using XF.Material.Forms.UI;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets
- {
- public partial class FrameDetailsPage : ContentPage
- {
- ScannerPage scanner = null;
- DeliveryItem _item = null;
- public FrameDetailsPage(String code)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- ToolbarItems.Clear();
- ToolbarItems.Add(new ToolbarItem("Back", "", () =>
- {
- Navigation.PopAsync();
- }));
- LoadData(code);
- }
- protected override async void OnAppearing()
- {
- base.OnAppearing();
- //if (scanner != null)
- //{
- // await LoadData(scanner.Result);
- // scanner = null;
- //}
- }
- Dictionary<Button, Guid> pdfs = new Dictionary<Button, Guid>();
- private async void LoadData(String code)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- DeliveryItem item = null;
- CoreTable items = new Client<DeliveryItem>().Query(
- new Filter<DeliveryItem>(x => x.Barcode).IsEqualTo(code),
- new Columns<DeliveryItem>(
- x => x.Description,
- x => x.ManufacturingPacketLink.Location,
- x => x.JobLink.JobNumber,
- x => x.JobLink.Name,
- x => x.ManufacturingPacketLink.SetoutLink.Number,
- x => x.ManufacturingPacketLink.SetoutLink.Description,
- x => x.ManufacturingPacketLink.Serial,
- x => x.SetoutLink.ID
- ));
- if (items.Rows.Any())
- {
- item = items.Rows.FirstOrDefault().ToObject<DeliveryItem>();
- if (item.SetoutLink.ID != Guid.Empty)
- Task.Run(() =>
- {
- CoreTable docs = new Client<SetoutDocument>().Query(
- new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.SetoutLink.ID)
- .And(x => x.Superceded).IsEqualTo(DateTime.MinValue),
- new Columns<SetoutDocument>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID)
- );
- foreach (var row in docs.Rows)
- {
- if (string.IsNullOrWhiteSpace(row.Get<SetoutDocument, string>(x => x.DocumentLink.FileName)))
- continue;
- MaterialButton button = new MaterialButton();
- button.Text = row.Get<SetoutDocument, String>(x => x.DocumentLink.FileName);
- button.Padding = new Thickness(0, 10, 0, 10);
- button.ButtonType = MaterialButtonType.Elevated;
- button.Clicked += ViewPDF;
- button.HorizontalOptions = LayoutOptions.FillAndExpand;
- pdfs[button] = row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- this.documents.Children.Clear();
- foreach (var button in pdfs.Keys)
- this.documents.Children.Add(button);
- });
- });
- }
- else
- item = new DeliveryItem();
- Device.BeginInvokeOnMainThread(() =>
- {
- if (item != null)
- this.BindingContext = item;
- });
- }
- }
- private void ViewPDF(object sender, EventArgs e)
- {
- MaterialButton button = sender as MaterialButton;
- if (pdfs.ContainsKey(button))
- {
- var page = new FrameDocumentPage(pdfs[button], button.Text);
- Navigation.PushAsync(page);
- }
- }
- void ScanBarcode_Clicked(System.Object sender, System.EventArgs e)
- {
- scanner = new ScannerPage();
- Navigation.PushAsync(scanner);
- }
- }
- }
|