private void ConnectAndSearch(ODThread odThread) { CentralConnection connection = (CentralConnection)odThread.Parameters[0]; if (!CentralConnectionHelper.UpdateCentralConnection(connection, false)) //No updating the cache since we're going to be connecting to multiple remote servers at the same time. { odThread.Tag = new object[] { connection, false }; //Can't connect, just return false to not include the connection. connection.ConnectionStatus = "OFFLINE"; return; } List <Provider> listProvs = Providers.GetProvsNoCache(); //If clinic and provider are both entered is it good enough to find one match among the two? I'm going to assume yes for now, and maybe later //if we decide that if both boxes have something entered that both entries need to be in the db we're searching I can change it. bool provMatch = false; for (int i = 0; i < listProvs.Count; i++) { if (textProviderSearch.Text == "") { provMatch = true; break; } if (listProvs[i].Abbr.ToLower().Contains(textProviderSearch.Text.ToLower()) || listProvs[i].LName.ToLower().Contains(textProviderSearch.Text.ToLower()) || listProvs[i].FName.ToLower().Contains(textProviderSearch.Text.ToLower())) { provMatch = true; break; } } List <Clinic> listClinics = Clinics.GetClinicsNoCache(); bool clinMatch = false; for (int i = 0; i < listClinics.Count; i++) { if (textClinicSearch.Text == "") { clinMatch = true; break; } if (listClinics[i].Description.ToLower().Contains(textClinicSearch.Text.ToLower())) { clinMatch = true; break; } } if (clinMatch && provMatch) { odThread.Tag = new object[] { connection, true }; //Match found } else { odThread.Tag = new object[] { connection, false }; //No match found } }
private void ConnectAndRunAnnualReport(ODThread odThread) { CentralConnection conn = (CentralConnection)odThread.Parameters[0]; DataSet listProdData = null; if (!CentralConnectionHelper.UpdateCentralConnection(conn, false)) { odThread.Tag = new object[] { listProdData, conn }; conn.ConnectionStatus = "OFFLINE"; return; } List <Provider> listProvs = Providers.GetProvsNoCache(); List <Clinic> listClinics = Clinics.GetClinicsNoCache(); Clinic unassigned = new Clinic(); unassigned.ClinicNum = 0; unassigned.Description = "Unassigned"; //Is this how we should do this? Will there always be different clinics? (I assume so, otherwise CEMT is kinda worthless) listClinics.Add(unassigned); listProdData = RpProdInc.GetAnnualData(_dateFrom, _dateTo, listProvs, listClinics, radioWriteoffPay.Checked, true, true, false, checkShowUnearned.Checked, true); odThread.Tag = new object[] { listProdData, conn }; }
private void ConnectAndRunProviderReport(ODThread odThread) { CentralConnection conn = (CentralConnection)odThread.Parameters[0]; DataSet listProdData = null; if (!CentralConnectionHelper.UpdateCentralConnection(conn, false)) { odThread.Tag = new object[] { listProdData, conn }; conn.ConnectionStatus = "OFFLINE"; return; } List <Provider> listProvs = Providers.GetProvsNoCache(); List <Clinic> listClinics = Clinics.GetClinicsNoCache(); Clinic unassigned = new Clinic(); unassigned.ClinicNum = 0; unassigned.Description = "Unassigned"; //Same issue here as above. listClinics.Add(unassigned); listProdData = RpProdInc.GetProviderDataForClinics(_dateFrom, _dateTo, listProvs, listClinics, radioWriteoffPay.Checked, true, true, false, checkShowUnearned.Checked, true); odThread.Tag = new object[] { listProdData, conn, listProvs }; }
///<summary>Function used by threads to connect to remote databases and sync user settings.</summary> private static void ConnectAndSyncUsers(ODThread odThread) { CentralConnection connection = (CentralConnection)odThread.Parameters[0]; List <CentralUserData> listCentralUserData = (List <CentralUserData>)odThread.Parameters[1]; string serverName = ""; if (connection.ServiceURI != "") { serverName = connection.ServiceURI; } else { serverName = connection.ServerName + ", " + connection.DatabaseName; } if (!CentralConnectionHelper.UpdateCentralConnection(connection, false)) //No updating the cache since we're going to be connecting to multiple remote servers at the same time. { odThread.Tag = new List <string>() { serverName + "\r\n", "", "" }; connection.ConnectionStatus = "OFFLINE"; return; } string remoteSyncCode = PrefC.GetStringNoCache(PrefName.CentralManagerSyncCode); if (remoteSyncCode != _syncCode) { if (remoteSyncCode == "") { Prefs.UpdateStringNoCache(PrefName.CentralManagerSyncCode, _syncCode); //Lock in the sync code for the remote server. } else { odThread.Tag = new List <string>() { serverName + "\r\n", "", remoteSyncCode }; return; } } //Get remote users, usergroups, associated permissions, and alertsubs List <Userod> listRemoteUsers = Userods.GetUsersNoCache(); #region Detect Conflicts //User conflicts bool nameConflict = false; string nameConflicts = ""; for (int i = 0; i < _listCEMTUsers.Count; i++) { for (int j = 0; j < listRemoteUsers.Count; j++) { if (listRemoteUsers[j].UserName == _listCEMTUsers[i].UserName && listRemoteUsers[j].UserNumCEMT == 0) //User doesn't belong to CEMT { nameConflicts += listRemoteUsers[j].UserName + " already exists in " + serverName + "\r\n"; nameConflict = true; break; } } } if (nameConflict) { odThread.Tag = new List <string>() { serverName + "\r\n", nameConflicts, "" }; return; //Skip on to the next connection. } #endregion Detect Conflicts List <UserGroup> listRemoteCEMTUserGroups = UserGroups.GetCEMTGroupsNoCache(); List <UserGroup> listCEMTUserGroups = new List <UserGroup>(); List <AlertSub> listRemoteAlertSubs = AlertSubs.GetAll(); List <Clinic> listRemoteClinics = Clinics.GetClinicsNoCache(); List <AlertSub> listAlertSubsToInsert = new List <AlertSub>(); for (int i = 0; i < listCentralUserData.Count; i++) { listCEMTUserGroups.Add(listCentralUserData[i].UserGroup.Copy()); } //SyncUserGroups returns the list of UserGroups for deletion so it can be used after syncing Users and GroupPermissions. List <UserGroup> listRemoteCEMTUserGroupsForDeletion = CentralUserGroups.Sync(listCEMTUserGroups, listRemoteCEMTUserGroups); listRemoteCEMTUserGroups = UserGroups.GetCEMTGroupsNoCache(); for (int i = 0; i < listCentralUserData.Count; i++) { List <GroupPermission> listGroupPerms = new List <GroupPermission>(); for (int j = 0; j < listRemoteCEMTUserGroups.Count; j++) { if (listCentralUserData[i].UserGroup.UserGroupNumCEMT == listRemoteCEMTUserGroups[j].UserGroupNumCEMT) { for (int k = 0; k < listCentralUserData[i].ListGroupPermissions.Count; k++) { listCentralUserData[i].ListGroupPermissions[k].UserGroupNum = listRemoteCEMTUserGroups[j].UserGroupNum; //fixing primary keys to be what's in remote db } listGroupPerms = GroupPermissions.GetPermsNoCache(listRemoteCEMTUserGroups[j].UserGroupNum); } } CentralUserods.Sync(listCentralUserData[i].ListUsers, listRemoteUsers); CentralGroupPermissions.Sync(listCentralUserData[i].ListGroupPermissions, listGroupPerms); } //Sync usergroup attaches SyncUserGroupAttaches(listCentralUserData); for (int j = 0; j < listRemoteCEMTUserGroupsForDeletion.Count; j++) { UserGroups.DeleteNoCache(listRemoteCEMTUserGroupsForDeletion[j]); } if (_listAlertSubs.Count > 0) { listRemoteUsers = Userods.GetUsersNoCache(); //Refresh users so we can do alertsubs. } //For each AlertSub, make a copy of that AlertSub for each Clinic. foreach (AlertSub alertSub in _listAlertSubs) { foreach (Clinic clinic in listRemoteClinics) { AlertSub alert = new AlertSub(); alert.ClinicNum = clinic.ClinicNum; alert.Type = alertSub.Type; alert.UserNum = listRemoteUsers.Find(x => x.UserName == _listCEMTUsers.Find(y => y.UserNum == alertSub.UserNum).UserName).UserNum; listAlertSubsToInsert.Add(alert); } } AlertSubs.DeleteAndInsertForSuperUsers(_listCEMTUsers, listAlertSubsToInsert); //Refresh server's cache of userods Signalods.SetInvalidNoCache(InvalidType.Security); SecurityLogs.MakeLogEntryNoCache(Permissions.SecurityAdmin, 0, "Enterprise Management Tool synced users."); odThread.Tag = new List <string>() { "", "", "" }; //No errors. }