| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System.Threading;
- using System.Linq;
- using Xamarin.Forms;
- using XF.Material.Forms.UI;
- using XF.Material.Forms.UI.Dialogs;
- using InABox.Core;
- using InABox.Clients;
- using Comal.Classes;
- using System.IO;
- using Plugin.Media;
- using InABox.Mobile;
- using System.Linq.Expressions;
- using Xamarin.Essentials;
- using Contact = Comal.Classes.Contact;
- using comal.timesheets.CustomControls;
- using comal.timesheets.Deliveries;
- namespace comal.timesheets
- {
- public delegate void DeliverySaved();
- public partial class DeliveryDetails
- {
-
- public Guid DeliveryID { get; set; }
- private Delivery _delivery = null;
-
- public event DeliverySaved OnDeliverySaved;
-
- private string address = "";
- public IEnumerable<Placemark> addresses;
-
- ToolbarItem CompleteDeliveryButton;
- ToolbarItem CreateDeliveryButton;
-
- private SelectionPage _selectionpage = null;
- ObservableList<Docket> dockets = new ObservableList<Docket>();
- private List<ImageSource> images = new List<ImageSource>();
- ObservableList<Document> newPhotoDocuments = new ObservableList<Document>();
-
- List<Guid> existingDocumentIDs = new List<Guid>();
- List<Tuple<ActionButton, Guid, String, List<DeliveryItem>>> requis = new List<Tuple<ActionButton, Guid, String, List<DeliveryItem>>>();
- List<Tuple<ActionButton, Guid, String, List<DeliveryItem>>> shipments = new List<Tuple<ActionButton, Guid, String, List<DeliveryItem>>>();
- public DeliveryDetails()
- {
- InitializeComponent();
-
- CompleteDeliveryButton = new ToolbarItem()
- {
- Text = "Record 'Delivered' Flag",
- Command = new DropDownMenuCommand(CompleteDelivery),
- Order = ToolbarItemOrder.Primary
- };
- ToolbarItems.Add(CompleteDeliveryButton);
-
- CreateDeliveryButton = new ToolbarItem()
- {
- Text = "Create Delivery/Pickup",
- Command = new Command(CreateDelivery)
- };
- ToolbarItems.Add(CreateDeliveryButton);
-
- }
-
- async void LoadData()
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading Delivery"))
- {
- if (DeliveryID != Guid.Empty)
- {
-
- var deltask = Task.Run(() =>
- {
- return _delivery = new Client<Delivery>().Query(
- new Filter<Delivery>(x => x.ID).IsEqualTo(DeliveryID)
- ).Rows
- .FirstOrDefault()?
- .ToObject<Delivery>();
- });
- var dkttask = Task.Run(() =>
- {
-
- var table = new Client<DeliveryItem>().Query(
- new Filter<DeliveryItem>(x => x.Delivery.ID).IsEqualTo(DeliveryID),
- new Columns<DeliveryItem>(
- X => X.ManufacturingPacketLink.SetoutLink.Number,
- X => X.ShipmentCode,
- X => X.Description,
- X => X.RequisitionLink.Number
- ),
- new SortOrder<DeliveryItem>(x => x.ShipmentCode)
- );
- foreach (var row in table.Rows)
- {
- Docket docket = new Docket();
- docket.Setout =
- $"Setout # {row.Get<DeliveryItem, String>(x => x.ManufacturingPacketLink.SetoutLink.Number)}";
- docket.Rack = $"Rack # {row.Get<DeliveryItem, String>(x => x.ShipmentCode)}";
- docket.Description = row.Get<DeliveryItem, String>(x => x.Description);
- docket.Requi = $"Requi # {row.Get<DeliveryItem, int>(x => x.RequisitionLink.Number)}";
- dockets.Add(docket);
- }
- });
-
- Task.WaitAll(new Task[] { deltask, dkttask });
- new Client<Document>().Query(
- new Filter<Document>(x => x.ID).InQuery(
- new Filter<DeliveryDocument>(x => x.EntityLink.ID).IsEqualTo(DeliveryID),
- x => x.DocumentLink.ID),
- null,
- null,
- (o,e) => Device.BeginInvokeOnMainThread(() => UpdateImages(o))
- );
-
- }
- if (_delivery == null)
- {
- _delivery = new Delivery();
- _delivery.Employee.ID = App.Data.Me.ID;
- _delivery.Employee.Name = App.Data.Me.Name;
- }
- }
-
- }
-
- private void ImageTapped(object sender, EventArgs e)
- {
- throw new NotImplementedException();
- }
-
- private void UpdateImages(CoreTable table)
- {
- if (table == null)
- return;
- foreach (var docrow in table.Rows)
- {
- byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
- ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- images.Add(src);
- }
- Device.BeginInvokeOnMainThread(RefreshPage);
- }
- private void RefreshPage()
- {
- Title = _delivery.ID != Guid.Empty
- ? _delivery.Number.ToString()
- : "New Delivery";
- JobName.Text = (!string.IsNullOrWhiteSpace(_delivery.Job.Name))
- ? _delivery.Job.Name + " (" + _delivery.Job.JobNumber + ")"
- : "";
- TypeLbl.Text = _delivery.Type.Description;
- ContactNameLbl.Text = _delivery.Contact.Name;
- streetEdt.Text = _delivery.Address.Street;
- cityEdt.Text = _delivery.Address.City;
- statePicker.SelectedIndex = SelectState();
- postCodeEdt.Text = _delivery.Address.PostCode;
- EmployeeName.Text = _delivery.Employee.Name;
- deliveryNotesEdt.Text = _delivery.Notes;
- dueDate.Date = !_delivery.Due.IsEmpty()
- ? _delivery.Due
- : DateTime.Today;
-
- convertToTaskBtn.Text = _delivery.KanbanNumber != 0
- ? "Saved To Task " + _delivery.KanbanNumber
- : "Create Task";
- convertToTaskBtn.IsEnabled = (_delivery.ID != Guid.Empty) && (_delivery.KanbanNumber == 0);
-
- convertToTaskBtn.IsEnabled = _delivery.ID != Guid.Empty;
-
- ItemsToBeDelivered.IsVisible = _delivery.ID != Guid.Empty;
-
- CompleteDeliveryButton.IsEnabled = !_delivery.Delivered.IsEmpty() && (_delivery.ID != Guid.Empty);
-
- ItemsFrame.IsVisible = _delivery.ID != Guid.Empty;
- loadDeliveryItems.IsVisible = _delivery.ID != Guid.Empty;
-
- streetEdt.Text = _delivery.Contact.Address.Street;
- cityEdt.Text = _delivery.Contact.Address.City;
- postCodeEdt.Text = _delivery.Contact.Address.PostCode;
- ContactNameLbl.Text = _delivery.Contact.Name;
-
- EmployeeName.Text = _delivery.Employee.Name;
-
- if (_delivery.Location.Longitude != 0 && _delivery.Location.Latitude != 0)
- {
- DeliveredFlagFrame.IsVisible = true;
- DeliveredLbl.IsVisible = true;
- DeliveredDetails.Text = "Loading Delivered Flag Details";
- if (string.IsNullOrWhiteSpace(_delivery.Location.Address))
- {
- GetLocationFromDetails();
- }
- else
- ShowDeliveredDetails(false);
- }
-
- loadDeliveryItems.Text = dockets.Any()
- ? $"View {dockets.Count} items"
- : "No Items Found";
- loadDeliveryItems.IsEnabled = dockets.Any();
- Images.IsVisible = images.Count > 0;
- photosLbl.Text = $"{images.Count} Photo(s)";
- }
-
- protected override async void OnAppearing()
- {
- if (_delivery == null)
- LoadData();
-
- _selectionpage = null;
-
- Device.BeginInvokeOnMainThread(RefreshPage);
-
- base.OnAppearing();
- }
-
- protected async override void OnDisappearing()
- {
- await Task.Run(() =>
- {
- if (_delivery.ID != Guid.Empty && (_selectionpage == null))
- {
- try
- {
- new Client<Delivery>().Save(_delivery, "Updated from mobile device");
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- }
- }
- });
- base.OnDisappearing();
- }
-
- #region Create Delivery or add delivered flag
-
- async void CreateDelivery()
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Saving Delivery"))
- {
- _delivery.Due = dueDate.Date; //unable to make duedate changed event without crashing the screen on startup....
- new Client<Delivery>().Save(_delivery, "Updated From Mobile Device");
- if (newPhotoDocuments.Count != 0)
- {
- new Client<Document>().Save(newPhotoDocuments, "Photo Taken on Device");
- ObservableList<DeliveryDocument> newDeliveryDocuments = new ObservableList<DeliveryDocument>();
- foreach (Document doc in newPhotoDocuments)
- {
- var deliveryDocument = new DeliveryDocument();
- deliveryDocument.EntityLink.ID = _delivery.ID;
- deliveryDocument.DocumentLink.ID = doc.ID;
- deliveryDocument.DocumentLink.FileName = doc.FileName;
- newDeliveryDocuments.Add(deliveryDocument);
- }
- new Client<DeliveryDocument>().Save(newDeliveryDocuments, "Photo Taken on Device");
- newPhotoDocuments.Clear();
- }
- }
- string successMessage = "Delivery Created" + System.Environment.NewLine + "Delivery Number: " + _delivery.Number;
- }
- catch (Exception ex)
- {
- DisplayAlert("Error creating delivery", ex.Message, "OK");
- }
- OnDeliverySaved?.Invoke();
- await Navigation.PopAsync();
- }
- private async void CompleteDelivery()
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Getting Location..Please wait"))
- {
- LocationServices locationServices = new LocationServices();
- locationServices.OnLocationFound += LocationFound;
- locationServices.OnLocationError += LocationError;
- locationServices.GetLocation();
- Thread.Sleep(1000); //"Getting Location" notification disappears too quickly on some devices - ensures a minimum of 1 second while location tasks execute on other threads
- }
- }
- catch { }
- }
- private async void LocationFound(LocationServices sender)
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Getting Location..Please wait"))
- {
- _delivery.Location.Latitude = sender.Latitude;
- _delivery.Location.Longitude = sender.Longitude;
- _delivery.Location.Timestamp = DateTime.Now;
- _delivery.Location.Address = sender.Address;
- _delivery.DeliveredBy.ID = App.Data.Me.ID;
- _delivery.DeliveredBy.Name = App.Data.Me.Name;
- address = sender.Address;
- _delivery.Delivered = DateTime.Now;
- await Task.Run(() =>
- {
- new Client<Delivery>().Save(_delivery, "Updated From Mobile Device");
- });
- }
- await DisplayAlert("Success", "Delivered: " + _delivery.Delivered.ToString("hh:mm:ss tt dd-MMM-yy")
- + System.Environment.NewLine + "Location Now: " + address
- , "OK");
- ShowDeliveredDetails();
- }
- catch { }
- }
- private void LocationError(LocationServices sender, Exception error)
- {
- DisplayAlert("GPS Error", error.Message, "OK");
- }
- #endregion
- #region Load Screen values from Database
- public IEnumerable<Placemark> Addresses
- {
- get { return addresses; }
- set { addresses = value; ShowDeliveredDetails(); }
- }
- private void ShowDeliveredDetails(bool wait = true)
- {
- Task.Run(() =>
- {
- if (wait)
- {
- Thread.Sleep(5000);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- CompleteDeliveryButton.IsEnabled = false;
- DeliveredFlagFrame.IsVisible = true;
- DeliveredLbl.IsVisible = true;
- if (string.IsNullOrWhiteSpace(address))
- {
- if (!string.IsNullOrWhiteSpace(_delivery.Location.Address))
- address = _delivery.Location.Address;
- else
- address = "(Address service failed). Driver was at Latitude: " + _delivery.Location.Latitude + " Longitude: " + _delivery.Location.Longitude;
- }
- DeliveredDetails.Text = address + " at " + _delivery.Delivered.ToString("hh:mm:ss tt dd MMM yy") + System.Environment.NewLine
- + "by: " + _delivery.DeliveredBy.Name;
- openMapBtn.IsEnabled = true;
- });
- });
-
- }
- private async void GetLocationFromDetails()
- {
- await Task.Run(async () =>
- {
- try
- {
- Addresses = await Geocoding.GetPlacemarksAsync(_delivery.Location.Latitude, _delivery.Location.Longitude);
- Placemark placemark = null;
- foreach (var cur in Addresses)
- {
- placemark = cur;
- if (placemark != null)
- {
- address = String.Format("{0} {1} {2}", placemark.SubThoroughfare, placemark.Thoroughfare, placemark.Locality);
- _delivery.Location.Address = address;
- return;
- }
- }
-
- }
- catch
- {
- address = "Longitude: " + _delivery.Location.Longitude + "Latitude: " + _delivery.Location.Latitude + " Address service failed to load address";
- }
- });
- }
- private async void OpenMapBtn_Clicked(object sender, EventArgs e)
- {
- var location = new Xamarin.Essentials.Location(_delivery.Location.Latitude, _delivery.Location.Longitude);
- var options = new MapLaunchOptions { };
- await Map.OpenAsync(location, options);
- }
- #endregion
- #region Values Changed Events
- private async void SelectType_Clicked(object sender, EventArgs e)
- {
- try
- {
- Dictionary<string, Guid> deliveryTypePairs = new Dictionary<string, Guid>();
- List<string> _deliveryTypes = new List<string>();
- var table = new Client<DeliveryType>().Query(new Filter<DeliveryType>(x => x.Description).IsNotEqualTo(string.Empty));
- foreach (CoreRow row in table.Rows)
- {
- DeliveryType _deliveryType = row.ToObject<DeliveryType>();
- _deliveryTypes.Add(_deliveryType.Description);
- deliveryTypePairs.Add(_deliveryType.Description, _deliveryType.ID);
- }
- if (_deliveryTypes.Count != 0)
- {
- string[] array = _deliveryTypes.ToArray();
- string chosenOption = await DisplayActionSheet("Choose Delivery Type", "Cancel", null, array);
- if (!chosenOption.Equals("Cancel"))
- {
- _delivery.Type.Description = chosenOption;
- TypeLbl.Text = _delivery.Type.Description;
- _delivery.Type.ID = deliveryTypePairs[chosenOption];
- }
- }
- }
- catch { }
- }
- private void SelectJob_Clicked(object sender, EventArgs e)
- {
- _selectionpage = new JobSelectionPage(
- (job) =>
- {
- _delivery.Job.ID = job.ID;
- _delivery.Job.Name = job.Name;
- _delivery.Job.JobNumber = job.JobNumber;
- JobName.Text = _delivery.Job.Name + " (" + _delivery.Job.JobNumber + ")";
- }
- );
- Navigation.PushAsync(_selectionpage);
- }
- #region Address
- private void StreetEdt_Changed(object sender, EventArgs e)
- {
- _delivery.Address.Street = streetEdt.Text;
- }
- private void CityEdt_Changed(object sender, EventArgs e)
- {
- _delivery.Address.City = cityEdt.Text;
- }
- private void StatePicker_Changed(object sender, EventArgs e)
- {
- _delivery.Address.State = statePicker.SelectedItem.ToString();
- }
- private void PostCode_Changed(object sender, EventArgs e)
- {
- _delivery.Address.PostCode = postCodeEdt.Text;
- }
- private int SelectState()
- {
- int state = 0;
- switch (_delivery.Address.State)
- {
- case "Western Australia":
- state = 0;
- break;
- case "Victoria":
- state = 1;
- break;
- case "South Australia":
- state = 2;
- break;
- case "New South Wales":
- state = 3;
- break;
- case "Queensland":
- state = 4;
- break;
- case "Tasmania":
- state = 5;
- break;
- default:
- state = 0;
- break;
- }
- return state;
- }
- #endregion Address
- private async void SelectContact_Clicked(object sender, EventArgs e)
- {
- _selectionpage = new ContactSelectionPage(
- (contact) =>
- {
- if (contact != null)
- {
- _delivery.Contact.Address.Street = contact.Street;
- _delivery.Contact.Address.City = contact.City;
- _delivery.Contact.Address.PostCode = contact.PostCode;
- _delivery.Contact.Address.State = contact.State;
- }
- }
- );
- Navigation.PushAsync(_selectionpage);
- }
- private void SelectCustomerPage()
- {
- //if (_searching)
- // return;
- //else
- //{
- // _searching = true;
- // GenericSelectionPage page = new GenericSelectionPage
- // (
- // "Select Customer",
- // new SelectionViewModel<CustomerContact>
- // (
- // new Filter<CustomerContact>(x => x.Contact.ID).IsNotEqualTo(Guid.Empty).And(x => x.Contact.Address.Street).IsNotEqualTo(string.Empty),
- // new Expression<Func<CustomerContact, object>>[] { x => x.Contact.Name, x => x.Contact.Address.Street, x => x.Contact.Address.City },
- // new Expression<Func<CustomerContact, object>>[] { x => x.Contact.Address.PostCode, x => x.Contact.ID, x => x.Contact },
- // new SortOrder<CustomerContact>(x => x.Contact.Name)
- // ));
- // page.OnItemSelected += (row) =>
- // {
- // var customerContact = row.ToObject<CustomerContact>();
- // _delivery.Contact.Address.Street = customerContact.Contact.Address.Street;
- // _delivery.Contact.Address.City = customerContact.Contact.Address.City;
- // _delivery.Contact.Address.PostCode = customerContact.Contact.Address.PostCode;
- // _delivery.Contact.Address.State = customerContact.Contact.Address.State;
- // Device.BeginInvokeOnMainThread(() =>
- // {
- // streetEdt.Text = _delivery.Contact.Address.Street;
- // cityEdt.Text = _delivery.Contact.Address.City;
- // postCodeEdt.Text = _delivery.Contact.Address.PostCode;
- // ContactNameLbl.Text = _delivery.Contact.Name;
- // });
- // };
- // Navigation.PushAsync(page);
- //}
- }
- private void SelectSupplierPage()
- {
- //if (_searching)
- // return;
- //else
- //{
- // _searching = true;
- // GenericSelectionPage page = new GenericSelectionPage
- // (
- // "Select Supplier",
- // new SelectionViewModel<SupplierContact>
- // (
- // new Filter<SupplierContact>(x => x.Contact.ID).IsNotEqualTo(Guid.Empty).And(x =>x.Contact.Address.Street).IsNotEqualTo(string.Empty),
- // new Expression<Func<SupplierContact, object>>[] { x => x.Contact.Name, x => x.Contact.Address.Street, x => x.Contact.Address.City },
- // new Expression<Func<SupplierContact, object>>[] { x => x.Contact.Address.PostCode, x => x.Contact.ID, x => x.Contact },
- // new SortOrder<SupplierContact>(x => x.Contact.Name)
- // ));
- // page.OnItemSelected += (row) =>
- // {
- // SupplierContact supplierContact = row.ToObject<SupplierContact>();
- // _delivery.Contact.ID = supplierContact.Contact.ID;
- // _delivery.Contact.Address.Street = supplierContact.Contact.Address.Street;
- // _delivery.Contact.Address.City = supplierContact.Contact.Address.City;
- // _delivery.Contact.Address.PostCode = supplierContact.Contact.Address.PostCode;
- // _delivery.Contact.Address.State = supplierContact.Contact.Address.State;
- // Device.BeginInvokeOnMainThread(() =>
- // {
- // streetEdt.Text = _delivery.Contact.Address.Street;
- // cityEdt.Text = _delivery.Contact.Address.City;
- // postCodeEdt.Text = _delivery.Contact.Address.PostCode;
- // ContactNameLbl.Text = _delivery.Contact.Name;
- // });
- // };
- // Navigation.PushAsync(page);
- //}
- }
- private void SelectOtherPage()
- {
- //if (_searching)
- // return;
- //else
- //{
- // _searching = true;
- // GenericSelectionPage page = new GenericSelectionPage
- // (
- // "Select",
- // new SelectionViewModel<Comal.Classes.Contact>
- // (
- // new Filter<Comal.Classes.Contact>(x => x.Name).IsNotEqualTo(String.Empty).And(x => x.Address.Street).IsNotEqualTo(string.Empty),
- // new Expression<Func<Comal.Classes.Contact, object>>[] { x => x.Name, x => x.Address.Street, x => x.Address.City },
- // new Expression<Func<Comal.Classes.Contact, object>>[] { },
- // new SortOrder<Comal.Classes.Contact>(x => x.Name)
- // ));
- // page.OnItemSelected += (row) =>
- // {
- // Comal.Classes.Contact contact = row.ToObject<Comal.Classes.Contact>();
- // _delivery.Contact.ID = contact.ID;
- // _delivery.Contact.Address.Street = contact.Address.Street;
- // _delivery.Contact.Address.City = contact.Address.City;
- // _delivery.Contact.Address.PostCode = contact.Address.PostCode;
- // _delivery.Contact.Address.State = contact.Address.State;
- // Device.BeginInvokeOnMainThread(() =>
- // {
- // streetEdt.Text = _delivery.Contact.Address.Street;
- // cityEdt.Text = _delivery.Contact.Address.City;
- // postCodeEdt.Text = _delivery.Contact.Address.PostCode;
- // ContactNameLbl.Text = _delivery.Contact.Name;
- // });
- // };
- // Navigation.PushAsync(page);
- //}
- }
-
- private void SelectEmployee_Clicked(object sender, EventArgs e)
- {
- _selectionpage = new EmployeeSelectionPage(
- (employee) =>
- {
- if (employee != null)
- {
- _delivery.Employee.ID = employee.ID;
- _delivery.Employee.Name = employee.Name;
- }
- }
- );
- Navigation.PushAsync(_selectionpage);
- }
- private void DeliveryNotes_Completed(object sender, EventArgs e)
- {
- _delivery.Notes = deliveryNotesEdt.Text;
- }
- #endregion
- #region Photos
-
- async void ChooseImage_Clicked(System.Object sender, System.EventArgs e)
- {
- // try
- // {
- // //openingAnotherPage = true;
- // await CrossMedia.Current.Initialize();
- //
- // if (!CrossMedia.Current.IsPickPhotoSupported)
- // {
- // await DisplayAlert("No Library", ":( No Photo Library available.", "OK");
- // //openingAnotherPage = false;
- // return;
- // }
- //
- // var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions()
- // {
- // CompressionQuality = 10,
- // PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full
- // });
- //
- // if (file == null)
- // {
- // //openingAnotherPage = false;
- // return;
- // }
- //
- // Image img = null;
- // using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Adding Photo"))
- // {
- // var memoryStream = new MemoryStream();
- // file.GetStream().CopyTo(memoryStream);
- // var data = memoryStream.ToArray();
- //
- // Document doc = new Document()
- // {
- // FileName = Path.GetFileName(file.Path),
- // Data = data,
- // CRC = CoreUtils.CalculateCRC(data),
- // TimeStamp = DateTime.Now
- // };
- //
- // SavePhoto(doc);
- //
- // ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- // img = new Image();
- // img.HeightRequest = 150;
- // img.WidthRequest = 150;
- // img.Aspect = Aspect.AspectFit;
- // img.Source = src;
- // img.GestureRecognizers.Add(new TapGestureRecognizer
- // {
- // Command = new Command(OnTap),
- // CommandParameter = src,
- // NumberOfTapsRequired = 1
- // });
- // file.Dispose();
- // }
- // if (img != null)
- // {
- //
- // {
- // //Images.IsVisible = true;
- // //images.Children.Add(img);
- // //openingAnotherPage = false;
- // });
- // //await pageScroller.ScrollToAsync(ImageScroller, ScrollToPosition.Center, false);
- // }
- // }
- // catch { }
- }
- async void SavePhoto(Document doc)
- {
- try
- {
- await Task.Run(() =>
- {
- if (_delivery.ID != Guid.Empty)
- {
- new Client<Document>().Save(doc, "Photo Taken on Device");
- var deliveryDocument = new DeliveryDocument();
- deliveryDocument.EntityLink.ID = _delivery.ID;
- deliveryDocument.DocumentLink.ID = doc.ID;
- deliveryDocument.DocumentLink.FileName = doc.FileName;
- new Client<DeliveryDocument>().Save(deliveryDocument, "Photo Taken on Device");
- existingDocumentIDs.Add(doc.ID);
- }
- else
- {
- newPhotoDocuments.Add(doc);
- }
- });
- }
- catch { }
- }
- async void TakePhoto_Clicked(System.Object sender, System.EventArgs e)
- {
- // try
- // {
- // openingAnotherPage = true;
- // await CrossMedia.Current.Initialize();
- //
- // if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
- // {
- // await DisplayAlert("No Camera", ":( No camera available.", "OK");
- // openingAnotherPage = false;
- // return;
- // }
- //
- // String filename = String.Format("{0:yyyy-MM-dd HH:mm:ss.fff}.png", DateTime.Now);
- //
- // var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
- // {
- // Name = filename,
- // CompressionQuality = 10,
- // PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full
- // });
- //
- // if (file == null)
- // {
- // openingAnotherPage = false;
- // return;
- // }
- //
- // Image img = null;
- // using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Adding Photo"))
- // {
- // var memoryStream = new MemoryStream();
- // file.GetStream().CopyTo(memoryStream);
- // var data = memoryStream.ToArray();
- //
- // Document doc = new Document()
- // {
- // FileName = filename,
- // Data = data,
- // CRC = CoreUtils.CalculateCRC(data),
- // TimeStamp = DateTime.Now
- // };
- //
- // SavePhoto(doc);
- //
- // ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- // img = new Image();
- // img.HeightRequest = 150;
- // img.WidthRequest = 150;
- // img.Aspect = Aspect.AspectFit;
- // img.Source = src;
- // img.GestureRecognizers.Add(new TapGestureRecognizer
- // {
- // Command = new Command(OnTap),
- // CommandParameter = src,
- // NumberOfTapsRequired = 1
- // });
- // file.Dispose();
- // }
- // if (img != null)
- // {
- // Device.BeginInvokeOnMainThread(() =>
- // {
- // ImageScroller.IsVisible = true;
- // images.Children.Add(img);
- // openingAnotherPage = false;
- // });
- // await pageScroller.ScrollToAsync(ImageScroller, ScrollToPosition.Center, false);
- // }
- // }
- // catch { }
- }
- private void OnTap(object obj)
- {
- ImageViewer viewer = new ImageViewer(obj as ImageSource);
- Navigation.PushAsync(viewer);
- }
- #endregion
- private void Docket_Clicked(object sender, EventArgs e)
- {
- try
- {
- //openingAnotherPage = true;
- var docket = new DeliveryDocket(_delivery.Number, dockets);
- Navigation.PushAsync(docket);
- }
- catch { }
- }
- #region last row buttons
- void ConvertToTaskBtn_Clicked(Object sender, EventArgs e)
- {
- _selectionpage = new EmployeeSelectionPage(
- (employee) =>
- {
- if (employee != null)
- {
- Kanban kanban = new Kanban();
- kanban.EmployeeLink.ID = employee.ID;
- ConfirmPerson(employee.Name, kanban);
- }
- }
- );
- Navigation.PushAsync(_selectionpage);
- }
- async void ConfirmPerson(string name, Kanban kanban)
- {
- string chosenOption = await DisplayActionSheet("Confirm send to " + name, "Cancel", null, "Yes", "No");
- switch (chosenOption)
- {
- case "Cancel":
- break;
- case "No":
- break;
- case "Yes":
- CreateKanban(kanban);
- break;
- default:
- break;
- }
- }
- async void CreateKanban(Kanban kanban)
- {
- try
- {
- convertToTaskBtn.Text = "Saving..";
- convertToTaskBtn.IsEnabled = false;
- await Task.Run(() =>
- {
- kanban.ManagerLink.ID = App.Data.Me.ID;
- kanban.Title = "Delivery " + _delivery.Number + System.Environment.NewLine +
- "Delivery Type: " + _delivery.Type.Description + System.Environment.NewLine +
- App.Data.Me.Name + " converted to Task for further action";
- kanban.DueDate = DateTime.Today;
- kanban.Category = "Open";
- if (!_delivery.Job.ID.Equals(Guid.Empty)) kanban.JobLink.ID = _delivery.Job.ID;
- kanban.Description = _delivery.Notes;
- new Client<Kanban>().Save(kanban, "Kanban Created from Deliveries Module");
- _delivery.KanbanNumber = kanban.Number;
- new Client<Delivery>().Save(_delivery, "Updated From Mobile Device");
- List<KanbanDocument> kanbanDocuments = new List<KanbanDocument>();
- if (existingDocumentIDs.Count != 0)
- {
- foreach (Guid id in existingDocumentIDs)
- {
- KanbanDocument kanbanDocument = new KanbanDocument();
- kanbanDocument.DocumentLink.ID = id;
- kanbanDocument.EntityLink.ID = kanban.ID;
- kanbanDocuments.Add(kanbanDocument);
- }
- }
- if (kanbanDocuments.Count != 0)
- {
- new Client<KanbanDocument>().Save(kanbanDocuments, "Updated from mobile device");
- }
- List<KanbanSubscriber> subscribers = new List<KanbanSubscriber>();
- KanbanSubscriber sub1 = new KanbanSubscriber();
- sub1.Kanban.ID = kanban.ID;
- sub1.Employee.ID = kanban.EmployeeLink.ID;
- sub1.Assignee = true;
- subscribers.Add(sub1);
- //KanbanSubscriber sub2 = new KanbanSubscriber();
- //sub2.Kanban.ID = kanban.ID;
- //sub2.Employee.ID = kanban.ManagerLink.ID;
- //sub2.Manager = true;
- //if (sub2.Employee.ID != sub1.Employee.ID)
- // subscribers.Add(sub2);
- new Client<KanbanSubscriber>().Save(subscribers, "Updated from mobile device");
- Device.BeginInvokeOnMainThread(() =>
- {
- convertToTaskBtn.Text = "Saved To Task " + kanban.Number;
- });
- });
- //save kanban - return kanban ID
- //load list of photos - save as kanbandocs
- //save subscribers
- }
- catch { }
- }
-
- #endregion
- }
- }
|