| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Xamarin.CommunityToolkit.UI.Views;
- using Xamarin.Essentials;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class RecTrans
- {
- #region Fields + Constructor + Loading
- /// <summary>
- /// The list of available holdings to take from.
- /// </summary>
- private List<StockHoldingShell_Old> issuingHoldings = new List<StockHoldingShell_Old>();
- /// <summary>
- /// The list of items on the right hand side, representing the new locations.
- /// </summary>
- private List<StockHoldingShell_Old> receivingHoldings = new List<StockHoldingShell_Old>();
- /// <summary>
- /// The list of items that have been taken; the originals.
- /// </summary>
- private List<StockHoldingShell_Old> originalHoldings = new List<StockHoldingShell_Old>();
- // We can either be receiving to a job or a location, so only one of these should be non-empty at a time.
- private Job ReceivingJob = new Job();
- private StockLocation ReceivingStockLocation = new StockLocation();
- // We can be issuing from just locations (can't issue from a job).
- private StockLocation IssuingStockLocation = new StockLocation();
- private ProductStyle DefaultStyle = new ProductStyle();
- private ProductStyle PreviousStyle = new ProductStyle();
- private bool bTapping = false;
- private double frameHeight = 80;
- private List<StockLocation> favourites = new List<StockLocation>();
- private readonly StockMovementBatchType BatchType;
- private string DeviceType = "";
- public RecTrans(StockMovementBatchType batchType, string issuingGuidString = "")
- {
- InitializeComponent();
- Title = BatchType == StockMovementBatchType.Issue
- ? "Issue Stock"
- : "Transfer Stock";
- 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)
- {
- 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;
- case "New Location":
- ChooseNewLocation();
- CollapseExpanderOnButtonPress();
- break;
- case "Existing Location":
- ChooseReceivingLocation();
- CollapseExpanderOnButtonPress();
- break;
- default:
- return;
- }
- }
- 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 IssueToLocation(StockLocation location)
- {
- if (location.ID == IssuingStockLocation.ID)
- return;
- // Clear the job, because we're going to a location now.
- ReceivingJob = new Job();
- ReceivingStockLocation = location;
- LoadDefaultStyle();
- Device.BeginInvokeOnMainThread(() =>
- {
- //titleLbl.Text = "Transfer Stock";
- receivingLocationLbl.Text = ReceivingStockLocation.Description;
- });
- }
- private void IssueToJob(JobShell job)
- {
- // Clear the location, because we're going to a job now.
- ReceivingStockLocation = new StockLocation();
- ReceivingJob.ID = job.ID;
- ReceivingJob.Name = job.Name;
- ReceivingJob.JobNumber = job.JobNumber;
- Device.BeginInvokeOnMainThread(() =>
- {
- //titleLbl.Text = "Issue to Job";
- receivingLocationLbl.Text = ReceivingJob.JobNumber;
- });
- }
- private void ReceivingFavouriteChosen(string chosenFavourite)
- {
- StockLocation location = favourites.Find(x => x.Code.Equals(chosenFavourite));
- IssueToLocation(location);
- }
- private void ChooseReceivingLocation()
- {
- StockLocationSelectionPage page = new StockLocationSelectionPage();
- page.OnLocationSelected += (s) =>
- {
- IssueToLocation(new StockLocation
- {
- ID = s.ID,
- Code = s.Code,
- Description = s.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");
- IssueToLocation(loc);
- }
- 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()
- {
- var jobSelectionPage = new JobSelectionPage(
- (job) =>
- {
- IssueToJob(job);
- });
- 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;
- var originalShell = issuingListView.SelectedItem as StockHoldingShell_Old;
- var job = new Job();
- if (ReceivingStockLocation.Job.ID != Guid.Empty)
- {
- job = new Job
- {
- ID = ReceivingStockLocation.Job.ID,
- JobNumber = ReceivingStockLocation.Job.JobNumber,
- Name = ReceivingStockLocation.Job.Name
- };
- }
- var popup = new RecTransferPopup(DuplicateShell(originalShell), job, ReceivingJob);
- popup.OnRecTransferItemAccepted += () =>
- {
- if (popup.Shell.Units == originalShell.Units)
- {
- // Remove from left-hand list, because we can't select any more of this.
- issuingHoldings.Remove(originalShell);
- receivingHoldings.Add(popup.Shell);
- RefreshLists();
- }
- else if (originalShell.Units > popup.Shell.Units)
- {
- originalShell.Units -= popup.Shell.Units;
- originalShell.DisplayUnits = "Units: " + originalShell.Units;
- 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 += () =>
- {
- bTapping = false;
- RefreshLists();
- };
- Navigation.PushAsync(popup);
- }
- private void ReceivingListView_Tapped(object sender, EventArgs e)
- {
- StockHoldingShell_Old shell = receivingListView.SelectedItem as StockHoldingShell_Old;
- RemoveHoldingFromBatch(shell);
- }
- /// <summary>
- /// Remove from the batch being transferred, and put back in the issuing list.
- /// </summary>
- /// <param name="shell"></param>
- private void RemoveHoldingFromBatch(StockHoldingShell_Old shell)
- {
- receivingHoldings.Remove(shell);
- if (issuingHoldings.Find(x => x.ID.Equals(shell.ID)) != null)
- {
- var existingHolding = issuingHoldings.Find(x => x.ID.Equals(shell.ID));
- existingHolding.Units += shell.Units;
- existingHolding.DisplayUnits = "Units: " + existingHolding.Units;
- }
- 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)
- {
- Save.IsEnabled = true;
- }
- else
- {
- Save.IsEnabled = 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)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- CoreTable table = DoQuery(filter);
- while (table == null)
- table = DoQuery(filter);
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- StockHoldingShell_Old shell = new StockHoldingShell_Old();
- shell.ID = row.Get<StockHolding, Guid>(x => x.Location.ID).ToString()
- + row.Get<StockHolding, Guid>(x => x.Product.ID).ToString()
- + row.Get<StockHolding, Guid>(x => x.Job.ID).ToString()
- + row.Get<StockHolding, Guid>(x => x.Style.ID).ToString()
- + row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
- shell.Code = row.Get<StockHolding, string>(x => x.Product.Code);
- shell.Name = row.Get<StockHolding, string>(x => x.Product.Name);
- shell.Finish = row.Get<StockHolding, string>(x => x.Style.Description);
- shell.StyleName = "Finish: " + shell.Finish;
- shell.DimensionsUnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
- shell.Units = row.Get<StockHolding, double>(x => x.Units);
- shell.DisplaySize = "Size: " + shell.DimensionsUnitSize;
- shell.DisplayUnits = "Units: " + shell.Units;
- shell.JobID = row.Get<StockHolding, Guid>(x => x.Job.ID);
- shell.JobName = row.Get<StockHolding, string>(x => x.Job.Name);
- shell.JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber);
- shell.DisplayJob = "Job: " + shell.JobNumber;
- shell.StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID);
- shell.StyleCode = row.Get<StockHolding, string>(x => x.Style.Code);
- shell.ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID);
- shell.ImageID = row.Get<StockHolding, Guid>(x => x.Product.Image.ID);
- shell.DimensionsUnitID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
- shell.DimensionsQuantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
- shell.DimensionsLength = row.Get<StockHolding, double>(x => x.Dimensions.Length);
- shell.DimensionsWidth = row.Get<StockHolding, double>(x => x.Dimensions.Width);
- shell.DimensionsHeight = row.Get<StockHolding, double>(x => x.Dimensions.Height);
- shell.DimensionsWeight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
- shell.DimensionsValue = row.Get<StockHolding, double>(x => x.Dimensions.Value);
- shell.DimensionsHasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
- shell.DimensionsHasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
- shell.DimensionsHasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
- shell.DimensionsHasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
- shell.DimensionsHasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
- shell.DimensionsUnitFormula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
- shell.DimensionsUnitFormat = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
- shell.DimensionsUnitCode = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Code);
- shell.DimensionsUnitDescription = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Description);
- if (!shell.Code.Contains("FREIGHT"))
- {
- if (shell.Units > 0)
- {
- shell.DisplayUnits = "Units: " + shell.Units;
- issuingHoldings.Add(shell);
- }
- }
- }
- }
- RefreshLists();
- LoadProductImages();
- }
- }
- private CoreTable DoQuery(Filter<StockHolding> filter)
- {
- try
- {
- return 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
- x => x.Dimensions.Unit.HasHeight, //21
- x => x.Dimensions.Unit.HasLength, //22
- x => x.Dimensions.Unit.HasWidth, //23
- x => x.Dimensions.Unit.HasWeight, //24
- x => x.Dimensions.Unit.HasQuantity, //25
- x => x.Dimensions.Unit.Formula, //26
- x => x.Dimensions.Unit.Format, //27
- x => x.Dimensions.Unit.Code, //28
- x => x.Dimensions.Unit.Description //29
- ),
- null
- );
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void LoadProductImages()
- {
- Task.Run(() =>
- {
- List<Guid> imageIDs = new List<Guid>();
- foreach (var item in issuingHoldings)
- {
- if (item.ImageID != Guid.Empty)
- imageIDs.Add(item.ImageID);
- }
- CoreTable table = QueryDocuments(imageIDs);
- while (table == null)
- table = QueryDocuments(imageIDs);
- foreach (CoreRow row in table.Rows)
- {
- Guid id = row.Get<Document, Guid>(x => x.ID);
- var item = issuingHoldings.FirstOrDefault(x => x.ImageID == id);
- item.ImageSource = ImageSource.FromStream(() => new MemoryStream(row.Get<Document, byte[]>(x => x.Data)));
- item.ImageVisible = true;
- if (DeviceType == "Tablet")
- {
- item.LastRowHeight = 300;
- }
- else
- {
- item.LastRowHeight = 150;
- }
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- issuingListView.ItemsSource = null;
- issuingListView.ItemsSource = issuingHoldings;
- });
- });
- }
- private CoreTable QueryDocuments(List<Guid> imageIDs)
- {
- try
- {
- return new Client<Document>().Query(new Filter<Document>(x => x.ID).InList(imageIDs.ToArray()),
- new Columns<Document>(x => x.ID, x => x.Data));
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void LoadImages()
- {
- Task.Run(() =>
- {
- foreach (StockHoldingShell_Old 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_Old DuplicateShell(StockHoldingShell_Old shell)
- {
- StockHoldingShell_Old NewShell = new StockHoldingShell_Old()
- {
- 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,
- StyleName = shell.StyleName,
- 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,
- DimensionsHasHeight = shell.DimensionsHasHeight,
- DimensionsHasLength = shell.DimensionsHasLength,
- DimensionsHasWidth = shell.DimensionsHasWidth,
- DimensionsHasWeight = shell.DimensionsHasWeight,
- DimensionsHasQuantity = shell.DimensionsHasQuantity,
- DimensionsUnitFormula = shell.DimensionsUnitFormula,
- DimensionsUnitFormat = shell.DimensionsUnitFormat,
- DimensionsUnitCode = shell.DimensionsUnitCode,
- DimensionsUnitDescription = shell.DimensionsUnitDescription,
- };
- 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
- }
-
- }
|