using Comal.Classes; using InABox.Clients; using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Xamarin.Forms; using comal.timesheets; using comal.timesheets.CustomControls; using Xamarin.Essentials; namespace comal.timesheets { public static class GlobalVariables { //do not change these or cache will not be able to find them on the next update public const string CacheURLString = "ConnectionSettingsURL"; public const string CachePortString = "ConnectionSettingsPort"; public const string CacheUserIDString = "ConnectionSettingsUserID"; public const string CachePasswordString = "ConnectionSettingsPassword"; public const string CacheSettingsURL = "CacheSettingsURL"; public static List ProductShells { get; set; } public static List ProductFamilies { get; set; } public static bool ProductsLoaded { get; set; } public static Guid EmpID { get; set; } public static string EmpName { get; set; } public static List EmployeeShells { get; set; } public static List TeamEmployeeShells { get; set; } public static bool EmployeesLoaded { get; set; } public static List TeamNames { get; set; } public static List JobShells { get; set; } public static bool JobsLoaded { get; set; } public static int EmployeeFormsToDo { get; set; } public static double XamarinWidth { get; set; } public static List GPSTrackerCache { get; set; } public static string DeviceString { get; set; } public static bool ChangeUser { get; set; } public static bool InternalOnAppearing { get; set; } public static int QualificationsNeedingAttention { get; set; } public static string LoadFromLinkString { get; set; } public static bool IsJobOnlyEmployee { get => InABox.Core.Security.IsAllowed(); } public static List EmployeeJobs { get; set; } public static bool IsDeliveryDriver { get; set; } public static string GetEmployeeName() { try { String employeeName = new Client().Query(new Filter(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns(x => x.Name)).Rows.First().ToObject().Name; return employeeName; } catch (Exception ex) { var log = new MobileLogging(LogType.Query, "GetEmployeeName", ex.Message + ex.StackTrace, "GlobalVariables.GetEmployeeName()"); return ""; } } public static Guid GetEmployeeID() { try { Guid employeeID = new Client().Query(new Filter(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid), new Columns(x => x.ID)).Rows.First().ToObject().ID; return employeeID; } catch(Exception ex) { var log = new MobileLogging(LogType.Query, "GetEmployeeID", ex.Message + ex.StackTrace, "GlobalVariables.GetEmployeeID()"); return Guid.Empty; } } public static bool VisibleToTestTeam() { bool isVisible = false; if (EmpID.Equals(Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac")) || EmpID.Equals(Guid.Parse("b0d7246e-4506-4149-bd8b-cbeebe047b53")) || EmpID.Equals(Guid.Parse("a83346a1-dde5-4ff7-8053-33daf92a9298")) || EmpID.Equals(Guid.Parse("3fe88ee9-7f07-4293-8036-fcd8ce6c4342"))) { isVisible = true; } return isVisible; } public static void GetXamarinWidth() { var mainDisplayInfo = DeviceDisplay.MainDisplayInfo; var width = mainDisplayInfo.Width; XamarinWidth = width / mainDisplayInfo.Density; } public static bool UpdateHRItemsNeedingAttention() { try { GlobalVariables.EmployeeFormsToDo = 0; GlobalVariables.QualificationsNeedingAttention = 0; CoreTable table = new Client().Query( new Filter(x => x.Employee.ID).IsEqualTo(GlobalVariables.EmpID), new Columns( x => x.ID, //0 x => x.Expiry, //1 x => x.FrontPhoto.ID //2 ) ); if (table.Rows.Any()) { List IDs = new List(); foreach (CoreRow row in table.Rows) { List list = row.Values; if (list[0] == null) { list[0] = Guid.Empty; } //0 if (list[1] == null) { list[1] = DateTime.MinValue; } //1 if (list[2] == null) { list[2] = Guid.Empty; } //2 if (DateTime.Parse(list[1].ToString()) <= DateTime.Today.AddDays(30)) { if (!Guid.Parse(list[2].ToString()).Equals(Guid.Empty)) { CoreTable innerTable = new Client().Query( new Filter(x => x.ID).IsEqualTo(Guid.Parse(list[2].ToString())), new Columns(x => x.Created) ); CoreRow innerRow = innerTable.Rows.First(); List innerList = innerRow.Values; if (DateTime.Parse(innerList[0].ToString()) < DateTime.Today.AddDays(-7)) //if photo was added more than 7 days ago, added to list needing attention { if (!IDs.Contains(Guid.Parse(list[0].ToString()))) IDs.Add(Guid.Parse(list[0].ToString())); } } else { if (!IDs.Contains(Guid.Parse(list[0].ToString()))) IDs.Add(Guid.Parse(list[0].ToString())); } } if (Guid.Parse(list[2].ToString()).Equals(Guid.Empty)) { if (!IDs.Contains(Guid.Parse(list[0].ToString()))) IDs.Add(Guid.Parse(list[0].ToString())); } } GlobalVariables.QualificationsNeedingAttention = IDs.Count; } CoreTable table1 = new Client().Query( new Filter(x => x.Parent.ID).IsEqualTo(GlobalVariables.EmpID).And (x => x.FormCompleted).IsEqualTo(DateTime.MinValue), new Columns(x => x.FormCompleted) ); if (table1.Rows.Any()) { GlobalVariables.EmployeeFormsToDo = table1.Rows.Count; } if (GlobalVariables.QualificationsNeedingAttention > 0 || GlobalVariables.EmployeeFormsToDo > 0) { return true; } else return false; } catch { return false; } } public static void CheckEmployeeFormsToDo() { try { CoreTable table1 = new Client().Query( new Filter(x => x.Parent.ID).IsEqualTo(GlobalVariables.EmpID).And (x => x.FormCompleted).IsEqualTo(DateTime.MinValue), new Columns(x => x.FormCompleted) ); if (table1.Rows.Any()) { GlobalVariables.EmployeeFormsToDo = table1.Rows.Count; } else { GlobalVariables.EmployeeFormsToDo = 0; } } catch { } } } }