123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using iText.StyledXmlParser.Node;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class PurchaseOrderDetails : ContentPage
- {
- List<PurchaseOrderRequiItemShell> shells = new List<PurchaseOrderRequiItemShell>();
- public PurchaseOrderDetails(PurchaseOrderShell purchaseOrderShell)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- LoadList(purchaseOrderShell);
- }
- private void ExitBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- private void LoadList(PurchaseOrderShell purchaseOrderShell)
- {
- try
- {
- CoreTable table = DoPOItemQuery(purchaseOrderShell.ID);
- if (table.Rows.Any())
- GenerateShells(table);
- purchaseOrderItemListView.ItemsSource = shells;
- }
- catch { }
- }
- private void GenerateShells(CoreTable table)
- {
- foreach (CoreRow row in table.Rows)
- {
- shells.Add(CreateShell(row));
- }
- }
- private CoreTable DoPOItemQuery(Guid ID)
- {
- return new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(ID),
- new Columns<PurchaseOrderItem>(
- x => x.ID,
- x => x.Job.JobNumber,
- x => x.Description,
- x => x.Qty,
- x => x.ReceivedDate
- )
- );
- }
- private PurchaseOrderRequiItemShell CreateShell(CoreRow row)
- {
- PurchaseOrderRequiItemShell shell = new PurchaseOrderRequiItemShell
- {
- ID = row.Get<PurchaseOrderItem, Guid>(x => x.ID),
- JobNumber = row.Get<PurchaseOrderItem, string>(x => x.Job.JobNumber),
- Description = row.Get<PurchaseOrderItem, string>(x => x.Description),
- Qty = row.Get<PurchaseOrderItem, double>(x => x.Qty).ToString()
- };
- if (row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate) != DateTime.MinValue)
- shell.ReceivedDate = (row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate)).ToString("dd MMM yy HH:mm");
- return shell;
- }
- private void PoItem_Tapped(object sender, EventArgs e)
- {
- PurchaseOrderRequiItemShell shell = purchaseOrderItemListView.SelectedItem as PurchaseOrderRequiItemShell;
- if (shell.RequiVisible)
- {
- var foundShell = shells.FirstOrDefault(x => x.ID == shell.ID);
- int index = shells.IndexOf(foundShell);
- foundShell.RequiVisible = false;
- foundShell.RequiRowHeight = 0;
- shells.RemoveAt(index);
- shells.Insert(index, foundShell);
- purchaseOrderItemListView.ItemsSource = null;
- purchaseOrderItemListView.ItemsSource = shells;
- }
- else
- {
- CoreTable table = new Client<JobRequisitionItem>().Query(new Filter<JobRequisitionItem>(x => x.PurchaseOrderItem.ID).IsEqualTo(shell.ID),
- new Columns<JobRequisitionItem>(x => x.ID, x => x.Qty, x => x.Requisition.Number, x => x.Product.Code, x => x.Product.Name)
- );
- if (table.Rows.Any())
- {
- CoreRow row = table.Rows.FirstOrDefault();
- var foundShell = shells.FirstOrDefault(x => x.ID == shell.ID);
- int index = shells.IndexOf(foundShell);
- foundShell.RequiNumber = "NO." + (row.Get<JobRequisitionItem, int>(x => x.Requisition.Number)).ToString();
- foundShell.RequiQty = (row.Get<JobRequisitionItem, double>(x => x.Qty)).ToString();
- foundShell.ProductCode = row.Get<JobRequisitionItem, string>(x => x.Product.Name);
- foundShell.RequiVisible = true;
- foundShell.RequiRowHeight = CalculateHeight(foundShell.ProductCode.Length);
- shells.RemoveAt(index);
- shells.Insert(index, foundShell);
- purchaseOrderItemListView.ItemsSource = null;
- purchaseOrderItemListView.ItemsSource = shells;
- }
- }
- }
- private int CalculateHeight(int calculatedHeight)
- {
- if (calculatedHeight > 25)
- calculatedHeight = 25;
- else if (calculatedHeight <= 25 && calculatedHeight < 50)
- calculatedHeight = 50;
- else if (calculatedHeight <= 50 && calculatedHeight < 75)
- calculatedHeight = 75;
- calculatedHeight = calculatedHeight + 60;
- return calculatedHeight;
- }
- }
- public class PurchaseOrderRequiItemShell
- {
- public Guid ID { get; set; }
- public string JobNumber { get; set; }
- public string Description { get; set; }
- public string Qty { get; set; }
- public string ReceivedDate { get; set; }
- public int RequiRowHeight { get; set; }
- public bool RequiVisible { get; set; }
- public string RequiNumber { get; set; }
- public string ProductCode { get; set; }
- public string RequiQty { get; set; }
- public PurchaseOrderRequiItemShell()
- {
- ID = Guid.Empty;
- JobNumber = "";
- Description = "";
- Qty = "";
- ReceivedDate = "";
- RequiRowHeight = 0;
- RequiVisible = false;
- RequiNumber = "";
- ProductCode = "";
- RequiQty = "";
- }
- }
- }
|