示例#1
0
        /// <summary>
        /// Add select bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddSingleBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            //Add a space before text.
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // add select text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // set cursor after bookmark
            servicePro.ContentService.MoveChars_Count  = 1;
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
示例#2
0
        private string ImportPdeTag(Word.Document wDoc, string key, string value)
        {
            if (wDoc == null || string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            // add a space before text.
            wDoc.Application.Selection.TypeText(" ");

            // add select text
            string bmValue = MarkupUtilities.GenTextXslTag(value, XsltType.Select, true);

            wDoc.Application.Selection.TypeText(bmValue);
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, bmValue.Length, Word.WdMovementType.wdExtend);

            // add select bookmark
            string bmName = Core.MarkupConstant.MarkupPdeTag + key;

            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }
            Word.Range range = wDoc.Application.Selection.Range;
            wDoc.Bookmarks.Add(bmName, range);
            wDoc.Bookmarks.DefaultSorting = Word.WdBookmarkSortBy.wdSortByLocation;
            wDoc.Bookmarks.ShowHidden     = false;

            // set cursor after bookmark
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1);

            // markup ProntoDoc;
            WKL.DataController.MainController.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsProntoDoc = true;
            if (!System.IO.File.Exists(wDoc.FullName))
            {
                wDoc.Application.Options.SaveInterval = 0;
            }

            return(bmName);
        }
示例#3
0
        private string ImportPdeChart(Word.Document wDoc, string chartName, string chartContent)
        {
            string chartPath = AssetManager.FileAdapter.GenRandomFilePath(ChartExtension);
            string bmValue   = MarkupUtilities.GenTextXslTag(chartName, XsltType.Select, true);
            string bmName    = BaseMarkupUtilities.XmlEncode(chartName);

            // create temporary image
            bmName = string.Format("{0}{1}{2}", MarkupConstant.MarkupPdeTag, bmName, MarkupConstant.MarkupPdeChart);
            ProntoDoc.Framework.Utils.FileHelper.FileFromBase64(chartContent, chartPath);

            // delete old bm
            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }

            // add image into word
            wDoc.Application.Selection.TypeText(" ");
            Word.InlineShape inlineShape = wDoc.Application.Selection.InlineShapes.AddPicture(chartPath, false, true);
            inlineShape.AlternativeText = MarkupUtilities.CreateAlternativeText(bmName, bmValue);

            // add bookmark
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, 1);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1, Word.WdMovementType.wdExtend);
            wDoc.Bookmarks.Add(bmName, wDoc.Application.Selection.Range);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter);

            // delete temporary file
            System.IO.File.Delete(chartPath);

            return(bmName);
        }
示例#4
0
        /// <summary>
        /// Add internal bookmark item
        /// </summary>
        /// <param name="bm"></param>
        public void AddInternalBookmark(string key)
        {
            try
            {
                ServicesProfile           serviceProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
                IntegrationServiceProfile integrationPro = serviceProfile.IntegrationService;
                InternalBookmarkItem      ibmItem        = integrationPro.AddInternalBM_IBookmark;
                if (string.IsNullOrWhiteSpace(ibmItem.DomainName))
                {
                    ibmItem.DomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.SelectedDomainName;
                }
                switch (ibmItem.Type)
                {
                case XsltType.Foreach:
                case XsltType.If:
                    InternalBookmarkItem start = ibmItem.Clone();
                    InternalBookmarkItem end   = ibmItem.Clone();

                    start.BizName = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, true);
                    start.Key     = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, true);

                    serviceProfile.IbmItem = start;
                    AddInternalBookmarkItem(key);

                    end.BizName            = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, false);
                    end.Key                = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, false);
                    serviceProfile.IbmItem = end;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Select:
                    InternalBookmarkItem select = ibmItem.Clone();
                    select.BizName = MarkupUtilities.GenTextXslTag(select.BizName, select.Type, true);
                    select.Key     = ibmItem.IsImage() ? select.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(select.Key, select.Type, true);

                    serviceProfile.IbmItem = select;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Comment:
                    InternalBookmarkItem comment = ibmItem.Clone();
                    comment.BizName = MarkupUtilities.GenTextXslTag(comment.BizName, comment.Type, true);
                    comment.Key     = ibmItem.IsImage() ? comment.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(comment.Key, comment.Type, true);

                    serviceProfile.IbmItem = comment;
                    AddInternalBookmarkItem(key);
                    break;

                default:
                    break;
                }
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_AddIbmItemError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_AddIbmItemError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_AddIbmItemError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
示例#5
0
        /// <summary>
        /// Add a bookmark into current document
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        /// <param name="xsltType">XsltType (Select, Foreach or If)</param>
        /// <returns></returns>
        public bool AddBookmark(string key)
        {
            try
            {
                ServicesProfile      serviceProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
                InternalBookmarkItem bm             = serviceProfile.ContentService.AddBookmark_IBookmark;
                Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsAdding = true;

                serviceProfile.ContentService.MarkProntDoc = true;
                switch (bm.Type)
                {
                case XsltType.Foreach:
                    AddDoubleBookmark(bm);
                    MarkProntoDoc(key);
                    break;

                case XsltType.If:
                    AddDoubleBookmark(bm);
                    MarkProntoDoc(key);
                    break;

                case XsltType.Select:
                    if (bm.IsImage())
                    {
                        serviceProfile.WbmKey          = bm.Key + ProntoMarkup.KeyImage;
                        serviceProfile.WbmValue        = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);
                        serviceProfile.AlternativeText = MarkupUtilities.CreateAlternativeText(serviceProfile.WbmKey,
                                                                                               serviceProfile.WbmValue);
                        AddBookmarkImageEvent(key);
                    }
                    else
                    {
                        AddSingleBookmark(bm);
                    }
                    MarkProntoDoc(key);
                    break;

                case XsltType.Comment:
                    AddCommentBookmark(bm);
                    break;

                default:
                    break;
                }

                Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsAdding = false;
                return(true);
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_AddBookmarkError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_AddBookmarkError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_AddBookmarkError, ex.Message), ex.StackTrace);

                throw srvExp;
            }
        }
示例#6
0
        /// <summary>
        /// Add foreach bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddDoubleBookmark(InternalBookmarkItem bm)
        {
            //1. Get FontColor of BM
            //2. Generate tag
            //3. Add start tag (text) to document
            //4. Add start tag to BM
            //5. Move cursor to after
            //6. Add end tag (text) to document
            //7. Add end tag to BM
            //8. Move cursor to between two tags
            //9. Set color

            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            WdColor fontColor  = GetFontColor(bm.Type);
            WdColor textColor  = WdColor.wdColorBlack;
            int     textLength = 0;

            if (Globals.ThisAddIn.Application.Selection.Range.Start != Globals.ThisAddIn.Application.Selection.Range.End)
            {
                textLength = Globals.ThisAddIn.Application.Selection.Range.Text.Length;
                textColor  = Globals.ThisAddIn.Application.Selection.Range.Font.Color;
                servicePro.ContentService.MoveChars_Count  = 1;
                servicePro.ContentService.MoveChars_IsLeft = true;
                MoveChars(key);
            }

            //2.Generate tag
            string startTag = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            //Add a space before text
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            //3. add start foreach text
            servicePro.ContentService.AddToSelection_Text       = startTag.Trim();
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //4. add start foreach bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //5. add space
            servicePro.ContentService.MoveChars_Count  = (textLength > 0 ? textLength + 1 : 1);
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            //6. add end foreach text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, false);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //7. add end foreach bookmarl
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, false);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //8.set cursor before end tag
            servicePro.ContentService.MoveChars_Count  = 2;
            servicePro.ContentService.MoveChars_IsLeft = true;

            MoveChars(key);

            //9. reset color
            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
示例#7
0
        /// <summary>
        /// add a comment
        /// </summary>
        /// <pparam name="bm"></pparam>
        private void AddCommentBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            // add a space before comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to Red
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdRed;
            SetFontForCurrentSelection(key);

            // add select text
            string commentText = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            servicePro.ContentService.AddToSelection_Text       = commentText;
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            // add a space after comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // move left a character to back to comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // select comment
            servicePro.ContentService.MoveChars_Count    = commentText.Length;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = true;
            MoveChars(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // move to end of comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = false;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // move to comment text position
            servicePro.ContentService.MoveChars_Count    = ProntoMarkup.ValueCommentTextPosition;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }