public void FillAttachments() {
			_listEmailAttachDisplayed=new List<EmailAttach>();
			if(!_isComposing) {
				SetSig(null);
			}
			gridAttachments.BeginUpdate();
			gridAttachments.ListGridRows.Clear();
			gridAttachments.ListGridColumns.Clear();
			gridAttachments.ListGridColumns.Add(new OpenDental.UI.GridColumn("",0));//No name column, since there is only one column.
			for(int i=0;i<_emailMessage.Attachments.Count;i++) {
				if(_emailMessage.Attachments[i].DisplayedFileName.ToLower()=="smime.p7s") {
					if(!_isComposing) {
						string smimeP7sFilePath=FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(),_emailMessage.Attachments[i].ActualFileName);
						string localFile=PrefC.GetRandomTempFile(".p7s");
						FileAtoZ.Copy(smimeP7sFilePath,localFile,FileAtoZSourceDestination.AtoZToLocal,doOverwrite:true);
						SetSig(EmailMessages.GetEmailSignatureFromSmimeP7sFile(localFile));
					}
					//Do not display email signatures in the attachment list, because "smime.p7s" has no meaning to a user
					//Also, Windows will install the smime.p7s into an useless place in the Windows certificate store.
					continue;
				}
				OpenDental.UI.GridRow row=new UI.GridRow();
				row.Cells.Add(_emailMessage.Attachments[i].DisplayedFileName);
				gridAttachments.ListGridRows.Add(row);
				_listEmailAttachDisplayed.Add(_emailMessage.Attachments[i]);
			}
			gridAttachments.EndUpdate();
			if(gridAttachments.ListGridRows.Count>0) {
				gridAttachments.SetSelected(0,true);
			}
		}
Example #2
0
        private void SaveToImageFolder(string fileSourcePath, LetterMerge letterCur)
        {
            if (letterCur.ImageFolder == 0)           //This shouldn't happen
            {
                return;
            }
            string rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(fileSourcePath));
            }
            Document docSave = new Document();

            docSave.DocNum = Documents.Insert(docSave);
            string fileName     = Lans.g(this, "LetterMerge") + "_" + letterCur.Description + docSave.DocNum;
            string fileDestPath = FileAtoZ.CombinePaths(ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()), fileName + ".doc");

            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatCur.PatNum;
            docSave.DocCategory = letterCur.ImageFolder;
            docSave.Description = fileName;          //no extension.
            docSave.RawBase64   = rawBase64;         //blank if using AtoZfolder
            docSave.FileName    = fileName + ".doc"; //file extension used for both DB images and AtoZ images
            FileAtoZ.Copy(fileSourcePath, fileDestPath, FileAtoZSourceDestination.LocalToAtoZ);
            Documents.Update(docSave);
        }
Example #3
0
        private Document SaveToImageFolder(string fileSourcePath, LetterMerge letterCur)
        {
            if (letterCur.ImageFolder == 0)           //This shouldn't happen
            {
                return(new Document());
            }
            string rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(fileSourcePath));
            }
            Document docSave = new Document();

            docSave.DocNum      = Documents.Insert(docSave);
            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatCur.PatNum;
            docSave.DocCategory = letterCur.ImageFolder;
            docSave.Description = letterCur.Description + docSave.DocNum; //no extension.
            docSave.RawBase64   = rawBase64;                              //blank if using AtoZfolder
            docSave.FileName    = ODFileUtils.CleanFileName(letterCur.Description) + GetFileExtensionForWordDoc(fileSourcePath);
            string fileDestPath = ImageStore.GetFilePath(docSave, ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()));

            FileAtoZ.Copy(fileSourcePath, fileDestPath, FileAtoZSourceDestination.LocalToAtoZ);
            Documents.Update(docSave);
            return(docSave);
        }
Example #4
0
        private void ButLog_Click(object sender, EventArgs e)
        {
            if (_isMonitoring)
            {
                MsgBox.Show(this, "Stop monitoring queries before creating a log.");
                return;
            }
            if (_dictQueries.Count == 0)
            {
                MsgBox.Show(this, "No queries in the Query Feed to log.");
                return;
            }
            if (ODBuild.IsWeb())
            {
                MsgBox.Show(this, "Logging not supported for the Web version at this time.");
                return;
            }
            if (!MsgBox.Show(MsgBoxButtons.YesNo, Lan.g(this, "Log all queries to a file?  Total query count") + $": {_dictQueries.Count.ToString("N0")}"))
            {
                return;
            }
            string logFolderPath = "QueryMonitorLogs";
            string logFileName   = "";

            try {
                //Create the query monitor log folder in the AtoZ image path.
                if (!OpenDentBusiness.FileIO.FileAtoZ.DirectoryExistsRelative(logFolderPath))
                {
                    OpenDentBusiness.FileIO.FileAtoZ.CreateDirectoryRelative(logFolderPath);
                }
                //Get a unique file name within the log folder.
                logFileName = $"QueryMonitorLog_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.txt";
                while (OpenDentBusiness.FileIO.FileAtoZ.ExistsRelative(logFolderPath, logFileName))
                {
                    logFileName = $"QueryMonitorLog_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.txt";
                    Thread.Sleep(100);
                }
                //Dump the entire query history into the log file.
                OpenDentBusiness.FileIO.FileAtoZ.WriteAllTextRelative(logFolderPath, logFileName,
                                                                      $"Query Monitor Log - {DateTime.Now.ToString()}\r\n{string.Join("\r\n",_dictQueries.Values.Select(x => x.ToString()))}");
            }
            catch (ODException ode) {
                MsgBox.Show(ode.Message);
                return;
            }
            catch (Exception ex) {
                MsgBox.Show(Lan.g(this, "Error creating log file") + $":\r\n{ex.Message}");
                return;
            }
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Log file created.  Would you like to open the file?"))
            {
                try {
                    FileAtoZ.StartProcessRelative(logFolderPath, logFileName);
                }
                catch (Exception ex) {
                    MsgBox.Show(Lan.g(this, "Could not open log file") + $":\r\n{ex.Message}");
                }
            }
        }
        private void listAttachments_DoubleClick(object sender, EventArgs e)
        {
            if (listAttachments.SelectedIndex == -1)
            {
                return;
            }
            EmailAttach attach = _listAttachments[listAttachments.SelectedIndex];

            FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), attach.ActualFileName), attach.DisplayedFileName);
        }
        private void butSavePDFToImages_Click(object sender, EventArgs e)
        {
            if (gridMain.ListGridRows.Count == 0)
            {
                MsgBox.Show(this, "Grid is empty.");
                return;
            }
            //Get image category to save to. First image "Statement(S)" category.
            List <Def> listImageCatDefs = Defs.GetDefsForCategory(DefCat.ImageCats, true).Where(x => x.ItemValue.Contains("S")).ToList();

            if (listImageCatDefs.IsNullOrEmpty())
            {
                MsgBox.Show(this, "No image category set for Statements.");
                return;
            }
            string tempFile = PrefC.GetRandomTempFile(".pdf");

            CreatePDF(tempFile);
            Patient patCur    = _fam.GetPatient(PatNum);
            string  rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(tempFile));
            }
            Document docSave = new Document();

            docSave.DocNum      = Documents.Insert(docSave);
            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatNum;
            docSave.DocCategory = listImageCatDefs.FirstOrDefault().DefNum;
            docSave.Description = $"ServiceDateView" + docSave.DocNum + $"{docSave.DateCreated.Year}_{docSave.DateCreated.Month}_{docSave.DateCreated.Day}";
            docSave.RawBase64   = rawBase64;        //blank if using AtoZfolder
            string fileName = ODFileUtils.CleanFileName(docSave.Description);
            string filePath = ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath());

            while (FileAtoZ.Exists(FileAtoZ.CombinePaths(filePath, fileName + ".pdf")))
            {
                fileName += "x";
            }
            FileAtoZ.Copy(tempFile, ODFileUtils.CombinePaths(filePath, fileName + ".pdf"), FileAtoZSourceDestination.LocalToAtoZ);
            docSave.FileName = fileName + ".pdf";        //file extension used for both DB images and AtoZ images
            Documents.Update(docSave);
            try {
                File.Delete(tempFile);                 //cleanup the temp file.
            }
            catch (Exception ex) {
                ex.DoNothing();
            }
            MsgBox.Show(this, "PDF saved successfully.");
        }
Example #7
0
        private void OpenFile()
        {
            EmailAttach emailAttach       = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];
            string      strFilePathAttach = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName);

            try {
                if (EhrCCD.IsCcdEmailAttachment(emailAttach))
                {
                    string strTextXml = FileAtoZ.ReadAllText(strFilePathAttach);
                    if (EhrCCD.IsCCD(strTextXml))
                    {
                        Patient patEmail = null;                      //Will be null for most email messages.
                        if (_emailMessage.SentOrReceived == EmailSentOrReceived.ReadDirect || _emailMessage.SentOrReceived == EmailSentOrReceived.ReceivedDirect)
                        {
                            patEmail = _patCur;                          //Only allow reconcile if received via Direct.
                        }
                        string strAlterateFilPathXslCCD = "";
                        //Try to find a corresponding stylesheet. This will only be used in the event that the default stylesheet cannot be loaded from the EHR dll.
                        for (int i = 0; i < _listEmailAttachDisplayed.Count; i++)
                        {
                            if (Path.GetExtension(_listEmailAttachDisplayed[i].ActualFileName).ToLower() == ".xsl")
                            {
                                strAlterateFilPathXslCCD = FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), _listEmailAttachDisplayed[i].ActualFileName);
                                break;
                            }
                        }
                        FormEhrSummaryOfCare.DisplayCCD(strTextXml, patEmail, strAlterateFilPathXslCCD);
                        return;
                    }
                }
                else if (IsORU_R01message(strFilePathAttach))
                {
                    if (DataConnection.DBtype == DatabaseType.Oracle)
                    {
                        MsgBox.Show(this, "Labs not supported with Oracle.  Opening raw file instead.");
                    }
                    else
                    {
                        FormEhrLabOrderImport FormELOI = new FormEhrLabOrderImport();
                        FormELOI.Hl7LabMessage = FileAtoZ.ReadAllText(strFilePathAttach);
                        FormELOI.ShowDialog();
                        return;
                    }
                }
                FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), emailAttach.ActualFileName), emailAttach.DisplayedFileName);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
 private void menuItemAttachmentRemove_Click(object sender, EventArgs e)
 {
     try {
         if (listAttachments.SelectedIndex == -1)
         {
             return;
         }
         FileAtoZ.Delete(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), _listAttachments[listAttachments.SelectedIndex].ActualFileName));
         _listAttachments.RemoveAt(listAttachments.SelectedIndex);
         FillAttachments();
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
Example #9
0
        private void butImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect      = true;
            dlg.InitialDirectory = "";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            foreach (string fileName in dlg.FileNames)
            {
                FileAtoZ.Copy(fileName, FileAtoZ.CombinePaths(textPath.Text, Path.GetFileName(fileName)), FileAtoZSourceDestination.LocalToAtoZ);
            }
            FillGrid();
        }
		///<summary>Attempts to parse message and detects if it is an ORU_R01 HL7 message.  Returns false if it fails, or does not detect message type.</summary>
		private bool IsORU_R01message(string strFilePathAttach) {
			if(Path.GetExtension(strFilePathAttach) != "txt") {
				return false;
			}
			try {
				string[] ArrayMSHFields=FileAtoZ.ReadAllText(strFilePathAttach).Split(new string[] { "\r\n" },
					StringSplitOptions.RemoveEmptyEntries)[0].Split('|');
				if(ArrayMSHFields[8]!="ORU^R01^ORU_R01") {
					return false;
				}
			}
			catch(Exception ex) {
				ex.DoNothing();
				return false;
			}
			return true;
		}
Example #11
0
        /// <summary></summary>
        private void FillGrid()
        {
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g(this, "Image Name"), 70);

            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            string wikiPath = "";

            try {
                wikiPath = WikiPages.GetWikiPath();
            }
            catch (Exception ex) {
                MessageBox.Show(this, ex.Message);
                DialogResult = DialogResult.Cancel;
                return;
            }
            List <string> listFileNames = FileAtoZ.GetFilesInDirectory(wikiPath);         //All files from the wiki file path, including images and other files.

            ImageNamesList = new List <string>();
            for (int i = 0; i < listFileNames.Count; i++)
            {
                //If the user has entered a search keyword, then only show file names which contain the keyword.
                if (textSearch.Text != "" && !Path.GetFileName(listFileNames[i]).ToLower().Contains(textSearch.Text.ToLower()))
                {
                    continue;
                }
                //Only add image files to the ImageNamesList, not other files such at text files.
                if (ImageHelper.HasImageExtension(listFileNames[i]))
                {
                    ImageNamesList.Add(listFileNames[i]);
                }
            }
            for (int i = 0; i < ImageNamesList.Count; i++)
            {
                ODGridRow row = new ODGridRow();
                row.Cells.Add(Path.GetFileName(ImageNamesList[i]));
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            labelImageSize.Text  = Lan.g(this, "Image Size") + ":";
            picturePreview.Image = null;
            picturePreview.Invalidate();
        }
Example #12
0
        ///<summary>This form will get the necessary images off disk or from the cloud so that it can control layout.</summary>
        public void SetImage(Document thisDocument, string displayTitle)
        {
            //for now, the document is single. Later, it will get groups for composite images/mounts.
            Text         = displayTitle;
            displayedDoc = thisDocument;
            List <long> docNums = new List <long>();

            docNums.Add(thisDocument.DocNum);
            string fileName = CloudStorage.PathTidy(Documents.GetPaths(docNums, ImageStore.GetPreferredAtoZpath())[0]);

            if (!FileAtoZ.Exists(fileName))
            {
                MessageBox.Show(fileName + " +" + Lan.g(this, "could not be found."));
                return;
            }
            ImageCurrent = (Bitmap)FileAtoZ.GetImage(fileName);
            DisplayImage();
        }
 private void PaintPreviewPicture()
 {
     try {
         Document doc       = GetSelectedDocument();
         string   imagePath = FileAtoZ.CombinePaths(_patFolder, doc.FileName);
         if (!FileAtoZ.Exists(imagePath))
         {
             throw new Exception("File not found");
         }
         Image tmpImg   = FileAtoZ.GetImage(imagePath);
         float imgScale = 1;                                                                                                   //will be between 0 and 1
         if (tmpImg.PhysicalDimension.Height > picturePreview.Height || tmpImg.PhysicalDimension.Width > picturePreview.Width) //image is too large
         //Image is larger than PictureBox, resize to fit.
         {
             if (tmpImg.PhysicalDimension.Width / picturePreview.Width > tmpImg.PhysicalDimension.Height / picturePreview.Height)               //resize image based on width
             {
                 imgScale = picturePreview.Width / tmpImg.PhysicalDimension.Width;
             }
             else                      //resize image based on height
             {
                 imgScale = picturePreview.Height / tmpImg.PhysicalDimension.Height;
             }
         }
         if (picturePreview.Image != null)
         {
             picturePreview.Image.Dispose();
             picturePreview.Image = null;
         }
         picturePreview.Image = new Bitmap(tmpImg, (int)(tmpImg.PhysicalDimension.Width * imgScale), (int)(tmpImg.PhysicalDimension.Height * imgScale));
         //labelDescription.Text=Lan.g(this,"Description")+": "+doc.Description;
         picturePreview.Invalidate();
         if (tmpImg != null)
         {
             tmpImg.Dispose();
         }
         tmpImg = null;
     }
     catch (Exception e) {
         e.DoNothing();
         picturePreview.Image = null;
         picturePreview.Invalidate();
     }
 }
Example #14
0
        private void paintPreviewPicture()
        {
            if (gridMain.GetSelectedIndex() == -1)
            {
                return;
            }
            string imagePath = ImageNamesList[gridMain.GetSelectedIndex()];
            Image  tmpImg    = FileAtoZ.GetImage(imagePath);                                                                      //Could throw an exception if someone deletes the image right after this window loads.
            float  imgScale  = 1;                                                                                                 //will be between 0 and 1

            if (tmpImg.PhysicalDimension.Height > picturePreview.Height || tmpImg.PhysicalDimension.Width > picturePreview.Width) //image is too large
            //Image is larger than PictureBox, resize to fit.
            {
                if (tmpImg.PhysicalDimension.Width / picturePreview.Width > tmpImg.PhysicalDimension.Height / picturePreview.Height)           //resize image based on width
                {
                    imgScale = picturePreview.Width / tmpImg.PhysicalDimension.Width;
                }
                else                  //resize image based on height
                {
                    imgScale = picturePreview.Height / tmpImg.PhysicalDimension.Height;
                }
            }
            if (picturePreview.Image != null)
            {
                picturePreview.Image.Dispose();
                picturePreview.Image = null;
            }
            picturePreview.Image = new Bitmap(tmpImg, (int)(tmpImg.PhysicalDimension.Width * imgScale), (int)(tmpImg.PhysicalDimension.Height * imgScale));
            labelImageSize.Text  = Lan.g(this, "Image Size") + ": " + (int)tmpImg.PhysicalDimension.Width + " x " + (int)tmpImg.PhysicalDimension.Height;
            picturePreview.Invalidate();
            if (tmpImg != null)
            {
                tmpImg.Dispose();
            }
            tmpImg = null;
        }
Example #15
0
        ///<summary>Allow the user to pick the files to be attached. The 'pat' argument can be null. If the user cancels at any step, the return value
        ///will be an empty list.</summary>
        public static List <EmailAttach> PickAttachments(Patient pat)
        {
            List <EmailAttach> listAttaches = new List <EmailAttach>();
            OpenFileDialog     dlg          = new OpenFileDialog();

            dlg.Multiselect = true;
            bool          isLocalFileSelected = false;
            List <string> listFileNames;

            if (pat != null && PrefC.AtoZfolderUsed != DataStorageType.InDatabase)
            {
                string patFolder = ImageStore.GetPatientFolder(pat, ImageStore.GetPreferredAtoZpath());
                if (CloudStorage.IsCloudStorage)
                {
                    FormFilePicker FormFP = new FormFilePicker(patFolder);
                    if (FormFP.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = FormFP.WasLocalFileSelected;
                    listFileNames       = FormFP.SelectedFiles;
                }
                else
                {
                    dlg.InitialDirectory = patFolder;
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return(listAttaches);
                    }
                    isLocalFileSelected = true;
                    listFileNames       = dlg.FileNames.ToList();
                }
            }
            else              //No patient selected or images in database
                              //Use the OS default directory for this type of file viewer.
            {
                dlg.InitialDirectory = "";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return(listAttaches);
                }
                isLocalFileSelected = true;
                listFileNames       = dlg.FileNames.ToList();
            }
            try {
                for (int i = 0; i < listFileNames.Count; i++)
                {
                    if (CloudStorage.IsCloudStorage)
                    {
                        FileAtoZSourceDestination sourceDestination;
                        if (isLocalFileSelected)
                        {
                            sourceDestination = FileAtoZSourceDestination.LocalToAtoZ;
                        }
                        else
                        {
                            sourceDestination = FileAtoZSourceDestination.AtoZToAtoZ;
                        }
                        //Create EmailAttach using EmailAttaches.CreateAttach logic, shortened for our specific purpose.
                        EmailAttach emailAttach = new EmailAttach();
                        emailAttach.DisplayedFileName = Path.GetFileName(listFileNames[i]);
                        string attachDir = EmailAttaches.GetAttachPath();
                        string subDir    = "Out";
                        emailAttach.ActualFileName = ODFileUtils.CombinePaths(subDir,
                                                                              DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString()
                                                                              + "_" + MiscUtils.CreateRandomAlphaNumericString(4) + "_" + emailAttach.DisplayedFileName).Replace("\\", "/");
                        FileAtoZ.Copy(listFileNames[i], FileAtoZ.CombinePaths(attachDir, emailAttach.ActualFileName), sourceDestination);
                        listAttaches.Add(emailAttach);
                    }
                    else                      //Not cloud
                    {
                        listAttaches.Add(EmailAttaches.CreateAttach(Path.GetFileName(listFileNames[i]), File.ReadAllBytes(listFileNames[i])));
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            return(listAttaches);
        }
Example #16
0
        private void butPreview_Click(object sender, System.EventArgs e)
        {
#if !DISABLE_MICROSOFT_OFFICE
            if (listLetters.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a letter first.");
                return;
            }
            LetterMerge letterCur = ListForCat[listLetters.SelectedIndex];
            letterCur.ImageFolder = comboImageCategory.SelectedTag <Def>().DefNum;
            string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName);
            string dataFile     = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName);
            if (!File.Exists(templateFile))
            {
                MsgBox.Show(this, "Template file does not exist.");
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            Word.MailMerge wrdMailMerge;
            //Create an instance of Word.
            Word.Application WrdApp;
            try{
                WrdApp = LetterMerges.WordApp;
            }
            catch {
                MsgBox.Show(this, "Error. Is Word installed?");
                return;
            }
            string errorMessage = "";
            //Open a document.
            try {
                Object oName = templateFile;
                wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing,
                                               ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                               ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                wrdDoc.Select();
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error opening document:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            //Attach the data file.
            try {
                wrdMailMerge = wrdDoc.MailMerge;
                wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                wrdMailMerge.Execute(ref oFalse);
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error attaching data file:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            if (letterCur.ImageFolder != 0)           //if image folder exist for this letter, save to AtoZ folder
            //Open document from the atoz folder.
            {
                try {
                    WrdApp.Activate();
                    string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile));
                    Object oFileName    = tempFilePath;
                    WrdApp.ActiveDocument.SaveAs(oFileName);                    //save the document to temp location
                    Document doc       = SaveToImageFolder(tempFilePath, letterCur);
                    string   patFolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath());
                    string   fileName  = ImageStore.GetFilePath(doc, patFolder);
                    if (!FileAtoZ.Exists(fileName))
                    {
                        throw new ApplicationException(Lans.g("LetterMerge", "Error opening document" + " " + doc.FileName));
                    }
                    FileAtoZ.StartProcess(fileName);
                    WrdApp.ActiveDocument.Close();                    //Necessary since we created an extra document
                    try {
                        File.Delete(tempFilePath);                    //Clean up the temp file
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                    }
                }
                catch (Exception ex) {
                    FriendlyException.Show(Lan.g(this, "Error saving file to the Image module:") + "\r\n" + ex.Message, ex);
                }
            }
            //Close the original form document since just one record.
            try {
                wrdDoc.Saved = true;
                wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error closing document:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            //At this point, Word remains open with just one new document.
            try {
                WrdApp.Activate();
                if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize)
                {
                    WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;
                }
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error showing Microsoft Word:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            wrdMailMerge = null;
            wrdDoc       = null;
            Commlog CommlogCur = new Commlog();
            CommlogCur.CommDateTime   = DateTime.Now;
            CommlogCur.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
            CommlogCur.Mode_          = CommItemMode.Mail;
            CommlogCur.SentOrReceived = CommSentOrReceived.Sent;
            CommlogCur.PatNum         = PatCur.PatNum;
            CommlogCur.Note           = "Letter sent: " + letterCur.Description + ". ";
            CommlogCur.UserNum        = Security.CurUser.UserNum;
            Commlogs.Insert(CommlogCur);
#else
            MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
#endif
            //this window now closes regardless of whether the user saved the comm item.
            DialogResult = DialogResult.OK;
        }
        private void menuItemOpen_Click(object sender, EventArgs e)
        {
            EmailAttach attach = _listEmailAttachDisplayed[gridAttachments.SelectedIndices[0]];

            FileAtoZ.OpenFile(FileAtoZ.CombinePaths(EmailAttaches.GetAttachPath(), attach.ActualFileName), attach.DisplayedFileName);
        }
Example #18
0
        private void butImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFD = new OpenFileDialog();

            openFD.Multiselect = true;
            if (openFD.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Invalidate();
            foreach (string fileName in openFD.FileNames)
            {
                //check file types?
                string destinationPath = FileAtoZ.CombinePaths(_imageFolder, Path.GetFileName(fileName));
                if (FileAtoZ.Exists(destinationPath))
                {
                    switch (MessageBox.Show(Lan.g(this, "Overwrite Existing File") + ": " + destinationPath, "", MessageBoxButtons.YesNoCancel))
                    {
                    case DialogResult.No:                            //rename, do not overwrite
                        InputBox ip = new InputBox(Lan.g(this, "New file name."));
                        ip.textResult.Text = Path.GetFileName(fileName);
                        ip.ShowDialog();
                        if (ip.DialogResult != DialogResult.OK)
                        {
                            continue;                                    //cancel, next file.
                        }
                        bool cancel = false;
                        while (!cancel && FileAtoZ.Exists(FileAtoZ.CombinePaths(_imageFolder, ip.textResult.Text)))
                        {
                            MsgBox.Show(this, "File name already exists.");
                            if (ip.ShowDialog() != DialogResult.OK)
                            {
                                cancel = true;
                            }
                        }
                        if (cancel)
                        {
                            continue;                                    //cancel rename, and go to next file.
                        }
                        destinationPath = FileAtoZ.CombinePaths(_imageFolder, ip.textResult.Text);
                        break;                                //proceed to save file.

                    case DialogResult.Yes:                    //overwrite
                        try {
                            FileAtoZ.Delete(destinationPath);
                        }
                        catch (Exception ex) {
                            MessageBox.Show(Lan.g(this, "Cannot copy file") + ":" + fileName + "\r\n" + ex.Message);
                            continue;
                        }
                        break;                          //file deleted, proceed to save.

                    default:                            //cancel
                        continue;                       //skip this file.
                    }
                }
                FileAtoZ.Copy(fileName, destinationPath, FileAtoZSourceDestination.LocalToAtoZ);
            }
            FillGrid();
            if (openFD.FileNames.Length == 1)           //if importing exactly one image, select it upon returning.
            {
                textSearch.Text = Path.GetFileName(openFD.FileNames[0]);
            }
        }
Example #19
0
        ///<summary>Validates content, and keywords.  isForSaving can be false if just validating for refresh.</summary>
        public static bool ValidateMarkup(ODcodeBox textContent, bool isForSaving, bool showMsgBox = true, bool isEmail = false)
        {
            MatchCollection matches;
            //xml validation----------------------------------------------------------------------------------------------------
            string s = textContent.Text;

            //"<",">", and "&"-----------------------------------------------------------------------------------------------------------
            s = s.Replace("&", "&amp;");
            s = s.Replace("&amp;<", "&lt;");         //because "&" was changed to "&amp;" in the line above.
            s = s.Replace("&amp;>", "&gt;");         //because "&" was changed to "&amp;" in the line above.
            s = "<body>" + s + "</body>";
            XmlDocument  doc    = new XmlDocument();
            StringReader reader = new StringReader(s);

            try {
                doc.Load(reader);
            }
            catch (Exception ex) {
                if (showMsgBox)
                {
                    MessageBox.Show(ex.Message);
                }
                return(false);
            }
            try{
                //we do it this way to skip checking the main node itself since it's a dummy node.
                if (!isEmail)                 //We are allowing any XHTML markup in emails.
                {
                    MarkupEdit.ValidateNodes(doc.DocumentElement.ChildNodes);
                }
            }
            catch (Exception ex) {
                if (showMsgBox)
                {
                    MessageBox.Show(ex.Message);
                }
                return(false);
            }
            //Cannot have CR within tag definition---------------------------------------------------------------------------------
            //(?<!&) means only match strings that do not start with an '&'. This is so we can continue to use '&' as an escape character for '<'.
            //<.*?> means anything as short as possible that is contained inside a tag
            MatchCollection tagMatches = Regex.Matches(textContent.Text, "(?<!&)<.*?>", RegexOptions.Singleline);

            for (int i = 0; i < tagMatches.Count; i++)
            {
                if (tagMatches[i].ToString().Contains("\n"))
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(tagMatches[i].Index) + " - "
                                        + Lans.g(_lanThis, "Tag definitions cannot contain a return line:") + " " + tagMatches[i].Value.Replace("\n", ""));
                    }
                    return(false);
                }
            }
            //wiki image validation-----------------------------------------------------------------------------------------------------
            if (!isEmail)
            {
                string wikiImagePath = "";
                try {
                    wikiImagePath = WikiPages.GetWikiPath();                  //this also creates folder if it's missing.
                }
                catch (Exception ex) {
                    ex.DoNothing();
                    //do nothing, the wikiImagePath is only important if the user adds an image to the wiki page and is checked below
                }
                matches = Regex.Matches(textContent.Text, @"\[\[(img:).*?\]\]");             // [[img:myimage.jpg]]
                if (matches.Count > 0 && PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(matches[0].Index) + " - "
                                        + Lans.g(_lanThis, "Cannot use images in wiki if storing images in database."));
                    }
                    return(false);
                }
                if (isForSaving)
                {
                    for (int i = 0; i < matches.Count; i++)
                    {
                        string imgPath = FileAtoZ.CombinePaths(wikiImagePath, matches[i].Value.Substring(6).Trim(']'));
                        if (!FileAtoZ.Exists(imgPath))
                        {
                            if (showMsgBox)
                            {
                                MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(matches[i].Index) + " - "
                                                + Lans.g(_lanThis, "Not allowed to save because image does not exist:") + " " + imgPath);
                            }
                            return(false);
                        }
                    }
                }
            }
            //Email image validation----------------------------------------------------------------------------------------------
            if (isEmail)
            {
                string emailImagePath = "";
                try {
                    emailImagePath = ImageStore.GetEmailImagePath();
                }
                catch (Exception ex) {
                    ex.DoNothing();
                }
                matches = Regex.Matches(textContent.Text, @"\[\[(img:).*?\]\]");
                if (isForSaving)
                {
                    for (int i = 0; i < matches.Count; i++)
                    {
                        string imgPath = FileAtoZ.CombinePaths(emailImagePath, matches[i].Value.Substring(6).Trim(']'));
                        if (!FileAtoZ.Exists(imgPath))
                        {
                            if (showMsgBox)
                            {
                                MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(matches[i].Index) + " - "
                                                + Lans.g(_lanThis, "Not allowed to save because image does not exist: ") + " " + imgPath);
                            }
                        }
                    }
                }
            }
            //List validation-----------------------------------------------------------------------------------------------------
            matches = Regex.Matches(textContent.Text, @"\[\[(list:).*?\]\]");         // [[list:CustomList]]
            foreach (Match match in matches)
            {
                if (!WikiLists.CheckExists(match.Value.Substring(7).Trim(']')))
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                        + Lans.g(_lanThis, "Wiki list does not exist in database:") + " " + match.Value.Substring(7).Trim(']'));
                    }
                    return(false);
                }
            }
            //spacing around bullets-----------------------------------------------------------------------------------------------
            string[] lines = textContent.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Trim().StartsWith("*"))
                {
                    if (!lines[i].StartsWith("*"))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + (i + 1) + " - "
                                            + Lans.g(_lanThis, "Stars used for lists may not have a space before them."));
                        }
                        return(false);
                    }
                    if (lines[i].Trim().StartsWith("* "))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + (i + 1) + " - "
                                            + Lans.g(_lanThis, "Stars used for lists may not have a space after them."));
                        }
                        return(false);
                    }
                }
                if (lines[i].Trim().StartsWith("#"))
                {
                    if (!lines[i].StartsWith("#"))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + (i + 1) + " - "
                                            + Lans.g(_lanThis, "Hashes used for lists may not have a space before them."));
                        }
                        return(false);
                    }
                    if (lines[i].Trim().StartsWith("# "))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + (i + 1) + " - "
                                            + Lans.g(_lanThis, "Hashes used for lists may not have a space after them."));
                        }
                        return(false);
                    }
                }
            }
            //Invalid characters inside of various tags--------------------------------------------
            matches = Regex.Matches(textContent.Text, @"\[\[.*?\]\]");
            foreach (Match match in matches)
            {
                if (match.Value.Contains("\"") && !match.Value.StartsWith("[[color:") && !match.Value.StartsWith("[[font:"))                 //allow colored text to have quotes.
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                        + Lans.g(_lanThis, "Link cannot contain double quotes:") + " " + match.Value);
                    }
                    return(false);
                }
                //This is not needed because our regex doesn't even catch them if the span a line break.  It's just interpreted as plain text.
                //if(match.Value.Contains("\r") || match.Value.Contains("\n")) {
                //	MessageBox.Show(Lan.g(this,"Link cannot contain carriage returns: ")+match.Value);
                //	return false;
                //}
                if (match.Value.StartsWith("[[img:") ||
                    match.Value.StartsWith("[[keywords:") ||
                    match.Value.StartsWith("[[file:") ||
                    match.Value.StartsWith("[[folder:") ||
                    match.Value.StartsWith("[[list:") ||
                    match.Value.StartsWith("[[color:") ||
                    match.Value.StartsWith("[[font:"))
                {
                    //other tags
                }
                else
                {
                    if (match.Value.Contains("|"))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                            + Lans.g(_lanThis, "Internal link cannot contain a pipe character:") + " " + match.Value);
                        }
                        return(false);
                    }
                }
            }
            //Table markup rigorously formatted----------------------------------------------------------------------
            //{|
            //!Width="100"|Column Heading 1!!Width="150"|Column Heading 2!!Width="75"|Column Heading 3
            //|-
            //|Cell 1||Cell 2||Cell 3
            //|-
            //|Cell A||Cell B||Cell C
            //|}
            //Although rarely needed, it might still come in handy in certain cases, like paste, or when user doesn't add the |} until later, and other hacks.
            matches = Regex.Matches(s, @"\{\|\n.+?\n\|\}", RegexOptions.Singleline);
            //matches = Regex.Matches(textContent.Text,
            //	@"(?<=(?:\n|<body>))" //Checks for preceding newline or beggining of file
            //	+@"\{\|.+?\n\|\}" //Matches the table markup.
            //	+@"(?=(?:\n|</body>))" //Checks for following newline or end of file
            //	,RegexOptions.Singleline);
            foreach (Match match in matches)
            {
                lines = match.Value.Split(new string[] { "{|\n", "\n|-\n", "\n|}" }, StringSplitOptions.RemoveEmptyEntries);
                if (!lines[0].StartsWith("!"))
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                        + Lans.g(_lanThis, "The second line of a table markup section must start with ! to indicate column headers."));
                    }
                    return(false);
                }
                if (lines[0].StartsWith("! "))
                {
                    if (showMsgBox)
                    {
                        MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                        + Lans.g(_lanThis, "In the table, at line 2, there cannot be a space after the first !"));
                    }
                    return(false);
                }
                string[] cells = lines[0].Substring(1).Split(new string[] { "!!" }, StringSplitOptions.None);             //this also strips off the leading !
                for (int c = 0; c < cells.Length; c++)
                {
                    if (!Regex.IsMatch(cells[c], @"^(Width="")\d+""\|"))                    //e.g. Width="90"|
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Error at line:") + " " + textContent.GetLineFromCharIndex(match.Index) + " - "
                                            + Lans.g(_lanThis, "In the table markup, each header must be formatted like this: Width=\"#\"|..."));
                        }
                        return(false);
                    }
                }
                for (int i = 1; i < lines.Length; i++)           //loop through the lines after the header
                {
                    if (!lines[i].StartsWith("|"))
                    {
                        if (showMsgBox)
                        {
                            MessageBox.Show(Lans.g(_lanThis, "Table rows must start with |.  At line ") + (i + 1).ToString() + Lans.g(_lanThis, ", this was found instead:")
                                            + lines[i]);
                        }
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #20
0
 private void webBrowserWiki_Navigating(object sender, WebBrowserNavigatingEventArgs e)
 {
     //For debugging, we need to remember that the following happens when you click on an internal link:
     //1. This method fires. url includes 'wiki:'
     //2. This causes LoadWikiPage method to fire.  It loads the document text.
     //3. Which causes this method to fire again.  url is "about:blank".
     //This doesn't seem to be a problem.  We wrote it so that it won't go into an infinite loop, but it's something to be aware of.
     if (e.Url.ToString() == "about:blank" || e.Url.ToString().StartsWith("about:blank#"))
     {
         //This is a typical wiki page OR this is an internal bookmark.
         //We want to let the browser control handle the "navigation" so that it correctly loads the page OR simply auto scrolls to the div.
     }
     else if (e.Url.ToString().StartsWith("about:"))
     {
         //All other URLs that start with about: and do not have the required "blank#" are treated as malformed URLs.
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().StartsWith("wiki:"))             //user clicked on an internal link
     //It is invalid to have more than one space in a row in URLs.
     //When there is more than one space in a row, WebBrowserNavigatingEventArgs will convert the spaces into '&nbsp'
     //In order for our internal wiki page links to work, we need to always replace the '&nbsp' chars with spaces again.
     {
         string   wikiPageTitle   = Regex.Replace(e.Url.ToString(), @"\u00A0", " ").Substring(5);
         WikiPage wikiPageDeleted = WikiPages.GetByTitle(wikiPageTitle, isDeleted: true);            //Should most likely be null.
         if (wikiPageDeleted != null)
         {
             if (MessageBox.Show(Lan.g(this, "WikiPage '") + wikiPageTitle + Lan.g(this, "' is currently archived. Would you like to restore it?"),
                                 "", MessageBoxButtons.OKCancel) != DialogResult.OK)
             {
                 e.Cancel = true;
                 return;
             }
             else
             {
                 //User wants to restore the WikiPage.
                 WikiPages.WikiPageRestore(wikiPageDeleted, Security.CurUser.UserNum);
             }
         }
         historyNavBack--;                //We have to decrement historyNavBack to tell whether or not we need to branch our page history or add to page history
         LoadWikiPage(wikiPageTitle);
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().Contains("wikifile:"))
     {
         string fileName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("wikifile:") + 9).Replace("/", "\\");
         if (!File.Exists(fileName))
         {
             MessageBox.Show(Lan.g(this, "File does not exist: ") + fileName);
             e.Cancel = true;
             return;
         }
         try {
             System.Diagnostics.Process.Start(fileName);
         }
         catch (Exception ex) {
             ex.DoNothing();
         }
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().Contains("folder:"))
     {
         string folderName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("folder:") + 7).Replace("/", "\\");
         if (!Directory.Exists(folderName))
         {
             MessageBox.Show(Lan.g(this, "Folder does not exist: ") + folderName);
             e.Cancel = true;
             return;
         }
         try {
             System.Diagnostics.Process.Start(folderName);
         }
         catch (Exception ex) {
             ex.DoNothing();
         }
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().Contains("wikifilecloud:"))
     {
         string fileName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("wikifilecloud:") + 14);
         if (!FileAtoZ.Exists(fileName))
         {
             MessageBox.Show(Lan.g(this, "File does not exist: ") + fileName);
             e.Cancel = true;
             return;
         }
         try {
             FileAtoZ.StartProcess(fileName);
         }
         catch (Exception ex) {
             ex.DoNothing();
         }
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().Contains("foldercloud:"))
     {
         string folderName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("foldercloud:") + 12);
         if (!FileAtoZ.DirectoryExists(folderName))
         {
             MessageBox.Show(Lan.g(this, "Folder does not exist: ") + folderName);
             e.Cancel = true;
             return;
         }
         try {
             FileAtoZ.OpenDirectory(folderName);
         }
         catch (Exception ex) {
             ex.DoNothing();
         }
         e.Cancel = true;
         return;
     }
     else if (e.Url.ToString().StartsWith("http"))             //navigating outside of wiki by clicking a link
     {
         try {
             System.Diagnostics.Process.Start(e.Url.ToString());
         }
         catch (Exception ex) {
             ex.DoNothing();
         }
         e.Cancel = true;              //Stops the page from loading in FormWiki.
         return;
     }
 }
Example #21
0
        private void butSendToPortal_Click(object sender, EventArgs e)
        {
            //Validate
            string strCcdValidationErrors = EhrCCD.ValidateSettings();

            if (strCcdValidationErrors != "")            //Do not even try to export if global settings are invalid.
            {
                MessageBox.Show(strCcdValidationErrors); //We do not want to use translations here, because the text is dynamic. The errors are generated in the business layer, and Lan.g() is not available there.
                return;
            }
            strCcdValidationErrors = EhrCCD.ValidatePatient(PatCur);          //Patient cannot be null, because a patient must be selected before the EHR dashboard will open.
            if (strCcdValidationErrors != "")
            {
                MessageBox.Show(strCcdValidationErrors);                //We do not want to use translations here, because the text is dynamic. The errors are generated in the business layer, and Lan.g() is not available there.
                return;
            }
            Provider prov = null;

            if (Security.CurUser.ProvNum != 0)           //If the current user is a provider.
            {
                prov = Providers.GetProv(Security.CurUser.ProvNum);
            }
            else
            {
                prov = Providers.GetProv(PatCur.PriProv);              //PriProv is not 0, because EhrCCD.ValidatePatient() will block if PriProv is 0.
            }
            try {
                //Create the Clinical Summary.
                FormEhrExportCCD FormEEC = new FormEhrExportCCD(PatCur);
                FormEEC.ShowDialog();
                if (FormEEC.DialogResult != DialogResult.OK)               //Canceled
                {
                    return;
                }
                //Save the clinical summary (ccd.xml) and style sheet (ccd.xsl) as webmail message attachments.
                //TODO: It would be more patient friendly if we instead generated a PDF file containing the Clinical Summary printout, or if we simply displayed the Clinical Summary in the portal.
                //The CMS definition does not prohibit sending human readable files, and sending a PDF to the portal mimics printing the Clinical Summary and handing to patient.
                Random             rnd             = new Random();
                string             attachPath      = EmailAttaches.GetAttachPath();
                List <EmailAttach> listAttachments = new List <EmailAttach>();
                EmailAttach        attachCcd       = new EmailAttach(); //Save Clinical Summary to file in the email attachments folder.
                attachCcd.DisplayedFileName = "ccd.xml";
                attachCcd.ActualFileName    = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString() + ".xml";
                listAttachments.Add(attachCcd);
                FileAtoZ.WriteAllText(FileAtoZ.CombinePaths(attachPath, attachCcd.ActualFileName), FormEEC.CCD, "Uploading Attachment for Clinical Summary...");
                EmailAttach attachSs = new EmailAttach();                                                                         //Style sheet attachment.
                attachSs.DisplayedFileName = "ccd.xsl";
                attachSs.ActualFileName    = attachCcd.ActualFileName.Substring(0, attachCcd.ActualFileName.Length - 4) + ".xsl"; //Same base name as the CCD.  The base names must match or the file will not display properly in internet browsers.
                listAttachments.Add(attachSs);
                FileAtoZ.WriteAllText(FileAtoZ.CombinePaths(attachPath, attachSs.ActualFileName), FormEHR.GetEhrResource("CCD"),
                                      "Uploading Attachment for Clinical Summary...");
                //Create and save the webmail message containing the attachments.
                EmailMessage msgWebMail = new EmailMessage();
                msgWebMail.FromAddress    = prov.GetFormalName();
                msgWebMail.ToAddress      = PatCur.GetNameFL();
                msgWebMail.PatNum         = PatCur.PatNum;
                msgWebMail.SentOrReceived = EmailSentOrReceived.WebMailSent;
                msgWebMail.ProvNumWebMail = prov.ProvNum;
                msgWebMail.Subject        = "Clinical Summary";
                msgWebMail.BodyText       = "To view the clinical summary:\r\n1) Download all attachments to the same folder.  Do not rename the files.\r\n2) Open the ccd.xml file in an internet browser.";
                msgWebMail.MsgDateTime    = DateTime.Now;
                msgWebMail.PatNumSubj     = PatCur.PatNum;
                msgWebMail.Attachments    = listAttachments;
                EmailMessages.Insert(msgWebMail);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }
            EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();

            newMeasureEvent.DateTEvent = DateTime.Now;
            newMeasureEvent.EventType  = EhrMeasureEventType.ClinicalSummaryProvidedToPt;
            newMeasureEvent.PatNum     = PatCur.PatNum;
            EhrMeasureEvents.Insert(newMeasureEvent);
            FillGridEHRMeasureEvents();            //This will cause the measure event to show in the grid below the popup message on the next line.  Reassures the user that the event was immediately recorded.
            MsgBox.Show(this, "Clinical Summary Sent");
        }