MainPageUtils.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. using static comal.timesheets.CustomControls.JobShell;
  20. using static InABox.Mobile.LocationServices;
  21. using iText.Kernel.XMP.Impl;
  22. namespace comal.timesheets
  23. {
  24. public delegate void MainPageNotificationsChanged();
  25. public delegate void RefreshScreen();
  26. public delegate void RequestUserInputForTask(Guid taskID);
  27. public delegate void TaskTitleChanged(string title);
  28. public static class MainPageUtils
  29. {
  30. public static event MainPageNotificationsChanged OnMainPageNotificationsChanged;
  31. public static event RefreshScreen OnRefreshScreen;
  32. public static event RequestUserInputForTask OnRequestUserInput;
  33. public static event TaskTitleChanged OnTaskTitleChanged;
  34. public static Assignment CurrentAssignment = null;
  35. public static JobShell Job = new JobShell();
  36. public static int NumberOfNotifications = 0;
  37. public static string matchedDeviceName = "";
  38. public static string deviceName = "";
  39. public static bool bRecentlyUpdatedTiles = false;
  40. public static TimeSheet _timesheet = null;
  41. public static Employee _employee = null;
  42. public static CoreTable _jobs = null;
  43. public static bool firstLoad = true;
  44. public static bool recentlyAskedToUpdate = true;
  45. public static int updateCounter;
  46. public static Kanban CurrentTask = null;
  47. public static void Init()
  48. {
  49. InitEvents();
  50. InitData();
  51. InitTimers();
  52. CheckJobOnlyEmployee();
  53. }
  54. private static void CheckJobOnlyEmployee()
  55. {
  56. try
  57. {
  58. GlobalVariables.EmployeeJobs = new List<JobShell>();
  59. if (!PRSSecurity.IsAllowed<IsJobOnlyEmployee>())
  60. return;
  61. CoreTable table = new Client<JobEmployee>().Query(new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID));
  62. if (!table.Rows.Any())
  63. return;
  64. foreach (CoreRow row in table.Rows)
  65. GlobalVariables.EmployeeJobs.Add(CreateJobShell(row));
  66. }
  67. catch (Exception ex)
  68. {
  69. var log = new MobileLogging(LogType.Query, "CheckJobOnlyEmployee()", ex.Message + ex.StackTrace, "MainPageUtils");
  70. }
  71. }
  72. private static JobShell CreateJobShell(CoreRow row)
  73. {
  74. JobShell job = new JobShell();
  75. job.ID = row.Get<JobEmployee, Guid>(x => x.JobLink.ID);
  76. job.JobNumber = row.Get<JobEmployee, string>(x => x.JobLink.JobNumber);
  77. job.Name = row.Get<JobEmployee, string>(x => x.JobLink.Name);
  78. job.JobStatusDescription = row.Get<JobEmployee, string>(x => x.JobLink.JobStatus.Description);
  79. return job;
  80. }
  81. private static void InitEvents()
  82. {
  83. try
  84. {
  85. App.GPS.OnLocationFound += LocationFound;
  86. App.GPS.OnLocationError += LocationError;
  87. App.Bluetooth.OnScanFinished += ScanFinished;
  88. App.Data.DataChanged += (s, t) => { OnRefreshScreen?.Invoke(); };
  89. App.Data.DataRefreshed += () => { OnRefreshScreen?.Invoke(); };
  90. }
  91. catch (Exception ex)
  92. {
  93. var log = new MobileLogging(LogType.BackgroundProcess, "InitEvents()", ex.Message + ex.StackTrace, "MainPageUtils");
  94. }
  95. }
  96. private static void InitData()
  97. {
  98. try
  99. {
  100. GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
  101. GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
  102. App.Data.Employee.ID = GlobalVariables.EmpID;
  103. App.Data.Employee.Name = GlobalVariables.EmpName;
  104. }
  105. catch (Exception ex)
  106. {
  107. var log = new MobileLogging(LogType.BackgroundProcess, "InitData()", ex.Message + ex.StackTrace, "MainPageUtils");
  108. }
  109. try
  110. {
  111. bool deliveryteam = new Client<EmployeeTeam>().Query(new Filter<EmployeeTeam>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
  112. .And(x => x.TeamLink.ID).IsEqualTo(Guid.Parse("b7871075-4768-411f-b4f0-30874d5e6db6"))).Rows.Any() ? true : false;
  113. if (deliveryteam || GlobalVariables.EmpID == Guid.Parse("ec88c8cc-9c05-4da8-89d8-060519ea1b70"))
  114. GlobalVariables.IsDeliveryDriver = true;
  115. else
  116. GlobalVariables.IsDeliveryDriver = false;
  117. _timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  118. _employee = App.Data.Employee;
  119. _jobs = App.Data.Jobs;
  120. deviceName = MobileUtils.GetDeviceID();
  121. firstLoad = false;
  122. }
  123. catch (Exception ex)
  124. {
  125. var log = new MobileLogging(LogType.Query, "InitData()", ex.Message + ex.StackTrace, "MainPageUtils");
  126. }
  127. }
  128. private static void InitTimers()
  129. {
  130. Timer t = new Timer(RecentlyAskedToUpdateTimer, null, 600000, 600000); //user is reminded to update when opening screen after timer of 10 minutes
  131. updateCounter = 1; //user is forced to update after 3rd reminder
  132. Timer t1 = new Timer(RecentlyUpdatedTilesTimer, null, 30000, 30000);
  133. //bluetooth data is allowed to upload once every minute, notifications refreshing is piggybacked to this too
  134. }
  135. private static void RecentlyAskedToUpdateTimer(object o)
  136. {
  137. recentlyAskedToUpdate = false;
  138. }
  139. private static void RecentlyUpdatedTilesTimer(object o)
  140. {
  141. bRecentlyUpdatedTiles = false;
  142. App.Data.Refresh(true);
  143. SearchForNewNotifications();
  144. }
  145. #region Assignments
  146. public static Assignment CheckCurrentAssignment()
  147. {
  148. Thread.Sleep(5000);
  149. StartAssignmentTimer();
  150. CoreTable table = new Client<Assignment>().Query(
  151. new Filter<Assignment>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
  152. .And(x => x.Date).IsEqualTo(DateTime.Today.Date)
  153. .And(x => x.Completed).IsEqualTo(null)
  154. .And(x => x.Booked.Finish).IsEqualTo(null),
  155. null,
  156. new SortOrder<Assignment>(x => x.Actual.Start, SortDirection.Ascending));
  157. if (!table.Rows.Any())
  158. {
  159. Job.OnJobIDChanged += OnJobIDChanged;
  160. return null;
  161. }
  162. else
  163. return table.Rows.LastOrDefault().ToObject<Assignment>();
  164. }
  165. private static void StartAssignmentTimer()
  166. {
  167. Timer t = new Timer(AssignmentTimerCallback, null, 300000, 300000);
  168. }
  169. private static void AssignmentTimerCallback(object state)
  170. {
  171. try
  172. {
  173. if (CurrentAssignment != null)
  174. SaveCurrentAssignment("PRS Mobile main screen - Saving assignment on 5 minute timer");
  175. }
  176. catch (Exception ex)
  177. {
  178. var log = new MobileLogging(LogType.Save, "AssignmentTimerCallback()", ex.Message + ex.StackTrace, "MainPageUtils");
  179. }
  180. }
  181. public static void SaveCurrentAssignment(string auditnote, bool complete = false)
  182. {
  183. if (!complete)
  184. CurrentAssignment.Booked.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  185. else
  186. {
  187. CurrentAssignment.Actual.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  188. CurrentAssignment.Completed = DateTime.Now;
  189. }
  190. new Client<Assignment>().Save(CurrentAssignment, auditnote);
  191. }
  192. static DateTime RoundToNearestInterval(DateTime dt, TimeSpan d)
  193. {
  194. int f = 0;
  195. double m = (double)(dt.Ticks % d.Ticks) / d.Ticks;
  196. if (m >= 0.5)
  197. f = 1;
  198. return new DateTime(((dt.Ticks / d.Ticks) + f) * d.Ticks);
  199. }
  200. public static void UseCurrentAssignment(Assignment assgn)
  201. {
  202. try
  203. {
  204. CurrentAssignment = assgn;
  205. SaveCurrentAssignment("PRS Mobile main screen - saving assignment on re-login to App");
  206. if (CurrentAssignment.JobLink.ID != Guid.Empty)
  207. {
  208. Job.ID = CurrentAssignment.JobLink.ID;
  209. var job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(Job.ID)).Rows.FirstOrDefault().ToObject<Job>();
  210. Job.JobNumber = job.JobNumber;
  211. Job.Name = job.Name;
  212. Job.OnJobIDChanged += OnJobIDChanged;
  213. }
  214. if (CurrentAssignment.Task.ID != Guid.Empty)
  215. {
  216. var task = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(CurrentAssignment.Task.ID)).Rows.FirstOrDefault().ToObject<Kanban>();
  217. OnTaskTitleChanged?.Invoke(task.Title);
  218. }
  219. }
  220. catch (Exception ex)
  221. {
  222. var log = new MobileLogging(LogType.Query, "UseCurrentAssignment()", ex.Message + ex.StackTrace, "MainPageUtils");
  223. }
  224. }
  225. public static void OnJobIDChanged(Guid jobid)
  226. {
  227. if (CurrentAssignment == null)
  228. CreateNewAssignment(jobid, Guid.Empty);
  229. else
  230. {
  231. SaveCurrentAssignment("PRS Mobile main screen - saving assignment on job change", true);
  232. CreateNewAssignment(jobid, Guid.Empty);
  233. }
  234. }
  235. public static void CreateNewAssignment(Guid jobid, Guid taskID)
  236. {
  237. CurrentAssignment = new Assignment { Date = DateTime.Now.Date };
  238. CurrentAssignment.EmployeeLink.ID = GlobalVariables.EmpID;
  239. CurrentAssignment.Actual.Start = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay;
  240. CurrentAssignment.Booked.Start = CurrentAssignment.Actual.Start;
  241. CurrentAssignment.Booked.Finish = RoundToNearestInterval(DateTime.Now, new TimeSpan(0, 5, 0)).TimeOfDay.Add(new TimeSpan(0, 5, 0));
  242. if (jobid != Guid.Empty)
  243. AddJobDetails(jobid);
  244. if (taskID != Guid.Empty)
  245. AddTaskDetails(taskID);
  246. }
  247. private static void AddJobDetails(Guid jobid)
  248. {
  249. try
  250. {
  251. CurrentAssignment.JobLink.ID = jobid;
  252. var job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(jobid)).Rows.FirstOrDefault().ToObject<Job>();
  253. CurrentAssignment.Title = "Clocking on to job " + job.Name + " (" + job.JobNumber + ") on PRS Mobile";
  254. OnTaskTitleChanged?.Invoke("Task");
  255. new Client<Assignment>().Save(CurrentAssignment, "Changed job on mobile - creating new assignment");
  256. }
  257. catch (Exception ex)
  258. {
  259. var log = new MobileLogging(LogType.Query, "AddJobDetails()", ex.Message + ex.StackTrace, "MainPageUtils");
  260. }
  261. }
  262. private static void AddTaskDetails(Guid taskID)
  263. {
  264. try
  265. {
  266. CurrentAssignment.Task.ID = taskID;
  267. var task = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(taskID)).Rows.FirstOrDefault().ToObject<Kanban>();
  268. CurrentAssignment.Title = "Clocking on to task " + task.Title + " on PRS Mobile";
  269. OnTaskTitleChanged?.Invoke(task.Title);
  270. if (!string.IsNullOrWhiteSpace(task.JobLink.JobNumber))
  271. Job.JobNumber = task.JobLink.JobNumber;
  272. new Client<Assignment>().Save(CurrentAssignment, "Changed task on mobile - creating new assignment");
  273. }
  274. catch (Exception ex)
  275. {
  276. var log = new MobileLogging(LogType.Query, "AddTaskDetails()", ex.Message + ex.StackTrace, "MainPageUtils");
  277. }
  278. }
  279. #endregion
  280. #region Notifications
  281. public static Page DetermineCorrectPage(Plugin.LocalNotification.EventArgs.NotificationActionEventArgs e)
  282. {
  283. string data = e.Request.ReturningData;
  284. int index = data.IndexOf("$");
  285. Guid ID = Guid.Parse(data.Remove(index));
  286. string type = data.Substring(index + 1);
  287. if (type == "Comal.Classes.Kanban")
  288. return new AddEditTask(ID);
  289. else if (type == "Comal.Classes.Delivery")
  290. return new DeliveryDetails(ID);
  291. else
  292. return null;
  293. }
  294. public static void SearchForNewNotifications()
  295. {
  296. //notifications poll reliably in the background for Anroid, unreliable for iOS due to difficulty with cross-platform plugins for notifications
  297. Task.Run(() =>
  298. {
  299. try
  300. {
  301. if (ClientFactory.UserGuid != Guid.Empty)
  302. {
  303. CoreTable table = new Client<Notification>().Query
  304. (new Filter<Notification>(x => x.Employee.UserLink.ID).IsEqualTo(ClientFactory.UserGuid).And(X => X.Closed).IsEqualTo(DateTime.MinValue),
  305. new Columns<Notification>(
  306. x => x.ID, //0
  307. x => x.Sender.Name, //1
  308. x => x.Title, //2
  309. x => x.Created, //3
  310. x => x.Description, //4
  311. x => x.EntityType, //5
  312. x => x.EntityID //6
  313. )
  314. );
  315. if (NumberOfNotifications == table.Rows.Count()) //no new notifications or none present at all
  316. return;
  317. else //new notifications or previous notifications have now been dismissed
  318. {
  319. NumberOfNotifications = table.Rows.Count();
  320. OnMainPageNotificationsChanged?.Invoke();
  321. CheckNotificationsPushed(table);
  322. }
  323. }
  324. }
  325. catch (Exception ex)
  326. {
  327. var log = new MobileLogging(LogType.Query, "SearchForNewNotifications()", ex.Message + ex.StackTrace, "MainPageUtils");
  328. }
  329. });
  330. }
  331. private static void CheckNotificationsPushed(CoreTable table)
  332. {
  333. try
  334. {
  335. if (!Application.Current.Properties.ContainsKey("LastPushedNotifications"))
  336. {
  337. Application.Current.Properties.Add("LastPushedNotifications", DateTime.Now);
  338. }
  339. DateTime lastPushed = DateTime.Parse(Application.Current.Properties["LastPushedNotifications"].ToString());
  340. List<NotificationShell> toNotify = new List<NotificationShell>();
  341. foreach (CoreRow row in table.Rows)
  342. {
  343. List<object> list = row.Values;
  344. DateTime created = DateTime.Parse(list[3].ToString());
  345. if (created > new DateTime(2022, 8, 22)) // prevent spam from buildup of old notifications before this is released
  346. {
  347. if (created > lastPushed)
  348. {
  349. if (list[1] == null) list[1] = "";
  350. if (list[2] == null) list[2] = "";
  351. if (list[3] == null) list[3] = DateTime.MinValue;
  352. if (list[4] == null) list[4] = "";
  353. if (list[5] == null) list[5] = "";
  354. if (list[6] == null) list[6] = Guid.Empty;
  355. NotificationShell shell = new NotificationShell
  356. {
  357. ID = Guid.Parse(list[0].ToString()),
  358. Sender = list[1].ToString(),
  359. Title = list[2].ToString(),
  360. Created = DateTime.Parse(list[3].ToString()),
  361. EntityType = list[5].ToString(),
  362. EntityID = Guid.Parse(list[6].ToString())
  363. };
  364. toNotify.Add(shell); //add notification to be pushed
  365. }
  366. }
  367. }
  368. if (toNotify.Count > 0)
  369. PushNotificationsAsync(toNotify);
  370. }
  371. catch { }
  372. }
  373. private static async Task PushNotificationsAsync(List<NotificationShell> shells)
  374. {
  375. try
  376. {
  377. int count = 1;
  378. foreach (NotificationShell shell in shells)
  379. {
  380. var notification = new NotificationRequest
  381. {
  382. BadgeNumber = 1,
  383. Description = shell.Title,
  384. Title = "New PRS Notification: ",
  385. ReturningData = shell.EntityID.ToString() + "$" + shell.EntityType,
  386. NotificationId = count,
  387. };
  388. count++;
  389. NotificationImage img = new NotificationImage();
  390. img.ResourceName = "icon16.png";
  391. notification.Image = img;
  392. await LocalNotificationCenter.Current.Show(notification);
  393. }
  394. Application.Current.Properties["LastPushedNotifications"] = DateTime.Now;
  395. }
  396. catch { }
  397. }
  398. #endregion
  399. #region Location / Bluetooth
  400. private static void LocationFound(LocationServices sender)
  401. {
  402. if (App.Bluetooth.RecentlyScanned)
  403. UploadTiles();
  404. try
  405. {
  406. TimeSheet timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
  407. if (timesheet != null)
  408. {
  409. if (timesheet.StartLocation.Latitude.Equals(0.0F) && timesheet.StartLocation.Longitude.Equals(0.0F))
  410. {
  411. timesheet.StartLocation.Latitude = sender.Latitude;
  412. timesheet.StartLocation.Longitude = sender.Longitude;
  413. timesheet.StartLocation.Timestamp = sender.TimeStamp;
  414. timesheet.Address = sender.Address;
  415. new Client<TimeSheet>().Save(timesheet, "Updating Timesheet with GPS Coordinates", (o, e) => { });
  416. }
  417. }
  418. if (!string.IsNullOrWhiteSpace(matchedDeviceName))
  419. {
  420. InABox.Core.Location curlocation = new InABox.Core.Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };
  421. curlocation.Timestamp = DateTime.Now;
  422. GPSTrackerLocation gpsTrackerLocation = new GPSTrackerLocation();
  423. gpsTrackerLocation.DeviceID = matchedDeviceName;
  424. gpsTrackerLocation.Location.Timestamp = curlocation.Timestamp;
  425. gpsTrackerLocation.Location = curlocation;
  426. new Client<GPSTrackerLocation>().Save(gpsTrackerLocation, "Updated company device location from Timebench");
  427. }
  428. OnRefreshScreen?.Invoke();
  429. }
  430. catch (Exception ex)
  431. {
  432. var log = new MobileLogging(LogType.Save, "LocationFound()", ex.Message + ex.StackTrace, "MainPageUtils");
  433. }
  434. }
  435. private static async void UploadTiles()
  436. {
  437. try
  438. {
  439. if (App.GPS.Latitude.Equals(0.0F) && App.GPS.Longitude.Equals(0.0F))
  440. return;
  441. if (App.Bluetooth.DetectedBlueToothMACAddresses.Count == 0)
  442. return;
  443. if (bRecentlyUpdatedTiles)
  444. return;
  445. bRecentlyUpdatedTiles = true;
  446. await Task.Run(() =>
  447. {
  448. InABox.Core.Location curlocation = new InABox.Core.Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };
  449. curlocation.Timestamp = DateTime.Now;
  450. List<GPSTrackerLocation> trackersToUpdate = new List<GPSTrackerLocation>();
  451. foreach (String id in App.Bluetooth.DetectedBlueToothMACAddresses)
  452. {
  453. GPSTracker tracker = GlobalVariables.GPSTrackerCache.Find(x => x.DeviceID.Equals(id));
  454. bool stale = tracker.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 5, 0));
  455. bool moved = tracker.Location.DistanceTo(curlocation, UnitOfLength.Kilometers) > 0.1;
  456. if (stale || moved)
  457. {
  458. GlobalVariables.GPSTrackerCache.Remove(tracker);
  459. tracker.Location = curlocation;
  460. GlobalVariables.GPSTrackerCache.Add(tracker);
  461. //cache is updated
  462. GPSTrackerLocation gpsTrackerLocation = new GPSTrackerLocation();
  463. gpsTrackerLocation.DeviceID = tracker.DeviceID;
  464. gpsTrackerLocation.Location.Timestamp = tracker.Location.Timestamp;
  465. gpsTrackerLocation.Location = curlocation;
  466. trackersToUpdate.Add(gpsTrackerLocation);
  467. }
  468. }
  469. if (trackersToUpdate.Any())
  470. {
  471. if (ClientFactory.UserGuid != Guid.Empty)
  472. new Client<GPSTrackerLocation>().Save(trackersToUpdate, "Updating Bluetooth Device Locations");
  473. }
  474. App.Bluetooth.DetectedBlueToothMACAddresses.Clear();
  475. }
  476. );
  477. }
  478. catch (Exception ex)
  479. {
  480. var log = new MobileLogging(LogType.Save, "UploadTiles()", ex.Message + ex.StackTrace, "MainPageUtils");
  481. }
  482. //if ((master != null) && (master.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 15, 0))))
  483. //{
  484. // GPSTrackerLocation device = new GPSTrackerLocation();
  485. // device.DeviceID = MobileUtils.GetDeviceID();
  486. // device.Location.Latitude = App.GPS.Latitude;
  487. // device.Location.Longitude = App.GPS.Longitude;
  488. // device.Location.Timestamp = DateTime.Now;
  489. // locations.Add(device);
  490. // //device.BatteryLevel = ((double)CrossBattery.Current.RemainingChargePercent);
  491. // //new Client<GPSTrackerLocation>().Save(device, "Updating Device Location"); //, SaveTrackerCallback);
  492. //}
  493. #region OLD
  494. //for (int i = 0; i < App.Bluetooth.Devices.Length; i++)
  495. //{
  496. // String id = App.Bluetooth.Devices[i];
  497. // int level = App.Bluetooth.BatteryLevels[i];
  498. // var btmaster = trackers.FirstOrDefault(x => x.DeviceID.Equals(id));
  499. // if ((btmaster != null) && (!locations.Any(x => x.DeviceID.Equals(btmaster.DeviceID))))
  500. // {
  501. // bool stale = btmaster.Location.Timestamp < DateTime.Now.Subtract(new TimeSpan(0, 15, 0));
  502. // bool moved = btmaster.Location.DistanceTo(curlocation, UnitOfLength.Kilometers) > 0.1;
  503. // if (stale || moved)
  504. // {
  505. // GPSTrackerLocation location = new GPSTrackerLocation();
  506. // location.DeviceID = id;
  507. // location.Location.Latitude = App.GPS.Latitude;
  508. // location.Location.Longitude = App.GPS.Longitude;
  509. // location.Location.Timestamp = DateTime.Now;
  510. // location.BatteryLevel = level;
  511. // locations.Add(location);
  512. // }
  513. // }
  514. // //new Client<GPSTrackerLocation>().Save(location, "Found Kontakt Device"); //, SaveTrackerCallback);
  515. //}
  516. //if (locations.Any())
  517. // new Client<GPSTrackerLocation>().Save(locations, "Updating Bluetooth Device Locations", (o, e) => { });
  518. #endregion
  519. }
  520. private static void LocationError(LocationServices sebder, Exception error)
  521. {
  522. }
  523. private static void ScanFinished(Bluetooth sender)
  524. {
  525. try
  526. {
  527. OnRefreshScreen?.Invoke();
  528. if (App.GPS.RecentlyLocated)
  529. UploadTiles();
  530. }
  531. catch { }
  532. }
  533. #endregion
  534. public static Dictionary<Guid, string> GetTasks()
  535. {
  536. Dictionary<Guid, string> dict = new Dictionary<Guid, string>();
  537. try
  538. {
  539. CoreTable table = new Client<Kanban>().Query(
  540. new Filter<Kanban>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
  541. .And(x => x.Category).IsNotEqualTo("Complete"),
  542. new Columns<Kanban>(x => x.ID, x => x.Title)
  543. );
  544. foreach (CoreRow row in table.Rows)
  545. {
  546. dict.Add
  547. (
  548. row.Get<Kanban, Guid>(x => x.ID),
  549. row.Get<Kanban, string>(x => x.Title)
  550. );
  551. }
  552. }
  553. catch (Exception ex)
  554. {
  555. var log = new MobileLogging(LogType.Query, "GetTasks()", ex.Message + ex.StackTrace, "MainPageUtils");
  556. }
  557. return dict;
  558. }
  559. public static void OnTaskSelected(Guid ID, string title)
  560. {
  561. if (CurrentAssignment != null)
  562. OnRequestUserInput?.Invoke(ID);
  563. else
  564. CreateNewAssignment(Guid.Empty, ID);
  565. }
  566. public static void ChangeAssignmentTask(Guid taskID)
  567. {
  568. AddTaskDetails(taskID);
  569. }
  570. }
  571. }