GlobalVariables.cs 8.5 KB

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