Example #1
0
        private void butExportGrid_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Join(",", gridMain.ListGridColumns.OfType <GridColumn>().Select(x => x.Heading)));
            gridMain.ListGridRows.OfType <GridRow>().ToList()
            .ForEach(row => sb.AppendLine(string.Join(",", row.Cells.Select(cell => cell.Text.Replace(',', '-').Replace('\t', ',')))));
            if (ODBuild.IsWeb())
            {
                string exportFilename = "BenefitsRpt_" + _dtNow.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("hhmm") + ".csv";
                string dataString     = sb.ToString();
                ThinfinityUtils.ExportForDownload(exportFilename, dataString);
                return;
            }
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() != DialogResult.OK || string.IsNullOrEmpty(fbd.SelectedPath))
            {
                MsgBox.Show(this, "Invalid directory.");
                return;
            }
            string filename = ODFileUtils.CombinePaths(fbd.SelectedPath, "BenefitsRpt_" + _dtNow.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("hhmm") + ".csv");

            System.IO.File.WriteAllText(filename, sb.ToString());
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Would you like to open the file now?"))
            {
                try {
                    System.Diagnostics.Process.Start(filename);
                }
                catch (Exception ex) { ex.DoNothing(); }
            }
        }
Example #2
0
        ///<summary>Throws Exception.  Exports all medications to the passed in filename. Throws Exceptions.</summary>
        public static int ExportMedications(string filename, List <Medication> listMedications)
        {
            StringBuilder strBldrOutput = new StringBuilder();

            string encapsulate(string text)
            {
                return("\"" + text.Replace("\"", "\\\"") + "\"");
            }

            foreach (Medication med in listMedications)             //Loop through medications.
            {
                strBldrOutput.AppendLine(encapsulate(med.MedName) + '\t' + encapsulate(Medications.GetGenericName(med.GenericNum)) + '\t' + encapsulate(med.Notes)
                                         + '\t' + encapsulate(POut.Long(med.RxCui)));
            }
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.ExportForDownload(filename, strBldrOutput.ToString());
            }
            else
            {
                File.WriteAllText(filename, strBldrOutput.ToString());               //Allow Exception to trickle up.
            }
            SecurityLogs.MakeLogEntry(Permissions.Setup, 0,
                                      Lans.g("Medications", "Exported") + " " + POut.Int(listMedications.Count) + " " + Lans.g("Medications", "medications to:") + " " + filename
                                      );
            return(listMedications.Count);
        }
 private void butExport_Click(object sender, EventArgs e)
 {
     #region Web Build
     if (ODBuild.IsWeb())
     {
         string fileName = ElementCur.SigText + ".wav";
         string tempPath = ODFileUtils.CombinePaths(Path.GetTempPath(), fileName);
         try {
             PIn.Sound(ElementCur.Sound, tempPath);
         }
         catch (ApplicationException ex) {
             MessageBox.Show(ex.Message);
             return;
         }
         ThinfinityUtils.ExportForDownload(tempPath);
         return;
     }
     #endregion Web Build
     saveFileDialog1.FileName   = "";
     saveFileDialog1.DefaultExt = "wav";
     if (saveFileDialog1.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     try {
         PIn.Sound(ElementCur.Sound, saveFileDialog1.FileName);
     }
     catch (ApplicationException ex) {
         MessageBox.Show(ex.Message);
     }
 }
Example #4
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);
            }
        }
Example #5
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);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            string fileName = Lan.g(this, "Treatment Finder");
            string filePath = ODFileUtils.CombinePaths(Path.GetTempPath(), fileName);

            if (ODBuild.IsWeb())
            {
                //file download dialog will come up later, after file is created.
                filePath += ".txt";              //Provide the filepath an extension so that Thinfinity can offer as a download.
            }
            else
            {
                SaveFileDialog saveFileDialog2 = new SaveFileDialog();
                saveFileDialog2.AddExtension = true;
                saveFileDialog2.Title        = Lan.g(this, "Treatment Finder");
                saveFileDialog2.FileName     = Lan.g(this, "Treatment Finder");
                if (!Directory.Exists(PrefC.GetString(PrefName.ExportPath)))
                {
                    try {
                        Directory.CreateDirectory(PrefC.GetString(PrefName.ExportPath));
                        saveFileDialog2.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                    }
                    catch {
                        //initialDirectory will be blank
                    }
                }
                else
                {
                    saveFileDialog2.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                }
                saveFileDialog2.Filter      = "Text files(*.txt)|*.txt|Excel Files(*.xls)|*.xls|All files(*.*)|*.*";
                saveFileDialog2.FilterIndex = 0;
                if (saveFileDialog2.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                filePath = saveFileDialog2.FileName;
            }
            try{
                using (StreamWriter sw = new StreamWriter(filePath, false))
                {
                    sw.WriteLine(string.Join("\t", gridMain.ListGridColumns.Select(x => x.Heading)));
                    gridMain.ListGridRows.ForEach(x => sw.WriteLine(
                                                      string.Join("\t", x.Cells.Select(y => string.Concat(y.Text.Where(z => !z.In('\r', '\n', '\t', '\"')))))));
                }
            }
            catch {
                MessageBox.Show(Lan.g(this, "File in use by another program.  Close and try again."));
                return;
            }
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.ExportForDownload(filePath);
            }
            else
            {
                MessageBox.Show(Lan.g(this, "File created successfully"));
            }
        }
Example #8
0
        private void butExport_Click(object sender, EventArgs e)
        {
            if (gridCustomSheet.GetSelectedIndex() == -1)
            {
                MsgBox.Show(this, "Please select a sheet from the list first.");
                return;
            }
            SheetDef             sheetdef           = SheetDefs.GetSheetDef(_listSheetDefs[gridCustomSheet.GetSelectedIndex()].SheetDefNum);
            List <SheetFieldDef> listFieldDefImages = sheetdef.SheetFieldDefs
                                                      .Where(x => x.FieldType == SheetFieldType.Image && x.FieldName != "Patient Info.gif")
                                                      .ToList();

            if (!listFieldDefImages.IsNullOrEmpty())             //Alert them of any images they need to copy if there are any.
            {
                string sheetImagesPath = "";
                ODException.SwallowAnyException(() => {
                    sheetImagesPath = SheetUtil.GetImagePath();
                });
                StringBuilder strBuilder = new StringBuilder();
                strBuilder.AppendLine(Lan.g(this, "The following images will need to be manually imported with the same file name when importing this "
                                            + "sheet to a new environment."));
                strBuilder.AppendLine();
                listFieldDefImages.ForEach(x => strBuilder.AppendLine(ODFileUtils.CombinePaths(sheetImagesPath, x.FieldName)));
                MsgBoxCopyPaste msgBox = new MsgBoxCopyPaste(strBuilder.ToString());
                msgBox.ShowDialog();
            }
            XmlSerializer serializer = new XmlSerializer(typeof(SheetDef));
            string        filename   = "SheetDefCustom.xml";

            if (ODBuild.IsWeb())
            {
                StringBuilder strbuild = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(strbuild)) {
                    serializer.Serialize(writer, sheetdef);
                }
                ThinfinityUtils.ExportForDownload(filename, strbuild.ToString());
            }
            else
            {
                SaveFileDialog saveDlg = new SaveFileDialog();
                saveDlg.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                saveDlg.FileName         = filename;
                if (saveDlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                using (TextWriter writer = new StreamWriter(saveDlg.FileName)) {
                    serializer.Serialize(writer, sheetdef);
                }
            }
            MsgBox.Show(this, "Exported");
        }
Example #9
0
        ///<summary>Writes a set of serialized AutoNotes and AutoNoteControls in JSON format to the specified path.</summary>
        public static void WriteAutoNotesToJson(List <SerializableAutoNote> listAutoNotes, List <SerializableAutoNoteControl> listAutoNoteControls,
                                                string path)
        {
            //No need to check RemotingRole; no call to db.
            TransferableAutoNotes export = new TransferableAutoNotes(listAutoNotes, listAutoNoteControls);
            string json = JsonConvert.SerializeObject(export);

            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.ExportForDownload(path, json);
            }
            else
            {
                File.WriteAllText(path, json);
            }
        }
Example #10
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);
     }
 }
        ///<summary>Only exports for the current culture.</summary>
        private void butExport_Click(object sender, System.EventArgs e)
        {
            string fileName = CultureInfo.CurrentCulture.Name + ".sql";        //eg en-US.sql
            string filePath = ODFileUtils.CombinePaths(Path.GetTempPath(), fileName);

            if (ODBuild.IsWeb())
            {
                //file download dialog will come up later, after file is created.
            }
            else
            {
                saveFileDialog1.InitialDirectory = Application.StartupPath;
                saveFileDialog1.FileName         = fileName;
                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                filePath = saveFileDialog1.FileName;
            }
            StreamWriter sw = new StreamWriter(filePath, false, System.Text.Encoding.UTF8);

            sw.WriteLine("DELETE FROM languageforeign WHERE Culture='" + CultureInfo.CurrentCulture.Name + "';");
            LanguageForeign[] LFList = LanguageForeigns.GetListForCurrentCulture();
            for (int i = 0; i < LFList.Length; i++)
            {
                sw.WriteLine(
                    "INSERT INTO languageforeign (ClassType,English,Culture,Translation,Comments) VALUES ('" + POut.String(LFList[i].ClassType)
                    + "', '" + POut.String(LFList[i].English)
                    + "', '" + POut.String(LFList[i].Culture)
                    + "', '" + POut.String(LFList[i].Translation)
                    + "', '" + POut.String(LFList[i].Comments) + "');"
                    );
            }            //for
            sw.Close();
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.ExportForDownload(filePath);
            }
            else
            {
                MessageBox.Show("Done");
            }
        }
Example #12
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);
        }
Example #13
0
        private void butExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog()
            {
                Filter           = "PDF (*.pdf)|*.pdf",
                FilterIndex      = 1,
                RestoreDirectory = true,
            };

            if (ODBuild.IsWeb())
            {
                sd.FileName = ODFileUtils.CombinePaths(Path.GetTempPath(), "chart_export.pdf");
            }
            else
            {
                if (sd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            using (PdfDocument pdfDoc = new PdfDocument()) {
                //save the chart into the memoryStream as a BitMap
                try {
                    PdfPage page = new PdfPage();
                    pdfDoc.Pages.Add(page);
                    page.Orientation = checkLandscape.Checked ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;
                    using (XGraphics xGraphics = XGraphics.FromPdfPage(page)) {
                        xGraphics.DrawImage(_bmpSheet, 0, 0, page.Width, page.Height);
                    }
                    pdfDoc.Save(sd.FileName);
                    if (ODBuild.IsWeb())
                    {
                        ThinfinityUtils.ExportForDownload(sd.FileName);
                    }
                    MessageBox.Show(Lans.g(this, "Chart saved."));
                }
                catch (Exception ex) {
                    MessageBox.Show("Chart not saved." + "\r\n" + ex.Source + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }
        }
Example #14
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);
         }
     }
 }
Example #15
0
        ///<summary>Export a custom claim form. Even though we could probably allow this for internal claim forms as well,
        ///users can always copy over an internal claim form to a custom form and then export it.</summary>
        private void butExport_Click(object sender, System.EventArgs e)
        {
            if (gridCustom.GetSelectedIndex() == -1)
            {
                MsgBox.Show(this, "Please select a Custom Claim Form first.");
                return;
            }
            ClaimForm claimFormCur = (ClaimForm)gridCustom.ListGridRows[gridCustom.GetSelectedIndex()].Tag;
            string    filename     = "ClaimForm" + claimFormCur.Description + ".xml";

            if (ODBuild.IsWeb())
            {
                StringBuilder strbuild = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(strbuild)) {
                    XmlSerializer serializer = new XmlSerializer(typeof(ClaimForm));
                    serializer.Serialize(writer, claimFormCur);
                }
                ThinfinityUtils.ExportForDownload(filename, strbuild.ToString());
                return;
            }
            try {
                using (SaveFileDialog saveDlg = new SaveFileDialog()) {
                    saveDlg.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                    saveDlg.FileName         = filename;
                    if (saveDlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    XmlSerializer serializer = new XmlSerializer(typeof(ClaimForm));
                    using (TextWriter writer = new StreamWriter(saveDlg.FileName)) {
                        serializer.Serialize(writer, claimFormCur);
                    }
                }
                MsgBox.Show(this, "Exported");
            }
            catch (Exception ex) {
                ex.DoNothing();
                MsgBox.Show(this, "Export failed.  This could be due to lack of permissions in the designated folder.");
            }
        }
        //Copied from FormRpOutstandingIns.cs
        private void butExport_Click(object sender, System.EventArgs e)
        {
            string fileName = Lan.g(this, "Unfinalized Insurance Payments");
            string filePath = ODFileUtils.CombinePaths(Path.GetTempPath(), fileName);

            if (ODBuild.IsWeb())
            {
                //file download dialog will come up later, after file is created.
                filePath += ".txt";              //Provide the filepath an extension so that Thinfinity can offer as a download.
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.AddExtension = true;
                saveFileDialog.FileName     = fileName;
                if (!Directory.Exists(PrefC.GetString(PrefName.ExportPath)))
                {
                    try {
                        Directory.CreateDirectory(PrefC.GetString(PrefName.ExportPath));
                        saveFileDialog.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                    }
                    catch {
                        //initialDirectory will be blank
                    }
                }
                else
                {
                    saveFileDialog.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
                }
                saveFileDialog.Filter      = "Text files(*.txt)|*.txt|Excel Files(*.xls)|*.xls|All files(*.*)|*.*";
                saveFileDialog.FilterIndex = 0;
                if (saveFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                filePath = saveFileDialog.FileName;
            }
            try {
                using (StreamWriter sw = new StreamWriter(filePath, false))
                {
                    String line = "";
                    for (int i = 0; i < gridMain.ListGridColumns.Count; i++)
                    {
                        line += gridMain.ListGridColumns[i].Heading + "\t";
                    }
                    sw.WriteLine(line);
                    for (int i = 0; i < gridMain.ListGridRows.Count; i++)
                    {
                        line = "";
                        for (int j = 0; j < gridMain.ListGridColumns.Count; j++)
                        {
                            line += gridMain.ListGridRows[i].Cells[j].Text;
                            if (j < gridMain.ListGridColumns.Count - 1)
                            {
                                line += "\t";
                            }
                        }
                        sw.WriteLine(line);
                    }
                }
            }
            catch {
                MessageBox.Show(Lan.g(this, "File in use by another program.  Close and try again."));
                return;
            }
            if (ODBuild.IsWeb())
            {
                ThinfinityUtils.ExportForDownload(filePath);
            }
            else
            {
                MessageBox.Show(Lan.g(this, "File created successfully"));
            }
        }
Example #17
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;
        }