protected static string OpenWord(string Path)
        {
            Word._Application application = null;;
            Word._Document    document    = null;;

            Object _Path = Path;

            try
            {
                application = new Word.Application();
                if (!string.IsNullOrEmpty(_Path.ToString()))
                {
                    document = application.Documents.Open(ref _Path, Type.Missing, (object)false);
                }
                application.Visible = true;
            }
            catch (Exception error)
            {
                try
                {
                    document.Close();
                }
                catch { }
                try
                {
                    application.Quit();
                }
                catch { }
                document    = null;
                application = null;
                return(error.Message + "innerExeption: " + error.InnerException.Message);
            }
            return("Succed");
        }
Exemplo n.º 2
0
 public void checkin(Word._Document activeDocument)
 {
     try
     {
         if (MessageBox.Show(resources.GetString("sure_check_in"), resources.GetString("checkin"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
         {
             object saveChanges   = Word.WdSaveOptions.wdSaveChanges;
             object missing       = Type.Missing;
             String localFileName = activeDocument.FullName;
             activeDocument.Close(ref saveChanges, ref missing, ref missing); // Always we save document
             docXML.refresh();                                                // Refresh document list
             if (docXML.isOpenKMDocument(localFileName))
             {
                 OKMDocument oKMDocument = docXML.getOpenKMDocument(localFileName);
                 docXML.remove(oKMDocument);
                 DocumentLogic.checkin(oKMDocument, configXML.getHost(), configXML.getUser(), configXML.getPassword());
                 if (File.Exists(localFileName))
                 {
                     File.Delete(localFileName);
                 }
             }
         }
     }
     catch (Exception e)
     {
         String errorMsg = "OpenKMWordAddIn - (checkinButton_Click)\n" + e.Message + "\n\n" + e.StackTrace;
         MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Exemplo n.º 3
0
 public void NavigateComplete2(object sender, AxIEBrowser._IIEBrowserCtlEvents_NavigateCompleteEvent e)
 {
     try
     {
         if (_cleanup)
         {
             if (_cleanupResource != null)
             {
                 FileResource.CleanupSourceFile(_cleanupResource, _strFileName);
             }
             _cleanupResource = null;
             _cleanup         = false;
             return;
         }
         object o         = e.document;
         object oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);
         _document         = (Word._Document)oDocument;
         _navigateComplete = true;
         if (_highlightWords == true)
         {
             HighlightWords();
             _navigateComplete = false;
             _highlightWords   = false;
         }
     }
     catch (Exception exception)
     {
         _tracer.TraceException(exception);
     }
 }
Exemplo n.º 4
0
        public void MergeDoc(string outPutFilePath, params string[] filePath)
        {
            object oMissing = System.Reflection.Missing.Value;
            object oObject  = System.Reflection.Missing.Value;

            Word.ApplicationClass oWord = new Word.ApplicationClass();
            Word._Document        oDoc  = null;
            oWord.Visible = false;
            Word.Documents oDocs = oWord.Documents;
            try
            {
                oDoc = oDocs.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                foreach (string fs in filePath)
                {
                    if (File.Exists(fs))
                    {
                        oWord.Selection.InsertFile(fs, ref oObject, ref oObject, ref oObject, ref oObject);
                        object obj = Word.WdBreakType.wdPageBreak;
                        //oWord.Selection.InsertBreak(ref obj);
                    }
                }
                object objFinalFile = (object)outPutFilePath;
                oDoc.SaveAs(ref objFinalFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            }
            catch (Exception e)
            {
            }
            finally
            {
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            }
        }
Exemplo n.º 5
0
        public static Word.Table GetDocumentTable(Word._Document document, int i)
        {
#if OFFICE2003
            return(document.Tables[i]);
#else
            return(document.Tables.Item(i));
#endif
        }
Exemplo n.º 6
0
 private void OnNewDoc(Word._Document doc)
 {
     if (!deactivateevents)
     {
         deactivateevents = true;
         object dummy = null;
         doc.Close(ref dummy, ref dummy, ref dummy);
         deactivateevents = false;
     }
 }
Exemplo n.º 7
0
        public static void WordSaveAs(Word._Document doc, string fileName)
        {
            object name = fileName;

            doc.SaveAs(ref name, ref ObjMissing, ref ObjMissing, ref ObjMissing,
                       ref ObjMissing, ref ObjMissing, ref ObjMissing,
                       ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing
#if OFFICE2003
                       , ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing
#endif
                       );
        }
Exemplo n.º 8
0
        public static void WordSaveAsRtf(Word._Document doc, string fileName)
        {
            object name   = fileName;
            object format = Word.WdSaveFormat.wdFormatRTF;

            doc.SaveAs(ref name, ref format, ref ObjMissing, ref ObjMissing,
                       ref ObjMissing, ref ObjMissing, ref ObjMissing,
                       ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing
#if OFFICE2003
                       , ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing
#endif
                       );
        }
        public static void CombineWord(string fileToMerge1, string fileToMerge2, string outputFilename)
        {
            object missing    = System.Type.Missing;
            object pageBreak  = Word.WdBreakType.wdPageBreak;
            object outputFile = outputFilename;

            // Create  a new Word application
            Word._Application wordApplication = new Word.Application();
            try
            {
                Word._Document wordDocument = wordApplication.Documents.Open(
                    fileToMerge1
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing);

                Word.Selection selection = wordApplication.Selection;
                wordDocument.Merge(fileToMerge2, ref missing, ref missing, ref missing, ref missing);
                // Save the document to it's output file.
                wordDocument.SaveAs(
                    ref outputFile
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing);

                wordDocument = null;
            }
            catch (Exception ex)
            {
                //I didn't include a default error handler so i'm just throwing the error
                throw ex;
            }
            finally
            {
                wordApplication.Quit(ref missing, ref missing, ref missing);
            }
        }
Exemplo n.º 10
0
        /*
         * public static List<EnvelopeSource> WordImportSourceEnvelopes(string fileName)
         * {
         *  List<EnvelopeSource> sources = new List<EnvelopeSource>();
         *  Word._Application objApp = new Word.Application();
         *  objApp.Visible = false;
         *  objApp.ScreenUpdating = false;
         *
         *  try
         *  {
         *      Word._Document objDoc = null;
         *
         *      object objDocName = fileName;
         *
         *      objDoc = UtilWord.WordOpen(objApp, objDocName);
         *
         *      int nCountRows = 0;
         *      foreach (Word.Table t in objDoc.Tables)
         *      {
         *          nCountRows += t.Rows.Count;
         *      }
         *
         *      string sColId = null, sColWho = null, sColAdr = null;
         *      string sColIdPrev = null, sColIdBase;
         *
         *      foreach (Word.Table t in objDoc.Tables)
         *      {
         *          int tableFirstRow = 3;
         *          for (int i = tableFirstRow; i <= t.Rows.Count; i++)
         *          {
         *              try
         *              {
         *                  EnvelopeSource source = new EnvelopeSource();
         *
         *                  sColIdBase = t.Cell(i, 1).Range.Text;
         *                  sColId = Util.TrimId(sColIdBase);
         *                  sColWho = t.Cell(i, 2).Range.Text;
         *                  sColAdr = t.Cell(i, 3).Range.Text;
         *
         *                  if (string.IsNullOrEmpty(sColId))
         *                      sColId = sColIdPrev;
         *
         *                  source.Adres = sColAdr;
         *                  source.Adresat = sColWho;
         *                  source.Id = sColId;
         *
         *                  sources.Add(source);
         *
         *                  sColIdPrev = sColId;
         *              }
         *              catch (COMException)
         *              {
         *                  if (i > t.Rows.Count)
         *                  {
         *                      break;
         *                  }
         *              }
         *          }
         *      }
         *      objDoc.Close(ref ObjMissing, ref ObjMissing, ref ObjMissing);
         *  }
         *  catch (COMException)
         *  {
         *  }
         *  finally
         *  {
         *      objApp.Quit(ref ObjMissing, ref ObjMissing, ref ObjMissing);
         *  }
         *  return sources;
         * }
         */
        /*
         * public static void WordSaveEnvelopes(string fileName, List<Envelope> envelopes)
         * {
         *  Word._Application app = new Word.Application();
         *  app.Visible = true;
         *  Word._Document doc =
         *      app.Documents.Add(
         *          ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing);
         *
         *  Word.Table tab = null;
         *  if (envelopes.Count > 0)
         *      tab = doc.Tables.Add(app.Selection.Range,
         *          envelopes.Count, 3, ref ObjMissing, ref ObjMissing);
         *
         *  int nRow = 1;
         *  foreach (Envelope envelope in envelopes)
         *  {
         *      tab.Cell(nRow, 1).Range.Text = envelope.Id;
         *      if (envelope.Text != null)
         *      {
         *          tab.Cell(nRow, 2).Range.Text = envelope.Adresat;
         *          tab.Cell(nRow, 3).Range.Text = envelope.Adres;
         *      }
         *      else
         *      {
         *          tab.Cell(nRow, 2).Range.Text = envelope.Adresat;
         *          tab.Cell(nRow, 3).Range.Text = envelope.Adres;
         *      }
         *
         *      nRow++;
         *  }
         *  WordSaveAs(doc, fileName);
         * }
         */
        #endregion

        #region Notification

        /*
         * public static string WordShowNotification(string notification, string adresat, string adres)
         * {
         *  Word._Application wordApp = new Word.Application();
         *  wordApp.Visible = true;
         *
         *  bool found = false;
         *  string message = "";
         *  try
         *  {
         *      Word._Document objDoc = null;
         *      object objStrDoc = notification;
         *      objDoc = WordOpen(wordApp, objStrDoc);
         *
         *      wordApp.Selection.Find.ClearFormatting();
         *      wordApp.Selection.Find.Replacement.ClearFormatting();
         *
         *      object objMatchText = Properties.Settings.Default.AddressPattern;
         *      object objReplaceWith = adresat;
         *
         *      found = wordApp.Selection.Find.ExecuteOld(ref objMatchText,
         *          ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing,
         *          ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing);
         *
         *      if (found)
         *      {
         *          if (adresat != "")
         *              wordApp.Selection.TypeText(adresat);
         *
         *          string[] rows = adres.Split((char)13);
         *          foreach (string row in rows)
         *          {
         *              wordApp.Selection.TypeParagraph();
         *              wordApp.Selection.TypeText(Util.TrimAdres(row));
         *          }
         *      }
         *  }
         *  catch (COMException com)
         *  {
         *      return com.Message;
         *  }
         *  finally
         *  {
         *  }
         *  return found ? message :
         *      "Nie znaleziono wyra¿enia do zamiany.\nZawiadomienie powinno zawieraæ ci¹g do podmiany " +
         *      Properties.Settings.Default.AddressPattern;
         * }
         */
        /*
         * public static string WordPrintNotification(string notification, string adresat, string adres)
         * {
         *  Word._Application wordApp = new Word.Application();
         *  wordApp.Visible = false;
         *
         *  bool found = false;
         *  string message = "";
         *  try
         *  {
         *      Word._Document objDoc = null;
         *      object objStrDoc = notification;
         *      objDoc = WordOpen(wordApp, objStrDoc);
         *
         *      wordApp.Selection.Find.ClearFormatting();
         *      wordApp.Selection.Find.Replacement.ClearFormatting();
         *
         *      object objMatchText = Properties.Settings.Default.AddressPattern;
         *      object objReplaceWith = adresat;
         *
         *      found = wordApp.Selection.Find.ExecuteOld(ref objMatchText,
         *          ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing,
         *          ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing);
         *
         *      if (found)
         *      {
         *          if (adresat != "")
         *              wordApp.Selection.TypeText(adresat);
         *
         *          string[] rows = adres.Split((char)13);
         *          foreach (string row in rows)
         *          {
         *              wordApp.Selection.TypeParagraph();
         *              wordApp.Selection.TypeText(Util.TrimAdres(row));
         *          }
         *
         *          objDoc.PrintOutOld(ref ObjTrue, ref ObjMissing, ref ObjMissing,
         *              ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing,
         *              ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing,
         *              ref ObjMissing);
         *      }
         *
         *      objDoc.Close(ref ObjFalse, ref ObjMissing, ref ObjMissing);
         *  }
         *  catch (COMException com)
         *  {
         *      message = com.Message;
         *  }
         *  finally
         *  {
         *      while (wordApp.BackgroundPrintingStatus > 0)
         *      {
         *          continue;
         *      }
         *      WordQuit(wordApp);
         *  }
         *  return found ? message :
         *      "Nie znaleziono wyra¿enia do zamiany.\nZawiadomienie powinno zawieraæ ci¹g do podmiany " +
         *      Properties.Settings.Default.AddressPattern;
         * }
         */
        public static string WordSaveNotificationAsRtf(string notification, string adresat, string adres)
        {
            Word._Application wordApp = new Word.Application();
            wordApp.Visible = false;

            string message = "";

            try
            {
                Word._Document objDoc    = null;
                object         objStrDoc = notification;
                objDoc = WordOpenForWrite(wordApp, objStrDoc);

                wordApp.Selection.Find.ClearFormatting();
                wordApp.Selection.Find.Replacement.ClearFormatting();

                object objMatchText   = "";// Properties.Settings.Default.AddressPattern;
                object objReplaceWith = adresat;

                wordApp.Selection.Find.ExecuteOld(ref objMatchText,
                                                  ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing,
                                                  ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing);

                if (adresat != "")
                {
                    wordApp.Selection.TypeText(adresat);
                }

                string[] rows = adres.Split((char)13);
                foreach (string row in rows)
                {
                    wordApp.Selection.TypeParagraph();
                    //wordApp.Selection.TypeText(Util.TrimAdres(row));
                }

                WordSaveAsRtf(objDoc, notification + ".rtf");

                objDoc.Close(ref ObjTrue, ref ObjMissing, ref ObjMissing);
            }
            catch (COMException com)
            {
                message = com.Message;
            }
            finally
            {
                WordQuit(wordApp);
            }
            return(message);
        }
Exemplo n.º 11
0
        private void butEditTemplate_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];
            string      templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName);
            string      dataFile     = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName);
            if (!File.Exists(templateFile))
            {
                MessageBox.Show(Lan.g(this, "Template file does not exist:") + "  " + templateFile);
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            //Create an instance of Word.
            Word.Application WrdApp;
            try {
                WrdApp = LetterMerges.WordApp;
            }
            catch {
                MsgBox.Show(this, "Error.  Is MS Word installed?");
                return;
            }
            //Open a document.
            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();
            //Attach the data file.
            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);
            //At this point, Word remains open with just one new document.
            if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize)
            {
                WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;
            }
            wrdDoc = null;
#else
            MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
#endif
        }
Exemplo n.º 12
0
        public string CopyToWord()
        {
            object filename = @"C:\" + System.DateTime.Now.ToFileTime() + ".doc";

            Word._Application application = new Word.ApplicationClass();
            Word._Document    document    = application.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            foreach (Excel.Worksheet sheet in wbb.Sheets)
            {
                if (sheet.Index == wbb.Sheets.Count)
                {
                    continue;
                }
                for (int i = 1; i < sheet.UsedRange.Rows.Count; i++)
                {
                    Word.Paragraph para = document.Paragraphs.Add(ref missing);
                    string         text = "";
                    for (int j = 1; j < sheet.UsedRange.Columns.Count; j++)
                    {
                        Excel.Range range = (Excel.Range)sheet.Cells[i, j];
                        if (range.Value2 != null)
                        {
                            text += range.Value2.ToString() + "\t";
                            if (range.Value2.ToString().StartsWith("#picture"))
                            {
                                string[]    value = System.Text.RegularExpressions.Regex.Split(range.Value2.ToString(), "_");
                                Excel.Shape shape = sheet.Shapes.Item(int.Parse(value[1])) as Excel.Shape;
                                shape.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap);
                                Word.Paragraph picture = document.Paragraphs.Add(ref missing);
                                picture.Range.Paste();
                                picture.Format.CharacterUnitFirstLineIndent = 2;
                                picture.Range.InsertParagraphAfter();
                                text = "";
                                i   += int.Parse(value[2]) - 1;
                                break;
                            }
                        }
                    }
                    para.Range.Text = text;
                    para.Format.CharacterUnitFirstLineIndent = 2;
                    para.Range.InsertParagraphAfter();
                }
            }
            document.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            document.Close(ref missing, ref missing, ref missing);
            application.Quit(ref missing, ref missing, ref missing);
            return(filename.ToString());
        }
Exemplo n.º 13
0
 public short CloseDocument()
 {
     try
     {
         object saveChanges = false;
         object originalFormat = null;
         object routeDocument = null;
         if (this.m_WordDoc != null)
             this.m_WordDoc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
         this.m_WordDoc = null;
         return SystemConst.ReturnValue.OK;
     }
     catch (Exception ex)
     {
         LogManager.Instance.WriteLog("WinWordControl.CloseDocument", ex);
         return SystemConst.ReturnValue.EXCEPTION;
     }
 }
    void Application_DocumentBeforeClose(Word.Document document, ref bool Cancel)
    {
        try
        {
            string filePath = this.Application.ActiveDocument.FullName.ToString();
            string fileName = this.Application.ActiveDocument.Name;

            //dialogFilePath = filePath;
            dialogFileName = fileName;
            doc            = document;

            string tempFile;
            string tempPath;

            //var form = new SaveFileDialog();
            //form.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            //form.ShowDialog();
            //System.Windows.Forms.MessageBox.Show(form.ToString());
            //_T is for editing template and save file after saving.
            //+ is for saving

            //document.Save();
            var iPersistFile = (IPersistFile)document;
            iPersistFile.Save(tempPath, false);

            if (filePath.Contains("_T"))
            {
                //Store file into DB
            }
            else
            {
                //Store file into DB
            }
            //object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
            //document.Close(ref doNotSaveChanges, ref missing, ref missing);
            Word._Document wDocument = Application.Documents[fileName] as Word._Document;
            //wDocument.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
            ThisAddIn.doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
        }
        catch (Exception exception)
        {
        }
    }
Exemplo n.º 15
0
 public short CloseDocument()
 {
     try
     {
         object saveChanges    = false;
         object originalFormat = null;
         object routeDocument  = null;
         if (this.m_WordDoc != null)
         {
             this.m_WordDoc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
         }
         this.m_WordDoc = null;
         return(SystemConst.ReturnValue.OK);
     }
     catch (Exception ex)
     {
         LogManager.Instance.WriteLog("WinWordControl.CloseDocument", ex);
         return(SystemConst.ReturnValue.EXCEPTION);
     }
 }
Exemplo n.º 16
0
        private void butEditTemplate_Click(object sender, System.EventArgs e)
        {
            if (listLetters.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a letter first.");
                return;
            }
            LetterMerge letterCur    = ListForCat[listLetters.SelectedIndex];
            string      templateFile = PrefB.GetString("LetterMergePath") + letterCur.TemplateName;
            string      dataFile     = PrefB.GetString("LetterMergePath") + letterCur.DataFileName;

            if (!File.Exists(templateFile))
            {
                MessageBox.Show(Lan.g(this, "Template file does not exist:") + "  " + templateFile);
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            //Create an instance of Word.
            Word.Application WrdApp = LetterMerges.WordApp;
            //Open a document.
            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();
            //Attach the data file.
            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);
            //At this point, Word remains open with just one new document.
            if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize)
            {
                WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;
            }
            wrdDoc = null;
        }
Exemplo n.º 17
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
#if DISABLE_MICROSOFT_OFFICE
            MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
            return;
#endif
            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;
            }
            PrintDocument pd = new PrintDocument();
            if (!PrinterL.SetPrinter(pd, PrintSituation.Default, PatCur.PatNum, "Letter merge " + letterCur.Description + " printed"))
            {
                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 MS Word installed?");
                return;
            }
            //Open a document.
            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();
            wrdMailMerge = wrdDoc.MailMerge;
            //Attach the data file.
            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.wdSendToPrinter;
            //WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName;
            //replaced with following 4 lines due to MS bug that changes computer default printer
            object   oWBasic   = WrdApp.WordBasic;
            object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 };
            String[] sWBNames  = new String[] { "Printer", "DoNotSetAsSysDefault" };
            oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames);
            wrdMailMerge.Execute(ref oFalse);
            if (letterCur.ImageFolder != 0)           //if image folder exist for this letter, save to AtoZ folder
            {
                try {
                    wrdDoc.Select();
                    wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                    wrdMailMerge.Execute(ref oFalse);
                    WrdApp.Activate();
                    string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile));
                    Object oFileName    = tempFilePath;
                    WrdApp.ActiveDocument.SaveAs(oFileName);                    //save the document
                    WrdApp.ActiveDocument.Close();
                    SaveToImageFolder(tempFilePath, letterCur);
                }
                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.
            wrdDoc.Saved = true;
            wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            //At this point, Word remains open with no documents.
            WrdApp.WindowState = Word.WdWindowState.wdWindowStateMinimize;
            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);
            DialogResult = DialogResult.OK;
        }
Exemplo n.º 18
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];
     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;
     }
     //Open a document.
     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();
     wrdMailMerge=wrdDoc.MailMerge;
     //Attach the data file.
     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);
     //Close the original form document since just one record.
     wrdDoc.Saved=true;
     wrdDoc.Close(ref oFalse,ref oMissing,ref oMissing);
     //At this point, Word remains open with just one new document.
     WrdApp.Activate();
     if(WrdApp.WindowState==Word.WdWindowState.wdWindowStateMinimize){
         WrdApp.WindowState=Word.WdWindowState.wdWindowStateMaximize;
     }
     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;
 }
Exemplo n.º 19
0
 private void butPrint_Click(object sender, System.EventArgs e)
 {
     #if DISABLE_MICROSOFT_OFFICE
     MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
     return;
     #endif
     if(listLetters.SelectedIndex==-1){
         MsgBox.Show(this,"Please select a letter first.");
         return;
     }
     LetterMerge letterCur=ListForCat[listLetters.SelectedIndex];
     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;
     }
     PrintDocument pd=new PrintDocument();
     if(!PrinterL.SetPrinter(pd,PrintSituation.Default)){
         return;
     }
     if(!CreateDataFile(dataFile,letterCur)){
         return;
     }
     Word.MailMerge wrdMailMerge;
     //Create an instance of Word.
     Word.Application WrdApp=LetterMerges.WordApp;
     //Open a document.
     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();
     wrdMailMerge=wrdDoc.MailMerge;
     //Attach the data file.
     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.wdSendToPrinter;
     //WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName;
     //replaced with following 4 lines due to MS bug that changes computer default printer
     object oWBasic = WrdApp.WordBasic;
     object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 };
     String[] sWBNames = new String[] { "Printer", "DoNotSetAsSysDefault" };
     oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames);
     wrdMailMerge.Execute(ref oFalse);
     //Close the original form document since just one record.
     wrdDoc.Saved=true;
     wrdDoc.Close(ref oFalse,ref oMissing,ref oMissing);
     //At this point, Word remains open with no documents.
     WrdApp.WindowState=Word.WdWindowState.wdWindowStateMinimize;
     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);
     DialogResult=DialogResult.OK;
 }
Exemplo n.º 20
0
        public void LoadDocument(string t_filename)
        {
            deactivateevents = true;
            filename         = t_filename;

            if (applicationClass == null)
            {
                applicationClass = new Word.ApplicationClass();
            }
            try
            {
                applicationClass.CommandBars.AdaptiveMenus = false;
                applicationClass.DocumentBeforeClose      += new Word.ApplicationEvents2_DocumentBeforeCloseEventHandler(OnClose);
                applicationClass.NewDocument  += new Word.ApplicationEvents2_NewDocumentEventHandler(OnNewDoc);
                applicationClass.DocumentOpen += new Word.ApplicationEvents2_DocumentOpenEventHandler(OnOpenDoc);
                applicationClass.ApplicationEvents2_Event_Quit += new Word.ApplicationEvents2_QuitEventHandler(OnQuit);
            }
            catch { }



            if (document != null)
            {
                try
                {
                    object dummy = null;
                    applicationClass.Documents.Close(ref dummy, ref dummy, ref dummy);
                }
                catch { }
            }

            if (wordWnd == 0)
            {
                wordWnd = FindWindow("Opusapp", null);
            }
            if (wordWnd != 0)
            {
                SetParent(wordWnd, this.Handle.ToInt32());

                object fileName    = filename;
                object newTemplate = false;
                object docType     = 0;
                object readOnly    = true;
                object isVisible   = true;
                object missing     = System.Reflection.Missing.Value;


                try
                {
                    if (applicationClass == null)
                    {
                        throw new WordInstanceException();
                    }

                    if (applicationClass.Documents == null)
                    {
                        throw new DocumentInstanceException();
                    }

                    if (applicationClass != null && applicationClass.Documents != null)
                    {
                        document = applicationClass.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
                    }

                    if (document == null)
                    {
                        throw new ValidDocumentException();
                    }
                }
                catch
                {
                }

                try
                {
                    applicationClass.ActiveWindow.DisplayRightRuler        = false;
                    applicationClass.ActiveWindow.DisplayScreenTips        = false;
                    applicationClass.ActiveWindow.DisplayVerticalRuler     = false;
                    applicationClass.ActiveWindow.DisplayRightRuler        = false;
                    applicationClass.ActiveWindow.ActivePane.DisplayRulers = false;
                    applicationClass.ActiveWindow.ActivePane.View.Type     = Word.WdViewType.wdWebView;
                    //wd.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView;//wdWebView; // .wdNormalView;
                }
                catch
                {
                }
                int counter = applicationClass.ActiveWindow.Application.CommandBars.Count;
                for (int i = 1; i <= counter; i++)
                {
                    try
                    {
                        String nm = applicationClass.ActiveWindow.Application.CommandBars[i].Name;
                        if (nm == "Standard")
                        {
                            int count_control = applicationClass.ActiveWindow.Application.CommandBars[i].Controls.Count;
                            for (int j = 1; j <= 2; j++)
                            {
                                applicationClass.ActiveWindow.Application.CommandBars[i].Controls[j].Enabled = false;
                            }
                        }

                        if (nm == "Menu Bar")
                        {
                            applicationClass.ActiveWindow.Application.CommandBars[i].Enabled = false;
                        }

                        nm = "";
                    }
                    catch
                    {
                        //MessageBox.Show(ex.ToString());
                    }
                }



                try
                {
                    applicationClass.Visible = true;
                    applicationClass.Activate();

                    SetWindowPos(wordWnd, this.Handle.ToInt32(), 0, 0, this.Bounds.Width, this.Bounds.Height, SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME | SWP_NOSIZE);
                    OnResize();
                    this.GetWordContentHeight(wordWnd);
                }
                catch
                {
                    MessageBox.Show("Error: do not load the document into the control until the parent window is shown!");
                }


                try
                {
                    int hMenu = GetSystemMenu(wordWnd, false);
                    if (hMenu > 0)
                    {
                        int menuItemCount = GetMenuItemCount(hMenu);
                        RemoveMenu(hMenu, menuItemCount - 1, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 2, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 3, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 4, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 5, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 6, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 7, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 8, MF_REMOVE | MF_BYPOSITION);
                        DrawMenuBar(wordWnd);
                    }
                }
                catch { };



                this.Parent.Focus();
            }
            deactivateevents = false;
        }
Exemplo n.º 21
0
 private void butEditTemplate_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];
     string templateFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.TemplateName);
     string dataFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.DataFileName);
     if(!File.Exists(templateFile)){
         MessageBox.Show(Lan.g(this,"Template file does not exist:")+"  "+templateFile);
         return;
     }
     if(!CreateDataFile(dataFile,letterCur)){
         return;
     }
     //Create an instance of Word.
     Word.Application WrdApp=LetterMerges.WordApp;
     //Open a document.
     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();
     //Attach the data file.
     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);
     //At this point, Word remains open with just one new document.
     if(WrdApp.WindowState==Word.WdWindowState.wdWindowStateMinimize){
         WrdApp.WindowState=Word.WdWindowState.wdWindowStateMaximize;
     }
     wrdDoc=null;
     #else
     MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
     #endif
 }
Exemplo n.º 22
0
        public static bool WordImportUmowa(string fileName, ref string rodzaj, ref string numer, ref string konto, ref string osoba)
        {
            Word._Application wordApp = new Word.Application();
            wordApp.Visible        = true;
            wordApp.ScreenUpdating = true;

            object wdStory  = Word.WdUnits.wdStory;
            object wdLine   = Word.WdUnits.wdLine;
            object wdMove   = Word.WdMovementType.wdMove;
            object count1   = (object)1;
            object wdExtend = Word.WdMovementType.wdExtend;

            try
            {
                Word._Document objDoc     = null;
                object         objDocName = fileName;
                objDoc = WordOpen(wordApp, objDocName);

                string text = "";
                int    granica;
                bool   isend = false;

                granica = 0;
                while (true)//while szukaj kopert
                {
                    wordApp.Selection.HomeKey(ref wdLine, ref wdMove);
                    wordApp.Selection.EndKey(ref wdLine, ref wdExtend);

                    if (++granica > 30)
                    {
                        isend = true;
                    }

                    //if(wordApp.Selection.End == ((Word.Range)objDoc.Range).End)
                    //  isend = true;

                    text = wordApp.Selection.Text.Trim();

                    if (text.Contains("UMOWA"))
                    {
                        if (text.Contains("DZIE£O"))
                        {
                            rodzaj = "Umowa o dzie³o";
                        }
                        else if (text.Contains("ZLECENIE"))
                        {
                            rodzaj = "Umowa na zlecenie";
                            if (text.Contains("student"))
                            {
                                rodzaj = "Umowa na zlecenie - student";
                            }
                        }
                        //numer = text.Substring(text.Length - 14);
                        numer = text;
                    }
                    else if (text.Contains("konta"))
                    {
                        konto = text;
                    }

                    if (text.Contains(osoba))
                    {
                        osoba = text;
                    }

                    wordApp.Selection.HomeKey(ref wdLine, ref wdMove);
                    wordApp.Selection.MoveDown(ref wdLine, ref count1, ref wdMove);

                    if (isend)
                    {
                        break;
                    }
                }//end while szukaj kopert

                objDoc.Close(ref ObjMissing, ref ObjMissing, ref ObjMissing);
            }
            catch (COMException)
            {
                return(false);
            }
            finally
            {
                wordApp.Quit(ref ObjMissing, ref ObjMissing, ref ObjMissing);
            }
            return(true);
        }
Exemplo n.º 23
0
		public WordFieldsUnlinker(object document)
		{
			m_document = document as Word._Document;
		}
Exemplo n.º 24
0
        private void CheckSpelling()
        {
            TextDocumentHandler handler = new TextDocumentHandler(this.dte);

            if (handler.HasNonEmptySelection)
            {
                try
                {
                    // Launch Word.
                    Word._Application wordApp = new Word.Application();

                    // Add a document.
                    Word._Document wordDoc = wordApp.Documents.Add();

                    // Clear current contents.
                    Word.Range range = wordApp.Selection.Range;
                    range.WholeStory();
                    range.Delete();
                    range = null;

                    // Add the text the user selected.
                    wordApp.Selection.Text = handler.SelectedText;

                    // Show it
                    wordApp.Visible = true;
                    wordApp.Activate();
                    wordDoc.Activate();

                    // Check spelling
                    wordDoc.CheckSpelling();

                    // Get the edited text back
                    wordApp.Selection.WholeStory();
                    string newText = wordApp.Selection.Text;

                    // Word always adds an extra CR, so strip that off.
                    // Also it converts all LFs to CRs, so change
                    // that back.
                    if (!string.IsNullOrEmpty(newText))
                    {
                        if (newText.EndsWith("\r"))
                        {
                            newText = newText.Substring(0, newText.Length - 1);
                        }

                        newText = newText.Replace("\r", "\r\n");
                    }

                    handler.SetSelectedTextIfUnchanged(newText, "Check Spelling");

                    // Tell the doc and Word to go away.
                    object saveChanges = false;
                    wordDoc.Close(ref saveChanges);
                    wordApp.Visible = false;
                    wordApp.Quit();
                }
                catch (COMException ex)
                {
                    // If we get REGDB_E_CLASSNOTREG, then Word probably isn't installed.
                    const uint REGDB_E_CLASSNOTREG = 0x80040154;
                    if (unchecked ((uint)ex.ErrorCode) == REGDB_E_CLASSNOTREG)
                    {
                        this.package.ShowMessageBox(
                            "Microsoft Word is required in order to check spelling, but it isn't available.\r\n\r\nDetails:\r\n" + ex.Message,
                            true);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 打开指定的本地WORD病历文件
        /// </summary>
        /// <param name="szFilePath">本地路径</param>
        /// <returns>DataLayer.SystemData.ReturnValue</returns>
        public short OpenDocument(string szFilePath)
        {
            try
            {
                if (this.m_WordApp == null)
                    this.m_WordApp = new Word.ApplicationClass();
                this.m_WordApp.CommandBars.AdaptiveMenus = this.m_bShowInternalMenuStrip;
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
                return SystemConst.ReturnValue.EXCEPTION;
            }

            this.CloseDocument();

            if (this.m_hWordWnd == IntPtr.Zero)
                this.m_hWordWnd = NativeMethods.User32.FindWindow("OpusApp", null);

            if (this.m_hWordWnd == IntPtr.Zero)
                return SystemConst.ReturnValue.FAILED;

            NativeMethods.User32.SetParent(this.m_hWordWnd, this.Handle);

            try
            {
                if (this.m_WordApp == null || this.m_WordApp.Documents == null)
                    return SystemConst.ReturnValue.FAILED;

                object fileName = szFilePath;
                object newTemplate = false;
                object docType = Word.WdDocumentType.wdTypeDocument;
                object isVisible = true;
                this.m_WordDoc = this.m_WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
                return SystemConst.ReturnValue.EXCEPTION;
            }
            this.ResumeLayout();
               this.Activate();

            try
            {
                this.HandleWordUILayout();
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
            }
            return SystemConst.ReturnValue.OK;
        }
Exemplo n.º 26
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
            if (listLetters.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a letter first.");
                return;
            }
            LetterMerge letterCur    = ListForCat[listLetters.SelectedIndex];
            string      templateFile = PrefB.GetString("LetterMergePath") + letterCur.TemplateName;
            string      dataFile     = PrefB.GetString("LetterMergePath") + letterCur.DataFileName;

            if (!File.Exists(templateFile))
            {
                MsgBox.Show(this, "Template file does not exist.");
                return;
            }
            PrintDocument pd = new PrintDocument();

            if (!Printers.SetPrinter(pd, PrintSituation.Default))
            {
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            Word.MailMerge wrdMailMerge;
            //Create an instance of Word.
            Word.Application WrdApp = LetterMerges.WordApp;
            //Open a document.
            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();
            wrdMailMerge = wrdDoc.MailMerge;
            //Attach the data file.
            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.wdSendToPrinter;
            WrdApp.ActivePrinter     = pd.PrinterSettings.PrinterName;
            wrdMailMerge.Execute(ref oFalse);
            //Close the original form document since just one record.
            wrdDoc.Saved = true;
            wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            //At this point, Word remains open with no documents.
            WrdApp.WindowState = Word.WdWindowState.wdWindowStateMinimize;
            wrdMailMerge       = null;
            wrdDoc             = null;
            Commlog CommlogCur = new Commlog();

            CommlogCur.CommDateTime   = DateTime.Now;
            CommlogCur.CommType       = CommItemType.Misc;
            CommlogCur.Mode_          = CommItemMode.Mail;
            CommlogCur.SentOrReceived = CommSentOrReceived.Sent;
            CommlogCur.PatNum         = PatCur.PatNum;
            CommlogCur.Note           = "Letter sent: " + letterCur.Description + ". ";
            Commlogs.Insert(CommlogCur);
            DialogResult = DialogResult.OK;
        }
Exemplo n.º 27
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;
        }
Exemplo n.º 28
0
        /// <summary>
        /// 打开指定的本地WORD病历文件
        /// </summary>
        /// <param name="szFilePath">本地路径</param>
        /// <returns>DataLayer.SystemData.ReturnValue</returns>
        public short OpenDocument(string szFilePath)
        {
            try
            {
                if (this.m_WordApp == null)
                {
                    this.m_WordApp = new Word.ApplicationClass();
                }
                this.m_WordApp.CommandBars.AdaptiveMenus = this.m_bShowInternalMenuStrip;
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
                return(SystemConst.ReturnValue.EXCEPTION);
            }

            this.CloseDocument();

            if (this.m_hWordWnd == IntPtr.Zero)
            {
                this.m_hWordWnd = NativeMethods.User32.FindWindow("OpusApp", null);
            }

            if (this.m_hWordWnd == IntPtr.Zero)
            {
                return(SystemConst.ReturnValue.FAILED);
            }

            NativeMethods.User32.SetParent(this.m_hWordWnd, this.Handle);

            try
            {
                if (this.m_WordApp == null || this.m_WordApp.Documents == null)
                {
                    return(SystemConst.ReturnValue.FAILED);
                }

                object fileName    = szFilePath;
                object newTemplate = false;
                object docType     = Word.WdDocumentType.wdTypeDocument;
                object isVisible   = true;
                this.m_WordDoc = this.m_WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
                return(SystemConst.ReturnValue.EXCEPTION);
            }
            this.ResumeLayout();
            this.Activate();

            try
            {
                this.HandleWordUILayout();
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("WinWordControl.OpenDocument", ex);
            }
            return(SystemConst.ReturnValue.OK);
        }
Exemplo n.º 29
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];
            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;
            }
            //Open a document.
            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();
            wrdMailMerge = wrdDoc.MailMerge;
            //Attach the data file.
            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);
            //Close the original form document since just one record.
            wrdDoc.Saved = true;
            wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            //At this point, Word remains open with just one new document.
            WrdApp.Activate();
            if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize)
            {
                WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;
            }
            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;
        }
Exemplo n.º 30
0
        public void LoadDocument(string t_filename)
        {
            deactivateevents = true;
            filename = t_filename;

            if (applicationClass == null) applicationClass = new Word.ApplicationClass();
            try
            {
                applicationClass.CommandBars.AdaptiveMenus = false;
                applicationClass.DocumentBeforeClose += new Word.ApplicationEvents2_DocumentBeforeCloseEventHandler(OnClose);
                applicationClass.NewDocument += new Word.ApplicationEvents2_NewDocumentEventHandler(OnNewDoc);
                applicationClass.DocumentOpen += new Word.ApplicationEvents2_DocumentOpenEventHandler(OnOpenDoc);
                applicationClass.ApplicationEvents2_Event_Quit += new Word.ApplicationEvents2_QuitEventHandler(OnQuit);

            }
            catch { }

            if (document != null)
            {
                try
                {
                    object dummy = null;
                    applicationClass.Documents.Close(ref dummy, ref dummy, ref dummy);
                }
                catch { }
            }

            if (wordWnd == 0) wordWnd = FindWindow("Opusapp", null);
            if (wordWnd != 0)
            {
                SetParent(wordWnd, this.Handle.ToInt32());

                object fileName = filename;
                object newTemplate = false;
                object docType = 0;
                object readOnly = true;
                object isVisible = true;
                object missing = System.Reflection.Missing.Value;

                try
                {
                    if (applicationClass == null)
                    {
                        throw new WordInstanceException();
                    }

                    if (applicationClass.Documents == null)
                    {
                        throw new DocumentInstanceException();
                    }

                    if (applicationClass != null && applicationClass.Documents != null)
                    {
                        document = applicationClass.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
                    }

                    if (document == null)
                    {
                        throw new ValidDocumentException();
                    }
                }
                catch
                {
                }

                try
                {
                    applicationClass.ActiveWindow.DisplayRightRuler = false;
                    applicationClass.ActiveWindow.DisplayScreenTips = false;
                    applicationClass.ActiveWindow.DisplayVerticalRuler = false;
                    applicationClass.ActiveWindow.DisplayRightRuler = false;
                    applicationClass.ActiveWindow.ActivePane.DisplayRulers = false;
                    applicationClass.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdWebView;
                    //wd.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView;//wdWebView; // .wdNormalView;
                }
                catch
                {

                }
                int counter = applicationClass.ActiveWindow.Application.CommandBars.Count;
                for (int i = 1; i <= counter; i++)
                {
                    try
                    {

                        String nm = applicationClass.ActiveWindow.Application.CommandBars[i].Name;
                        if (nm == "Standard")
                        {
                            int count_control = applicationClass.ActiveWindow.Application.CommandBars[i].Controls.Count;
                            for (int j = 1; j <= 2; j++)
                            {
                                applicationClass.ActiveWindow.Application.CommandBars[i].Controls[j].Enabled = false;
                            }
                        }

                        if (nm == "Menu Bar")
                        {
                            applicationClass.ActiveWindow.Application.CommandBars[i].Enabled = false;
                        }

                        nm = "";
                    }
                    catch
                    {
                        //MessageBox.Show(ex.ToString());
                    }
                }

                try
                {
                    applicationClass.Visible = true;
                    applicationClass.Activate();

                    SetWindowPos(wordWnd, this.Handle.ToInt32(), 0, 0, this.Bounds.Width, this.Bounds.Height, SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME | SWP_NOSIZE);
                    OnResize();
                    this.GetWordContentHeight(wordWnd);

                }
                catch
                {
                    MessageBox.Show("Error: do not load the document into the control until the parent window is shown!");
                }

                try
                {
                    int hMenu = GetSystemMenu(wordWnd, false);
                    if (hMenu > 0)
                    {
                        int menuItemCount = GetMenuItemCount(hMenu);
                        RemoveMenu(hMenu, menuItemCount - 1, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 2, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 3, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 4, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 5, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 6, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 7, MF_REMOVE | MF_BYPOSITION);
                        RemoveMenu(hMenu, menuItemCount - 8, MF_REMOVE | MF_BYPOSITION);
                        DrawMenuBar(wordWnd);
                    }
                }
                catch { };

                this.Parent.Focus();

            }
            deactivateevents = false;
        }