Beispiel #1
0
        ///<summary>This function will throw if the Process fails to start. Catch in calling class. Runs the file.
        ///Downloads it from the cloud if necessary.</summary>
        public static void StartProcess(string fileFullPath)
        {
            string filePathToOpen;

            if (CloudStorage.IsCloudStorage)
            {
                FormProgress FormP = CreateFormProgress("Downloading...");
                OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(Path.GetDirectoryName(fileFullPath), Path.GetFileName(fileFullPath),
                                                                                          new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                FormP.ShowDialog();
                if (FormP.DialogResult == DialogResult.Cancel)
                {
                    state.DoCancel = true;
                    return;
                }
                filePathToOpen = PrefC.GetRandomTempFile(Path.GetExtension(fileFullPath));
                File.WriteAllBytes(filePathToOpen, state.FileContent);
            }
            else
            {
                filePathToOpen = fileFullPath;
            }
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.HandleFile(filePathToOpen);
            }
            else
            {
                Process.Start(filePathToOpen);
            }
        }
Beispiel #2
0
        private void butLettersPreview_Click(object sender, EventArgs e)
        {
            //Create letters. loop through each row and insert information into sheets,
            //take all the sheets and add to one giant pdf for preview.
            if (gridMain.SelectedIndices.Length == 0)
            {
                MsgBox.Show(this, "Please select patient(s) first.");
                return;
            }
            FormSheetPicker FormS = new FormSheetPicker();

            FormS.SheetType = SheetTypeEnum.PatientLetter;
            FormS.ShowDialog();
            if (FormS.DialogResult != DialogResult.OK)
            {
                return;
            }
            SheetDef     sheetDef;
            Sheet        sheet      = null;
            List <Sheet> listSheets = new List <Sheet>();         //for saving

            for (int i = 0; i < FormS.SelectedSheetDefs.Count; i++)
            {
                PdfDocument document        = new PdfDocument();
                PdfPage     page            = new PdfPage();
                string      filePathAndName = "";
                for (int j = 0; j < gridMain.SelectedIndices.Length; j++)
                {
                    sheetDef = FormS.SelectedSheetDefs[i];
                    sheet    = SheetUtil.CreateSheet(sheetDef, PIn.Long(((DataRow)gridMain.SelectedGridRows[j].Tag)["PatNum"].ToString()));
                    SheetParameter.SetParameter(sheet, "PatNum", PIn.Long(((DataRow)gridMain.SelectedGridRows[j].Tag)["PatNum"].ToString()));
                    SheetFiller.FillFields(sheet);
                    sheet.SheetFields.Sort(SheetFields.SortDrawingOrderLayers);
                    SheetUtil.CalculateHeights(sheet);
                    SheetPrinting.PagesPrinted = 0;                  //Clear out the pages printed variable before printing all pages for this pdf.
                    int pageCount = Sheets.CalculatePageCount(sheet, SheetPrinting.PrintMargin);
                    for (int k = 0; k < pageCount; k++)
                    {
                        page = document.AddPage();
                        SheetPrinting.CreatePdfPage(sheet, page, null);
                    }
                    listSheets.Add(sheet);
                }
                filePathAndName = PrefC.GetRandomTempFile(".pdf");
                document.Save(filePathAndName);
                if (ODBuild.IsWeb())
                {
                    ThinfinityUtils.HandleFile(filePathAndName);
                }
                else
                {
                    Process.Start(filePathAndName);
                }
                DialogResult = DialogResult.OK;
            }
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Would you like to save the sheets for the selected patients?"))
            {
                Sheets.SaveNewSheetList(listSheets);
            }
        }
Beispiel #3
0
        private void butPreview_Click(object sender, EventArgs e)
        {
            //A couple options here
            //Download the file and run the explorer windows process to show the temporary file
            if (!gridMain.ListGridRows[gridMain.GetSelectedIndex()].Cells[0].Text.Contains("."))             //File path doesn't contain an extension and thus is a subfolder.
            {
                return;
            }
            FormProgress FormP = new FormProgress();

            FormP.DisplayText          = "Downloading...";
            FormP.NumberFormat         = "F";
            FormP.NumberMultiplication = 1;
            FormP.MaxVal = 100;          //Doesn't matter what this value is as long as it is greater than 0
            FormP.TickMS = 1000;
            OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(textPath.Text
                                                                                      , Path.GetFileName(gridMain.ListGridRows[gridMain.GetSelectedIndex()].Cells[0].Text)
                                                                                      , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
            if (FormP.ShowDialog() == DialogResult.Cancel)
            {
                state.DoCancel = true;
                return;
            }
            string tempFile = ODFileUtils.CreateRandomFile(Path.GetTempPath(), Path.GetExtension(gridMain.ListGridRows[gridMain.GetSelectedIndex()].Cells[0].Text));

            File.WriteAllBytes(tempFile, state.FileContent);
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.HandleFile(tempFile);
            }
            else
            {
                System.Diagnostics.Process.Start(tempFile);
            }
        }
Beispiel #4
0
 ///<summary>Copies or downloads the file and opens it. acutalFileName should be a full path, displayedFileName should be a file name only.
 ///</summary>
 public static void OpenFile(string actualFilePath, string displayedFileName = "")
 {
     try {
         string tempFile;
         if (displayedFileName == "")
         {
             tempFile = ODFileUtils.CombinePaths(PrefC.GetTempFolderPath(), Path.GetFileName(actualFilePath));
         }
         else
         {
             tempFile = ODFileUtils.CombinePaths(PrefC.GetTempFolderPath(), displayedFileName);
         }
         if (CloudStorage.IsCloudStorage)
         {
             FormProgress FormP = CreateFormProgress("Downloading...");
             OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(Path.GetDirectoryName(actualFilePath),
                                                                                       Path.GetFileName(actualFilePath), new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
             FormP.ShowDialog();
             if (FormP.DialogResult == DialogResult.Cancel)
             {
                 state.DoCancel = true;
                 return;
             }
             File.WriteAllBytes(tempFile, state.FileContent);
         }
         else                   //Not Cloud
                                //We have to create a copy of the file because the name is different.
                                //There is also a high probability that the attachment no longer exists if
                                //images are stored in the database, since the file will have originally been
                                //placed in the temporary directory.
         {
             File.Copy(actualFilePath, tempFile, true);
         }
         if (ODBuild.IsWeb())
         {
             ThinfinityUtils.HandleFile(tempFile);
         }
         else
         {
             Process.Start(tempFile);
         }
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #5
0
 private void butOpen_Click(object sender, EventArgs e)
 {
     if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
     {
         System.Diagnostics.Process.Start("Explorer", Path.GetDirectoryName(textFileName.Text));
     }
     else if (CloudStorage.IsCloudStorage)             //First download, then open
     {
         FormProgress FormP = new FormProgress();
         FormP.DisplayText          = "Downloading...";
         FormP.NumberFormat         = "F";
         FormP.NumberMultiplication = 1;
         FormP.MaxVal = 100;              //Doesn't matter what this value is as long as it is greater than 0
         FormP.TickMS = 1000;
         string patFolder;
         if (!TryGetPatientFolder(out patFolder, false))
         {
             return;
         }
         OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(patFolder
                                                                                   , DocCur.FileName
                                                                                   , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
         FormP.ShowDialog();
         if (FormP.DialogResult == DialogResult.Cancel)
         {
             state.DoCancel = true;
             return;
         }
         //Create temp file here or create the file with the actual name?  Changes made when opening the file won't be saved, so I think temp file is best.
         string tempFile = PrefC.GetRandomTempFile(Path.GetExtension(DocCur.FileName));
         File.WriteAllBytes(tempFile, state.FileContent);
         if (ODBuild.IsWeb())
         {
             ThinfinityUtils.HandleFile(tempFile);
         }
         else
         {
             System.Diagnostics.Process.Start(tempFile);
         }
     }
 }
Beispiel #6
0
        ///<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);
        }
Beispiel #7
0
        ///<summary>Uses sheet framework to generate a PDF file, save it to patient's image folder, and attempt to launch file with defualt reader.
        ///If using ImagesStoredInDB it will not launch PDF. If no valid patient is selected you cannot perform this action.</summary>
        private void butPDF_Click(object sender, EventArgs e)
        {
            if (PatCur == null)           //not attached to a patient when form loaded and they haven't selected a patient to attach to yet
            {
                MsgBox.Show(this, "The Medical Lab must be attached to a patient before the PDF can be saved.");
                return;
            }
            if (PatCur.PatNum > 0 && _medLabCur.PatNum != PatCur.PatNum)         //save the current patient attached to the MedLab if it has been changed
            {
                MoveLabsAndImagesHelper();
            }
            Cursor = Cursors.WaitCursor;
            SheetDef sheetDef = SheetUtil.GetMedLabResultsSheetDef();
            Sheet    sheet    = SheetUtil.CreateSheet(sheetDef, _medLabCur.PatNum);

            SheetFiller.FillFields(sheet, null, null, _medLabCur);
            //create the file in the temp folder location, then import so it works when storing images in the db
            string tempPath = ODFileUtils.CombinePaths(PrefC.GetTempFolderPath(), _medLabCur.PatNum.ToString() + ".pdf");

            SheetPrinting.CreatePdf(sheet, tempPath, null, _medLabCur);
            HL7Def defCur   = HL7Defs.GetOneDeepEnabled(true);
            long   category = defCur.LabResultImageCat;

            if (category == 0)
            {
                category = Defs.GetFirstForCategory(DefCat.ImageCats, true).DefNum;             //put it in the first category.
            }
            //create doc--------------------------------------------------------------------------------------
            OpenDentBusiness.Document docc = null;
            try {
                docc = ImageStore.Import(tempPath, category, Patients.GetPat(_medLabCur.PatNum));
            }
            catch (Exception ex) {
                ex.DoNothing();
                Cursor = Cursors.Default;
                MsgBox.Show(this, "Error saving document.");
                return;
            }
            finally {
                //Delete the temp file since we don't need it anymore.
                try {
                    File.Delete(tempPath);
                }
                catch {
                    //Do nothing.  This file will likely get cleaned up later.
                }
            }
            docc.Description = Lan.g(this, "MedLab Result");
            docc.DateCreated = DateTime.Now;
            Documents.Update(docc);
            string filePathAndName = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                string patFolder = ImageStore.GetPatientFolder(Patients.GetPat(_medLabCur.PatNum), ImageStore.GetPreferredAtoZpath());
                filePathAndName = ODFileUtils.CombinePaths(patFolder, docc.FileName);
            }
            else if (CloudStorage.IsCloudStorage)
            {
                FormProgress FormP = new FormProgress();
                FormP.DisplayText          = "Downloading...";
                FormP.NumberFormat         = "F";
                FormP.NumberMultiplication = 1;
                FormP.MaxVal = 100;              //Doesn't matter what this value is as long as it is greater than 0
                FormP.TickMS = 1000;
                OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(
                    ImageStore.GetPatientFolder(Patients.GetPat(_medLabCur.PatNum), ImageStore.GetPreferredAtoZpath())
                    , docc.FileName
                    , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                if (FormP.ShowDialog() == DialogResult.Cancel)
                {
                    state.DoCancel = true;
                    return;
                }
                filePathAndName = PrefC.GetRandomTempFile(Path.GetExtension(docc.FileName));
                File.WriteAllBytes(filePathAndName, state.FileContent);
            }
            Cursor = Cursors.Default;
            if (filePathAndName != "")
            {
                if (ODBuild.IsWeb())
                {
                    ThinfinityUtils.HandleFile(filePathAndName);
                }
                else
                {
                    Process.Start(filePathAndName);
                }
            }
            SecurityLogs.MakeLogEntry(Permissions.SheetEdit, sheet.PatNum, sheet.Description + " from " + sheet.DateTimeSheet.ToShortDateString() + " pdf was created");
            DialogResult = DialogResult.OK;
        }