Site.xaml.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using comal.timesheets.CustomControls;
  2. using System;
  3. using System.Collections.Generic;
  4. using InABox.Core;
  5. using InABox.Configuration;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using Xamarin.Forms;
  9. using Xamarin.Forms.Xaml;
  10. using XF.Material.Forms.UI.Dialogs;
  11. using comal.timesheets.SiteITPModule;
  12. using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
  13. using PRSClasses;
  14. using comal.timesheets.QAForms;
  15. using System.IO;
  16. namespace comal.timesheets
  17. {
  18. [XamlCompilation(XamlCompilationOptions.Compile)]
  19. public partial class Site : ContentPage
  20. {
  21. Job job = new Job();
  22. bool bDocViwerOpen = false;
  23. bool webViewNavigationFinished = false;
  24. public Site(Job _job)
  25. {
  26. InitializeComponent();
  27. NavigationPage.SetHasBackButton(this, false);
  28. job = _job;
  29. if (job.ID != Guid.Empty)
  30. {
  31. selectJobBtn.Text = job.JobNumber + " " + job.Name;
  32. }
  33. //if (Security.IsAllowed<CanViewGeneralJobDocuments>())
  34. // GeneralDocumentsFrame.IsVisible = true;
  35. //if (Security.IsAllowed<CanViewJobDocumentMileStoneFiles>())
  36. // JobDocumentsFrame.IsVisible = true;
  37. }
  38. void BackBtn_Clicked(object sender, EventArgs e)
  39. {
  40. if (bDocViwerOpen)
  41. {
  42. titleLbl.Text = "Site Module";
  43. bDocViwerOpen = false;
  44. Content = siteStackLayout;
  45. }
  46. else
  47. {
  48. Navigation.PopAsync();
  49. }
  50. }
  51. private void SelectJobBtn_Clicked(object sender, EventArgs e)
  52. {
  53. try
  54. {
  55. JobSelectionPage jobSelectionPage = new JobSelectionPage();
  56. jobSelectionPage.OnItemSelected += (() =>
  57. {
  58. JobShell jobshell = jobSelectionPage.Job;
  59. job.ID = jobshell.ID;
  60. job.JobNumber = jobshell.JobNumber;
  61. job.Name = jobshell.Name;
  62. selectJobBtn.Text = jobshell.DisplayName;
  63. });
  64. Navigation.PushAsync(jobSelectionPage);
  65. }
  66. catch { }
  67. }
  68. private void ITPs_Tapped(object sender, EventArgs e)
  69. {
  70. try
  71. {
  72. if (job.ID == Guid.Empty)
  73. {
  74. DisplayAlert("Alert", "Select a job first", "OK");
  75. return;
  76. }
  77. var siteITPChooser = new SiteITPChooser(job);
  78. Navigation.PushAsync(siteITPChooser);
  79. }
  80. catch { }
  81. }
  82. private void JobForms_Tapped(object sender, EventArgs e)
  83. {
  84. try
  85. {
  86. if (job.ID == Guid.Empty)
  87. {
  88. DisplayAlert("Alert", "Select a job first", "OK");
  89. return;
  90. }
  91. DigitalFormsPicker picker = new DigitalFormsPicker("Job", job.ID);
  92. Navigation.PushAsync(picker);
  93. }
  94. catch { }
  95. }
  96. private async void JobDocs_Tapped(object sender, EventArgs e)
  97. {
  98. try
  99. {
  100. if (job.ID == Guid.Empty)
  101. {
  102. DisplayAlert("Alert", "Select a job first", "OK");
  103. return;
  104. }
  105. JobDocViewer viewer = new JobDocViewer(job);
  106. Navigation.PushAsync(viewer);
  107. }
  108. catch (Exception ex)
  109. {
  110. DisplayAlert("Error", ex.Message, "OK");
  111. }
  112. }
  113. private async void SiteDocs_Tapped(object sender, EventArgs e)
  114. {
  115. try
  116. {
  117. if (job.ID == Guid.Empty)
  118. {
  119. DisplayAlert("Alert", "Select a job first", "OK");
  120. return;
  121. }
  122. webViewNavigationFinished = false;
  123. string jobid = job.ID.ToString();
  124. string userid = Encryption.Encrypt(App.Settings.UserID, DateTime.Now.ToString("yyyy-MM-dd"), true);
  125. string password = Encryption.Encrypt(App.Settings.Password, DateTime.Now.ToString("yyyy-MM-dd"), true);
  126. var webSettings = new GlobalConfiguration<WebSettings>().Load();
  127. string fullUrl = webSettings.URL + ":" + webSettings.Port + "/v1/Job/job_documents?id=" + jobid + "&userid=" + userid + "&password=" + password;
  128. Xamarin.Forms.WebView webView = new Xamarin.Forms.WebView() { Source = fullUrl };
  129. webView.On<Xamarin.Forms.PlatformConfiguration.Android>().EnableZoomControls(true);
  130. webView.On<Xamarin.Forms.PlatformConfiguration.Android>().DisplayZoomControls(true);
  131. titleLbl.Text = "View Documents";
  132. bDocViwerOpen = true;
  133. var progress = await MaterialDialog.Instance.LoadingDialogAsync(message: "Connecting to server");
  134. webView.Navigated += (object sender2, WebNavigatedEventArgs e2) => { Device.BeginInvokeOnMainThread(async () => { await progress.DismissAsync(); }); };
  135. Content = webView;
  136. }
  137. catch { }
  138. }
  139. private void Products_Tapped(object sender, EventArgs e)
  140. {
  141. if (GlobalVariables.ProductsLoaded)
  142. {
  143. ProductList products = new ProductList(GlobalVariables.ProductShells);
  144. Navigation.PushAsync(products);
  145. }
  146. else
  147. {
  148. ProductList products = new ProductList();
  149. Navigation.PushAsync(products);
  150. }
  151. }
  152. private void PurchaseOrders_Tapped(object sender, EventArgs e)
  153. {
  154. //if (Security.CanView<PurchaseOrder>())
  155. //{
  156. // if (job.ID == Guid.Empty)
  157. // {
  158. // DisplayAlert("Alert", "Select a job first", "OK");
  159. // return;
  160. // }
  161. //}
  162. }
  163. private void SiteManufacturing_Tapped(object sender, EventArgs e)
  164. {
  165. SiteManufacturing setoutsScreen = new SiteManufacturing(job.ID);
  166. Navigation.PushAsync(setoutsScreen);
  167. }
  168. }
  169. }