GlobalVariables.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using Xamarin.Forms;
  9. using comal.timesheets;
  10. using comal.timesheets.CustomControls;
  11. using Xamarin.Essentials;
  12. namespace comal.timesheets
  13. {
  14. public static class GlobalVariables
  15. {
  16. //do not change these or cache will not be able to find them on the next update
  17. public const string CacheURLString = "ConnectionSettingsURL";
  18. public const string CachePortString = "ConnectionSettingsPort";
  19. public const string CacheUserIDString = "ConnectionSettingsUserID";
  20. public const string CachePasswordString = "ConnectionSettingsPassword";
  21. public static List<ProductShell> ProductShells { get; set; }
  22. public static List<ProductFamily> ProductFamilies { get; set; }
  23. public static bool ProductsLoaded { get; set; }
  24. public static Guid EmpID { get; set; }
  25. public static string EmpName { get; set; }
  26. public static List<EmployeeShell> EmployeeShells { get; set; }
  27. public static List<EmployeeShell> TeamEmployeeShells { get; set; }
  28. public static bool EmployeesLoaded { get; set; }
  29. public static List<String> TeamNames { get; set; }
  30. public static List<JobShell> JobShells { get; set; }
  31. public static bool JobsLoaded { get; set; }
  32. public static int EmployeeFormsToDo { get; set; }
  33. public static double XamarinWidth { get; set; }
  34. public static List<GPSTracker> GPSTrackerCache { get; set; }
  35. public static string DeviceString { get; set; }
  36. public static bool ChangeUser { get; set; }
  37. public static bool InternalOnAppearing { get; set; }
  38. public static int QualificationsNeedingAttention { get; set; }
  39. public static string LoadFromLinkString { get; set; }
  40. public static bool IsJobOnlyEmployee { get => InABox.Core.Security.IsAllowed<IsJobOnlyEmployee>(); }
  41. public static List<JobShell> EmployeeJobs { get; set; }
  42. public static bool IsDeliveryDriver { get; set; }
  43. public static string GetEmployeeName()
  44. {
  45. try
  46. {
  47. String employeeName = new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns<Employee>(x => x.Name)).Rows.First().ToObject<Employee>().Name;
  48. return employeeName;
  49. }
  50. catch
  51. {
  52. return "";
  53. }
  54. }
  55. public static Guid GetEmployeeID()
  56. {
  57. try
  58. {
  59. Guid employeeID = new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns<Employee>(x => x.ID)).Rows.First().ToObject<Employee>().ID;
  60. return employeeID;
  61. }
  62. catch
  63. {
  64. return Guid.Empty;
  65. }
  66. }
  67. public static bool VisibleToTestTeam()
  68. {
  69. bool isVisible = false;
  70. if (EmpID.Equals(Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac")) || EmpID.Equals(Guid.Parse("b0d7246e-4506-4149-bd8b-cbeebe047b53"))
  71. || EmpID.Equals(Guid.Parse("a83346a1-dde5-4ff7-8053-33daf92a9298")) || EmpID.Equals(Guid.Parse("3fe88ee9-7f07-4293-8036-fcd8ce6c4342")))
  72. {
  73. isVisible = true;
  74. }
  75. return isVisible;
  76. }
  77. public static void GetXamarinWidth()
  78. {
  79. var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
  80. var width = mainDisplayInfo.Width;
  81. XamarinWidth = width / mainDisplayInfo.Density;
  82. }
  83. public static bool UpdateHRItemsNeedingAttention()
  84. {
  85. try
  86. {
  87. GlobalVariables.EmployeeFormsToDo = 0;
  88. GlobalVariables.QualificationsNeedingAttention = 0;
  89. CoreTable table = new Client<EmployeeQualification>().Query(
  90. new Filter<EmployeeQualification>(x => x.Employee.ID).IsEqualTo(GlobalVariables.EmpID),
  91. new Columns<EmployeeQualification>(
  92. x => x.ID, //0
  93. x => x.Expiry, //1
  94. x => x.FrontPhoto.ID //2
  95. )
  96. );
  97. if (table.Rows.Any())
  98. {
  99. List<Guid> IDs = new List<Guid>();
  100. foreach (CoreRow row in table.Rows)
  101. {
  102. List<object> list = row.Values;
  103. if (list[0] == null) { list[0] = Guid.Empty; } //0
  104. if (list[1] == null) { list[1] = DateTime.MinValue; } //1
  105. if (list[2] == null) { list[2] = Guid.Empty; } //2
  106. if (DateTime.Parse(list[1].ToString()) <= DateTime.Today.AddDays(30))
  107. {
  108. if (!Guid.Parse(list[2].ToString()).Equals(Guid.Empty))
  109. {
  110. CoreTable innerTable = new Client<Document>().Query(
  111. new Filter<Document>(x => x.ID).IsEqualTo(Guid.Parse(list[2].ToString())),
  112. new Columns<Document>(x => x.Created)
  113. );
  114. CoreRow innerRow = innerTable.Rows.First();
  115. List<object> innerList = innerRow.Values;
  116. if (DateTime.Parse(innerList[0].ToString()) < DateTime.Today.AddDays(-7)) //if photo was added more than 7 days ago, added to list needing attention
  117. {
  118. if (!IDs.Contains(Guid.Parse(list[0].ToString())))
  119. IDs.Add(Guid.Parse(list[0].ToString()));
  120. }
  121. }
  122. else
  123. {
  124. if (!IDs.Contains(Guid.Parse(list[0].ToString())))
  125. IDs.Add(Guid.Parse(list[0].ToString()));
  126. }
  127. }
  128. if (Guid.Parse(list[2].ToString()).Equals(Guid.Empty))
  129. {
  130. if (!IDs.Contains(Guid.Parse(list[0].ToString())))
  131. IDs.Add(Guid.Parse(list[0].ToString()));
  132. }
  133. }
  134. GlobalVariables.QualificationsNeedingAttention = IDs.Count;
  135. }
  136. CoreTable table1 = new Client<EmployeeForm>().Query(
  137. new Filter<EmployeeForm>(x => x.Parent.ID).IsEqualTo(GlobalVariables.EmpID).And
  138. (x => x.FormCompleted).IsEqualTo(DateTime.MinValue),
  139. new Columns<EmployeeForm>(x => x.FormCompleted)
  140. );
  141. if (table1.Rows.Any())
  142. {
  143. GlobalVariables.EmployeeFormsToDo = table1.Rows.Count;
  144. }
  145. if (GlobalVariables.QualificationsNeedingAttention > 0 || GlobalVariables.EmployeeFormsToDo > 0)
  146. {
  147. return true;
  148. }
  149. else
  150. return false;
  151. }
  152. catch
  153. {
  154. return false;
  155. }
  156. }
  157. public static void CheckEmployeeFormsToDo()
  158. {
  159. try
  160. {
  161. CoreTable table1 = new Client<EmployeeForm>().Query(
  162. new Filter<EmployeeForm>(x => x.Parent.ID).IsEqualTo(GlobalVariables.EmpID).And
  163. (x => x.FormCompleted).IsEqualTo(DateTime.MinValue),
  164. new Columns<EmployeeForm>(x => x.FormCompleted)
  165. );
  166. if (table1.Rows.Any())
  167. {
  168. GlobalVariables.EmployeeFormsToDo = table1.Rows.Count;
  169. }
  170. else
  171. {
  172. GlobalVariables.EmployeeFormsToDo = 0;
  173. }
  174. }
  175. catch
  176. {
  177. }
  178. }
  179. }
  180. }