GlobalVariables.cs 7.9 KB

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