예제 #1
0
        private void SaveAsNew()
        {
            try
            {
                var pdfDocument = _activeDocument.WsDocument;
                pdfDocument.bstrLocalFile = _options.Destination;
                pdfDocument.bstrDescription = Path.GetFileName(_options.Destination);
  
                var docProvider = new DocProviderClass();
                docProvider.Resolve(ref pdfDocument);
                int iFormatIndex = 1;
                var hr = docProvider.GetSaveInfoEx(_options.ParentWindow.Handle.ToInt32(), "PDF Documents (*.pdf)|*.pdf||",
                    (int)(wsGetSaveInfoFlags.DF_NEW_DOCUMENT | wsGetSaveInfoFlags.DF_NO_WORKSHARE_SAVEAS_UI), (int)MessageBranding.WsProtect, ref iFormatIndex, ref pdfDocument);

                if (hr == 0)
                {
					pdfDocument.bstrLocalFile = _options.Destination; // need to reset for the save (GetSaveInfoEx clears the field)
                    docProvider.SaveDocument(ref pdfDocument, 0);
                    docProvider.CloseDocument(ref pdfDocument, (int)wsCloseDocFlags.DF_UNLOCK_ONLY);
					_options.DocumentID = pdfDocument.bstrDocumentID;
                }

                _activeDocument.AddActivityToDmsHistory(DmsActivityType.Print);
            }
            catch (COMException e)
            {
                const int cancelledOperation = -2146303990;

                if (e.ErrorCode == cancelledOperation)
                    return;

                Logger.LogError(e);
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.SystemIdle, TimeSpan.FromSeconds(1),
                   new System.Action(delegate()
                   {
                       btnSave_Click(sender, e);
                   }
                ));
            }
            else
            {
                try
                {
                    Button b = sender as Button;
                    if (b == null)
                        return;

                    AttachedComparison comp = b.DataContext as AttachedComparison;
                    if (comp == null)
                        return;

                    tagWSDOCUMENT doc = new tagWSDOCUMENT();
                    doc.bstrDescription = Path.ChangeExtension(comp.Title, "rtf");
                    doc.bstrExtension = "rtf";
                    doc.bstrLocalFile = comp.RedlineRtfPath;
                    int formatIndex = 1;

                    DocProviderClass docProv = new DocProviderClass();
                    if (docProv != null)
                    {
						HwndSource source = HwndSource.FromVisual(this) as HwndSource;
						int hWnd = source == null ? 0 : (int) source.Handle;
                        Int32 retVal = docProv.GetSaveInfoEx(hWnd, "Rich text documents (*.rtf)|*.rtf||", (int)wsGetSaveInfoFlags.DF_NEW_DOCUMENT, 1, ref formatIndex, ref doc);

                        if (retVal == 0) // 0 == S_OK
                        {
                            doc.bstrLocalFile = comp.RedlineRtfPath;
                            const int DF_UNLOCK_ONLY = 1;
                            docProv.SaveDocument(ref doc, 0);
                            docProv.CloseDocument(ref doc, DF_UNLOCK_ONLY);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    Forms.MessageBox.Show(ex.Message);
                }
            }
        }