Esempio n. 1
0
        //--- Intercept save handler
        void Application_DocumentBeforeSave(Word.Document doc, ref bool SaveAsUI, ref bool Cancel)
        {
            //Check if this is one of our docs and if it is then do the right thing, not the black and white thing
            //Add a document property so we know that is a contract template and what the id is
            try
            {
                bool hidep = false;
                if (!Globals.ThisAddIn._p.IsVisible)
                {
                    Globals.ThisAddIn.ProcessingStart("Saving");
                    hidep = true;
                }

                string prop = GetCurrentAxiomDocProp();
                if (prop != null)
                {
                    string[] propa = prop.Split('|');
                    if (propa[0] == "ContractTemplate")
                    {
                        Globals.ThisAddIn.ProcessingUpdate("Save Contract Template");

                        // Get the Sidebar and save the elemnt value if that has changed
                        TemplateEdit.TEditSidebar tsb = Globals.ThisAddIn.GetTaskPaneControlTemplate(doc);
                        if(tsb!=null) tsb.FormSave();

                        //save this to a scratch file
                        Globals.ThisAddIn.ProcessingUpdate("Save Scratch");
                        string filename = Utility.SaveTempFile(propa[1]);
                        doc.SaveAs2(FileName: filename, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        //Save a copy!
                        Globals.ThisAddIn.ProcessingUpdate("Save Copy");
                        string filenamecopy = Utility.SaveTempFile(propa[1] + "X");
                        Word.Document dcopy = Globals.ThisAddIn.Application.Documents.Add(filename, Visible: false);
                        dcopy.SaveAs2(FileName: filenamecopy, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        var docclose = (Microsoft.Office.Interop.Word._Document)dcopy;
                        docclose.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(docclose);

                        //Now
                        Globals.ThisAddIn.ProcessingUpdate("Save To SalesForce");
                        _d.SaveTemplateFile(propa[1], filenamecopy);

                        //d.SaveTemplateXML(propa[1], doc.WordOpenXML);

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "ClauseTemplate")
                    {
                        //Save!
                        //doc = Globals.ThisAddIn.Application.ActiveDocument;
                        //d.SaveClauseXML(propa[1],doc.Content.Text ,doc.WordOpenXML);
                        Globals.ThisAddIn.ProcessingUpdate("Save Clause Template");
                        // doc = Globals.ThisAddIn.Application.ActiveDocument;

                        //save this to a scratch file
                        Globals.ThisAddIn.ProcessingUpdate("Save Scratch");
                        string filename = Utility.SaveTempFile(propa[1]);
                        doc.SaveAs2(FileName: filename, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        //Save a copy!
                        Globals.ThisAddIn.ProcessingUpdate("Save Copy");
                        string filenamecopy = Utility.SaveTempFile(propa[1] + "X");
                        Word.Document dcopy = Globals.ThisAddIn.Application.Documents.Add(filename, Visible: false);
                        dcopy.SaveAs2(FileName: filenamecopy, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        var docclose = (Microsoft.Office.Interop.Word._Document)dcopy;
                        docclose.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(docclose);

                        //Now save the file and then refresh any other docsto reflect the change
                        Globals.ThisAddIn.ProcessingUpdate("Save To SalesForce");
                        _d.SaveClauseFile(propa[1], doc.Content.Text, filenamecopy);

                        Globals.ThisAddIn.ProcessingUpdate("Update Any Templates with the clause");
                        RefreshAllTaskPanesWithClause(propa[1], doc.WordOpenXML);
                        doc.Activate();

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "Contract" || propa[0] == "UAContract")
                    {
                        //Save the doc and the data
                        GetTaskPaneControlContract().SaveContract(false,true);

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "Compare")
                    {
                        //Save the doc and the data
                        GetTaskPaneControlCompare().SaveContract(false, true);

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (hidep)
                    {
                        Globals.ThisAddIn.ProcessingStop("Stop");
                    }

                }
            }
            catch (Exception e)
            {
                Globals.ThisAddIn.ProcessingStop("Stop");
                System.Windows.MessageBox.Show("Sorry there has been a problem:"+e.Message);

            }
        }