Esempio n. 1
0
        private void Frm_FindandChangeTL_Load(object sender, EventArgs e)
        {
            adddata();
            string conn = "LayoutID='" + layoutID + "' order by StartP";
            IList <LayoutBookMark> templist = Common.Services.BaseService.GetList <LayoutBookMark>("SelectLayoutBookMarkList", conn);

            marklist = templist;
            if (marklist.Count == 0)
            {
                MessageBox.Show("无书签!请先添加书签");
                this.Close();
                return;
            }
            if (W_Bkm.Exists(marklist[0].UID.ToString()))
            {
                object tempid = marklist[0].UID.ToString();
                tempmk = W_Bkm.get_Item(ref tempid);
                tempmk.Select();
                oldstr      = tempmk.Range.Text;
                txtold.Text = oldstr;
                if (mkd.FindStr(marklist[0].UID.ToString()) != -1)
                {
                    txtnew.Text = mkd.Data[mkd.FindStr(marklist[0].UID.ToString())].BQdata.ToString();
                    data_object = mkd.Data[mkd.FindStr(marklist[0].UID.ToString())].BQdata;
                    newstr      = txtnew.Text;
                }
                else
                {
                    newstr      = "暂无值";
                    txtnew.Text = newstr;
                    txtnew.SelectAll();
                }
            }
        }
Esempio n. 2
0
        //删除书签
        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            BM_Word = FrmGHBZTLContents.W_Doc;
            W_Bkm   = BM_Word.Bookmarks;
            if (gridView2.SelectedRowsCount == 0)
            {
                MessageBox.Show("请选择标签");
                return;
            }
            object bookmarkid   = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "UID").ToString();
            string bookmarkname = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "MarkName").ToString();
            string booktype     = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "MarkType").ToString();

            Word.Range temprange = null;
            bool       flag      = W_Bkm.Exists("test");

            if (W_Bkm.Exists(bookmarkid.ToString()))
            {
                temprange = W_Bkm.get_Item(ref bookmarkid).Range;
                temprange.Select();
            }
            if (booktype == "程序员")
            {
                MessageBox.Show("您不能删除程序员定义的标签,否则程序无法正常更新数据!");
                return;
            }
            if (MessageBox.Show("确定要删除书签" + bookmarkname + "?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                //替换后标签就自动删除了
                if (W_Bkm.Exists(bookmarkid.ToString()))
                {
                    temprange.Text       = temprange.Text;
                    temprange.Font.Color = Word.WdColor.wdColorBlack;
                }

                LayoutBookMark data = this.gridView2.GetRow(this.gridView2.FocusedRowHandle) as LayoutBookMark;// new Ps_Table_GDP();
                try
                {
                    Common.Services.BaseService.Delete <LayoutBookMark>(data);
                    InitGrid2();
                    this.Refresh();
                    MessageBox.Show("删除成功");
                    FrmGHBZTLContents.ParentForm.SaveData_Word();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 3
0
        //查找名称
        private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barEditItem1.EditValue == null)
            {
                MessageBox.Show("请输入要查找的书签的名称");
                return;
            }
            if (gridView2.RowCount == 0)
            {
                MessageBox.Show("没有书签可查找");
                return;
            }
            string tagstr = barEditItem1.EditValue.ToString();

            for (int i = num + 1; i <= gridView2.RowCount; i++)
            {
                if (i == gridView2.RowCount)
                {
                    num = -1;
                    MessageBox.Show("已搜索到结尾");
                }
                if (gridView2.GetRowCellDisplayText(i, "MarkName").ToString().Contains(tagstr))
                {
                    gridView2.FocusedRowHandle = i;
                    this.Refresh();
                    num = i;
                    //定位该书签
                    BM_Word = FrmGHBZTLContents.W_Doc;
                    W_Bkm   = BM_Word.Bookmarks;
                    object     bookmarkid   = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "UID").ToString();
                    string     bookmarkname = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "MarkName").ToString();
                    Word.Range temprange    = null;
                    if (W_Bkm.Exists(bookmarkid.ToString()))
                    {
                        temprange = W_Bkm.get_Item(ref bookmarkid).Range;
                        temprange.Select();
                    }
                    break;
                }
            }
            //barEditItem1.Caption;
        }
Esempio n. 4
0
        //定位书签
        private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            BM_Word = FrmGHBZTLContents.W_Doc;
            W_Bkm   = BM_Word.Bookmarks;
            if (gridView2.SelectedRowsCount == 0)
            {
                MessageBox.Show("请选择标签");
                return;
            }
            object bookmarkid   = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "UID").ToString();
            string bookmarkname = gridView2.GetRowCellDisplayText(this.gridView2.FocusedRowHandle, "MarkName").ToString();

            Word.Range temprange = null;
            if (W_Bkm.Exists(bookmarkid.ToString()))
            {
                temprange = W_Bkm.get_Item(ref bookmarkid).Range;
                temprange.Select();
            }
            else
            {
                MessageBox.Show("无法定位,可能在Word中已删除了该标签");
            }
        }
Esempio n. 5
0
        public void Start()
        {
            try {
                //Make hidden document active to receive selection
                HiddenDoc.Activate();                 //results in a slight application focus loss
            }
            catch (System.Runtime.InteropServices.COMException ex) {
                if (ex.Message == "Object has been deleted.")
                {
                    //Open Blank document, then attach styles *and update
                    HiddenDoc = Globals.ThisAddIn.Application.Documents.Add(ref missing, ref missing, ref missing, ref FalseObj);
                    HiddenDoc.set_AttachedTemplate(ref templateObj);
                    HiddenDoc.UpdateStyles();
                    HiddenDoc.Activate();
                }
                else
                {
                    throw;
                }
            }

            //Remove Continue Bookmark, if exists
            Word.Bookmarks hiddenDocBookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            if (hiddenDocBookmarks.Exists("Continue"))
            {
                object        deleteMarkObj = "Continue";
                Word.Bookmark deleteMark    = hiddenDocBookmarks.get_Item(ref deleteMarkObj);
                deleteMark.Select();
                deleteMark.Delete();
            }

            //Tell hidden document it has been saved to remove rare prompt to save document
            HiddenDoc.Saved = true;

            //Keep track when started
            started = true;
        }
Esempio n. 6
0
        public void End()
        {
            //Exit quietly if buffer hasn't started
            if (!started)
            {
                return;
            }

            //Turn off buffer started flag
            started = false;

            //Verify hidden document is active
            if ((HiddenDoc as Word.Document) != Globals.ThisAddIn.Application.ActiveDocument)
            {
                HiddenDoc.Activate();
            }

            //Remove Continue Bookmark, if exists
            Word.Bookmarks hiddenDocBookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            hiddenDocBookmarks.ShowHidden = true;
            if (hiddenDocBookmarks.Exists("Continue"))
            {
                object        deleteMarkObj = "Continue";
                Word.Bookmark deleteMark    = hiddenDocBookmarks.get_Item(ref deleteMarkObj);
                deleteMark.Delete();
            }

            //Hidden doc selection
            curSel = Globals.ThisAddIn.Application.Selection;

            //Hidden doc range
            Word.Range hiddenDocRange;
            Word.Range bufDocRange;

            //Select entire doc, save range
            curSel.WholeStory();
            bufDocRange = curSel.Range;

            //If cursor bookmark placed in, move there, else find end of text, put a bookmark there
            Boolean cursorFound = false;

            if (hiddenDocBookmarks.Exists("_cursor"))
            {
                object        cursorBookmarkObj = "_cursor";
                Word.Bookmark cursorBookmark    = hiddenDocBookmarks.get_Item(ref cursorBookmarkObj);
                bufDocRange.SetRange(cursorBookmark.Range.End, cursorBookmark.Range.End);
                cursorBookmark.Delete();
                cursorFound = true;
            }
            else
            {
                //The -2 is done because [range object].WordOpenXML likes to drop bookmarks at the end of the range
                bufDocRange.SetRange(curSel.End - 2, curSel.End - 2);
            }

            object bookmarkObj = bufDocRange;

            //Generate GUID for hidden bookmark
            System.Guid guid = System.Guid.NewGuid();
            String      id   = "_buf" + guid.ToString().Replace("-", string.Empty);

            Word.Bookmark mark = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks.Add(id, ref bookmarkObj);

            //Get OpenXML Text (Text with formatting)
            curSel.WholeStory();
            hiddenDocRange = curSel.Range;
            string XMLText = hiddenDocRange.WordOpenXML;

            //Clear out contents of buffer
            hiddenDocRange.Delete(ref missing, ref missing);             //comment this for docbuffer troubleshooting

            //Tell hidden document it has been saved to remove rare prompt to save document
            HiddenDoc.Saved = true;

            //Make primary document active
            Globals.ThisAddIn.Application.ActiveDocument.Activate();

            //Get selection from new active document
            curSel = Globals.ThisAddIn.Application.Selection;

            //insert buffered formatted text into main document
            curSel.InsertXML(XMLText, ref missing);

            //Place cursor at bookmark+1 (this is done due to WordOpenXML ignoring bookmarks at the end of the selection)
            Word.Bookmarks bookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            bookmarks.ShowHidden = true;

            object stringObj = id;

            Word.Bookmark get_mark = bookmarks.get_Item(ref stringObj);
            bufDocRange = get_mark.Range;

            if (cursorFound)             //Canned language actively placed cursor
            {
                bufDocRange.SetRange(get_mark.Range.End, get_mark.Range.End);
            }
            else             //default cursor at the end of text
            {
                bufDocRange.SetRange(get_mark.Range.End + 1, get_mark.Range.End + 1);
            }
            bufDocRange.Select();
        }