SetoutsScreen.xaml.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using comal.timesheets.CustomControls;
  2. using comal.timesheets.Data_Classes;
  3. using Comal.Classes;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using Xamarin.Forms;
  13. using Xamarin.Forms.Xaml;
  14. using XF.Material.Forms.UI.Dialogs;
  15. namespace comal.timesheets
  16. {
  17. [XamlCompilation(XamlCompilationOptions.Compile)]
  18. public partial class SetoutsScreen : ContentPage
  19. {
  20. #region Constructor / navigation
  21. Guid JobID = new Guid();
  22. List<SetoutShell> Setouts = new List<SetoutShell>();
  23. List<ManufacturingPacketShell> packets = new List<ManufacturingPacketShell>();
  24. Dictionary<string, Guid> fileNameIDS = new Dictionary<string, Guid>();
  25. public SetoutsScreen()
  26. {
  27. InitializeComponent();
  28. NavigationPage.SetHasBackButton(this, false);
  29. if (Device.RuntimePlatform == Device.iOS)
  30. {
  31. closeImg.HeightRequest = 45;
  32. closeImg.WidthRequest = 45;
  33. }
  34. }
  35. private void ExitBtn_Clicked(object sender, EventArgs e)
  36. {
  37. Navigation.PopAsync();
  38. }
  39. #endregion
  40. #region Loading Setouts
  41. private async void LoadSetouts()
  42. {
  43. try
  44. {
  45. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  46. {
  47. AddSetoutsToList(DoSetoutsQuery());
  48. DisplayList();
  49. }
  50. }
  51. catch { }
  52. }
  53. private CoreTable DoSetoutsQuery()
  54. {
  55. CoreTable table = new Client<Setout>().Query
  56. (
  57. new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(JobID),
  58. new Columns<Setout>(
  59. x => x.ID,
  60. x => x.Number,
  61. x => x.Description
  62. )
  63. );
  64. return table;
  65. }
  66. private void AddSetoutsToList(CoreTable table)
  67. {
  68. foreach (CoreRow row in table.Rows)
  69. Setouts.Add(CreateSetoutShell(row));
  70. }
  71. private SetoutShell CreateSetoutShell(CoreRow row)
  72. {
  73. List<object> list = row.Values;
  74. if (list[0] == null) list[0] = Guid.Empty;
  75. if (list[1] == null) list[1] = "";
  76. if (list[2] == null) list[2] = "";
  77. SetoutShell shell = new SetoutShell();
  78. shell.ID = Guid.Parse(list[0].ToString());
  79. shell.Number = list[1].ToString();
  80. shell.Description = list[2].ToString();
  81. return shell;
  82. }
  83. private void DisplayList()
  84. {
  85. Device.BeginInvokeOnMainThread(() =>
  86. {
  87. setoutsListView.ItemsSource = Setouts;
  88. });
  89. }
  90. #endregion
  91. #region Button Presses
  92. private void JobsBtn_Clicked(object sender, EventArgs e)
  93. {
  94. JobSelectionPage page = new JobSelectionPage();
  95. page.OnItemSelected += () =>
  96. {
  97. JobID = page.Job.ID;
  98. jobBtn.Text = page.Job.JobNumber + " " + page.Job.Name;
  99. LoadSetouts();
  100. };
  101. Navigation.PushAsync(page);
  102. }
  103. private void SetoutsListView_Tapped(object sender, EventArgs e)
  104. {
  105. try
  106. {
  107. SetoutShell shell = setoutsListView.SelectedItem as SetoutShell;
  108. QueryPDFsAndPackets(shell.ID);
  109. DisplayPackets();
  110. }
  111. catch { }
  112. }
  113. private async void ClosePackets_Clicked(object sender, EventArgs e)
  114. {
  115. await packetsFrame.TranslateTo(0, 900, 500);
  116. packetsFrame.IsVisible = false;
  117. packetsFrame.TranslateTo(0, 0, 500);
  118. packetsFrame.IsVisible = false;
  119. packetRow.Height = 0;
  120. }
  121. private void PDFs_Tapped(object sender, EventArgs e)
  122. {
  123. PDFList list = new PDFList(fileNameIDS);
  124. Navigation.PushAsync(list);
  125. }
  126. private void PacketListView_Tapped(object sender, EventArgs e)
  127. {
  128. ManufacturingPacketShell shell = packetListView.SelectedItem as ManufacturingPacketShell;
  129. ManufacturingPacketPopup popup = new ManufacturingPacketPopup(shell.ID, shell.OrderID);
  130. Navigation.PushAsync(popup);
  131. }
  132. #endregion
  133. #region Loading Setout Details (Packets and PDFs)
  134. private async void DisplayPackets()
  135. {
  136. packetsFrame.IsVisible = false;
  137. int height = 60 + (packets.Count * 150);
  138. if (height > 600)
  139. height = 600;
  140. packetRow.Height = height;
  141. packetListView.ItemsSource = null;
  142. packetListView.ItemsSource = packets;
  143. packetsLbl.Text = "Packets (" + packets.Count + ")";
  144. await packetsFrame.TranslateTo(0, 900, 0);
  145. packetsFrame.IsVisible = true;
  146. await packetsFrame.TranslateTo(0, 0, 500);
  147. }
  148. private void QueryPDFsAndPackets(Guid setoutID)
  149. {
  150. QueryPackets(setoutID);
  151. Task.Run(() => { QueryPDFs(setoutID); });
  152. }
  153. private void AddPacketsToList(CoreTable table)
  154. {
  155. packets.Clear();
  156. foreach (CoreRow row in table.Rows)
  157. packets.Add(CreatePacket(row));
  158. }
  159. private ManufacturingPacketShell CreatePacket(CoreRow row)
  160. {
  161. List<object> list = row.Values;
  162. if (list[0] == null) { list[0] = ""; } //0
  163. if (list[1] == null) { list[1] = 0; } //1
  164. if (list[2] == null) { list[2] = Guid.Empty; } //2
  165. if (list[3] == null) { list[3] = ""; } //3
  166. if (list[4] == null) { list[4] = ""; } //4
  167. if (list[5] == null) { list[5] = ""; } //5
  168. if (list[6] == null) { list[6] = DateTime.MinValue; } //6
  169. if (list[7] == null) { list[7] = DateTime.MinValue; } //7
  170. if (list[8] == null) { list[8] = 0; } //8
  171. if (list[9] == null) { list[9] = 0.0; } //9
  172. if (list[10] == null) { list[10] = ""; } //10
  173. if (list[11] == null) { list[11] = ""; } //11
  174. if (list[12] == null) { list[12] = ""; } //12
  175. if (list[13] == null) { list[13] = Guid.Empty; } //13
  176. if (list[14] == null) { list[14] = ""; } //14
  177. if (list[15] == null) { list[15] = Guid.Empty; } //15
  178. if (list[16] == null) { list[16] = ""; } //16
  179. if (list[17] == null) { list[17] = ""; } //17
  180. if (list[18] == null) { list[18] = ""; } //18
  181. if (list[19] == null) { list[19] = ""; } //19
  182. if (list[20] == null) { list[20] = Guid.Empty; } //20
  183. if (list[21] == null) { list[21] = DateTime.MinValue; } //21
  184. if (list[22] == null) { list[22] = DateTime.MinValue; } //22
  185. if (list[23] == null) { list[23] = Guid.Empty; } //23
  186. ManufacturingPacketShell shell = new ManufacturingPacketShell()
  187. {
  188. Title = list[0].ToString(),
  189. Quantity = list[1].ToString(),
  190. DrawingID = Guid.Parse(list[2].ToString()),
  191. StageLinkSection = list[3].ToString(),
  192. JobNumber = list[4].ToString(),
  193. ITPCode = list[4].ToString() + " " + list[5].ToString(),
  194. Created = "C: " + DateTime.Parse(list[6].ToString()).ToString("dd MMM yy"),
  195. DueDate = "D: " + DateTime.Parse(list[7].ToString()).ToString("dd MMM yy"),
  196. StageLinkStation = int.Parse(list[8].ToString()),
  197. StageLinkPercentage = list[9].ToString() + "%",
  198. FactoryName = list[10].ToString(),
  199. Location = list[11].ToString(),
  200. SetoutID = Guid.Parse(list[13].ToString()),
  201. SetoutNumber = list[14].ToString(),
  202. ID = Guid.Parse(list[15].ToString()),
  203. TemplateLinkCode = list[16].ToString(),
  204. JobName = list[17].ToString(),
  205. OrderID = Guid.Parse(list[20].ToString()),
  206. OrderRecDate = DateTime.Parse(list[21].ToString()),
  207. JobID = Guid.Parse(list[23].ToString()),
  208. };
  209. if (!string.IsNullOrWhiteSpace(list[18].ToString()))
  210. {
  211. shell.Serial = "[" + list[18].ToString() + "] " + list[12].ToString() + ":";
  212. }
  213. else
  214. {
  215. shell.Serial = list[12].ToString();
  216. }
  217. if (!string.IsNullOrWhiteSpace(shell.StageLinkSection))
  218. shell.StageLinkPercentage = shell.StageLinkPercentage + " of " + shell.StageLinkSection;
  219. else
  220. shell.StageLinkPercentage = "TBI";
  221. if (!string.IsNullOrWhiteSpace(list[19].ToString()))
  222. {
  223. shell.ImagePath = "notifications.png";
  224. shell.ImageHeight = 25.0;
  225. shell.ImageWidth = 25.0;
  226. if (Device.RuntimePlatform.Equals(Device.iOS))
  227. {
  228. shell.ImageHeight = 35.0;
  229. shell.ImageWidth = 35.0;
  230. }
  231. }
  232. if (shell.OrderID != Guid.Empty && shell.OrderRecDate == DateTime.MinValue)
  233. {
  234. shell.OnOrderVisible = true;
  235. shell.LastRowHeight = 30;
  236. if (DateTime.TryParse(list[22].ToString(), out DateTime ETA))
  237. {
  238. shell.OrderETA = "ON ORDER ETA: " + ETA.ToString("dd MMM yy");
  239. }
  240. else
  241. {
  242. shell.OrderETA = "ON ORDER";
  243. }
  244. }
  245. return shell;
  246. }
  247. private void QueryPDFs(Guid setoutID)
  248. {
  249. fileNameIDS.Clear();
  250. CoreTable table = new Client<SetoutDocument>().Query
  251. (
  252. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutID),
  253. new Columns<SetoutDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
  254. );
  255. if (table.Rows.Any())
  256. {
  257. foreach (CoreRow row in table.Rows)
  258. {
  259. fileNameIDS.Add(row.Get<string>("DocumentLink.FileName"), row.Get<Guid>("DocumentLink.ID"));
  260. }
  261. }
  262. Device.BeginInvokeOnMainThread(() =>
  263. {
  264. numberOfDocsLbl.Text = fileNameIDS.Count.ToString();
  265. });
  266. }
  267. private void QueryPackets(Guid setoutID)
  268. {
  269. AddPacketsToList(new Client<ManufacturingPacket>().Query
  270. (
  271. new Filter<ManufacturingPacket>(x => x.SetoutLink.ID).IsEqualTo(setoutID),
  272. Columns
  273. ));
  274. }
  275. Columns<ManufacturingPacket> Columns = new Columns<ManufacturingPacket>(
  276. x => x.Title, //0
  277. x => x.Quantity, //1
  278. x => x.Drawing.ID, //2
  279. x => x.StageLink.Section, //3
  280. x => x.SetoutLink.JobLink.JobNumber, //4
  281. x => x.ITP.Code, //5
  282. x => x.Created, //6
  283. x => x.DueDate, //7
  284. x => x.StageLink.Station, //8
  285. x => x.StageLink.PercentageComplete, //9
  286. x => x.ManufacturingTemplateLink.Factory.Name, //10
  287. x => x.Location, //11
  288. x => x.Serial, //12
  289. x => x.SetoutLink.ID, //13
  290. x => x.SetoutLink.Number, //14
  291. x => x.ID, //15
  292. x => x.ManufacturingTemplateLink.Code, //16
  293. x => x.SetoutLink.JobLink.Name, //17
  294. x => x.WaterMark, //18
  295. x => x.Issues, //19
  296. x => x.OrderItem.ID, //20
  297. x => x.OrderItem.ReceivedDate, //21
  298. x => x.OrderItem.Consignment.EstimatedWarehouseArrival, //22
  299. x => x.SetoutLink.JobLink.ID //23
  300. );
  301. #endregion
  302. #region Searching
  303. private void SearchEnt_Changed(object sender, EventArgs e)
  304. {
  305. if (!string.IsNullOrWhiteSpace(searchEnt.Text))
  306. setoutsListView.ItemsSource = Setouts.Where(x => x.Number.Contains(searchEnt.Text)
  307. || x.Description.Contains(searchEnt.Text) || x.Description.Contains(SearchUtils.UpperCaseFirst(searchEnt.Text))
  308. || x.Description.Contains(searchEnt.Text.ToLower()) || x.Description.Contains(searchEnt.Text.ToUpper()));
  309. else
  310. setoutsListView.ItemsSource = Setouts;
  311. }
  312. #endregion
  313. }
  314. public class SetoutShell
  315. {
  316. public Guid ID { get; set; }
  317. public string Number { get; set; }
  318. public string Description { get; set; }
  319. public SetoutShell()
  320. {
  321. ID = Guid.Empty;
  322. Number = "";
  323. Description = "";
  324. }
  325. }
  326. }