示例#1
0
        public static List <GraphViewWindow> OpenAll()
        {
            List <GraphViewWindow> windows = new List <GraphViewWindow>();

            if (!System.IO.Directory.Exists(@".\Config\FlowChart\"))
            {
                System.IO.Directory.CreateDirectory(@".\Config\FlowChart\");
            }
            var filePaths = Directory.GetFiles(@".\Config\FlowChart\");

            foreach (var item in filePaths)
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.FileName = item;
                String   loc    = item;
                GraphDoc olddoc = GraphDoc.FindDocument(loc);
                if (olddoc != null)
                {
                    //IList windows = GraphViewWindow.FindWindows(mdiparent, olddoc);
                    //if (windows.Count > 0)
                    //{
                    //    GraphViewWindow w = windows[0] as GraphViewWindow;
                    //    if (w.Reload())
                    //    {
                    //        w.Show();
                    //       w.Activate();
                    //    }
                    //    return w;
                    //}
                }
                else
                {
                    Stream file = dlg.OpenFile();
                    if (file != null)
                    {
                        GraphDoc doc = null;
                        try
                        {
                            doc = GraphDoc.Load(file, loc);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error reading graph from a file");
                        }
                        finally
                        {
                            file.Close();
                        }
                        if (doc != null)
                        {
                            GraphViewWindow w = new GraphViewWindow();
                            w.View.Document = doc;
                            w.Activate();
                            windows.Add(w);
                        }
                    }
                }
            }
            return(windows);
        }
示例#2
0
        public static GraphViewWindow Open(DockPanel dockPanel1)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                String   loc    = dlg.FileName;
                GraphDoc olddoc = GraphDoc.FindDocument(loc);
                if (olddoc != null)
                {
                    return(null);
                    //IList windows = GraphViewWindow.FindWindows(mdiparent, olddoc);
                    //if (windows.Count > 0)
                    //{
                    //    GraphViewWindow w = windows[0] as GraphViewWindow;
                    //    if (w.Reload())
                    //    {
                    //        w.Show();
                    //       w.Activate();
                    //    }
                    //    return w;
                    //}
                }
                else
                {
                    Stream file = dlg.OpenFile();
                    if (file != null)
                    {
                        GraphDoc doc = null;
                        try
                        {
                            doc = GraphDoc.Load(file, loc);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error reading graph from a file");
                        }
                        finally
                        {
                            file.Close();
                        }
                        if (doc != null)
                        {
                            GraphViewWindow w = new GraphViewWindow();
                            w.View.Document = doc;
                            w.Show(dockPanel1, DockState.Document);
                            w.Activate();
                            return(w);
                        }
                    }
                    return(null);
                }
            }
            return(null);
        }