123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987 |
- 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 Xamarin.CommunityToolkit.Extensions;
- using Xamarin.CommunityToolkit.UI.Views;
- using Xamarin.Essentials;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class RecTrans : ContentPage
- {
- #region Fields + Constructor + Loading
- List<StockHoldingShell> issuingHoldings = new List<StockHoldingShell>();
- List<StockHoldingShell> receivingHoldings = new List<StockHoldingShell>();
- List<StockHoldingShell> originalHoldings = new List<StockHoldingShell>();
- StockLocation ReceivingStockLocation = new StockLocation();
- StockLocation IssuingStockLocation = new StockLocation();
- ProductStyle DefaultStyle = new ProductStyle();
- ProductStyle PreviousStyle = new ProductStyle();
- Filter<StockHolding> issuingFilter = new Filter<StockHolding>();
- Job ReceivingJob = new Job();
- bool bTapping = false;
- double frameHeight = 80;
- List<StockLocation> favourites = new List<StockLocation>();
- StockMovementBatchType BatchType = new StockMovementBatchType();
- string DeviceType = "";
- public RecTrans(StockMovementBatchType batchType, string issuingGuidString = "")
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- BatchType = batchType;
- var idiom = DeviceInfo.Idiom;
- if (idiom.Equals(DeviceIdiom.Tablet))
- {
- DeviceType = "Tablet";
- }
- //DisplayAlert("Instructions", "1. Select Issuing Location or use default (incoming stores)." + System.Environment.NewLine
- // + System.Environment.NewLine
- // + "2. Select Receiving Location or Job to Issue to." + System.Environment.NewLine
- // + System.Environment.NewLine
- // + "3. Tap items to transfer." + System.Environment.NewLine
- // + System.Environment.NewLine
- // + "4. Save with photos + notes." + System.Environment.NewLine
- // + System.Environment.NewLine
- // + "Note: Exiting loses unsaved work", "OK");
- IssuingStockLocation.PropertyChanged += IssuingStockLocation_PropertyChanged;
- ReceivingStockLocation.PropertyChanged += ReceivingStockLocation_PropertyChanged;
- LoadFavourites();
- ShowHideButtonsBasedOnType();
- LoadFromProductSearch(issuingGuidString);
- }
- private void LoadFromProductSearch(string issuingGuidString)
- {
- if (!string.IsNullOrWhiteSpace(issuingGuidString))
- {
- try
- {
- Guid issuingLocationID = Guid.Parse(issuingGuidString);
- CoreTable table = new Client<StockLocation>().Query(new Filter<StockLocation>(x => x.ID).IsEqualTo(issuingLocationID),
- new Columns<StockLocation>(x => x.ID, x => x.Code, x => x.Description)
- );
- if (table.Rows.Any())
- {
- List<object> list = table.Rows.First().Values;
- IssuingStockLocation.ID = Guid.Parse(list[0].ToString());
- IssuingStockLocation.Code = list[1].ToString();
- IssuingStockLocation.Description = list[2].ToString();
- }
- Filter<StockHolding> filter = new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(issuingLocationID);
- LoadIncomingListData(filter);
- }
- catch { }
- }
- }
- private void ShowHideButtonsBasedOnType()
- {
- if (BatchType == StockMovementBatchType.Issue)
- {
- receivingFavouriteBtn1.IsEnabled = false;
- receivingFavouriteBtn2.IsEnabled = false;
- receivingFavouriteBtn3.IsEnabled = false;
- chooseReceivingLocationBtn.IsVisible = false;
- receivingLocationLbl.Text = "Choose Job";
- titleLbl.Text = "Issue to Job";
- }
- else if (BatchType == StockMovementBatchType.Transfer)
- {
- chooseJobBtn.IsVisible = false;
- }
- }
- #endregion
- #region Issuing Button Presses
- private async void ChooseIssuingLocationBtn_Clicked(object sender, EventArgs e)
- {
- CollapseExpanderOnButtonPress();
- if (receivingHoldings.Count > 0)
- {
- PromptResetScreen();
- }
- else
- {
- ChooseIssuingLocation();
- }
- }
- private void IssuingFavourite_Clicked(object sender, EventArgs e)
- {
- string chosenFavourite = (sender as Button).Text;
- CollapseExpanderOnButtonPress();
- if (receivingHoldings.Count > 0)
- {
- PromptResetScreen(chosenFavourite);
- }
- else
- {
- IssuingFavouriteChosen(chosenFavourite);
- }
- }
- #endregion
- #region Issuing Location Methods
- private void ChooseIssuingLocation()
- {
- StockLocationSelectionPage page = new StockLocationSelectionPage();
- page.OnLocationSelected += (s) =>
- {
- if (ReceivingStockLocation.ID == s.ID)
- return;
- IssuingStockLocation.ID = s.ID;
- IssuingStockLocation.Code = s.Code;
- IssuingStockLocation.Description = s.Description;
- Filter<StockHolding> newIssuingFilter = new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(IssuingStockLocation.ID);
- issuingHoldings.Clear();
- receivingHoldings.Clear();
- LoadIncomingListData(newIssuingFilter);
- Device.BeginInvokeOnMainThread(() =>
- {
- });
- };
- Navigation.PushAsync(page);
- }
- private async void IssuingFavouriteChosen(string chosenFavourite)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- ClearLists();
- StockLocation location = favourites.Find(x => x.Code.Equals(chosenFavourite));
- IssuingStockLocation.ID = location.ID;
- IssuingStockLocation.Code = location.Code;
- IssuingStockLocation.Description = location.Description;
- Filter<StockHolding> filter = new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(IssuingStockLocation.ID);
- LoadIncomingListData(filter);
- }
- }
- #endregion
- #region Receiving Button Presses
- private async void ChooseReceivingLocationBtn_Clicked(object sender, EventArgs e)
- {
- string chosenOption = await DisplayActionSheet("Choose an Option", "Cancel", null, "New Location", "Existing Location");
- switch (chosenOption)
- {
- case "Cancel":
- return;
- break;
- case "New Location":
- ChooseNewLocation();
- CollapseExpanderOnButtonPress();
- break;
- case "Existing Location":
- ChooseReceivingLocation();
- CollapseExpanderOnButtonPress();
- break;
- default:
- return;
- break;
- }
- }
- private void JobBtn_Clicked(object sender, EventArgs e)
- {
- ChooseJob();
- CollapseExpanderOnButtonPress();
- }
- private void ReceivingFavourite_Clicked(object sender, EventArgs e)
- {
- CollapseExpanderOnButtonPress();
- string chosenFavourite = (sender as Button).Text;
- ReceivingFavouriteChosen(chosenFavourite);
- }
- #endregion
- #region Receiving Location Methods
- private void ReceivingFavouriteChosen(string chosenFavourite)
- {
- StockLocation location = favourites.Find(x => x.Code.Equals(chosenFavourite));
- ReceivingStockLocation.ID = location.ID;
- ReceivingStockLocation.Code = location.Code;
- ReceivingStockLocation.Description = location.Description;
- receivingLocationLbl.Text = ReceivingStockLocation.Description;
- }
- private void ChooseReceivingLocation()
- {
- StockLocationSelectionPage page = new StockLocationSelectionPage();
- page.OnLocationSelected += (s) =>
- {
- if (s.ID == IssuingStockLocation.ID)
- return;
- ReceivingStockLocation.ID = s.ID;
- ReceivingStockLocation.Code = s.Code;
- ReceivingStockLocation.Description = s.Description;
- ReceivingJob = new Job();
- LoadDefaultStyle();
- Device.BeginInvokeOnMainThread(() =>
- {
- titleLbl.Text = "Transfer Stock";
- receivingLocationLbl.Text = ReceivingStockLocation.Description;
- });
- };
- Navigation.PushAsync(page);
- }
- private void ChooseNewLocation()
- {
- try
- {
- StockLocation location = new StockLocation();
- location.Active = true;
- location.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
- location.Warehouse.Description = "Extrusions";
- location.Warehouse.Code = "EXTRUSIONS";
- location.Area.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
- location.Area.Warehouse.Description = "Extrusions";
- location.Area.ID = Guid.Parse("fa02ecd8-e642-49aa-98b5-c04d7ea0f4eb"); //Rack FLOOR
- location.Area.Description = "Rack FLOOR";
- location.Area.Code = "FLOOR";
- LocationDetailsPage locationDetailsPage = new LocationDetailsPage(location);
- locationDetailsPage.OnSave += (o, loc) =>
- {
- if (String.IsNullOrWhiteSpace(loc.Code))
- {
- MaterialDialog.Instance.AlertAsync(message: "Code may not be blank!");
- return false;
- }
- if (String.IsNullOrWhiteSpace(loc.Description))
- {
- MaterialDialog.Instance.AlertAsync(message: "Description may not be blank!");
- return false;
- }
- if (loc.Area.ID == Guid.Empty)
- {
- MaterialDialog.Instance.AlertAsync(message: "Area may not be blank!");
- return false;
- }
- CoreTable others = new Client<StockLocation>().Query(
- new Filter<StockLocation>(x => x.Code).IsEqualTo(loc.Code).And(x => x.ID).IsNotEqualTo(loc.ID),
- new Columns<StockLocation>(x => x.ID)
- );
- if (others.Rows.Any())
- {
- MaterialDialog.Instance.AlertAsync(message: "Location Code already exists!");
- return false;
- }
- try
- {
- new Client<StockLocation>().Save(loc, "Created Location");
- ReceivingStockLocation.ID = loc.ID;
- ReceivingStockLocation.Code = loc.Code;
- ReceivingStockLocation.Description = loc.Description;
- LoadDefaultStyle();
- Device.BeginInvokeOnMainThread(() =>
- {
- titleLbl.Text = "Transfer Stock";
- receivingLocationLbl.Text = ReceivingStockLocation.Description;
- });
- }
- catch (Exception err)
- {
- MaterialDialog.Instance.AlertAsync(message: "Unable to save Location\n" + err.Message);
- return false;
- }
- return true;
- };
- Navigation.PushAsync(locationDetailsPage);
- }
- catch { }
- }
- private void ChooseJob()
- {
- JobSelectionPage jobSelectionPage = new JobSelectionPage();
- jobSelectionPage.OnItemSelected += (() =>
- {
- ReceivingStockLocation = new StockLocation();
- ReceivingJob.ID = jobSelectionPage.Job.ID;
- ReceivingJob.Name = jobSelectionPage.Job.Name;
- ReceivingJob.JobNumber = jobSelectionPage.Job.JobNumber;
- Device.BeginInvokeOnMainThread(() =>
- {
- titleLbl.Text = "Issue to Job";
- receivingLocationLbl.Text = ReceivingJob.JobNumber;
- });
- });
- Navigation.PushAsync(jobSelectionPage);
- }
- #endregion
- #region Lists Tapped
- private void IssuingListView_Tapped(object sender, EventArgs e)
- {
- if (ReceivingStockLocation.ID == Guid.Empty && ReceivingJob.ID == Guid.Empty)
- return;
- if (bTapping)
- return;
- bTapping = true;
- StockHoldingShell shell = issuingListView.SelectedItem as StockHoldingShell;
- StockHoldingShell originalShell = DuplicateShell(shell);
- Job job = new Job();
- if (ReceivingStockLocation.Job.ID != Guid.Empty)
- {
- job.ID = ReceivingStockLocation.Job.ID;
- job.JobNumber = ReceivingStockLocation.Job.JobNumber;
- job.Name = ReceivingStockLocation.Job.Name;
- }
- RecTransferPopup popup = new RecTransferPopup(shell, PreviousStyle, job, ReceivingJob);
- popup.OnRecTransferItemAccepted += (() =>
- {
- if (popup.Shell.Units == originalShell.Units)
- {
- issuingHoldings.Remove(shell);
- receivingHoldings.Add(popup.Shell);
- RefreshLists();
- }
- else if (originalShell.Units > popup.Shell.Units)
- {
- int index = issuingHoldings.FindIndex(x => x.ID.Equals(originalShell.ID));
- issuingHoldings.Remove(shell);
- originalShell.Units = originalShell.Units - popup.Shell.Units;
- originalShell.DisplayUnits = "Units: " + originalShell.Units;
- issuingHoldings.Insert(index, originalShell);
- //original shell is updated to remove qty taken away
- receivingHoldings.Add(popup.Shell);
- //popup shell with new properties is added to receiving list
- RefreshLists();
- }
- originalHoldings.Add(originalShell);
- PreviousStyle.ID = popup.Shell.StyleID;
- PreviousStyle.Code = popup.Shell.StyleCode;
- PreviousStyle.Description = popup.Shell.Finish;
- bTapping = false;
- });
- popup.OnRecTransferPopupBackButtonPressed += (() =>
- {
- int index = issuingHoldings.FindIndex(x => x.ID.Equals(originalShell.ID));
- issuingHoldings.Remove(shell);
- issuingHoldings.Insert(index, originalShell);
- bTapping = false;
- RefreshLists();
- });
- Navigation.PushAsync(popup);
- }
- private void ReceivingListView_Tapped(object sender, EventArgs e)
- {
- StockHoldingShell shell = receivingListView.SelectedItem as StockHoldingShell;
- RemoveHoldingFromBatch(shell);
- }
- private void RemoveHoldingFromBatch(StockHoldingShell shell)
- {
- receivingHoldings.Remove(shell);
- if (issuingHoldings.Find(x => x.ID.Equals(shell.ID)) != null)
- {
- StockHoldingShell existingHolding = issuingHoldings.Find(x => x.ID.Equals(shell.ID));
- int index = issuingHoldings.FindIndex(x => x.ID.Equals(existingHolding.ID));
- issuingHoldings.Remove(existingHolding);
- existingHolding.Units = existingHolding.Units + shell.Units;
- existingHolding.DisplayUnits = "Units: " + existingHolding.Units;
- issuingHoldings.Insert(index, existingHolding);
- }
- else
- {
- issuingHoldings.Add(shell);
- }
- RefreshLists();
- }
- #endregion
- #region Refresh Reset Screen
- private async void PromptResetScreen(string chosenFavourite = "")
- {
- string chosenOption = await DisplayActionSheet("This will remove items in current batch", "Cancel", null, "Confirm");
- switch (chosenOption)
- {
- case "Confirm":
- ClearLists();
- if (!string.IsNullOrWhiteSpace(chosenFavourite))
- IssuingFavouriteChosen(chosenFavourite);
- else
- ChooseIssuingLocation();
- break;
- default:
- return;
- }
- }
- private void ClearLists()
- {
- issuingHoldings.Clear();
- receivingHoldings.Clear();
- RefreshLists();
- }
- private void RefreshLists()
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- issuingListView.ItemsSource = null;
- issuingListView.ItemsSource = issuingHoldings;
- receivingListView.ItemsSource = null;
- receivingListView.ItemsSource = receivingHoldings;
- issuingLocationCountLbl.Text = "Items: " + issuingHoldings.Count();
- receivingCountLbl.Text = "Items in Batch: " + receivingHoldings.Count();
- searchEnt.Text = "";
- if (receivingHoldings.Count > 0)
- {
- saveBatchBtn.IsVisible = true;
- }
- else
- {
- saveBatchBtn.IsVisible = false;
- }
- });
- }
- #endregion
- #region Search
- private void SearchEnt_Changed(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(searchEnt.Text))
- {
- issuingListView.ItemsSource = issuingHoldings;
- }
- else
- {
- RunSearch();
- }
- }
- private void RunSearch()
- {
- issuingListView.ItemsSource = issuingHoldings.Where
- (x => x.Code.Contains(searchEnt.Text) || x.Code.Contains(UpperCaseFirst(searchEnt.Text)) || x.Code.Contains(searchEnt.Text.ToLower()) || x.Code.Contains(searchEnt.Text.ToUpper())
- || x.Name.Contains(searchEnt.Text) || x.Name.Contains(UpperCaseFirst(searchEnt.Text)) || x.Name.Contains(searchEnt.Text.ToLower()) || x.Name.Contains(searchEnt.Text.ToUpper())
- || x.Finish.Contains(searchEnt.Text) || x.Finish.Contains(UpperCaseFirst(searchEnt.Text)) || x.Finish.Contains(searchEnt.Text.ToLower()) || x.Finish.Contains(searchEnt.Text.ToUpper())
- );
- }
- static String UpperCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- #endregion
- #region Utils
- private async void LoadIncomingListData(Filter<StockHolding> _filter)
- {
- await Task.Run(() =>
- {
- CoreTable table = new Client<StockHolding>().Query
- (
- _filter,
- new Columns<StockHolding>
- (
- x => x.ID, //0
- x => x.Product.Code, //1
- x => x.Product.Name, //2
- x => x.Style.Description, //3
- x => x.Dimensions.UnitSize, //4
- x => x.Units, //5
- x => x.Location.ID, //6
- x => x.Job.ID, //7
- x => x.Job.Name, //8
- x => x.Job.JobNumber, //9
- x => x.Style.ID, //10
- x => x.Style.Code, //11
- x => x.Product.ID, //12
- x => x.Product.Image.ID, //13
- x => x.Dimensions.Unit.ID, //14
- x => x.Dimensions.Quantity, //15
- x => x.Dimensions.Length, //16
- x => x.Dimensions.Width, //17
- x => x.Dimensions.Height, //18
- x => x.Dimensions.Weight, //19
- x => x.Dimensions.Value //20
- ),
- null
- );
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = Guid.Empty; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = ""; } //2
- if (list[3] == null) { list[3] = ""; } //3
- if (list[4] == null) { list[4] = ""; } //4
- if (list[5] == null) { list[5] = 0.0; } //5
- if (list[6] == null) { list[6] = Guid.Empty; } //6
- if (list[7] == null) { list[7] = Guid.Empty; } //7
- if (list[8] == null) { list[8] = ""; } //8
- if (list[9] == null) { list[9] = ""; } //9
- if (list[10] == null) { list[10] = Guid.Empty; } //10
- if (list[11] == null) { list[11] = ""; } //11
- if (list[12] == null) { list[12] = Guid.Empty; } //12
- if (list[13] == null) { list[13] = Guid.Empty; } //13
- if (list[14] == null) { list[14] = Guid.Empty; } //14
- if (list[15] == null) { list[15] = 0.0; } //15
- if (list[16] == null) { list[16] = 0.0; } //16
- if (list[17] == null) { list[17] = 0.0; } //17
- if (list[18] == null) { list[18] = 0.0; } //18
- if (list[19] == null) { list[19] = 0.0; } //19
- if (list[20] == null) { list[20] = 0.0; } //20
- StockHoldingShell shell = new StockHoldingShell();
- shell.ID = Guid.Parse(list[0].ToString());
- shell.Code = list[1].ToString();
- shell.Name = list[2].ToString();
- shell.Finish = list[3].ToString();
- shell.DisplayFinish = "Finish: " + list[3].ToString();
- shell.DimensionsUnitSize = list[4].ToString();
- shell.Units = double.Parse(list[5].ToString());
- shell.DisplaySize = "Size: " + list[4].ToString();
- shell.DisplayUnits = "Units: " + shell.Units;
- shell.JobID = Guid.Parse(list[7].ToString());
- shell.JobName = list[8].ToString();
- shell.JobNumber = list[9].ToString();
- shell.DisplayJob = "Job: " + shell.JobNumber;
- shell.StyleID = Guid.Parse(list[10].ToString());
- shell.StyleCode = list[11].ToString();
- shell.ProductID = Guid.Parse(list[12].ToString());
- shell.ImageID = Guid.Parse(list[13].ToString());
- shell.DimensionsUnitID = Guid.Parse(list[14].ToString());
- shell.DimensionsQuantity = double.Parse(list[15].ToString());
- shell.DimensionsLength = double.Parse(list[16].ToString());
- shell.DimensionsWidth = double.Parse(list[17].ToString());
- shell.DimensionsHeight = double.Parse(list[18].ToString());
- shell.DimensionsWeight = double.Parse(list[19].ToString());
- shell.DimensionsValue = double.Parse(list[20].ToString());
- double units = 0.0;
- if (!shell.Code.Contains("FREIGHT"))
- {
- if (double.TryParse(list[5].ToString(), out units))
- {
- if (units > 0)
- {
- shell.DisplayUnits = "Units: " + shell.Units;
- issuingHoldings.Add(shell);
- }
- }
- }
- }
- }
- RefreshLists();
- LoadImages();
- });
- }
- private void LoadImages()
- {
- Task.Run(() =>
- {
- foreach (StockHoldingShell shell in issuingHoldings)
- {
- if (shell.ImageID != Guid.Empty)
- {
- CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(shell.ImageID));
- if (table.Rows.Any())
- {
- CoreRow docrow = table.Rows.FirstOrDefault();
- if (docrow != null)
- {
- byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
- ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- if (src != null)
- {
- shell.ImageSource = src;
- shell.ImageVisible = true;
- if (DeviceType == "Tablet")
- {
- shell.LastRowHeight = 300;
- }
- else
- {
- shell.LastRowHeight = 150;
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- issuingListView.ItemsSource = null;
- issuingListView.ItemsSource = issuingHoldings;
- });
- }
- }
- }
- }
- }
- });
- }
- private void CollapseExpanderOnButtonPress()
- {
- if (issuingExpander.State.Equals(ExpandState.Expanding) || issuingExpander.State.Equals(ExpandState.Expanded))
- {
- issuingExpander.IsExpanded = false;
- issuingFrame.HeightRequest = frameHeight;
- ForceLayout();
- }
- if (receivingExpander.State.Equals(ExpandState.Expanding) || receivingExpander.State.Equals(ExpandState.Expanded))
- {
- receivingExpander.IsExpanded = false;
- receivingFrame.HeightRequest = frameHeight;
- ForceLayout();
- }
- }
- //TODO
- private StockHoldingShell DuplicateShell(StockHoldingShell shell)
- {
- StockHoldingShell NewShell = new StockHoldingShell()
- {
- ID = shell.ID,
- Code = shell.Code,
- Name = shell.Name,
- Finish = shell.Finish,
- Units = shell.Units,
- DisplayUnits = shell.DisplayUnits,
- JobID = shell.JobID,
- JobName = shell.JobName,
- JobNumber = shell.JobNumber,
- DisplayJob = shell.DisplayJob,
- DisplayFinish = shell.DisplayFinish,
- StyleID = shell.StyleID,
- StyleCode = shell.StyleCode,
- ProductID = shell.ProductID,
- DisplaySize = shell.DisplaySize,
- LastRowHeight = shell.LastRowHeight,
- ImageID = shell.ImageID,
- ImageSource = shell.ImageSource,
- ImageVisible = shell.ImageVisible,
- DimensionsUnitID = shell.DimensionsUnitID,
- DimensionsQuantity = shell.DimensionsQuantity,
- DimensionsLength = shell.DimensionsLength,
- DimensionsWidth = shell.DimensionsWidth,
- DimensionsHeight = shell.DimensionsHeight,
- DimensionsWeight = shell.DimensionsWeight,
- DimensionsValue = shell.DimensionsValue,
- DimensionsUnitSize = shell.DimensionsUnitSize,
- };
- return NewShell;
- }
- private void IssuingExpander_Tapped(object sender, EventArgs e)
- {
- if (issuingExpander.State.Equals(ExpandState.Expanding) || issuingExpander.State.Equals(ExpandState.Expanded))
- {
- }
- else if (issuingExpander.State.Equals(ExpandState.Collapsing) || issuingExpander.State.Equals(ExpandState.Collapsed))
- {
- issuingFrame.HeightRequest = frameHeight;
- ForceLayout();
- }
- }
- private void ReceivingExpander_Tapped(object sender, EventArgs e)
- {
- if (receivingExpander.State.Equals(ExpandState.Expanding) || receivingExpander.State.Equals(ExpandState.Expanded))
- {
- }
- else if (receivingExpander.State.Equals(ExpandState.Collapsing) || receivingExpander.State.Equals(ExpandState.Collapsed))
- {
- receivingFrame.HeightRequest = frameHeight;
- ForceLayout();
- }
- }
- private void ReceivingStockLocation_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- receivingLocationLbl.Text = ReceivingStockLocation.Description;
- });
- }
- private void IssuingStockLocation_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- issuingLocationLbl.Text = IssuingStockLocation.Description;
- });
- }
- private async void LoadDefaultStyle()
- {
- try
- {
- await Task.Run(() =>
- {
- CoreTable table = new Client<Job>().Query(
- new Filter<Job>(x => x.ID).IsEqualTo(ReceivingStockLocation.Job.ID),
- new Columns<Job>(x => x.Style.ID, x => x.Style.Code, x => x.Style.Description)
- );
- if (table.Rows.Any())
- {
- List<object> list = table.Rows.First().Values;
- if (list[0] == null) { list[0] = Guid.Empty; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = ""; } //2
- DefaultStyle.ID = Guid.Parse(list[0].ToString());
- DefaultStyle.Code = list[1].ToString();
- DefaultStyle.Description = list[2].ToString();
- }
- });
- }
- catch { }
- }
- private void LoadFavourites()
- {
- try
- {
- CoreTable table = new Client<StockLocation>().Query
- (
- new Filter<StockLocation>(x => x.Favourite).IsEqualTo(true),
- new Columns<StockLocation>(x => x.ID, x => x.Code, x => x.Description)
- );
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- if (favourites.Count < 3)
- {
- 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] = "";
- StockLocation location = new StockLocation()
- {
- ID = Guid.Parse(list[0].ToString()),
- Code = list[1].ToString(),
- Description = list[2].ToString(),
- };
- favourites.Add(location);
- }
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- if (favourites.Count == 0)
- {
- DisableButtonOne();
- DisableButtonTwo();
- DisableButtonThree();
- }
- if (favourites.Count == 1)
- {
- issuingFavouriteBtn1.Text = favourites[0].Code;
- receivingFavouriteBtn1.Text = favourites[0].Code;
- DisableButtonTwo();
- DisableButtonThree();
- }
- if (favourites.Count == 2)
- {
- issuingFavouriteBtn1.Text = favourites[0].Code;
- receivingFavouriteBtn1.Text = favourites[0].Code;
- issuingFavouriteBtn2.Text = favourites[1].Code;
- receivingFavouriteBtn2.Text = favourites[1].Code;
- DisableButtonThree();
- }
- if (favourites.Count == 3)
- {
- issuingFavouriteBtn1.Text = favourites[0].Code;
- receivingFavouriteBtn1.Text = favourites[0].Code;
- issuingFavouriteBtn2.Text = favourites[1].Code;
- receivingFavouriteBtn2.Text = favourites[1].Code;
- issuingFavouriteBtn3.Text = favourites[2].Code;
- receivingFavouriteBtn3.Text = favourites[2].Code;
- }
- });
- }
- }
- catch
- {
- }
- }
- void DisableButtonOne()
- {
- issuingFavouriteBtn1.Text = "Not set";
- issuingFavouriteBtn1.IsEnabled = false;
- receivingFavouriteBtn1.Text = "Not set";
- receivingFavouriteBtn1.IsEnabled = false;
- }
- void DisableButtonTwo()
- {
- issuingFavouriteBtn2.Text = "Not set";
- issuingFavouriteBtn2.IsEnabled = false;
- receivingFavouriteBtn2.Text = "Not set";
- receivingFavouriteBtn2.IsEnabled = false;
- }
- void DisableButtonThree()
- {
- issuingFavouriteBtn3.Text = "Not set";
- issuingFavouriteBtn3.IsEnabled = false;
- receivingFavouriteBtn3.Text = "Not set";
- receivingFavouriteBtn3.IsEnabled = false;
- }
- #endregion
- #region Page Navigation / Saving
- private async void ExitWithoutSaving(object sender, EventArgs e)
- {
- if (receivingHoldings.Count > 0)
- {
- string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
- switch (chosenOption)
- {
- case "Cancel":
- return;
- case "Yes":
- Navigation.PopAsync();
- break;
- case "No":
- return;
- default:
- return;
- }
- }
- else
- Navigation.PopAsync();
- }
- private void SaveBatch_Clicked(object sender, EventArgs e)
- {
- if (receivingHoldings.Count == 0)
- return;
- if (ReceivingStockLocation.ID == Guid.Empty && ReceivingJob.ID == Guid.Empty)
- return;
- RecTransCompletion completionPage = new RecTransCompletion(receivingHoldings, originalHoldings, IssuingStockLocation, ReceivingStockLocation, ReceivingJob);
- completionPage.OnRecTransCompleted += (() =>
- {
- ReceivingStockLocation = new StockLocation();
- ReceivingJob = new Job();
- receivingLocationLbl.Text = "Receiving Location:";
- receivingHoldings.Clear();
- originalHoldings.Clear();
- issuingListView.ItemsSource = null;
- receivingListView.ItemsSource = null;
- PreviousStyle = new ProductStyle();
- RefreshLists();
- });
- Navigation.PushAsync(completionPage);
- }
- #endregion
- }
- public class StockHoldingShell
- {
- public Guid ID { get; set; }
- public string Code { get; set; }
- public string Name { get; set; }
- public string DisplayFinish { get; set; }
- public string DisplayUnits { get; set; }
- public string Finish { get; set; } //style.description
- public double Units { get; set; }
- public Guid JobID { get; set; }
- public string JobName { get; set; }
- public string JobNumber { get; set; }
- public string DisplayJob { get; set; }
- public Guid StyleID { get; set; }
- public string StyleCode { get; set; }
- public Guid ProductID { get; set; }
- public string DisplaySize { get; set; }
- public double LastRowHeight { get; set; }
- public bool ImageVisible { get; set; }
- public ImageSource ImageSource { get; set; }
- public Guid ImageID { get; set; }
- public Color Color { get; set; }
- public Guid DimensionsUnitID { get; set; }
- public double DimensionsQuantity { get; set; }
- public double DimensionsLength { get; set; }
- public double DimensionsWidth { get; set; }
- public double DimensionsHeight { get; set; }
- public double DimensionsWeight { get; set; }
- public double DimensionsValue { get; set; }
- public string DimensionsUnitSize { get; set; }
- public StockHoldingShell()
- {
- ID = Guid.Empty;
- Code = "";
- Name = "";
- DisplayFinish = "";
- DisplayUnits = "";
- Finish = "";
- Units = 0.0;
- JobID = Guid.Empty;
- JobName = "";
- JobNumber = "";
- DisplayJob = "";
- StyleID = Guid.Empty;
- StyleCode = "";
- ProductID = Guid.Empty;
- DisplaySize = "";
- LastRowHeight = 0;
- ImageVisible = false;
- ImageSource = "";
- ImageID = Guid.Empty;
- Color = Color.Default;
- DimensionsUnitID = Guid.Empty;
- DimensionsQuantity = 0;
- DimensionsLength = 0;
- DimensionsWidth = 0;
- DimensionsHeight = 0;
- DimensionsWeight = 0;
- DimensionsValue = 0;
- DimensionsUnitSize = "";
- }
- }
- }
|