private void button3_Click(object sender, RibbonControlEventArgs e)
        {
            Microsoft.Office.Interop.Visio.Page visioPage =
                Globals.ThisAddIn.Application.ActivePage;
            Microsoft.Office.Interop.Visio.Window visioWindow =
                Globals.ThisAddIn.Application.ActiveWindow;

            try
            {
                if (visioWindow.Selection.Count == 0)
                {
                    MessageBox.Show("Please select a shape that has connections");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Please select a shape that has connections");
                return;
            }

            EncryptedConfigWriter encrypted = new EncryptedConfigWriter();
            Setting ConnectionSetting       = encrypted.ReadConfig();

            Process p = new Process();

            p.StartInfo.FileName         = _configDir + "\\Dashboard\\DSMPatchReportingGUI.exe";
            p.StartInfo.WorkingDirectory = _configDir + "\\Dashboard";
            p.StartInfo.LoadUserProfile  = true;
            p.StartInfo.Arguments        = "/API=" + ConnectionSetting.API +
                                           " /USER="******" /PWD=" + ConnectionSetting.Password +
                                           " /COMPUTER=" + visioWindow.Selection.PrimaryItem.Text;
            p.Start();
        }
        /// <summary>
        /// 根据指定的监测点在visio图形中绘出对应的测点图形
        /// </summary>
        /// <param name="vsoWindow">进行绘图的visio图形</param>
        /// <param name="strTags">要绘制的所有监测点的在列表中对应的文本</param>
        /// <param name="PointsToBeAdded">要绘制的所有监测点的集合</param>
        /// <remarks></remarks>
        public void AddMonitorPoints(Microsoft.Office.Interop.Visio.Window vsoWindow, string[] strTags, PointInVisio[] PointsToBeAdded)
        {
            int n = PointsToBeAdded.Count();

            if (n > 0)
            {
                //
                object[] arrMaster     = new object[n - 1 + 1];
                double[] arrCoordinate = new double[2 * n - 1 + 1];
                short[]  arrIDOut      = new short[n - 1 + 1];
                string[] arrPointTag   = new string[n - 1 + 1];
                //

                Microsoft.Office.Interop.Visio.Masters DocumentMasters = vsoWindow.Document.Masters;

                int i = 0;
                foreach (var pt in PointsToBeAdded)
                {
                    try
                    {
                        arrMaster[i] = DocumentMasters[pt.strItem];
                    }
                    catch (Exception)
                    {
                        Debug.Print("测点类型: {0} 在Visio模板文件中并不存在,此时用\"OtherTypes\"来表示。", pt.strItem);
                        arrMaster[i] = DocumentMasters["OtherTypes"];
                    }
                    arrPointTag[i]           = System.Convert.ToString(pt.strPoint);
                    arrCoordinate[2 * i]     = System.Convert.ToDouble(pt.Coordinates(0));
                    arrCoordinate[2 * i + 1] = System.Convert.ToDouble(pt.Coordinates(1));
                    i++;
                }

                Microsoft.Office.Interop.Visio.Page pg = vsoWindow.Page;
                int ProcessedCount = pg.DropMany(ref arrMaster, ref arrCoordinate, ref arrIDOut);

                //设置每一个测点形状上显示的文字
                pg.Application.ShowChanges = true;
                string tag = F_MonitorPointsInfo.ShapeName_MonitorPointTag;
                try
                {
                    for (int i_p = 0; i_p <= n - 1; i_p++)
                    {
                        int id = arrIDOut[i_p];
                        //设置主控形状的实例对象中,“某形状”的文本,“某形状”的索引等规范化。
                        pg.Shapes.ItemFromID(id).Shapes.Item(tag).Text = arrPointTag[i_p];
                        F_dicVisioPoints.Add(strTags[i_p], arrIDOut[i_p]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("主控形状中没有找到子形状:" + "tag" + "\r\n" + ex.Message + "\r\n" + "报错位置:" + ex.TargetSite.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#3
0
 void _VisioApplication_BeforeWindowClosed(Microsoft.Office.Interop.Visio.Window Window)
 {
     DisplayInWatchWindow(countBeforeWindowClosed++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
示例#4
0
 bool _VisioApplication_QueryCancelWindowClose(Microsoft.Office.Interop.Visio.Window Window)
 {
     DisplayInWatchWindow(countQueryCancelWindowClose++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     return(false);
 }
示例#5
0
 void _VisioApplication_WindowTurnedToPage(Microsoft.Office.Interop.Visio.Window Window)
 {
     DisplayInWatchWindow(countWindowTurnedToPage++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
        /// <summary>
        /// !进行监测点位的绘制
        /// </summary>
        /// <remarks></remarks>
        private void DrawPoints()
        {
            ClsDrawing_PlanView vso = GlobalApplication.Application.PlanView_VisioWindow;

            if (vso != null)
            {
                Microsoft.Office.Interop.Visio.Page pg = vso.Page;
                try
                {
                    Microsoft.Office.Interop.Visio.Window vsoWindow = pg.Application.ActiveWindow;
                    vsoWindow.Page = pg;
                    vsoWindow.Application.ShowChanges = false;
                    //
                    string[] arrListedPoints  = F_dicListedPoints.Keys.ToArray;
                    string[] arrExistedPoints = F_dicVisioPoints.Keys.ToArray;
                    //
                    object[] arrAddOrRemove = new object[2];
                    arrAddOrRemove = GetPointsToBeProcessed(arrExistedPoints, arrListedPoints);
                    string[] arrToBeAdded   = arrAddOrRemove[0];
                    string[] arrToBeRemoved = arrAddOrRemove[1];


                    // ----- arrPointsToBeAdded ------------- 处理要进行添加的图形
                    PointInVisio[] arrPointsToBeAdded = new PointInVisio[arrToBeAdded.Length - 1 + 1];
                    int            i            = 0;
                    string         strSeparator = TreeViewPoints.PathSeparator;
                    foreach (string tag_Add in arrToBeAdded)
                    {
                        TreeNode     nd           = F_dicListedPoints.Item(tag_Add);
                        PointInVisio struct_Point = new PointInVisio();
                        var          str          = tag_Add;
                        struct_Point.strItem     = str.Substring(0, str.IndexOf(strSeparator));
                        struct_Point.strPoint    = nd.Text;
                        struct_Point.Coordinates = nd.Tag;
                        arrPointsToBeAdded[i]    = struct_Point;
                        i++;
                    }

                    AddMonitorPoints(vsoWindow, arrToBeAdded, arrPointsToBeAdded);

                    // ----- arrToBeRemoved ------------- 处理要进行删除的图形
                    foreach (string strPointTag in arrToBeRemoved)
                    {
                        Microsoft.Office.Interop.Visio.Shape shp = default(Microsoft.Office.Interop.Visio.Shape);
                        shp = pg.Shapes.ItemFromID(System.Convert.ToInt32(F_dicVisioPoints.Item(strPointTag)));
                        shp.Delete();
                        //
                        F_dicVisioPoints.Remove(strPointTag);
                    }

                    // -----------------------
                    this.blnRefreshed = true;
                    vsoWindow.Application.ShowChanges = true;
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                    MessageBox.Show("出错!" + "\r\n" + ex.Message + "\r\n" + "报错位置:" + ex.TargetSite.Name,
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Visio绘图已经关闭,请重新打开。", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }