///<summary>Sets Clinics.ClinicNum. Used when logging on to determines what clinic to start with based on user and workstation preferences.</summary> public static void LoadClinicNumForUser() { _clinicNum = 0; //aka headquarters clinic when clinics are enabled. if (!PrefC.HasClinicsEnabled || Security.CurUser == null) { return; } List <Clinic> listClinics = Clinics.GetForUserod(Security.CurUser); switch (PrefC.GetString(PrefName.ClinicTrackLast)) { case "Workstation": if (Security.CurUser.ClinicIsRestricted && Security.CurUser.ClinicNum != ComputerPrefs.LocalComputer.ClinicNum) //The user is restricted and it's not the clinic this computer has by default //User's default clinic isn't the LocalComputer's clinic, see if they have access to the Localcomputer's clinic, if so, use it. { Clinic clinic = listClinics.Find(x => x.ClinicNum == ComputerPrefs.LocalComputer.ClinicNum); if (clinic != null) { _clinicNum = clinic.ClinicNum; } else { _clinicNum = Security.CurUser.ClinicNum; //Use the user's default clinic if they don't have access to LocalComputer's clinic. } } else //The user is not restricted, just use the clinic in the ComputerPref table. { _clinicNum = ComputerPrefs.LocalComputer.ClinicNum; } return; //Error case "User": List <UserOdPref> prefs = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.ClinicLast); //should only be one or none. if (prefs.Count == 0) { UserOdPref pref = new UserOdPref() { UserNum = Security.CurUser.UserNum, FkeyType = UserOdFkeyType.ClinicLast, Fkey = Security.CurUser.ClinicNum //default clinic num }; UserOdPrefs.Insert(pref); prefs.Add(pref); } if (listClinics.Any(x => x.ClinicNum == prefs[0].Fkey)) //user is restricted and does not have access to the computerpref clinic { _clinicNum = prefs[0].Fkey; } return; case "None": default: if (listClinics.Any(x => x.ClinicNum == Security.CurUser.ClinicNum)) { _clinicNum = Security.CurUser.ClinicNum; } break; } }
///<summary>This should be called when the user is changed (excluding temporay logins such as job review logins). ///In the future, we could also call this if we detect the office theme has changed via signal preference cache refresh or if ///another person using the same login information changes the theme for a group of users.</summary> public static void SetThemeForUserIfNeeded() { OdTheme themeDefault = OdTheme.Standard; try { themeDefault = (OdTheme)PrefC.GetInt(PrefName.ColorTheme); } catch { //try/catch in case you are trying to convert from an older version of OD and need to update the DB. } if (Security.CurUser == null) //no current user, set to the default practice theme. { ODColorTheme.SetTheme(themeDefault); return; } UserOdPref themePref = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.UserTheme).FirstOrDefault(); //user theme not allowed or hasn't been set if (!PrefC.GetBool(PrefName.ThemeSetByUser) || themePref == null) { ODColorTheme.SetTheme(themeDefault); } else if (themePref != null) //user theme allowed but needs to update for user pref { ODColorTheme.SetTheme((OdTheme)themePref.Fkey); } }
///<summary>Called when logging user off or closing opendental.</summary> public static void LogOff() { if (!PrefC.HasClinicsEnabled) { _clinicNum = 0; return; } switch (PrefC.GetString(PrefName.ClinicTrackLast)) { case "Workstation": ComputerPref compPref = ComputerPrefs.LocalComputer; compPref.ClinicNum = Clinics.ClinicNum; ComputerPrefs.Update(compPref); break; case "User": List <UserOdPref> UserPrefs = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.ClinicLast); //should only be one or none. if (UserPrefs.Count == 0) { //this situation should never happen. UserOdPref pref = new UserOdPref() { UserNum = Security.CurUser.UserNum, FkeyType = UserOdFkeyType.ClinicLast, Fkey = Clinics.ClinicNum }; UserOdPrefs.Insert(pref); break; } UserPrefs.ForEach(x => x.Fkey = Clinics.ClinicNum); UserPrefs.ForEach(UserOdPrefs.Update); break; case "None": default: break; } _clinicNum = 0; }
///<summary>Called when logging user off or closing opendental.</summary> public static void LogOff() { if (!PrefC.HasClinicsEnabled) { _clinicNum = 0; return; } switch (PrefC.GetString(PrefName.ClinicTrackLast)) { case "Workstation": ComputerPrefs.LocalComputer.ClinicNum = Clinics.ClinicNum; ComputerPrefs.Update(ComputerPrefs.LocalComputer); break; case "User": //handled below case "None": default: break; } //We want to always upsert a user pref for the user because we will be looking at it for MobileWeb regardless of the preference for //ClinicTrackLast. List <UserOdPref> UserPrefs = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.ClinicLast); //should only be one or none. if (UserPrefs.Count == 0) { UserOdPref pref = new UserOdPref() { UserNum = Security.CurUser.UserNum, FkeyType = UserOdFkeyType.ClinicLast, Fkey = Clinics.ClinicNum }; UserOdPrefs.Insert(pref); } UserPrefs.ForEach(x => { x.Fkey = Clinics.ClinicNum; UserOdPrefs.Update(x); }); _clinicNum = 0; }