///<summary>Cascading delete that deletes all MedLab, MedLabResult, MedLabSpecimen, and MedLabFacAttach. ///Also deletes any embedded PDFs that are linked to by the MedLabResults. ///The MedLabs and all associated results, specimens, and FacAttaches referenced by the MedLabNums in listExcludeMedLabNums will not be deleted. ///Used for deleting old entries and keeping new ones. The list may be empty and then all will be deleted.</summary> public static int DeleteLabsAndResults(MedLab medLab, List <long> listExcludeMedLabNums = null) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetInt(MethodBase.GetCurrentMethod(), medLab, listExcludeMedLabNums)); } List <MedLab> listLabsOld = MedLabs.GetForPatAndSpecimen(medLab.PatNum, medLab.SpecimenID, medLab.SpecimenIDFiller); //patNum could be 0 if (listExcludeMedLabNums != null) { listLabsOld = listLabsOld.FindAll(x => !listExcludeMedLabNums.Contains(x.MedLabNum)); } if (listLabsOld.Count < 1) { return(0); } int failedCount = 0; List <long> listLabNumsOld = listLabsOld.Select(x => x.MedLabNum).ToList(); List <MedLabResult> listResultsOld = listLabsOld.SelectMany(x => x.ListMedLabResults).ToList(); //sends one query to the db per MedLab MedLabFacAttaches.DeleteAllForLabsOrResults(listLabNumsOld, listResultsOld.Select(x => x.MedLabResultNum).ToList()); MedLabSpecimens.DeleteAllForLabs(listLabNumsOld); //MedLabSpecimens have a FK to MedLabNum MedLabResults.DeleteAllForMedLabs(listLabNumsOld); //MedLabResults have a FK to MedLabNum MedLabs.DeleteAll(listLabNumsOld); foreach (Document doc in Documents.GetByNums(listResultsOld.Select(x => x.DocNum).ToList())) { Patient docPat = Patients.GetPat(doc.PatNum); if (docPat == null) { Documents.Delete(doc); continue; } try { ImageStore.DeleteDocuments(new List <Document> { doc }, ImageStore.GetPatientFolder(docPat, ImageStore.GetPreferredAtoZpath())); } catch (Exception ex) { ex.DoNothing(); //To avoid a warning message. The ex is needed to ensure all exceptions are caught. failedCount++; } } return(failedCount); }
///<summary>Attempts to open the document using the default program. If not using AtoZfolder saves a local temp file and opens it.</summary> public static void OpenDoc(long docNum) { Document docCur = Documents.GetByNum(docNum); if (docCur.DocNum == 0) { return; } Patient patCur = Patients.GetPat(docCur.PatNum); if (patCur == null) { return; } string docPath; if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { docPath = ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath())); } else if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase) { //Some programs require a file on disk and cannot open in memory files. Save to temp file from DB. docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur)); File.WriteAllBytes(docPath, Convert.FromBase64String(docCur.RawBase64)); } else //Cloud storage //Download file to temp directory { OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.Download(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()) , docCur.FileName); docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur)); if (ODBuild.IsWeb()) { ThinfinityUtils.HandleFile(docPath); return; } File.WriteAllBytes(docPath, state.FileContent); } Process.Start(docPath); }
//Checks to see if the document exists in the correct location, or checks DB for stored content. public static bool DocExists(long docNum) { Document docCur = Documents.GetByNum(docNum); if (docCur.DocNum == 0) { return(false); } Patient patCur = Patients.GetPat(docCur.PatNum); if (patCur == null) { return(false); } if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { return(File.Exists(ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath())))); } else if (CloudStorage.IsCloudStorage) { return(CloudStorage.FileExists(ODFileUtils.CombinePaths(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()), docCur.FileName, '/'))); } return(!string.IsNullOrEmpty(docCur.RawBase64)); }
///<summary>If this is middle tier, pass in null.</summary> public static void LoadAllPlugins(Form host) { //No need to check RemotingRole; no call to db. List <PluginContainer> listPlugins = new List <PluginContainer>(); //Loop through all programs that are enabled with a plug-in dll name set. foreach (Program program in Programs.GetWhere(x => x.Enabled && !string.IsNullOrEmpty(x.PluginDllName))) { string dllPath = ODFileUtils.CombinePaths(Application.StartupPath, program.PluginDllName); if (RemotingClient.RemotingRole == RemotingRole.ServerWeb) { dllPath = ODFileUtils.CombinePaths(System.Web.HttpContext.Current.Server.MapPath(null), program.PluginDllName); } //Check for the versioning trigger. //For example, the plug-in might be entered as MyPlugin[VersionMajMin].dll. The bracketed section will be removed when loading the dll. //So it will look for MyPlugin.dll as the dll to load. However, before it loads, it will look for a similar dll with a version number. //For example, if using version 14.3.23, it would look for MyPlugin14.3.dll. //If that file is found, it would replace MyPlugin.dll with the contents of MyPlugin14.3.dll, and then it would load MyPlugin.dll as normal. if (dllPath.Contains("[VersionMajMin]")) { Version vers = new Version(Application.ProductVersion); string dllPathWithVersion = dllPath.Replace("[VersionMajMin]", vers.Major.ToString() + "." + vers.Minor.ToString()); dllPath = dllPath.Replace("[VersionMajMin]", ""); //now stripped clean if (File.Exists(dllPathWithVersion)) { File.Copy(dllPathWithVersion, dllPath, true); } else { //try the Plugins folder if (PrefC.AtoZfolderUsed != DataStorageType.InDatabase) //must have an AtoZ folder to check { string dllPathVersionCentral = FileAtoZ.CombinePaths(ImageStore.GetPreferredAtoZpath(), "Plugins", program.PluginDllName.Replace("[VersionMajMin]", vers.Major.ToString() + "." + vers.Minor.ToString())); if (FileAtoZ.Exists(dllPathVersionCentral)) { FileAtoZ.Copy(dllPathVersionCentral, dllPath, FileAtoZSourceDestination.AtoZToLocal, doOverwrite: true); } } } } //We now know the exact name of the dll for the plug-in. Check to see if it is present. if (!File.Exists(dllPath)) { continue; //Nothing to do. } //The dll was found, try and load it in. PluginBase plugin = null; Assembly ass = null; string assName = ""; try { ass = Assembly.LoadFile(dllPath); assName = Path.GetFileNameWithoutExtension(dllPath); string typeName = assName + ".Plugin"; Type type = ass.GetType(typeName); plugin = (PluginBase)Activator.CreateInstance(type); plugin.Host = host; } catch (Exception ex) { //Never try and show message boxes when on the middle tier, there is no UI. We should instead log to a file or the event viewer. if (RemotingClient.RemotingRole != RemotingRole.ServerWeb) { //Notify the user that their plug-in is not loaded. MessageBox.Show("Error loading Plugin:" + program.PluginDllName + "\r\n" + ex.Message); } continue; //Don't add it to plugin list. } //The plug-in was successfully loaded and will start getting hook notifications. Add it to the list of loaded plug-ins. PluginContainer container = new PluginContainer(); container.Plugin = plugin; container.ProgramNum = program.ProgramNum; container.Assemb = ass; container.Name = assName; listPlugins.Add(container); } ListPlugins = listPlugins; }