MovementViewer.xaml.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using Xamarin.Forms;
  9. using Xamarin.Forms.Xaml;
  10. namespace PRS.Mobile
  11. {
  12. [XamlCompilation(XamlCompilationOptions.Compile)]
  13. public partial class MovementViewer
  14. {
  15. Guid productID = Guid.Empty;
  16. ObservableList<StockMovementShell_Old> stockMovementShells = new ObservableList<StockMovementShell_Old>();
  17. string productName = "";
  18. public MovementViewer(Guid _productID, string _productName)
  19. {
  20. InitializeComponent();
  21. productID = _productID;
  22. productName = _productName;
  23. LoadMovements();
  24. }
  25. private async void LoadMovements()
  26. {
  27. titleLbl.Text = "Loading Movements...";
  28. await Task.Run(() =>
  29. {
  30. CoreTable table = new Client<StockMovement>().Query
  31. (
  32. new Filter<StockMovement>(x => x.Product.ID).IsEqualTo(productID),
  33. new Columns<StockMovement>(ColumnTypeFlags.None).Add
  34. (
  35. x => x.Date, //0
  36. x => x.Location.Code, //1
  37. x => x.Style.Code, //2
  38. x => x.Qty, //3
  39. x => x.Dimensions.UnitSize //4
  40. ),
  41. new SortOrder<StockMovement>(x => x.Date, SortDirection.Descending)
  42. );
  43. if (table.Rows.Any())
  44. {
  45. string emptyString = "";
  46. foreach (CoreRow row in table.Rows)
  47. {
  48. List<object> list = row.Values;
  49. if (list[0] == null) { list[0] = DateTime.MinValue; } //0
  50. if (list[1] == null) { list[1] = emptyString; } //1
  51. if (list[2] == null) { list[2] = emptyString; } //2
  52. if (list[3] == null) { list[3] = 0.0; } //3
  53. if (list[4] == null) { list[4] = emptyString; } //4
  54. StockMovementShell_Old stockMovementShell = new StockMovementShell_Old();
  55. stockMovementShell.Date = DateTime.Parse(list[0].ToString());
  56. stockMovementShell.Pack = list[1].ToString();
  57. stockMovementShell.Finish = list[2].ToString();
  58. stockMovementShell.Qty = double.Parse(list[3].ToString());
  59. stockMovementShells.Add(stockMovementShell);
  60. qtyLbl.Text = "Qty: (" + list[4].ToString() + ")";
  61. }
  62. }
  63. Device.BeginInvokeOnMainThread(() =>
  64. {
  65. movementListView.ItemsSource = stockMovementShells;
  66. titleLbl.Text = productName;
  67. });
  68. });
  69. }
  70. }
  71. }