/// <summary>
        /// Workbook changed or opened ,this function will be process
        /// Get the workbook's meat data to init the ribbons
        /// </summary>
        /// <param name="Wb"></param>
        private void Application_WorkbookActivate(Excel.Workbook Wb)
        {
            try
            {
                Office.DocumentProperties prp = this.Application.ActiveWorkbook.CustomDocumentProperties;

                bool isSenitive = false;

                foreach (Office.DocumentProperty documentProperty in prp)
                {
                    if (documentProperty.Name.Equals("Sensitive"))
                    {
                        InitRabbionControl(documentProperty.Value);
                        isSenitive = true;
                    }
                }

                if (isSenitive == false)
                {
                    InitRabbionControl(string.Empty);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// set the confidential level
        /// </summary>
        /// <param name="sensitive"> confidential level string</param>
        private void SetWorkbookSensitive(string sensitive)
        {
            try
            {
                Microsoft.Office.Core.DocumentProperties prp = Globals.ThisAddIn.Application.ActivePresentation.CustomDocumentProperties;

                bool isSenitive = false;

                foreach (Microsoft.Office.Core.DocumentProperty documentProperty in prp)
                {
                    if (documentProperty.Name.Equals("Sensitive"))
                    {
                        //MessageBox.Show(documentProperty.Value);
                        //InitRabbionControl(documentProperty.Value);
                        documentProperty.Value = sensitive;
                        isSenitive             = true;
                    }
                }

                if (isSenitive == false)
                {
                    prp.Add("Sensitive", false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, sensitive, null);
                }

                Globals.ThisAddIn.InitRabbionControl(sensitive);
            }
            catch (Exception)
            {
                throw;
            }
        }
 protected override void CleanContentProperties()
 {
     Office.DocumentProperties docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(CONTENT_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(REPOSITORY_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     workbook.Saved = false;
     try
     {
         workbook.Save();
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }
Example #4
0
        private void Application_WindowActivate(PowerPoint.Presentation Pres, PowerPoint.DocumentWindow Wn)
        {
            //throw new NotImplementedException();
            //            MessageBox.Show("hehe");

            try
            {
                Office.DocumentProperties prp = this.Application.ActivePresentation.CustomDocumentProperties;

                bool isSenitive = false;

                foreach (Office.DocumentProperty documentProperty in prp)
                {
                    if (documentProperty.Name.Equals("Sensitive"))
                    {
                        InitRabbionControl(documentProperty.Value);
                        isSenitive = true;
                    }
                }

                if (isSenitive == false)
                {
                    InitRabbionControl(string.Empty);
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                throw;
            }
        }
 private void FrmDocProp_Load(object sender, EventArgs e)
 {
     Office.DocumentProperties props = Globals.ThisWorkbook.BuiltinDocumentProperties as Office.DocumentProperties;
     txtCompany.Text  = props["Company"].Value as string;
     txtAuthor.Text   = props["Author"].Value as string;
     txtComments.Text = props["Comments"].Value as string;
 }
 private void btnRecord_Click(object sender, EventArgs e)
 {
     Office.DocumentProperties props = Globals.ThisWorkbook.BuiltinDocumentProperties as Office.DocumentProperties;
     props["Company"].Value  = txtCompany.Text;
     props["Author"].Value   = txtAuthor.Text;
     props["Comments"].Value = txtComments.Text;
 }
Example #7
0
        protected override void SaveCustomProperties(Dictionary <string, string> properties)
        {
            try
            {
                Office.DocumentProperties docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties;

                foreach (String key in properties.Keys)
                {
                    foreach (Office.DocumentProperty prop in docProperties)
                    {
                        if (prop.Name.Equals(key, StringComparison.InvariantCulture))
                        {
                            prop.Delete();
                            break;
                        }
                    }
                }
                foreach (String key in properties.Keys)
                {
                    docProperties.Add(key, false, Office.MsoDocProperties.msoPropertyTypeString, properties[key], nullObjStr);
                }
                workbook.Save();
            }
            catch (Exception e)
            {
                throw new WBOfficeErrorException("No puede obtener las propiedades del documento", e);
            }
        }
Example #8
0
 private void ThisDocument_Startup(object sender, System.EventArgs e)
 {
     this.ContentControlOnEnter += ThisDocument_ContentControlOnEnter;
     this.BeforeSave            += ThisDocument_BeforeSave;
     try
     {
         Office.DocumentProperties docProps =
             this.CustomDocumentProperties as Office.DocumentProperties;
         foreach (Office.DocumentProperty docprop in docProps)
         {
             if (docprop.Name == "HurTestDataSet")
             {
                 docDataSetID = (string)docprop.Value;
                 if (docDataSetID != null)
                 {
                     Office.CustomXMLPart docDataSetPart =
                         this.CustomXMLParts.SelectByID(docDataSetID);
                     System.IO.StringReader srdr = new System.IO.StringReader(docDataSetPart.XML);
                     docDataSet.ReadXml(srdr);
                 }
             }
         }
     }
     catch
     {
     }
 }
Example #9
0
        public void IUO(Office.IRibbonControl control)
        {
            Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument;
            Microsoft.Office.Tools.Word.Document   vstoDocument   = Globals.Factory.GetVstoObject(nativeDocument);
            Office.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties;

            if (ReadDocumentProperty("Classification") != null)
            {
                properties["Classification"].Delete();
            }

            properties.Add("Classification", false,
                           Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
                           "Internal");

            foreach (Word.Section wordSection in Globals.ThisAddIn.Application.ActiveDocument.Sections)
            {
                Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footerRange.Font.ColorIndex           = Word.WdColorIndex.wdDarkBlue;
                footerRange.Font.Size                 = 15;
                footerRange.Text                      = "Classification: Internal Use Only";
                footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

                Word.Range headerRange = wordSection.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Font.ColorIndex           = Word.WdColorIndex.wdDarkBlue;
                headerRange.Font.Size                 = 15;
                headerRange.Text                      = "Classification: Internal Use Only";
                headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            }
        }
 public void Updatelabels(Core.DocumentProperties properties, OfficeConnectorExtensionAddinRibbon MyRibbon)
 {
     UpdateLifeCycleRibbonName(properties[Settings.Default.ArasDocumentId].Value, MyRibbon.LifeCycleRibbonLabel);
     UpdateStateRibbonName(properties[Settings.Default.ArasDocumentId].Value, MyRibbon.StateNameRibbonLabel);
     UpdateNextStateComboBox(properties[Settings.Default.ArasDocumentId].Value, MyRibbon);
     UpdateWorkFlowRibbonName(properties[Settings.Default.arasPrimaryLinkItemId].Value, MyRibbon.WorkflowNameRibbonLabel);
     UpdateActivityRibbonName(properties[Settings.Default.arasPrimaryLinkItemId].Value, MyRibbon.ActivityRibbonLabel, MyRibbon.CompleteTaskButton);
 }
Example #11
0
        /// <summary>
        /// Finds a custom property on a word document. If it exists, deletes
        /// and replaces it. Else, it will add the property.
        /// </summary>
        /// <param name="stringToReplaceCustProperty"></param>
        public void ReplaceTestProperty(string custPropertyName, string custPropertyValue)
        {
            Office.DocumentProperties properties = (Office.DocumentProperties) this.CustomDocumentProperties;

            if (ReadDocumentProperty(custPropertyName) != null)
            {
                properties[custPropertyName].Delete();
            }

            properties.Add(custPropertyName, false,
                           Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
                           custPropertyValue);
        }
Example #12
0
 public static void CustomFooterExists(bool hasCustomFooter)
 {
     try
     {
         Office.DocumentProperties prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
         // Add a new property.
         Office.DocumentProperty prp = prps.Add("HasCustomFooter", false, Office.MsoDocProperties.msoPropertyTypeBoolean, hasCustomFooter);
     } catch (Exception ex)
     {
         //PLLog.Error(ex, Globals.PROJECT_NAME)
         MessageBox.Show("CustomFooterExists() Unable to add HasCustomFooter property" + ex.Message);
     }
 }
Example #13
0
        public string ReadDocumentProperty(string propertyName)
        {
            Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument;
            Microsoft.Office.Tools.Word.Document   vstoDocument   = Globals.Factory.GetVstoObject(nativeDocument);
            Office.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties;

            foreach (Office.DocumentProperty prop in properties)
            {
                if (prop.Name == propertyName)
                {
                    return(prop.Value.ToString());
                }
            }
            return(null);
        }
Example #14
0
 public static bool HasCustomTableOfContents()
 {
     try
     {
         Office.DocumentProperties prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
         Office.DocumentProperty   prp  = prps["HasCustomTableOfContents"];
         // If the property exists we don't really care about the value
         return(true);
     }
     catch (Exception)
     {
         // Exception is thrown if property does not exist
         return(false);
     }
 }
Example #15
0
        private static Office.DocumentProperty Add(Excel.Workbook workbook, string propertyName, Office.MsoDocProperties propertyType, object value)
        {
            if (null == workbook)
            {
                throw new ArgumentNullException("workbook");
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Office.DocumentProperties properties = workbook.CustomDocumentProperties;
            Office.DocumentProperty   property   = properties.Add(propertyName, false, propertyType, value);

            return(property);
        }
Example #16
0
 protected override void SaveCustomProperties(Dictionary <string, string> properties)
 {
     try
     {
         Office.DocumentProperties docProperties = (Office.DocumentProperties)document.CustomDocumentProperties;
         foreach (String key in properties.Keys)
         {
             docProperties[key].Delete();
             docProperties.Add(key, false, Office.MsoDocProperties.msoPropertyTypeString, properties[key], nullObjStr);
         }
         this.Save();
     }
     catch (Exception e)
     {
         throw new WBOfficeErrorException("No puede obtener las propiedades del documento", e);
     }
 }
Example #17
0
        public static bool HasCustomFooter()
        {
            Office.DocumentProperty   prp  = default(Office.DocumentProperty);
            Office.DocumentProperties prps = default(Office.DocumentProperties);

            try
            {
                prps = (Office.DocumentProperties)ExcelApplication.ActiveWorkbook.CustomDocumentProperties;
                prp  = prps["HasCustomFooter"];
                // If the property exists we don't really care about the value
                return(true);
            }
            catch (Exception)
            {
                // Exception is thrown if property does not exist
                return(false);
            }
        }
        private void RibbonSyntech_Load(object sender, RibbonUIEventArgs e)
        {
            chkLockMyobData.Checked = Globals.Sheet1.Locked;
            chkLockItemAttr.Checked = Globals.Sheet2.Locked;
            chkShowMyobData.Checked = Globals.Sheet1.Shown;
            chkShowItemAttr.Checked = Globals.Sheet2.Shown;
            Office.DocumentProperties props = Globals.ThisWorkbook.BuiltinDocumentProperties as Office.DocumentProperties;
            string company_caption          = props["Company"].Value as string;

            //if (!string.IsNullOrEmpty(company_caption))
            //{
            //    this.tabSyntech.Label = company_caption;
            //}
            Globals.Sheet2.SheetVisibilityChanged += new Sheet2.SheetVisiblityChangedHandler(Sheet2_SheetVisibilityChanged);
            Globals.Sheet2.SheetLockChanged       += new Sheet2.SheetLockChangedHandler(Sheet2_SheetLockChanged);
            Globals.Sheet1.SheetVisibilityChanged += new Sheet1.SheetVisiblityChangedHandler(Sheet1_SheetVisibilityChanged);
            Globals.Sheet1.SheetLockChanged       += new Sheet1.SheetLockChangedHandler(Sheet1_SheetLockChanged);
        }
Example #19
0
        private void DisplayDocumentProperties()
        {
            Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;

            Office.DocumentProperties documentProperties = (Office.DocumentProperties)wb.BuiltinDocumentProperties;
            StringBuilder             sb = new StringBuilder();
            string value = "";
            string name  = "";

            if (documentProperties != null)
            {
                foreach (Office.DocumentProperty property in documentProperties)
                {
                    try
                    {
                        name  = property.Name;
                        value = property.Value.ToString();
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) COMException ErrorCode:({1})", name, ex.ErrorCode));
                        value = "Property Not Available Yet";
                    }
                    catch (NullReferenceException)
                    {
                        Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) NullReferenceException", name));
                        value = "Property Not Set";
                    }
                    catch (Exception ex)
                    {
                        Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) Exception >{1})<", name, ex));
                        value = "";
                    }

                    sb.AppendLine(string.Format("P:{0}->{1}<", name, value));
                }
            }
            else
            {
                sb.AppendLine("No Document Properties");
            }

            MessageBox.Show(sb.ToString(), "Document Properties", MessageBoxButtons.OK);
        }
Example #20
0
        public void RemoveClassificationButton(Office.IRibbonControl control)
        {
            Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument;
            Microsoft.Office.Tools.Word.Document   vstoDocument   = Globals.Factory.GetVstoObject(nativeDocument);
            Office.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties;

            if (ReadDocumentProperty("Classification") != null)
            {
                properties["Classification"].Delete();
            }

            foreach (Word.Section wordSection in Globals.ThisAddIn.Application.ActiveDocument.Sections)
            {
                Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footerRange.Delete();
                Word.Range headerRange = wordSection.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Delete();
            }
        }
Example #21
0
        public static string GetBuiltInPropertyValue(Workbook workBook, string propName)
        {
            string returnValue = "";

            //// This procedure returns the value of the built-in document
            //// property specified in the propName argument for the Office
            //// document object specified in the workBook argument.

            //DocumentProperty prpDocProp = default(DocumentProperty);
            //object varValue = null;

            //const long ERR_BADPROPERTY = 5;
            //const long ERR_BADDOCOBJ = 438;
            //const long ERR_BADCONTEXT = -2147467259;

            Office.DocumentProperties documentProperties = (Office.DocumentProperties)workBook.BuiltinDocumentProperties;

            if (documentProperties != null)
            {
                try
                {
                    Office.DocumentProperty property = documentProperties[propName];
                    returnValue = property.Value.ToString();
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) COMException ErrorCode:({1})", propName, ex.ErrorCode));
                    returnValue = "Property Not Available Yet";
                }
                catch (NullReferenceException)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) NullReferenceException", propName));
                    returnValue = "Property Not Set";
                }
                catch (Exception)
                {
                    //Common.WriteToDebugWindow(string.Format("GetBuiltInPropertyValue({0}) Exception >{1})<", propName, ex));
                }
            }

            return(returnValue);
        }
Example #22
0
 protected override void CleanContentProperties()
 {
     Office.DocumentProperties docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(CONTENT_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     docProperties = (Office.DocumentProperties)workbook.CustomDocumentProperties;
     foreach (Office.DocumentProperty prop in docProperties)
     {
         if (prop.Name.Equals(REPOSITORY_ID_NAME, StringComparison.InvariantCulture))
         {
             prop.Delete();
             break;
         }
     }
     workbook.Save();
 }
        public void Complete_Activity(Core.DocumentProperties properties, OfficeConnectorExtensionAddinRibbon MyRibbon)
        {
            List <Core.DocumentProperty> propertylist = properties.Cast <Core.DocumentProperty>().ToList();
            bool PrimaryLinkItemIdexist = propertylist.Where(x => x.Name == Settings.Default.arasPrimaryLinkItemId).Any();

            if (PrimaryLinkItemIdexist)
            {
                if ((inn = Connect_to_Aras(MyRibbon)) != null)
                {
                    ActivityForm AF = new ActivityForm()
                    {
                        inn             = inn,
                        primarylinkedid = properties[Settings.Default.arasPrimaryLinkItemId].Value
                    };

                    AF.ShowDialog();
                    Updatelabels(properties, MyRibbon);

                    MyRibbon.CompleteTaskButton.Enabled = !String.IsNullOrEmpty(MyRibbon.WorkflowNameRibbonLabel.Label);
                }
            }
        }
        public void Refresh_ribbon(Core.DocumentProperties properties, OfficeConnectorExtensionAddinRibbon MyRibbon)
        {
            if ((inn = Connect_to_Aras(MyRibbon)) != null)
            {
                List <Core.DocumentProperty> propertylist = properties.Cast <Core.DocumentProperty>().ToList();
                bool PrimaryLinkItemIdexist = propertylist.Where(x => x.Name == Settings.Default.arasPrimaryLinkItemId).Any();
                if (PrimaryLinkItemIdexist)
                {
                    UpdateWorkFlowRibbonName(properties[Settings.Default.arasPrimaryLinkItemId].Value, MyRibbon.WorkflowNameRibbonLabel);
                    UpdateActivityRibbonName(properties[Settings.Default.arasPrimaryLinkItemId].Value, MyRibbon.ActivityRibbonLabel, MyRibbon.CompleteTaskButton);
                }
                bool DocumentIdexist = propertylist.Where(x => x.Name == Settings.Default.ArasDocumentId).Any();
                if (DocumentIdexist)
                {
                    UpdateLifeCycleRibbonName(properties[Settings.Default.ArasDocumentId].Value, MyRibbon.LifeCycleRibbonLabel);
                    UpdateStateRibbonName(properties[Settings.Default.ArasDocumentId].Value, MyRibbon.StateNameRibbonLabel);
                    UpdateNextStateComboBox(properties[Settings.Default.ArasDocumentId].Value, MyRibbon);
                }
                MyRibbon.PromoteButton.Enabled = !String.IsNullOrEmpty(MyRibbon.NextStateComboBox.Text);

                //MyRibbon.CompleteTaskButton.Enabled = !MyRibbon.WorkflowNameRibbonLabel.Label.Contains("Not Assigned");
            }
        }
 public void Complete_Promote(Core.DocumentProperties properties, OfficeConnectorExtensionAddinRibbon MyRibbon)
 {
     //execute the AML to promote
     if ((inn = Connect_to_Aras(MyRibbon)) != null)
     {
         Item      result       = inn.applyAML(AddtoItem(Settings.Default.promoteAML.Replace("document.id=", "document.id='" + properties[Settings.Default.ArasDocumentId].Value + "'\">"), "state", MyRibbon.NextStateComboBox.Text));
         XmlReader readerresult = XmlReader.Create(new StringReader(result.ToString()));
         if (readerresult.ReadToDescendant("faultcode"))
         {
             readerresult.Read();
             string error = readerresult.Value;
             if (error.Contains("IsLocked"))
             {
                 System.Windows.Forms.MessageBox.Show("Document needs to be locked before promoting");
             }
             else
             {
                 System.Windows.Forms.MessageBox.Show(error);
             }
         }
         //Updatelabels(properties, MyRibbon);
     }
 }
Example #26
0
        private void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
        {
            Office.CustomXMLPart docDataSetPart = null;
            // Belgedeki içerik kontrol kutularıyla ilgili bilgileri içeren
            // veri setini belgeye ait XML alanları arasında sakla.
            if (docDataSetID != null)
            {
                docDataSetPart = this.CustomXMLParts.SelectByID(docDataSetID);
                if (docDataSetPart != null)
                {
                    docDataSetPart.Delete();
                }
            }
            string xmlDataSet = docDataSet.GetXml();

            docDataSetPart = this.CustomXMLParts.Add(xmlDataSet);
            Office.DocumentProperties docProps =
                this.CustomDocumentProperties as Office.DocumentProperties;
            if (docDataSetID != null)
            {
                docDataSetID = docDataSetPart.Id;
                foreach (Office.DocumentProperty docprop in docProps)
                {
                    if (docprop.Name == "HurTestDataSet")
                    {
                        docprop.Value = docDataSetID;
                        break;
                    }
                }
            }
            else
            {
                docDataSetID = docDataSetPart.Id;
                docProps.Add("HurTestDataSet", false, Office.MsoDocProperties.msoPropertyTypeString,
                             docDataSetID, missing);
            }
        }
Example #27
0
        private static Office.DocumentProperty GetProperty(Excel.Workbook workbook, string propertyName)
        {
            if (null == workbook)
            {
                throw new ArgumentNullException("workbook");
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            Office.DocumentProperties properties = workbook.CustomDocumentProperties;

            foreach (Office.DocumentProperty property in properties)
            {
                if (property.Name == propertyName)
                {
                    return(property);
                }
            }

            return(null);
        }