SetoutsScreen.xaml.cs 13 KB

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