Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
     }
 }