Example #1
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);
        }
		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);
			}
		}
        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 #5
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 #7
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();
        }
 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 #9
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 #10
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");
        }
Example #11
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);
        }
        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 #13
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);
        }