Exemplo n.º 1
0
        public static frmFlow Open(Form mdiparent)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                String   loc    = dlg.FileName;
                GraphDoc olddoc = GraphDoc.FindDocument(loc);
                if (olddoc != null)
                {
                    IList windows = frmFlow.FindWindows(mdiparent, olddoc);
                    if (windows.Count > 0)
                    {
                        frmFlow w = windows[0] as frmFlow;
                        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(mdiparent, ex.Message, "Error reading graph from a file");
                        }
                        finally
                        {
                            file.Close();
                        }
                        if (doc != null)
                        {
                            //frmMain w = new frmMain();
                            //w.View.Document = doc;
                            //w.MdiParent = mdiparent;
                            //w.Show();
                            //w.Activate();
                            //return w;
                            _frmMain.View.Document = doc;
                            _frmMain.Show();
                            _frmMain.Activate();
                            return(_frmMain);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public static IList FindWindows(Form mdiparent, GraphDoc doc)
        {
            ArrayList windows = new ArrayList();

            Form[] children = mdiparent.MdiChildren;
            foreach (Form f in children)
            {
                frmFlow w = f as frmFlow;
                if (w != null && w.Doc == doc)
                {
                    windows.Add(w);
                }
            }
            return(windows);
        }
Exemplo n.º 3
0
        public virtual bool Reload()
        {
            String loc = this.Doc.Location;

            if (loc != "")
            {
                FileStream file   = File.Open(loc, FileMode.Open);
                GraphDoc   olddoc = this.View.Doc;
                GraphDoc   newdoc = null;
                try
                {
                    newdoc = GraphDoc.Load(file, loc);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error reading graph from a file");
                    return(false);
                }
                finally
                {
                    file.Close();
                }
                if (newdoc != null)
                {
                    IList windows = frmFlow.FindWindows(this.MdiParent, olddoc);
                    foreach (Object obj in windows)
                    {
                        frmFlow w = obj as frmFlow;
                        if (w != null)
                        {
                            w.View.Document = newdoc;
                        }
                    }
                }
            }
            return(true);
        }