| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class RecTransferPopup
- {
- public delegate void RecTransferItemAcceptedEvent();
- public delegate void RecTransferPopupBackButtonPressed();
- public event RecTransferItemAcceptedEvent? OnRecTransferItemAccepted;
- public event RecTransferPopupBackButtonPressed? OnRecTransferPopupBackButtonPressed;
- public StockHoldingShell_Old Shell { get; set; }
- Job DefaultJob;
- Job ReceivingJob;
- bool stocktake = false;
- public double OriginalQty = 0.0;
- public RecTransferPopup(StockHoldingShell_Old _shell, Job _defaultJob, Job _receivingJob, bool _stocktake = false)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- stocktake = _stocktake;
- if (_stocktake)
- jobBtn.IsEnabled = false;
- Shell = _shell;
- OriginalQty = _shell.Units;
- DefaultJob = _defaultJob;
- ReceivingJob = _receivingJob;
- if (ReceivingJob.ID != Guid.Empty)
- {
- jobBtn.IsEnabled = false;
- styleBtn.IsEnabled = false;
- }
- LoadImage();
- LoadScreen();
- }
- private void BackBtn_Clicked(object sender, EventArgs e)
- {
- OnRecTransferPopupBackButtonPressed?.Invoke();
- Navigation.PopAsync();
- }
- private void LoadScreen()
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- if (ReceivingJob.ID != Guid.Empty)
- {
- Shell.JobID = ReceivingJob.ID;
- Shell.JobName = ReceivingJob.Name;
- Shell.JobNumber = ReceivingJob.JobNumber;
- Shell.DisplayJob = "Job: " + ReceivingJob.JobNumber;
- jobBtn.Text = Shell.JobNumber;
- }
- else if (Shell.JobID != Guid.Empty)
- {
- jobBtn.Text = Shell.JobNumber;
- }
- else if (DefaultJob.ID != Guid.Empty)
- {
- Shell.JobID = DefaultJob.ID;
- Shell.JobName = DefaultJob.Name;
- Shell.JobNumber = DefaultJob.JobNumber;
- Shell.DisplayJob = "Job: " + DefaultJob.JobNumber;
- jobBtn.Text = Shell.JobNumber;
- }
- if (!string.IsNullOrWhiteSpace(Shell.Finish))
- {
- styleBtn.Text = Shell.Finish;
- }
- qty.Text = Shell.Units.ToString();
- });
- }
- private void SelectJob_Clicked(object sender, EventArgs e)
- {
- if (ReceivingJob.ID != Guid.Empty)
- return;
- var jobSelectionPage = new JobSelectionPage(
- (job) =>
- {
- Shell.JobID = job.ID;
- Shell.JobName = job.Name;
- Shell.JobNumber = job.JobNumber;
- Shell.DisplayJob = "Job: " + Shell.JobNumber;
- jobBtn.Text = Shell.JobNumber;
- }
- );
- Navigation.PushAsync(jobSelectionPage);
- }
- private void SelectStyle_Clicked(object sender, EventArgs e)
- {
- var page = new GenericSelectionPage(
- "Select Product Style",
- new SelectionViewModel<ProductStyle>(
- null,
- new Expression<Func<ProductStyle, object>>[] { x => x.Code, x => x.Description },
- null,
- new SortOrder<ProductStyle>(x => x.Code)
- )
- );
- page.OnItemSelected += (o,e) =>
- {
- var style = e.Row.ToObject<ProductStyle>();
- Shell.StyleID = style.ID;
- Shell.Finish = style.Description;
- Shell.StyleName = "Finish: " + style.Description;
- Shell.StyleCode = style.Code;
- styleBtn.Text = Shell.Finish;
- };
- Navigation.PushAsync(page);
- }
- private void Qty_Changed(object sender, EventArgs e)
- {
- if (!string.IsNullOrWhiteSpace(qty.Text))
- {
- if (double.TryParse(qty.Text, out double value))
- {
- if (value > 0 || stocktake)
- {
- Shell.Units = value;
- Shell.DisplayUnits = "Units: " + Shell.Units;
- accept_Btn.IsEnabled = true;
- }
- else
- {
- qty.Text = OriginalQty.ToString();
- Shell.Units = OriginalQty;
- Shell.DisplayUnits = "Units: " + Shell.Units;
- accept_Btn.IsEnabled = true;
- }
- }
- else
- {
- accept_Btn.IsEnabled = false;
- }
- }
- else
- {
- accept_Btn.IsEnabled = false;
- }
- }
- private void AcceptBtn_Clicked(object sender, EventArgs e)
- {
- if (Shell.Units != 0 || stocktake)
- {
- OnRecTransferItemAccepted?.Invoke();
- Navigation.PopAsync();
- }
- }
- private async void LoadImage()
- {
- await Task.Run(() =>
- {
- CoreTable table = new Client<Product>().Query
- (
- new Filter<Product>(x => x.Code).IsEqualTo(Shell.Code),
- new Columns<Product>(x => x.Image.ID)
- );
- if (table.Rows.Any())
- {
- CoreTable table2 = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(table.Rows.FirstOrDefault().Get<Product, Guid>(x => x.Image.ID)));
- if (table2.Rows.Any())
- {
- CoreRow docrow = table2.Rows.FirstOrDefault();
- if (docrow != null)
- {
- byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
- DataToImage(data);
- }
- }
- }
- });
- }
- private void DataToImage(byte[] data)
- {
- ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- if (src != null)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- productImage.Source = src;
- ForceLayout();
- });
- }
- }
- }
- }
|