MainPage.xaml.cs 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using InABox.Core;
  8. using InABox.Configuration;
  9. using InABox.Clients;
  10. using InABox.Mobile;
  11. using Comal.Classes;
  12. using XF.Material.Forms.UI.Dialogs;
  13. using comal.timesheets.CustomControls;
  14. using comal.timesheets.StoreRequis;
  15. using PRSSecurity = InABox.Core.Security;
  16. using Plugin.LocalNotification;
  17. using comal.timesheets.Tasks;
  18. using System.IO;
  19. namespace comal.timesheets
  20. {
  21. public partial class MainPage : ContentPage
  22. {
  23. #region Fields
  24. List<ToolEntry> toolEntries = new List<ToolEntry>();
  25. private TimeSheet _timesheet = null;
  26. private Employee _employee = null;
  27. private CoreTable _jobs = null;
  28. public bool SettingsChanged { get; private set; }
  29. bool bUpdatingTimesheet = false;
  30. bool firstLoad = true;
  31. bool recentlyAskedToUpdate = true;
  32. int updateCounter;
  33. public static ConnectionSettings connectionSettings = null;
  34. bool midnightTimerOn = false;
  35. DateTime oneSecondBeforeMidnight = DateTime.Today.AddSeconds(864399);
  36. bool clockedOffInLast5Seconds = false;
  37. bool bRecentlyUpdatedTiles = false;
  38. bool bSharedDeviceFirstLoad = true;
  39. bool bSharedDevice = false;
  40. int NumberOfNotfications = 0;
  41. private JobShell _job = new JobShell();
  42. string deviceName = "";
  43. string matchedDeviceName = "";
  44. int notCount = 1;
  45. Assignment currentAssignment = null;
  46. #endregion
  47. #region Constructor
  48. public MainPage()
  49. {
  50. InitializeComponent();
  51. try
  52. {
  53. App.GPS.OnLocationFound += LocationFound;
  54. App.GPS.OnLocationError += LocationError;
  55. App.Bluetooth.OnScanFinished += ScanFinished;
  56. App.Data.DataChanged += DataChanged;
  57. App.Data.DataRefreshed += DataRefreshed;
  58. GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
  59. GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
  60. App.Data.Employee.ID = GlobalVariables.EmpID;
  61. App.Data.Employee.Name = GlobalVariables.EmpName;
  62. MessagingCenter.Subscribe<App>(this, App.MessageOnResume,
  63. (o) =>
  64. {
  65. if (!App.GPS.RecentlyLocated)
  66. App.GPS.GetLocation();
  67. RefreshScreen();
  68. }
  69. );
  70. _timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  71. _employee = App.Data.Employee;
  72. _jobs = App.Data.Jobs;
  73. deviceName = MobileUtils.GetDeviceID();
  74. LoadCacheLists();
  75. InitToolEntryList();
  76. Timer t = new Timer(RecentlyAskedToUpdateTimer, null, 600000, 600000); //user is reminded to update when opening screen after timer of 10 minutes
  77. updateCounter = 1; //user is forced to update after 3rd reminder
  78. Timer t1 = new Timer(RecentlyUpdatedTilesTimer, null, 30000, 30000);
  79. //bluetooth data is allowed to upload once every minute, notifications refreshing is piggybacked to this too
  80. InitNotificationCentre();
  81. firstLoad = false;
  82. //if (GlobalVariables.EmpID == Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac"))
  83. //RunCustomScript();
  84. NotifyChanges();
  85. CheckCurrentAssignment();
  86. }
  87. catch (Exception e)
  88. {
  89. }
  90. NavigationPage.SetHasBackButton(this, false);
  91. }
  92. private void CheckCurrentAssignment()
  93. {
  94. Task.Run(() =>
  95. {
  96. Thread.Sleep(5000);
  97. StartAssignmentTimer();
  98. CoreTable table = new Client<Assignment>().Query(
  99. new Filter<Assignment>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
  100. .And(x => x.Date).IsEqualTo(DateTime.Today.Date)
  101. .And(x => x.Actual.Finish).IsEqualTo(null),
  102. null,
  103. new SortOrder<Assignment>(x => x.Actual.Start, SortDirection.Ascending));
  104. if (!table.Rows.Any())
  105. {
  106. _job.OnJobIDChanged += OnJobIDChanged;
  107. return;
  108. }
  109. var assgn = table.Rows.LastOrDefault().ToObject<Assignment>();
  110. Device.BeginInvokeOnMainThread(async () =>
  111. {
  112. string chosenOption = await DisplayActionSheet("Continue with current unfinished assignment?", "Cancel", null, "Yes", "No");
  113. switch(chosenOption)
  114. {
  115. case "Yes":
  116. currentAssignment = assgn;
  117. SaveCurrentAssignment("PRS Mobile main screen - saving assignment on re-login to App");
  118. if (currentAssignment.JobLink.ID != Guid.Empty)
  119. {
  120. _job.ID = currentAssignment.JobLink.ID;
  121. var job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(_job.ID)).Rows.FirstOrDefault().ToObject<Job>();
  122. _job.JobNumber = job.JobNumber;
  123. _job.Name = job.Name;
  124. RefreshJobBtn();
  125. _job.OnJobIDChanged += OnJobIDChanged;
  126. }
  127. break;
  128. default:
  129. _job.OnJobIDChanged += OnJobIDChanged;
  130. break;
  131. };
  132. });
  133. });
  134. }
  135. private void RunCustomScript()
  136. {
  137. }
  138. private void NotifyChanges()
  139. {
  140. Task.Run(() =>
  141. {
  142. string changes = NotifyMobileChanges.Notifiy();
  143. if (!string.IsNullOrWhiteSpace(changes))
  144. Device.BeginInvokeOnMainThread(() =>
  145. {
  146. DisplayAlert("Latest changes", changes, "OK");
  147. });
  148. });
  149. }
  150. #endregion
  151. #region OnAppearing and Display
  152. protected override void OnAppearing()
  153. {
  154. if (!App.IsUserLoggedIn)
  155. {
  156. Navigation.PopAsync();
  157. return;
  158. }
  159. //if (Application.Current.Properties.ContainsKey("IsSharedDevice"))
  160. //{
  161. // if (Application.Current.Properties["IsSharedDevice"].Equals("True"))
  162. // {
  163. // bSharedDevice = true;
  164. // if (!bSharedDeviceFirstLoad)
  165. // {
  166. // App.LogoutUser();
  167. // Navigation.PopToRootAsync();
  168. // }
  169. // else
  170. // {
  171. // bSharedDeviceFirstLoad = false;
  172. // clockOnButton.IsEnabled = false;
  173. // clockOnButton.Text = "Shared Device";
  174. // clockOnButton.BackgroundColor = Color.CornflowerBlue;
  175. // CurrentLocation.IsVisible = false;
  176. // jobBtn.IsVisible = false;
  177. // addNoteBtn.IsVisible = false;
  178. // Grid.SetRowSpan(flexLayoutScrollView, 3);
  179. // Grid.SetRow(flexLayoutScrollView, 1);
  180. // Timer t = new Timer(AutoLogoutUser, null, 600000, Timeout.Infinite);
  181. // }
  182. // }
  183. // else
  184. // bSharedDevice = false;
  185. //}
  186. //getting strange results from .IsAllowed
  187. //if (!PRSSecurity.IsAllowed<CanBypassTimeBench>())
  188. //{
  189. // clockOnButton.IsVisible = false;
  190. // jobBtn.IsVisible = false;
  191. // addNoteBtn.IsVisible = false;
  192. // CurrentLocation.IsVisible = false;
  193. // row0.Height = 0;
  194. // row1.Height = 0;
  195. // row2.Height = 0;
  196. // ForceLayout();
  197. //}
  198. if (!firstLoad)
  199. RefreshScreen();
  200. Task.Run(async () =>
  201. {
  202. bool isLatest = true;
  203. try
  204. {
  205. isLatest = await MobileUtils.AppVersion.IsUsingLatestVersion();
  206. }
  207. catch (Exception eLatest)
  208. {
  209. if (!recentlyAskedToUpdate)
  210. {
  211. Device.BeginInvokeOnMainThread(() =>
  212. {
  213. });
  214. recentlyAskedToUpdate = true;
  215. }
  216. string s = eLatest.Message;
  217. }
  218. if (!isLatest)
  219. {
  220. if (!recentlyAskedToUpdate)
  221. {
  222. string latestVersionNumber = await MobileUtils.AppVersion.GetLatestVersionNumber();
  223. if (updateCounter < 3)
  224. {
  225. Device.BeginInvokeOnMainThread(async () =>
  226. {
  227. string chosenOption = await DisplayActionSheet(String.Format("Version {0} Available. Update now?", latestVersionNumber), "You will be reminded again in 10 minutes.", null, "Yes", "No");
  228. switch (chosenOption)
  229. {
  230. case "No":
  231. break;
  232. case "Cancel":
  233. break;
  234. case "Yes":
  235. Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
  236. break;
  237. default:
  238. break;
  239. }
  240. });
  241. }
  242. else if (updateCounter >= 3)
  243. {
  244. Device.BeginInvokeOnMainThread(() =>
  245. {
  246. DisplayAlert(String.Format("Version {0} Available", latestVersionNumber), "Please update your software to the latest version.", "OK")
  247. .ContinueWith((Task task) =>
  248. {
  249. Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
  250. });
  251. });
  252. }
  253. recentlyAskedToUpdate = true;
  254. updateCounter++;
  255. }
  256. }
  257. });
  258. base.OnAppearing();
  259. }
  260. private void RecentlyAskedToUpdateTimer(object o)
  261. {
  262. recentlyAskedToUpdate = false;
  263. }
  264. private void AutoLogoutUser(object o)
  265. {
  266. App.LogoutUser();
  267. Navigation.PopToRootAsync();
  268. }
  269. private void RefreshScreen()
  270. {
  271. //if (bSharedDevice)
  272. // return;
  273. try
  274. {
  275. Device.BeginInvokeOnMainThread(() =>
  276. {
  277. homeScreenGrid.RaiseChild(CurrentLocation);
  278. bBusy = true;
  279. if (GlobalVariables.EmpID == Guid.Empty)
  280. {
  281. GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
  282. GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
  283. }
  284. clockOnButton.IsEnabled = false;
  285. bool PRSReady = (App.Data.Employee != null) && (App.Data.TimeSheets != null);
  286. bool GateReady = CheckLocation();
  287. CurrentLocation.Text = DisplayAddress();
  288. if (CurrentLocation.Text.Contains("ERROR"))
  289. CurrentLocation.Text = "Unknown Address";
  290. Title = null;
  291. Title = App.Data.Employee != null ? App.Data.Employee.Name : "";
  292. CoreRow timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault();
  293. clockOnButton.Text = PRSReady && GateReady ? timesheet == null ? "CLOCK ON" : "CLOCK OFF" : "PLEASE WAIT";
  294. clockOnButton.IsEnabled = PRSReady && GateReady;
  295. clockOnButton.BackgroundColor = PRSReady && GateReady ? timesheet == null ? Color.FromHex("#e6e6fa") : Color.FromHex("#15C7C1") : Color.Gainsboro;
  296. clockOnButton.BorderColor = PRSReady && GateReady ? timesheet == null ? Color.Black : Color.FromHex("#15C7C1") : Color.Gainsboro;
  297. if (clockOnButton.Text == "CLOCK OFF")
  298. {
  299. addNoteBtn.IsEnabled = true;
  300. if (GlobalVariables.JobsLoaded)
  301. jobBtn.IsEnabled = true;
  302. }
  303. else
  304. {
  305. addNoteBtn.IsEnabled = false;
  306. jobBtn.IsEnabled = false;
  307. }
  308. //if (firstLoad)
  309. // RefreshJobFromTimeSheet(timesheet);
  310. RefreshJobBtn();
  311. homeScreenGrid.RaiseChild(CurrentLocation);
  312. firstLoad = false;
  313. bBusy = false;
  314. });
  315. }
  316. catch (Exception e)
  317. {
  318. }
  319. //CurrentLocation.IsEnabled = PRSReady && GateReady;
  320. }
  321. private void RefreshJobBtn()
  322. {
  323. if (_job.ID == Guid.Empty)
  324. jobBtn.Text = "No Job Selected";
  325. else if(!string.IsNullOrWhiteSpace(_job.JobNumber))
  326. jobBtn.Text = "Job: " + _job.JobNumber;
  327. }
  328. private void RefreshJobFromTimeSheet(CoreRow timesheet)
  329. {
  330. Guid jobid = timesheet == null ? Guid.Empty : timesheet.Get<TimeSheet, Guid>(x => x.JobLink.ID);
  331. if (!jobid.Equals(Guid.Empty))
  332. {
  333. jobBtn.Text = String.Format("{0}: {1}", timesheet.Get<TimeSheet, String>(x => x.JobLink.JobNumber), timesheet.Get<TimeSheet, String>(x => x.JobLink.Name));
  334. _job.ID = timesheet == null ? Guid.Empty : timesheet.Get<TimeSheet, Guid>(x => x.JobLink.ID);
  335. _job.JobNumber = timesheet == null ? String.Empty : timesheet.Get<TimeSheet, String>(x => x.JobLink.JobNumber);
  336. _job.Name = timesheet == null ? String.Empty : timesheet.Get<TimeSheet, String>(x => x.JobLink.Name);
  337. }
  338. else
  339. {
  340. jobBtn.Text = "No Job Selected";
  341. _job = new JobShell();
  342. }
  343. }
  344. #endregion
  345. #region Clock on/off
  346. private void DataChanged(object sender, Type type, Exception e)
  347. {
  348. //if (bSharedDevice)
  349. // return;
  350. Device.BeginInvokeOnMainThread(() =>
  351. {
  352. if (e != null)
  353. {
  354. //DisplayAlert("Connection error with server - double check your connection", e.Message, "OK");
  355. }
  356. else
  357. RefreshScreen();
  358. });
  359. }
  360. private void DataRefreshed()
  361. {
  362. //if (bSharedDevice)
  363. // return;
  364. Device.BeginInvokeOnMainThread(() => { RefreshScreen(); });
  365. }
  366. bool bBusy = false;
  367. async void ClockOnOff_Clicked(object sender, System.EventArgs e)
  368. {
  369. if (bBusy)
  370. return;
  371. bBusy = true;
  372. string chosenOption = "Continue";
  373. if (clockOnButton.Text == "CLOCK OFF")
  374. {
  375. chosenOption = await DisplayActionSheet("Clock off?", "Cancel", null, "Continue", "Cancel");
  376. }
  377. switch (chosenOption)
  378. {
  379. case "Continue":
  380. break;
  381. case "Cancel":
  382. bBusy = false;
  383. return;
  384. break;
  385. default:
  386. bBusy = false;
  387. return;
  388. break;
  389. }
  390. if (clockOnButton.Text == "CLOCK ON" && clockedOffInLast5Seconds)
  391. {
  392. bBusy = false;
  393. return;
  394. }
  395. try
  396. {
  397. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  398. {
  399. InABox.Core.Location here = new InABox.Core.Location()
  400. {
  401. Latitude = App.GPS.Latitude,
  402. Longitude = App.GPS.Longitude,
  403. Timestamp = DateTime.Now
  404. };
  405. TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  406. if (timesheet != null)
  407. {
  408. if (timesheet.ID != Guid.Empty)
  409. {
  410. if (ZeroLengthTimesheet())
  411. {
  412. bUpdatingTimesheet = true;
  413. new Client<TimeSheet>().Delete(timesheet, "Deleted due to zero duration timesheet");
  414. App.Data.TimeSheets.Rows.Clear();
  415. }
  416. else
  417. {
  418. FinishTimeSheet(timesheet, here);
  419. }
  420. }
  421. }
  422. else
  423. {
  424. Guid jobid = Guid.Empty;
  425. String jobnumber = "";
  426. String jobname = "";
  427. if (!App.Data.CanBypassGates)
  428. {
  429. CoreRow row = App.Data.Gates.Rows.FirstOrDefault(r => App.Bluetooth.Devices.Contains(r.Get<JobTracker, String>(c => c.TrackerLink.DeviceID)));
  430. if (row != null)
  431. {
  432. jobid = row.Get<JobTracker, Guid>(x => x.JobLink.ID);
  433. jobnumber = row.Get<JobTracker, String>(x => x.JobLink.JobNumber);
  434. jobname = row.Get<JobTracker, String>(x => x.JobLink.Name);
  435. }
  436. CreateTimeSheet(jobid, jobnumber, jobname, here, App.GPS.Address, "Clocking On");
  437. }
  438. else
  439. {
  440. if ((!App.GPS.Latitude.Equals(0.0F)) && (!App.GPS.Longitude.Equals(0.0F)))
  441. {
  442. ChooseNearbyJob(here);
  443. }
  444. }
  445. }
  446. RefreshScreen();
  447. }
  448. }
  449. catch (Exception e2)
  450. {
  451. }
  452. bBusy = false;
  453. }
  454. #endregion
  455. #region Bluetooth
  456. private async void UploadTiles()
  457. {
  458. try
  459. {
  460. if (App.GPS.Latitude.Equals(0.0F) && App.GPS.Longitude.Equals(0.0F))
  461. return;
  462. if (App.Bluetooth.DetectedBlueToothMACAddresses.Count == 0)
  463. return;
  464. if (bRecentlyUpdatedTiles)
  465. return;
  466. bRecentlyUpdatedTiles = true;
  467. await Task.Run(() =>
  468. {
  469. InABox.Core.Location curlocation = new InABox.Core.Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };
  470. curlocation.Timestamp = DateTime.Now;
  471. List<GPSTrackerLocation> trackersToUpdate = new List<GPSTrackerLocation>();
  472. foreach (String id in App.Bluetooth.DetectedBlueToothMACAddresses)
  473. {
  474. GPSTracker tracker = GlobalVariables.GPSTrackerCache.Find(x => x.DeviceID.Equals(id));
  475. bool stale = tracker.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 5, 0));
  476. bool moved = tracker.Location.DistanceTo(curlocation, UnitOfLength.Kilometers) > 0.1;
  477. if (stale || moved)
  478. {
  479. GlobalVariables.GPSTrackerCache.Remove(tracker);
  480. tracker.Location = curlocation;
  481. GlobalVariables.GPSTrackerCache.Add(tracker);
  482. //cache is updated
  483. GPSTrackerLocation gpsTrackerLocation = new GPSTrackerLocation();
  484. gpsTrackerLocation.DeviceID = tracker.DeviceID;
  485. gpsTrackerLocation.Location.Timestamp = tracker.Location.Timestamp;
  486. gpsTrackerLocation.Location = curlocation;
  487. trackersToUpdate.Add(gpsTrackerLocation);
  488. }
  489. }
  490. if (trackersToUpdate.Any())
  491. {
  492. if (ClientFactory.UserGuid != Guid.Empty)
  493. new Client<GPSTrackerLocation>().Save(trackersToUpdate, "Updating Bluetooth Device Locations");
  494. }
  495. App.Bluetooth.DetectedBlueToothMACAddresses.Clear();
  496. }
  497. );
  498. }
  499. catch (Exception e)
  500. {
  501. }
  502. //if ((master != null) && (master.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 15, 0))))
  503. //{
  504. // GPSTrackerLocation device = new GPSTrackerLocation();
  505. // device.DeviceID = MobileUtils.GetDeviceID();
  506. // device.Location.Latitude = App.GPS.Latitude;
  507. // device.Location.Longitude = App.GPS.Longitude;
  508. // device.Location.Timestamp = DateTime.Now;
  509. // locations.Add(device);
  510. // //device.BatteryLevel = ((double)CrossBattery.Current.RemainingChargePercent);
  511. // //new Client<GPSTrackerLocation>().Save(device, "Updating Device Location"); //, SaveTrackerCallback);
  512. //}
  513. #region OLD
  514. //for (int i = 0; i < App.Bluetooth.Devices.Length; i++)
  515. //{
  516. // String id = App.Bluetooth.Devices[i];
  517. // int level = App.Bluetooth.BatteryLevels[i];
  518. // var btmaster = trackers.FirstOrDefault(x => x.DeviceID.Equals(id));
  519. // if ((btmaster != null) && (!locations.Any(x => x.DeviceID.Equals(btmaster.DeviceID))))
  520. // {
  521. // bool stale = btmaster.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 15, 0));
  522. // bool moved = btmaster.Location.DistanceTo(curlocation, UnitOfLength.Kilometers) > 0.1;
  523. // if (stale || moved)
  524. // {
  525. // GPSTrackerLocation location = new GPSTrackerLocation();
  526. // location.DeviceID = id;
  527. // location.Location.Latitude = App.GPS.Latitude;
  528. // location.Location.Longitude = App.GPS.Longitude;
  529. // location.Location.Timestamp = DateTime.Now;
  530. // location.BatteryLevel = level;
  531. // locations.Add(location);
  532. // }
  533. // }
  534. // //new Client<GPSTrackerLocation>().Save(location, "Found Kontakt Device"); //, SaveTrackerCallback);
  535. //}
  536. //if (locations.Any())
  537. // new Client<GPSTrackerLocation>().Save(locations, "Updating Bluetooth Device Locations", (o, e) => { });
  538. #endregion
  539. }
  540. private void RecentlyUpdatedTilesTimer(object o)
  541. {
  542. bRecentlyUpdatedTiles = false;
  543. App.Data.Refresh(true);
  544. SearchForNewNotifications();
  545. }
  546. private void LocationFound(LocationServices sender)
  547. {
  548. //if (bSharedDevice)
  549. // return;
  550. if (App.Bluetooth.RecentlyScanned)
  551. UploadTiles();
  552. try
  553. {
  554. TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  555. if (timesheet != null)
  556. {
  557. if (timesheet.StartLocation.Latitude.Equals(0.0F) && timesheet.StartLocation.Longitude.Equals(0.0F))
  558. {
  559. timesheet.StartLocation.Latitude = sender.Latitude;
  560. timesheet.StartLocation.Longitude = sender.Longitude;
  561. timesheet.StartLocation.Timestamp = sender.TimeStamp;
  562. timesheet.Address = sender.Address;
  563. new Client<TimeSheet>().Save(timesheet, "Updating Timesheet with GPS Coordinates", (o, e) => { });
  564. }
  565. }
  566. if (!string.IsNullOrWhiteSpace(matchedDeviceName))
  567. {
  568. InABox.Core.Location curlocation = new InABox.Core.Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };
  569. curlocation.Timestamp = DateTime.Now;
  570. GPSTrackerLocation gpsTrackerLocation = new GPSTrackerLocation();
  571. gpsTrackerLocation.DeviceID = matchedDeviceName;
  572. gpsTrackerLocation.Location.Timestamp = curlocation.Timestamp;
  573. gpsTrackerLocation.Location = curlocation;
  574. new Client<GPSTrackerLocation>().Save(gpsTrackerLocation, "Updated company device location from Timebench");
  575. }
  576. Device.BeginInvokeOnMainThread(() =>
  577. {
  578. RefreshScreen();
  579. });
  580. }
  581. catch { }
  582. }
  583. private void LocationError(LocationServices sebder, Exception error)
  584. {
  585. }
  586. private void ScanFinished(Bluetooth sender)
  587. {
  588. try
  589. {
  590. //if (bSharedDevice)
  591. // return;
  592. Device.BeginInvokeOnMainThread(() =>
  593. {
  594. RefreshScreen();
  595. //if (Button2.BackgroundColor == Color.WhiteSmoke)
  596. // Button2.BackgroundColor = Color.Red;
  597. //else
  598. // Button2.BackgroundColor = Color.WhiteSmoke;
  599. });
  600. if (App.GPS.RecentlyLocated)
  601. UploadTiles();
  602. }
  603. catch { }
  604. }
  605. #endregion
  606. #region Utilities
  607. private void OnJobIDChanged(Guid jobid)
  608. {
  609. if (currentAssignment == null)
  610. CreateNewAssignment(jobid);
  611. else
  612. {
  613. SaveCurrentAssignment("PRS Mobile main screen - saving assignment on job change", true);
  614. CreateNewAssignment(jobid);
  615. }
  616. }
  617. private void StartAssignmentTimer()
  618. {
  619. Timer t = new Timer(AssignmentTimerCallback, null, 300000, 300000);
  620. }
  621. private void AssignmentTimerCallback(object state)
  622. {
  623. if (currentAssignment != null)
  624. SaveCurrentAssignment("PRS MObile main screen - Saving assignment on 5 minute timer");
  625. }
  626. private void CreateNewAssignment(Guid jobid)
  627. {
  628. currentAssignment = new Assignment { Date = DateTime.Now.Date };
  629. currentAssignment.EmployeeLink.ID = GlobalVariables.EmpID;
  630. currentAssignment.JobLink.ID = jobid;
  631. currentAssignment.Actual.Start = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  632. currentAssignment.Booked.Start = currentAssignment.Actual.Start;
  633. currentAssignment.Booked.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay.Add(new TimeSpan(0, 5, 0));
  634. var job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(jobid)).Rows.FirstOrDefault().ToObject<Job>();
  635. currentAssignment.Title = "Clocking on to job " + job.Name + " (" + job.JobNumber + ") on PRS Mobile";
  636. new Client<Assignment>().Save(currentAssignment, "Changed job on mobile - creating new assignment");
  637. }
  638. private void SaveCurrentAssignment(string auditnote, bool complete = false)
  639. {
  640. if (!complete)
  641. currentAssignment.Booked.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  642. else
  643. currentAssignment.Actual.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  644. new Client<Assignment>().Save(currentAssignment, auditnote);
  645. }
  646. static DateTime RoundToNearestInterval(DateTime dt, TimeSpan d)
  647. {
  648. int f = 0;
  649. double m = (double)(dt.Ticks % d.Ticks) / d.Ticks;
  650. if (m >= 0.5)
  651. f = 1;
  652. return new DateTime(((dt.Ticks / d.Ticks) + f) * d.Ticks);
  653. }
  654. private void InitNotificationCentre()
  655. {
  656. try
  657. {
  658. LocalNotificationCenter.Current.NotificationActionTapped += (Plugin.LocalNotification.EventArgs.NotificationActionEventArgs e) =>
  659. {
  660. string data = e.Request.ReturningData;
  661. int index = data.IndexOf("$");
  662. Guid ID = Guid.Parse(data.Remove(index));
  663. string type = data.Substring(index + 1);
  664. if (type == "Comal.Classes.Kanban")
  665. {
  666. Device.BeginInvokeOnMainThread(() =>
  667. {
  668. AddEditTask page = new AddEditTask(ID);
  669. Navigation.PushAsync(page);
  670. });
  671. }
  672. else if (type == "Comal.Classes.Delivery")
  673. {
  674. Device.BeginInvokeOnMainThread(() =>
  675. {
  676. DeliveryDetails page = new DeliveryDetails(ID);
  677. Navigation.PushAsync(page);
  678. });
  679. }
  680. };
  681. }
  682. catch { }
  683. }
  684. private async void SearchForNewNotifications()
  685. {
  686. //notifications poll reliably in the background for Anroid, unreliable for iOS due to difficulty with cross-platform plugins for notifications
  687. try
  688. {
  689. await Task.Run(() =>
  690. {
  691. if (ClientFactory.UserGuid != Guid.Empty)
  692. {
  693. CoreTable table = new Client<Notification>().Query
  694. (new Filter<Notification>(x => x.Employee.UserLink.ID).IsEqualTo(ClientFactory.UserGuid).And(X => X.Closed).IsEqualTo(DateTime.MinValue),
  695. new Columns<Notification>(
  696. x => x.ID, //0
  697. x => x.Sender.Name, //1
  698. x => x.Title, //2
  699. x => x.Created, //3
  700. x => x.Description, //4
  701. x => x.EntityType, //5
  702. x => x.EntityID //6
  703. )
  704. );
  705. if (NumberOfNotfications == table.Rows.Count()) //no new notifications or none present at all
  706. return;
  707. else //new notifications or previous notifications have now been dismissed
  708. {
  709. NumberOfNotfications = table.Rows.Count();
  710. RefreshOnNotificationsChange();
  711. CheckNotificationsPushed(table);
  712. }
  713. }
  714. });
  715. }
  716. catch { }
  717. }
  718. private void RefreshOnNotificationsChange()
  719. {
  720. try
  721. {
  722. int index = toolEntries.FindIndex(x => x.Text.Equals("Notifications"));
  723. toolEntries.RemoveAt(index);
  724. string notificationsString = "";
  725. if (NumberOfNotfications != 0)
  726. {
  727. notificationsString = NumberOfNotfications.ToString();
  728. }
  729. ToolEntry Notifications = new ToolEntry(notificationsString)
  730. {
  731. Text = "Notifications",
  732. Image = "notifications"
  733. };
  734. Notifications.OnTapped += (async (object sender, EventArgs e) =>
  735. {
  736. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  737. {
  738. NotificationList notificationList = new NotificationList();
  739. notificationList.NotificationsClosed += (n) =>
  740. {
  741. NumberOfNotfications = n;
  742. RefreshOnNotificationsChange();
  743. };
  744. Navigation.PushAsync(notificationList);
  745. }
  746. });
  747. toolEntries.Insert(index, Notifications);
  748. Device.BeginInvokeOnMainThread(() =>
  749. {
  750. flexLayout.Children.RemoveAt(index);
  751. flexLayout.Children.Insert(index, toolEntries[index]);
  752. });
  753. }
  754. catch { }
  755. }
  756. private void CheckNotificationsPushed(CoreTable table)
  757. {
  758. try
  759. {
  760. if (!Application.Current.Properties.ContainsKey("LastPushedNotifications"))
  761. {
  762. Application.Current.Properties.Add("LastPushedNotifications", DateTime.Now);
  763. }
  764. DateTime lastPushed = DateTime.Parse(Application.Current.Properties["LastPushedNotifications"].ToString());
  765. List<NotificationShell> toNotify = new List<NotificationShell>();
  766. foreach (CoreRow row in table.Rows)
  767. {
  768. List<object> list = row.Values;
  769. DateTime created = DateTime.Parse(list[3].ToString());
  770. if (created > new DateTime(2022, 8, 22)) // prevent spam from buildup of old notifications before this is released
  771. {
  772. if (created > lastPushed)
  773. {
  774. if (list[1] == null) list[1] = "";
  775. if (list[2] == null) list[2] = "";
  776. if (list[3] == null) list[3] = DateTime.MinValue;
  777. if (list[4] == null) list[4] = "";
  778. if (list[5] == null) list[5] = "";
  779. if (list[6] == null) list[6] = Guid.Empty;
  780. NotificationShell shell = new NotificationShell
  781. {
  782. ID = Guid.Parse(list[0].ToString()),
  783. Sender = list[1].ToString(),
  784. Title = list[2].ToString(),
  785. Created = DateTime.Parse(list[3].ToString()),
  786. EntityType = list[5].ToString(),
  787. EntityID = Guid.Parse(list[6].ToString())
  788. };
  789. toNotify.Add(shell); //add notification to be pushed
  790. }
  791. }
  792. }
  793. if (toNotify.Count > 0)
  794. PushNotificationsAsync(toNotify);
  795. }
  796. catch { }
  797. }
  798. private async Task PushNotificationsAsync(List<NotificationShell> shells)
  799. {
  800. try
  801. {
  802. int count = 1;
  803. foreach (NotificationShell shell in shells)
  804. {
  805. var notification = new NotificationRequest
  806. {
  807. BadgeNumber = 1,
  808. Description = shell.Title,
  809. Title = "New PRS Notification: ",
  810. ReturningData = shell.EntityID.ToString() + "$" + shell.EntityType,
  811. NotificationId = count,
  812. };
  813. count++;
  814. NotificationImage img = new NotificationImage();
  815. img.ResourceName = "icon16.png";
  816. notification.Image = img;
  817. await LocalNotificationCenter.Current.Show(notification);
  818. //if (Device.RuntimePlatform.Equals(Device.iOS))
  819. //{
  820. // var content = new UNMutableNotificationContent();
  821. // content.Title = "New PRS Notification: ";
  822. // content.Subtitle = shell.Title;
  823. // content.Body = "";
  824. // content.Badge = 1;
  825. // var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);
  826. // var requestID = "request";
  827. // var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);
  828. // UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
  829. // {
  830. // if (err != null)
  831. // {
  832. // Do something with error...
  833. // }
  834. // });
  835. //}
  836. }
  837. Application.Current.Properties["LastPushedNotifications"] = DateTime.Now;
  838. }
  839. catch { }
  840. }
  841. private void StartMidnightTimeSheetTimer()
  842. {
  843. midnightTimerOn = true;
  844. int msUntilMidnight = (int)(oneSecondBeforeMidnight - DateTime.Now).TotalMilliseconds;
  845. Timer midnightTimer = new Timer(MidnightTimerCallback, null, msUntilMidnight, Timeout.Infinite);
  846. }
  847. private void MidnightTimerCallback(object o)
  848. {
  849. try
  850. {
  851. //if (bSharedDevice)
  852. // return;
  853. if (midnightTimerOn)
  854. {
  855. if (clockOnButton.Text == "CLOCK OFF")
  856. {
  857. InABox.Core.Location here = new InABox.Core.Location()
  858. {
  859. Latitude = App.GPS.Latitude,
  860. Longitude = App.GPS.Longitude,
  861. Timestamp = DateTime.Now
  862. };
  863. TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  864. if (timesheet != null)
  865. {
  866. if (timesheet.ID != Guid.Empty)
  867. {
  868. if (ZeroLengthTimesheet())
  869. {
  870. bUpdatingTimesheet = true;
  871. new Client<TimeSheet>().Delete(timesheet, "Deleted due to zero duration timesheet");
  872. App.Data.TimeSheets.Rows.Clear();
  873. }
  874. else
  875. {
  876. timesheet.Finish = new TimeSpan(23, 59, 59);
  877. timesheet.FinishLocation = here;
  878. bUpdatingTimesheet = true;
  879. new Client<TimeSheet>().Save(timesheet, "Auto Close timesheet at Midnight");
  880. App.Data.TimeSheets.Rows.Clear();
  881. Guid jobid = Guid.Empty;
  882. String jobnumber = "";
  883. String jobname = "";
  884. if (!App.Data.CanBypassGates)
  885. {
  886. CoreRow row = App.Data.Gates.Rows.FirstOrDefault(r => App.Bluetooth.Devices.Contains(r.Get<JobTracker, String>(c => c.TrackerLink.DeviceID)));
  887. if (row != null)
  888. {
  889. jobid = row.Get<JobTracker, Guid>(x => x.JobLink.ID);
  890. jobnumber = row.Get<JobTracker, String>(x => x.JobLink.JobNumber);
  891. jobname = row.Get<JobTracker, String>(x => x.JobLink.Name);
  892. }
  893. CreateTimeSheet(jobid, jobnumber, jobname, here, App.GPS.Address, "Clocking On");
  894. }
  895. else
  896. {
  897. if ((!App.GPS.Latitude.Equals(0.0F)) && (!App.GPS.Longitude.Equals(0.0F)))
  898. {
  899. ChooseNearbyJob(here);
  900. }
  901. }
  902. }
  903. }
  904. }
  905. }
  906. }
  907. }
  908. catch { }
  909. }
  910. private void FinishTimeSheet(TimeSheet timesheet, InABox.Core.Location here)
  911. {
  912. try
  913. {
  914. TimeSpan tod = DateTime.Now - DateTime.Today;
  915. timesheet.Finish = new TimeSpan(tod.Hours, tod.Minutes, 0);
  916. timesheet.FinishLocation = here;
  917. bUpdatingTimesheet = true;
  918. new Client<TimeSheet>().Save(timesheet, "Clocking Off");
  919. App.Data.TimeSheets.Rows.Clear();
  920. midnightTimerOn = false;
  921. Timer last60Seconds = new Timer(Last60SecondsTimerCallBack, null, 5000, Timeout.Infinite);
  922. clockedOffInLast5Seconds = true;
  923. if (currentAssignment != null)
  924. {
  925. SaveCurrentAssignment("PRS Mobile - clocking off", true);
  926. currentAssignment = null;
  927. }
  928. }
  929. catch { }
  930. }
  931. private void Last60SecondsTimerCallBack(object o)
  932. {
  933. clockedOffInLast5Seconds = false;
  934. }
  935. private async void ChooseNearbyJob(InABox.Core.Location here)
  936. {
  937. try
  938. {
  939. JobShell selectedJob = new JobShell();
  940. Dictionary<string, JobShell> nearbyJobs = new Dictionary<string, JobShell>();
  941. foreach (CoreRow row in App.Data.Jobs.Rows)
  942. {
  943. InABox.Core.Location jobLocation = new InABox.Core.Location() { Latitude = row.Get<Job, double>(X => X.SiteAddress.Location.Latitude), Longitude = row.Get<Job, double>(X => X.SiteAddress.Location.Longitude) };
  944. double distance = here.DistanceTo(jobLocation, UnitOfLength.Kilometers);
  945. if (distance < 1.0F)
  946. {
  947. JobShell jobShell = new JobShell();
  948. jobShell.ID = row.Get<Job, Guid>(X => X.ID);
  949. jobShell.JobNumber = row.Get<Job, String>(x => x.JobNumber);
  950. jobShell.Name = row.Get<Job, String>(x => x.Name);
  951. jobShell.DisplayName = jobShell.JobNumber + " " + jobShell.Name;
  952. nearbyJobs.Add(jobShell.DisplayName, jobShell);
  953. }
  954. }
  955. if (nearbyJobs.Count > 1)
  956. {
  957. string[] array = nearbyJobs.Keys.ToArray();
  958. string chosenOption = await DisplayActionSheet("Choose job site", "Cancel", null, array);
  959. if (string.IsNullOrEmpty(chosenOption) || chosenOption.Equals("Cancel"))
  960. {
  961. CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, here, App.GPS.Address, "Clocking On");
  962. return;
  963. }
  964. else
  965. {
  966. selectedJob = nearbyJobs[chosenOption];
  967. }
  968. }
  969. else if (nearbyJobs.Count == 1)
  970. {
  971. selectedJob = nearbyJobs.Values.First();
  972. }
  973. CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, here, App.GPS.Address, "Clocking On");
  974. }
  975. catch { }
  976. }
  977. void AddNote_Tapped(System.Object sender, System.EventArgs e)
  978. {
  979. try
  980. {
  981. TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  982. if (timesheet == null)
  983. return;
  984. var notepage = new NotePage(timesheet);
  985. Navigation.PushAsync(notepage);
  986. }
  987. catch { }
  988. }
  989. private void JobBtn_Tapped(object sender, EventArgs e)
  990. {
  991. try
  992. {
  993. JobSelectionPage jobSelectionPage = new JobSelectionPage();
  994. jobSelectionPage.OnItemSelected += (() =>
  995. {
  996. _job.ID = jobSelectionPage.Job.ID;
  997. _job.JobNumber = jobSelectionPage.Job.JobNumber;
  998. _job.Name = jobSelectionPage.Job.Name;
  999. RefreshScreen();
  1000. JobPage_OnItemSelected(jobSelectionPage.Job);
  1001. });
  1002. Navigation.PushAsync(jobSelectionPage);
  1003. }
  1004. catch { }
  1005. }
  1006. private void JobPage_OnItemSelected(JobShell job)
  1007. {
  1008. //try
  1009. //{
  1010. // TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  1011. // if (timesheet == null)
  1012. // return;
  1013. // String auditmessage = String.Format("Changed Selected Job to: {0}: {1}", timesheet.JobLink.JobNumber, timesheet.JobLink.Name);
  1014. // if (ZeroLengthTimesheet())
  1015. // {
  1016. // timesheet.JobLink.ID = job.ID;
  1017. // timesheet.JobLink.JobNumber = job.JobNumber;
  1018. // timesheet.JobLink.Name = job.Name;
  1019. // bUpdatingTimesheet = true;
  1020. // new Client<TimeSheet>().Save(timesheet, auditmessage);
  1021. // Device.BeginInvokeOnMainThread(() =>
  1022. // {
  1023. // if (timesheet.JobLink.ID != Guid.Empty)
  1024. // {
  1025. // jobBtn.Text = "(" + timesheet.JobLink.JobNumber + ") " + timesheet.JobLink.Name;
  1026. // }
  1027. // else
  1028. // {
  1029. // jobBtn.Text = "No Job Selected";
  1030. // }
  1031. // });
  1032. // }
  1033. // else
  1034. // {
  1035. // InABox.Core.Location here = new InABox.Core.Location()
  1036. // {
  1037. // Latitude = App.GPS.Latitude,
  1038. // Longitude = App.GPS.Longitude,
  1039. // Timestamp = DateTime.Now
  1040. // };
  1041. // TimeSpan tod = DateTime.Now - DateTime.Today;
  1042. // timesheet.Finish = new TimeSpan(tod.Hours, tod.Minutes, 0);
  1043. // timesheet.FinishLocation = here;
  1044. // new Client<TimeSheet>().Save(timesheet, "Changing Job");
  1045. // CreateTimeSheet(
  1046. // job.ID,
  1047. // job.JobNumber,
  1048. // job.Name,
  1049. // here,
  1050. // App.GPS.Address,
  1051. // auditmessage
  1052. // );
  1053. // }
  1054. // RefreshScreen();
  1055. //}
  1056. //catch { }
  1057. }
  1058. private bool CheckTimeSheetAgainstGates(TimeSheet timesheet)
  1059. {
  1060. DateTime now = DateTime.Now;
  1061. //var timesheet = CurrentTimeSheet();
  1062. //Can't confirm if there is no timesheet
  1063. if (timesheet == null)
  1064. return false;
  1065. // Can't confirm if there are no devices
  1066. if (App.Bluetooth.Devices.Length == 0)
  1067. return false;
  1068. if (App.Data.Gates == null)
  1069. return false;
  1070. long tsTicks = timesheet.Date.Add(timesheet.Start).Ticks;
  1071. long btTicks = App.Bluetooth.TimeStamp.Ticks;
  1072. if (Math.Abs(tsTicks - btTicks) > new TimeSpan(0, 2, 0).Ticks)
  1073. return false;
  1074. CoreRow firstgate = null;
  1075. List<String> gates = new List<string>();
  1076. // Scan every located d
  1077. foreach (var device in App.Bluetooth.Devices)
  1078. {
  1079. CoreRow gate = App.Data.Gates?.Rows.FirstOrDefault(r => r.Get<JobTracker, String>(c => c.TrackerLink.DeviceID) == device);
  1080. if (gate != null)
  1081. {
  1082. if ((gate.Get<JobTracker, bool>(x => x.IsJobSite) == true) && (firstgate == null))
  1083. firstgate = gate;
  1084. gates.Add(gate.Get<JobTracker, String>(x => x.Gate));
  1085. }
  1086. }
  1087. if (gates.Any())
  1088. {
  1089. timesheet.Gate = String.Join(", ", gates.OrderBy(x => x));
  1090. if (firstgate != null)
  1091. {
  1092. timesheet.JobLink.ID = firstgate.Get<JobTracker, Guid>(x => x.JobLink.ID);
  1093. timesheet.JobLink.JobNumber = firstgate.Get<JobTracker, String>(x => x.JobLink.JobNumber);
  1094. timesheet.JobLink.Name = firstgate.Get<JobTracker, String>(x => x.JobLink.Name);
  1095. }
  1096. return true;
  1097. //new Client<TimeSheet>().Save(timesheet, "Confirmed Gate Entry by Bluetooth Tracker", (o, e) => { });
  1098. }
  1099. return false;
  1100. }
  1101. private bool ZeroLengthTimesheet()
  1102. {
  1103. try
  1104. {
  1105. if (App.Data.TimeSheets == null)
  1106. return true;
  1107. CoreRow row = App.Data.TimeSheets.Rows.FirstOrDefault();
  1108. if (row == null)
  1109. return true;
  1110. String notes = row.Get<TimeSheet, String>(x => x.Notes);
  1111. if (!String.IsNullOrWhiteSpace(notes))
  1112. return false;
  1113. DateTime date = row.Get<TimeSheet, DateTime>(x => x.Date);
  1114. TimeSpan start = row.Get<TimeSheet, TimeSpan>(x => x.Start);
  1115. if (date.Equals(DateTime.Today))
  1116. {
  1117. TimeSpan tod = DateTime.Now - DateTime.Today;
  1118. var diff = (tod - start).TotalSeconds;
  1119. if (Math.Abs(diff) < 120.0F)
  1120. return true;
  1121. }
  1122. }
  1123. catch { }
  1124. return false;
  1125. }
  1126. private async void CreateTimeSheet(Guid jobid, string jobnumber, String jobname, InABox.Core.Location location, String address, String auditmessage)
  1127. {
  1128. try
  1129. {
  1130. var timesheet = new TimeSheet();
  1131. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  1132. {
  1133. timesheet.EmployeeLink.ID = App.Data.Employee.ID;
  1134. timesheet.Date = DateTime.Today;
  1135. TimeSpan tod = DateTime.Now - DateTime.Today;
  1136. tod = new TimeSpan(tod.Hours, tod.Minutes, 0);
  1137. timesheet.Start = tod;
  1138. timesheet.StartLocation = location;
  1139. timesheet.JobLink.ID = jobid;
  1140. timesheet.JobLink.JobNumber = jobnumber;
  1141. timesheet.JobLink.Name = jobname;
  1142. timesheet.Address = address;
  1143. timesheet.SoftwareVersion = MobileUtils.AppVersion.InstalledVersionNumber + GlobalVariables.DeviceString;
  1144. //if (ClientFactory.IsAllowed<AllowTimeSheetRollover>()) CheckTimeSheetAgainstGates(timesheet);
  1145. bUpdatingTimesheet = true;
  1146. new Client<TimeSheet>().Save(timesheet, auditmessage);
  1147. if (timesheet.ID == Guid.Empty)
  1148. {
  1149. DisplayAlert("Error creating new timesheet", "Please check your connection and try again", "OK");
  1150. return;
  1151. }
  1152. StartMidnightTimeSheetTimer();
  1153. // Don't Save Completed Timesheets!
  1154. App.Data.TimeSheets.Rows.Clear();
  1155. if (timesheet.Finish.Ticks == 0L)
  1156. {
  1157. CoreRow row = App.Data.TimeSheets.NewRow();
  1158. App.Data.TimeSheets.LoadRow(row, timesheet);
  1159. App.Data.TimeSheets.Rows.Add(row);
  1160. }
  1161. }
  1162. Device.BeginInvokeOnMainThread(() =>
  1163. {
  1164. if (timesheet.JobLink.ID != Guid.Empty)
  1165. {
  1166. jobBtn.Text = "(" + timesheet.JobLink.JobNumber + ") " + timesheet.JobLink.Name;
  1167. }
  1168. else
  1169. {
  1170. jobBtn.Text = "No Job Selected";
  1171. }
  1172. });
  1173. }
  1174. catch { }
  1175. }
  1176. private bool CheckLocation()
  1177. {
  1178. try
  1179. {
  1180. if (App.Data.CanBypassGates)
  1181. {
  1182. if (App.GPS.TimeStamp > DateTime.Now.Subtract(new TimeSpan(0, 5, 0)))
  1183. return true;
  1184. else
  1185. return false;
  1186. }
  1187. if (App.Data.Gates == null)
  1188. return false;
  1189. if (App.Bluetooth.TimeStamp < DateTime.Now.Subtract(new TimeSpan(0, 2, 0)))
  1190. return false;
  1191. if (!App.Bluetooth.Devices.Any())
  1192. return false;
  1193. return App.Data.Gates.Rows.Any(r => App.Bluetooth.Devices.Contains(r.Get<JobTracker, String>(c => c.TrackerLink.DeviceID)));
  1194. }
  1195. catch
  1196. {
  1197. return true;
  1198. }
  1199. }
  1200. private String DisplayAddress()
  1201. {
  1202. try
  1203. {
  1204. bool PRSReady = App.Data.Employee != null; // && (TimeSheet != null); // && (Activities != null);
  1205. if (!PRSReady)
  1206. return "Retrieving Data";
  1207. if (App.Data.CanBypassGates)
  1208. {
  1209. if (App.GPS.TimeStamp < DateTime.Now.Subtract(new TimeSpan(0, 5, 0)))
  1210. {
  1211. App.GPS.GetLocation(true);
  1212. return "Searching for GPS";
  1213. }
  1214. else
  1215. return App.GPS.Address;
  1216. }
  1217. else
  1218. {
  1219. // Hmm.. this can/should be simplified
  1220. // if in range of a gate
  1221. // Show Gate Description
  1222. // else
  1223. // "Looking for Gate"
  1224. if ((App.Data.Gates != null) && (App.Bluetooth.TimeStamp > DateTime.Now.Subtract(new TimeSpan(0, 2, 0))))
  1225. {
  1226. CoreRow row = App.Data.Gates.Rows.FirstOrDefault(r => App.Bluetooth.Devices.Contains(r.Get<JobTracker, String>(c => c.TrackerLink.DeviceID)));
  1227. if (row != null)
  1228. return row.Get<JobTracker, String>(x => x.Gate);
  1229. //else if ((CurrentTimeSheet() != null) && (!GPS.TimeStamp.IsEmpty()))
  1230. // return GPS.Address;
  1231. else
  1232. return "Looking for Gate";
  1233. }
  1234. //else if ((CurrentTimeSheet() != null) && (GPS.TimeStamp > DateTime.Now.Subtract(new TimeSpan(0, 2, 0))))
  1235. // return GPS.Address;
  1236. else
  1237. return "Looking for Gate";
  1238. }
  1239. }
  1240. catch
  1241. {
  1242. return "Address error";
  1243. }
  1244. }
  1245. #region Background Loading
  1246. private async Task LoadCacheLists()
  1247. {
  1248. GlobalVariables.ProductsLoaded = false;
  1249. GlobalVariables.JobsLoaded = false;
  1250. GlobalVariables.GetXamarinWidth();
  1251. await CacheLoader.LoadJobs();
  1252. LoadEmployeeShells();
  1253. LoadProducts();
  1254. LoadCompanyDevices();
  1255. LoadBlueToothAddresses();
  1256. //LoadHRToDos(); to be uncommented when ready for roll out
  1257. }
  1258. private void LoadCompanyDevices()
  1259. {
  1260. Task.Run(() =>
  1261. {
  1262. if (!string.IsNullOrWhiteSpace(deviceName) && deviceName != "unknown")
  1263. {
  1264. List<Equipment> companyDevices = new List<Equipment>();
  1265. CoreTable table = new Client<Equipment>().Query
  1266. (
  1267. new Filter<Equipment>(x => x.GroupLink.Code).IsEqualTo("DEVICE"),
  1268. new Columns<Equipment>(
  1269. x => x.TrackerLink.DeviceID
  1270. )
  1271. );
  1272. if (table.Rows.Any())
  1273. {
  1274. foreach (CoreRow row in table.Rows)
  1275. {
  1276. List<object> list = row.Values;
  1277. if (list[0].ToString().Equals(deviceName))
  1278. {
  1279. matchedDeviceName = deviceName;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. });
  1285. }
  1286. private async void LoadEmployeeShells()
  1287. {
  1288. await Task.Run(() =>
  1289. {
  1290. List<EmployeeShell> employeeShells = new List<EmployeeShell>();
  1291. List<EmployeeShell> teamEmployeeShells = new List<EmployeeShell>();
  1292. MultiQuery query = new MultiQuery();
  1293. query.Add<Employee>(
  1294. LookupFactory.DefineFilter<Employee>(),
  1295. new Columns<Employee>(x => x.ID)
  1296. .Add(x => x.Code)
  1297. .Add(x => x.Name),
  1298. LookupFactory.DefineSort<Employee>()
  1299. );
  1300. query.Add<Team>(
  1301. LookupFactory.DefineFilter<Team>(),
  1302. new Columns<Team>(x => x.Name),
  1303. new SortOrder<Team>(x => x.Name)
  1304. );
  1305. query.Add<EmployeeTeam>(
  1306. LookupFactory.DefineFilter<EmployeeTeam>(),
  1307. new Columns<EmployeeTeam>(x => x.EmployeeLink.ID)
  1308. .Add(x => x.EmployeeLink.Code)
  1309. .Add(x => x.EmployeeLink.Name)
  1310. .Add(x => x.TeamLink.Name),
  1311. new SortOrder<EmployeeTeam>(x => x.EmployeeLink.Name)
  1312. );
  1313. query.Query();
  1314. CoreTable emps = query.Get<Employee>();
  1315. foreach (var row in emps.Rows)
  1316. {
  1317. employeeShells.Add(
  1318. new EmployeeShell()
  1319. {
  1320. ID = row.Get<Employee, Guid>(x => x.ID),
  1321. Code = row.Get<Employee, String>(x => x.Code),
  1322. Name = row.Get<Employee, String>(x => x.Name),
  1323. TeamName = "All Staff"
  1324. }
  1325. );
  1326. }
  1327. GlobalVariables.TeamNames = query.Get<Team>().Rows.Select(r => r.Get<Team, String>(c => c.Name)).ToList();
  1328. CoreTable members = query.Get<EmployeeTeam>();
  1329. foreach (var row in members.Rows)
  1330. {
  1331. teamEmployeeShells.Add(
  1332. new EmployeeShell()
  1333. {
  1334. ID = row.Get<EmployeeTeam, Guid>(x => x.EmployeeLink.ID),
  1335. Code = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Code),
  1336. Name = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Name),
  1337. TeamName = row.Get<EmployeeTeam, String>(x => x.TeamLink.Name)
  1338. }
  1339. );
  1340. }
  1341. GlobalVariables.EmployeeShells = employeeShells;
  1342. GlobalVariables.TeamEmployeeShells = teamEmployeeShells;
  1343. });
  1344. }
  1345. private async void LoadHRToDos()
  1346. {
  1347. try
  1348. {
  1349. await Task.Run(() =>
  1350. {
  1351. Thread.Sleep(10000);
  1352. if (GlobalVariables.UpdateHRItemsNeedingAttention())
  1353. {
  1354. string message = "You have HR Items needing attention. Open My HR now?";
  1355. Device.BeginInvokeOnMainThread(async () =>
  1356. {
  1357. string chosenOption = await DisplayActionSheet(message, "Cancel", null, "Yes", "No");
  1358. switch (chosenOption)
  1359. {
  1360. case "Cancel":
  1361. break;
  1362. case "No":
  1363. break;
  1364. default:
  1365. break;
  1366. case "Yes":
  1367. MyHRHome myHRHome = new MyHRHome();
  1368. Navigation.PushAsync(myHRHome);
  1369. break;
  1370. }
  1371. });
  1372. }
  1373. });
  1374. }
  1375. catch { }
  1376. }
  1377. private async void LoadProducts()
  1378. {
  1379. try
  1380. {
  1381. await Task.Run(() =>
  1382. {
  1383. ProductsLoader productsLoader = new ProductsLoader();
  1384. //if (ClientFactory.IsAllowed<CanViewStoresRequisitions>())
  1385. //{
  1386. //}
  1387. });
  1388. }
  1389. catch { }
  1390. }
  1391. private async void LoadBlueToothAddresses()
  1392. {
  1393. try
  1394. {
  1395. //if (bSharedDevice)
  1396. // return;
  1397. await Task.Run(() =>
  1398. {
  1399. GlobalVariables.GPSTrackerCache = new List<GPSTracker>();
  1400. CoreTable table = new Client<GPSTracker>().Query(new Filter<GPSTracker>(x => x.Type.Description).Contains("Kontakt"));
  1401. foreach (CoreRow row in table.Rows)
  1402. {
  1403. GPSTracker tracker = row.ToObject<GPSTracker>();
  1404. GlobalVariables.GPSTrackerCache.Add(tracker);
  1405. App.Bluetooth.KnownBlueToothMACAddresses.Add(tracker.DeviceID);
  1406. }
  1407. });
  1408. }
  1409. catch { }
  1410. }
  1411. #endregion
  1412. #endregion
  1413. #region Modules
  1414. public async void InitToolEntryList()
  1415. {
  1416. try
  1417. {
  1418. await Task.Run(() =>
  1419. {
  1420. //Assignments
  1421. ToolEntry Assignments = new ToolEntry
  1422. {
  1423. Text = "Assignments",
  1424. Image = "calendar"
  1425. };
  1426. Assignments.IsVisible = PRSSecurity.CanView<Assignment>();
  1427. Assignments.OnTapped += ((object sender, EventArgs e) =>
  1428. {
  1429. var assignment_form = new AssignmentList();
  1430. Navigation.PushAsync(assignment_form);
  1431. });
  1432. toolEntries.Add(Assignments);
  1433. //Deliveries
  1434. ToolEntry Deliveries = new ToolEntry
  1435. {
  1436. Text = "Deliveries",
  1437. Image = "deliveries"
  1438. };
  1439. Deliveries.IsVisible = PRSSecurity.CanView<Delivery>();
  1440. Deliveries.OnTapped += ((object sender, EventArgs e) =>
  1441. {
  1442. var delivery_form = new DeliveryList();
  1443. Navigation.PushAsync(delivery_form);
  1444. });
  1445. toolEntries.Add(Deliveries);
  1446. //Digital Forms
  1447. ToolEntry Forms = new ToolEntry
  1448. {
  1449. Text = "Forms",
  1450. Image = "forms"
  1451. };
  1452. Forms.IsVisible = PRSSecurity.CanView<DigitalForm>();
  1453. Forms.OnTapped += ((object sender, EventArgs e) =>
  1454. {
  1455. var qaFormPicker = new DigitalFormsPicker();
  1456. Navigation.PushAsync(qaFormPicker);
  1457. });
  1458. toolEntries.Add(Forms);
  1459. //Equipment
  1460. ToolEntry Equipment = new ToolEntry
  1461. {
  1462. Text = "Equipment",
  1463. Image = "digger"
  1464. };
  1465. Equipment.IsVisible = PRSSecurity.CanView<Equipment>();
  1466. Equipment.OnTapped += (async (object sender, EventArgs e) =>
  1467. {
  1468. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  1469. {
  1470. var equipment = new EquipmentModule();
  1471. Navigation.PushAsync(equipment);
  1472. }
  1473. });
  1474. toolEntries.Add(Equipment);
  1475. //InOut
  1476. ToolEntry InOut = new ToolEntry
  1477. {
  1478. Text = "In/Out",
  1479. Image = "inout"
  1480. };
  1481. InOut.IsVisible = PRSSecurity.IsAllowed<CanViewInOutBoard>();
  1482. InOut.OnTapped += ((object sender, EventArgs e) =>
  1483. {
  1484. var staff_form = new StaffStatusPage();
  1485. Navigation.PushAsync(staff_form);
  1486. });
  1487. toolEntries.Add(InOut);
  1488. //Manufacturing
  1489. ToolEntry Manufacturing = new ToolEntry
  1490. {
  1491. Text = "Manufacturing",
  1492. Image = "manufacturingg"
  1493. };
  1494. if (Device.RuntimePlatform.Equals(Device.iOS))
  1495. {
  1496. Manufacturing.Image = "Image";
  1497. }
  1498. Manufacturing.IsVisible = PRSSecurity.IsAllowed<CanViewManufacturingOnMobile>();
  1499. Manufacturing.OnTapped += ((object sender, EventArgs e) =>
  1500. {
  1501. ManufacturingScreen manufacturingScreen = new ManufacturingScreen();
  1502. Navigation.PushAsync(manufacturingScreen);
  1503. });
  1504. toolEntries.Add(Manufacturing);
  1505. //My HR
  1506. ToolEntry MyHR = new ToolEntry
  1507. {
  1508. Text = "My HR",
  1509. Image = "myhr"
  1510. };
  1511. MyHR.OnTapped += ((object sender, EventArgs e) =>
  1512. {
  1513. MyHRHome myHRHome = new MyHRHome();
  1514. Navigation.PushAsync(myHRHome);
  1515. });
  1516. toolEntries.Add(MyHR);
  1517. //Notifications
  1518. ToolEntry Notifications = new ToolEntry()
  1519. {
  1520. Text = "Notifications",
  1521. Image = "notifications"
  1522. };
  1523. Notifications.OnTapped += (object sender, EventArgs e) =>
  1524. {
  1525. NotificationList notificationList = new NotificationList();
  1526. notificationList.NotificationsClosed += (n) =>
  1527. {
  1528. NumberOfNotfications = n;
  1529. RefreshOnNotificationsChange();
  1530. };
  1531. Navigation.PushAsync(notificationList);
  1532. };
  1533. toolEntries.Add(Notifications);
  1534. ToolEntry Products = new ToolEntry()
  1535. {
  1536. Text = "Products",
  1537. Image = "products"
  1538. };
  1539. Products.OnTapped += ((object sender, EventArgs e) =>
  1540. {
  1541. if (GlobalVariables.ProductsLoaded)
  1542. {
  1543. ProductList products = new ProductList(GlobalVariables.ProductShells);
  1544. Navigation.PushAsync(products);
  1545. }
  1546. else
  1547. {
  1548. ProductList products = new ProductList();
  1549. Navigation.PushAsync(products);
  1550. }
  1551. });
  1552. toolEntries.Add(Products);
  1553. //Purchase Orders
  1554. ToolEntry PurchaseOrders = new ToolEntry()
  1555. {
  1556. Text = "Purchase Orders",
  1557. Image = "shoppingcart"
  1558. };
  1559. PurchaseOrders.IsVisible = PRSSecurity.CanView<PurchaseOrder>();
  1560. PurchaseOrders.OnTapped += ((object sender, EventArgs e) =>
  1561. {
  1562. PurchaseOrderModule page = new PurchaseOrderModule();
  1563. Navigation.PushAsync(page);
  1564. });
  1565. toolEntries.Add(PurchaseOrders);
  1566. //Scanner
  1567. ToolEntry Scanner = new ToolEntry
  1568. {
  1569. Text = "Scanner",
  1570. Image = "scanner"
  1571. };
  1572. Scanner.OnTapped += ((object sender, EventArgs e) =>
  1573. {
  1574. ScannerPage scannerPage = new ScannerPage();
  1575. Navigation.PushAsync(scannerPage);
  1576. });
  1577. toolEntries.Add(Scanner);
  1578. //Site
  1579. ToolEntry Site = new ToolEntry
  1580. {
  1581. Text = "Site",
  1582. Image = "construction"
  1583. };
  1584. Site.OnTapped += ((object sender, EventArgs e) =>
  1585. {
  1586. Site site = new Site(new Job { ID = _job.ID, Name = _job.Name, JobNumber = _job.JobNumber });
  1587. Navigation.PushAsync(site);
  1588. //if (_job.ID == Guid.Empty)
  1589. //{
  1590. // JobSelectionPage jobSelectionPage = new JobSelectionPage(true);
  1591. // jobSelectionPage.OnItemSelected += (async () =>
  1592. // {
  1593. // if (jobSelectionPage.Job.ID != Guid.Empty)
  1594. // {
  1595. // Job selectedJob = new Job();
  1596. // selectedJob.ID = jobSelectionPage.Job.ID;
  1597. // selectedJob.JobNumber = jobSelectionPage.Job.JobNumber;
  1598. // selectedJob.Name = jobSelectionPage.Job.Name;
  1599. // Site site = new Site(selectedJob);
  1600. // var previousPage = Navigation.NavigationStack.LastOrDefault();
  1601. // await Navigation.PushAsync(site);
  1602. // Navigation.RemovePage(previousPage);
  1603. // }
  1604. // });
  1605. // Navigation.PushAsync(jobSelectionPage);
  1606. //}
  1607. });
  1608. toolEntries.Add(Site);
  1609. //Store Requis
  1610. ToolEntry StoreRequis = new ToolEntry
  1611. {
  1612. Text = "Store Requis",
  1613. Image = "storerequis"
  1614. };
  1615. StoreRequis.IsVisible = PRSSecurity.CanView<Requisition>();
  1616. StoreRequis.OnTapped += ((object sender, EventArgs e) =>
  1617. {
  1618. var storeRequisList = new StoreRequiList();
  1619. Navigation.PushAsync(storeRequisList);
  1620. });
  1621. toolEntries.Add(StoreRequis);
  1622. //Tasks
  1623. ToolEntry Tasks = new ToolEntry
  1624. {
  1625. Text = "Tasks",
  1626. Image = "tasks"
  1627. };
  1628. Tasks.IsVisible = PRSSecurity.IsAllowed<CanViewTasks>();
  1629. Tasks.OnTapped += ((object sender, EventArgs e) =>
  1630. {
  1631. var tasksForm = new TasksList();
  1632. Navigation.PushAsync(tasksForm);
  1633. });
  1634. toolEntries.Add(Tasks);
  1635. //Warehousing
  1636. ToolEntry Warehousing = new ToolEntry
  1637. {
  1638. Text = "Warehousing",
  1639. Image = "newwarehousing"
  1640. };
  1641. Warehousing.IsVisible = PRSSecurity.CanView<StockWarehouse>();
  1642. Warehousing.OnTapped += ((object sender, EventArgs e) =>
  1643. {
  1644. Warehousing2 locations = new Warehousing2();
  1645. Navigation.PushAsync(locations);
  1646. });
  1647. toolEntries.Add(Warehousing);
  1648. AddChildren();
  1649. });
  1650. }
  1651. catch { }
  1652. }
  1653. private void AddChildren()
  1654. {
  1655. Device.BeginInvokeOnMainThread(() =>
  1656. {
  1657. foreach (ToolEntry toolEntry in toolEntries)
  1658. {
  1659. toolEntry.Margin = new Thickness(5, 0, 5, 0);
  1660. flexLayout.Children.Add(toolEntry);
  1661. }
  1662. SearchForNewNotifications();
  1663. AddBlanks();
  1664. });
  1665. }
  1666. private void AddBlanks()
  1667. {
  1668. for (int x = 0; x < 6; x++)
  1669. {
  1670. ToolEntry toolEntry = new ToolEntry(true);
  1671. toolEntry.Margin = new Thickness(5, 0, 5, 0);
  1672. flexLayout.Children.Add(toolEntry);
  1673. }
  1674. }
  1675. private void Settings_Tapped(object sender, EventArgs e)
  1676. {
  1677. try
  1678. {
  1679. Settings settingsform = new Settings();
  1680. settingsform.Disappearing += (object sender2, EventArgs e2) =>
  1681. {
  1682. settingsform = (Settings)sender2;
  1683. if (settingsform.SettingsChanged)
  1684. Navigation.PopModalAsync();
  1685. };
  1686. Navigation.PushAsync(settingsform);
  1687. }
  1688. catch { }
  1689. }
  1690. #endregion
  1691. }
  1692. }