Example #1
0
        //链接
        /// <summary>
        /// 将Visio中的外部数据链接到Page中的指定形状。
        /// 此操作的作用:通过Visio的数据图形功能,在对应的形状上显示出它所链接的数据,比如此图形对应的开挖深度。
        /// </summary>
        /// <param name="DataRS">数据链接的源数据记录集</param>
        /// <param name="Page">要进行数据链接的形状所在的Page</param>
        /// <param name="ColumnIndex_PrimaryKey">在数据记录集中,用来记录形状的名称的数据所在的列号。如果是第一列,则为0.</param>
        /// <param name="DeleteDataRecordset">是否要在数据记录集的数据链接到形状后,将此数据记录集删除。</param>
        /// <remarks></remarks>
        private dynamic PassDataRecordsetToShape(Microsoft.Office.Interop.Visio.DataRecordset DataRS, Microsoft.Office.Interop.Visio.Page Page, short ColumnIndex_PrimaryKey = 0, bool DeleteDataRecordset = false)
        {
            bool blnSucceeded = true;

            int[] IDs = null;
            //  ------------------ GetDataRowIDs ---------------------
            //获取数据记录集内所有行的 ID 组成的数组,其中每一行均代表一个数据记录。
            //若要不应用筛选器(即获取所有行),则传递一个空字符串 ("") 即可。
            IDs = DataRS.GetDataRowIDs("");
            //
            Microsoft.Office.Interop.Visio.Shape shp = default(Microsoft.Office.Interop.Visio.Shape);
            try
            {
                foreach (int RowID in IDs)
                {
                    int shapeID = System.Convert.ToInt32(DataRS.GetRowData(RowID)[ColumnIndex_PrimaryKey]);
                    //ItemFromID可以进行页面或者形状集合中的全局索引,即可以索引子形状中的嵌套形状,而Item一般只能索引其下的子形状。
                    shp = Page.Shapes.ItemFromID(shapeID);
                    shp.LinkToData(DataRS.ID, RowID, false);
                }
            }
            catch (Exception)
            {
                blnSucceeded = false;
            }

            //是否要在数据记录集的数据链接到形状后,将此数据记录集删除。
            if (DeleteDataRecordset)
            {
                DataRS.Delete();
                DataRS = null;
            }
            return(blnSucceeded);
        }
Example #2
0
 /// <summary>
 /// Visio文档关闭
 /// </summary>
 /// <param name="Doc"></param>
 /// <remarks></remarks>
 private void F_vsoDoc_BeforeDocumentClose(Microsoft.Office.Interop.Visio.Document Doc)
 {
     this.F_vsoDoc = null;
     this.F_vsoDoc.BeforeDocumentClose += this.F_vsoDoc_BeforeDocumentClose;
     this.F_vsoDataRs = null;
     //
     ClearUI();
 }
Example #3
0
        /// <summary>
        /// 从Visio文档的数据记录集中返回其中的字段列对象的数组
        /// </summary>
        /// <param name="DRS"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private LstbxDisplayAndItem[] GetColumnsFromDataRS(Microsoft.Office.Interop.Visio.DataRecordset DRS)
        {
            int ColumnsCount = DRS.DataColumns.Count;

            LstbxDisplayAndItem[] arrItems = new LstbxDisplayAndItem[ColumnsCount - 1 + 1];
            int i = 0;

            foreach (Microsoft.Office.Interop.Visio.DataColumn Column in DRS.DataColumns)
            {
                //在数据记录集中,第一列数据的Index为0。
                arrItems[i] = new LstbxDisplayAndItem(Column.DisplayName, i);
                i++;
            }
            return(arrItems);
        }
Example #4
0
        public void ComboBox_DataRs_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstbxDisplayAndItem lstItem = this.ComboBox_DataRs.SelectedItem;

            try
            {
                Microsoft.Office.Interop.Visio.DataRecordset DataRs = (Microsoft.Office.Interop.Visio.DataRecordset)lstItem.Value;
                this.F_vsoDataRs = DataRs;
                //更新数据记录集中的字段列。
                this.ComboBox_Column_ShapeID.DataSource = GetColumnsFromDataRS(DataRs);
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message, "选择数据记录集出错!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            }
            this.btnLink.Enabled = false;
        }
Example #5
0
        //验证
        /// <summary>
        /// 验证页面中是否包含所有位于数据记录集中所记录的形状ID。
        /// </summary>
        /// <param name="page"></param>
        /// <param name="DRS"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private bool ValidateShapes(Microsoft.Office.Interop.Visio.Page page, Microsoft.Office.Interop.Visio.DataRecordset DRS, int intIndexOfShapeID)
        {
            bool blnValidated = true;

            if (DRS != null)
            {
                int[] lngRowIDs = DRS.GetDataRowIDs("");
                Microsoft.Office.Interop.Visio.Shape shp;
                foreach (int id in lngRowIDs)
                {
                    object[] RowData = DRS.GetRowData(id);
                    object   shapeID = RowData[intIndexOfShapeID];
                    try
                    {
                        shp = page.Shapes.ItemFromID(System.Convert.ToInt32(shapeID));
                    }
                    catch (Exception)
                    {
                        blnValidated = false;
                        var Result = MessageBox.Show("在页面中没有找到与形状ID \"" + System.Convert.ToString(shapeID) + "\" 相匹配的形状。请仔细检查记录的形状ID值。",
                                                     "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                        if (Result == Windows.Forms.DialogResult.OK)
                        {
                        }
                        else if (Result == Windows.Forms.DialogResult.Cancel)
                        {
                            //不再提示这条错误
                            goto endOfForLoop;
                        }
                    }
                }
endOfForLoop:
                1.GetHashCode();                  //VBConversions note: C# requires an executable line here, so a dummy line was added.
            }
            else
            {
                blnValidated = false;
            }
            return(blnValidated);
        }
Example #6
0
 void _VisioApplication_BeforeDataRecordsetDelete(Microsoft.Office.Interop.Visio.DataRecordset DataRecordset)
 {
     DisplayInWatchWindow(countBeforeDataRecordsetDelete++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }