コード例 #1
0
        public void Draw_Local_Network(int StartID)
        {
            string SQL, SQLOuter;
            string thisnodename;
            int node_id;
            OleDbCommand aLocal;
            OleDbCommand aLocalOuter;
            OleDbDataReader aReaderLocal;
            OleDbDataReader aReaderOuter;

            int rowcount = 0;

            double looper = 0;
            double xx2, yy2;
            double cx, cy;

            double size;
            double r;
            cx = 725;
            cy = 475;
            r = 33 * 10;
            double inc;

            double fromx, tox, fromy, toy;
            int duration = 1000;

            Repository localengine = new Repository();

            localengine.Open_Repository();

            // Draw the Central Point...
            PadPoint p = new PadPoint();
            p.Render(_FieldBackground, 725, 475, 20, StartID, "CenterName");

            Label nodecenter = new Label();
            nodecenter.Content = "Center";
            nodecenter.Foreground = new SolidColorBrush(Colors.White);
            nodecenter.FontSize = 12;
            _FieldBackground.Children.Add(nodecenter);
            Canvas.SetLeft(nodecenter, 735);
            Canvas.SetTop(nodecenter, 510);

            // How many records...
            SQL = "select n.ID, n.NodeName from edges e, nodes n where e.FromID = " + StartID.ToString() + " and e.ToID = n.ID";
            aLocal = new OleDbCommand(SQL, localengine.RepositoryConnection);
            //create the datareader object to connect to table
            aReaderLocal = aLocal.ExecuteReader();


            //Iterate throuth the database
            while (aReaderLocal.Read())
            {
                rowcount++;
            }
            aReaderLocal.Close();

            // Now, look backward the other way
            SQLOuter = "select n.ID, n.NodeName from edges e, nodes n where e.ToID = " + StartID.ToString() + " and e.FromID = n.ID";
            aLocalOuter = new OleDbCommand(SQLOuter, localengine.RepositoryConnection);
            aReaderOuter = aLocalOuter.ExecuteReader();
            while (aReaderOuter.Read())
            {
                rowcount++;
            }
            aReaderOuter.Close();

            // Base the spacing on the circle with how many relationships we found...
            inc = (6.4 / (rowcount));

            try
            {
                //create the datareader object to connect to table
                aReaderLocal = aLocal.ExecuteReader();


                //Iterate throuth the database
                while (aReaderLocal.Read())
                {
                    node_id = aReaderLocal.GetInt32(0);
                    thisnodename = aReaderLocal.GetString(1);

                    PadPoint p2 = new PadPoint();
                    xx2 = r * Math.Cos(looper);
                    yy2 = r * Math.Sin(looper);
                    xx2 = xx2 + cx;
                    yy2 = yy2 + cy;
                    size = 10;
                    p2.Render(_FieldBackground, 725, 460, size, node_id, thisnodename);

                    fromx = 725;
                    tox = xx2;
                    fromy = 460;
                    toy = yy2;
                    Animator.AnimatePenner(p2.Padback, Canvas.TopProperty, Tween.Equations.CubicEaseIn, fromy, toy, duration, OnAnimationComplete, OnAnimationComplete);
                    Animator.AnimatePenner(p2.Padback, Canvas.LeftProperty, Tween.Equations.CubicEaseIn, fromx, tox, duration, OnAnimationComplete, OnAnimationComplete);

                    Label nodel = new Label();
                    nodel.Content = thisnodename;
                    nodel.Foreground = new SolidColorBrush(Colors.White);
                    nodel.FontSize = 12;
                    _FieldBackground.Children.Add(nodel);
                    fromx = 725;
                    tox = xx2 + (size / 2); ;
                    fromy = 460;
                    toy = yy2 + size +10;
                    Animator.AnimatePenner(nodel, Canvas.LeftProperty, Tween.Equations.CubicEaseIn, fromx, tox, duration, OnAnimationComplete, OnAnimationComplete);
                    Animator.AnimatePenner(nodel, Canvas.TopProperty, Tween.Equations.CubicEaseIn, fromy, toy, duration, OnAnimationComplete, OnAnimationComplete);


                    Line l = new Line();
                    l.X1 = 725 + 10;
                    l.Y1 = 475 + 10;
                    l.X2 = xx2 + (size / 2);
                    l.Y2 = yy2 + (size / 2);
                    l.Stroke = new SolidColorBrush(Colors.Wheat);
                    l.Opacity = 0.4;
                    l.Tag = "EDGE";
                    _FieldBackground.Children.Add(l);

                    fromx = 725;
                    tox = xx2 + (size / 2); ;
                    fromy = 460;
                    toy = yy2 + (size / 2); ;
                    Animator.AnimatePenner(l, Line.X2Property, Tween.Equations.CubicEaseIn, fromx, tox, duration, OnAnimationComplete, OnAnimationComplete);
                    Animator.AnimatePenner(l, Line.Y2Property, Tween.Equations.CubicEaseIn, fromy, toy, duration, OnAnimationComplete, OnAnimationComplete);

                    looper = looper + inc;

                }
                aReaderLocal.Close();
            }
            catch (Exception elocalOutside)
            {
                MessageBox.Show(elocalOutside.Message);

            }

            try
            {
                //create the datareader object to connect to table
                aReaderOuter = aLocalOuter.ExecuteReader();


                //Iterate throuth the database
                while (aReaderOuter.Read())
                {
                    node_id = aReaderOuter.GetInt32(0);
                    thisnodename = aReaderOuter.GetString(1);

                    PadPoint p2 = new PadPoint();
                    xx2 = r * Math.Cos(looper);
                    yy2 = r * Math.Sin(looper);
                    xx2 = xx2 + cx;
                    yy2 = yy2 + cy;
                    size = 10;
                    p2.Render(_FieldBackground, 725, 460, size, node_id, thisnodename);

                    fromx = 725;
                    tox = xx2;
                    fromy = 460;
                    toy = yy2;
                    Animator.AnimatePenner(p2.Padback, Canvas.TopProperty, Tween.Equations.CubicEaseIn, fromy, toy, duration, OnAnimationComplete, OnAnimationComplete);
                    Animator.AnimatePenner(p2.Padback, Canvas.LeftProperty, Tween.Equations.CubicEaseIn, fromx, tox, duration, OnAnimationComplete, OnAnimationComplete);

                    Line l = new Line();
                    l.X1 = 725 + 10;
                    l.Y1 = 475 + 10;
                    l.X2 = xx2 + (size / 2);
                    l.Y2 = yy2 + (size / 2);
                    l.Stroke = new SolidColorBrush(Colors.Wheat);
                    l.Opacity = 0.4;
                    l.Tag = "EDGE";
                    _FieldBackground.Children.Add(l);
                    looper = looper + inc;

                }
                aReaderOuter.Close();
            }
            catch (Exception elocalOuter)
            {
                MessageBox.Show(elocalOuter.Message);

            }
        }
コード例 #2
0
        private void BuildNetwork(object sender, RoutedEventArgs e)
        {
            string cs = "";
            string inserts = "";
            string networkkey = "PAYR";

            Repository localenginecreate = new Repository();
            localenginecreate.Open_Repository();

            // Go grab everything we need, based on the net id
            string DataBaseRoot = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()).Replace(@"file:\", "") + "\\Friends.db";

            cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Firefly\\List of customers for firefly poc\\List of customers for firefly poc.mdb";
            
            // Node SQL
            string nodeSQL = "select cust_skey, cust_name from cust where cust_type_MDM in ('PLAN', 'PAYR', 'CORP','PHAR', 'UNSP')";
            int nodenameMap;
            int nodeidMap;
            string nodename;
            double nodeid;
            

            


            // Edge SQL
            string edgeSQL = "select from_cust_skey, to_cust_skey from cust_affl WHERE affl_type in ('PLAN_to_PAYR', 'PHAR_to_CORP', 'PAYR_to_CORP', 'CORP_to_CORP')";
            
            int EdgeFromidMap = 0;
            int EdgeToidMap = 1;
            double from;
            double to;
            double nodecount = 0;
            try
            {
                // Set up a network object
                Graph oGraph = new Graph(GraphDirectedness.Directed);
                IVertexCollection oVertices = oGraph.Vertices;
                IEdgeCollection oEdges = oGraph.Edges;

                // connection
                OleDbConnection TestConn = new OleDbConnection(cs);
                TestConn.Open();
                
                OleDbCommand aCommand = new OleDbCommand(nodeSQL, TestConn);

                //create the datareader object to connect to table
                OleDbDataReader aReader = aCommand.ExecuteReader();

                // Get the Nodes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                nodenameMap = 1;
                nodeidMap = 0;
                while (aReader.Read())
                {
                    nodename = aReader.GetString(nodenameMap);
                    nodeid = aReader.GetDouble(nodeidMap);
                    
                    // Add a node...
                    IVertex oVertexA = oVertices.Add();
                    oVertexA.Name = nodename;
                    oVertexA.Tag = nodeid;

                    nodecount++;
                }
                aReader.Close();

                // Get the Edges!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                OleDbCommand aEdgeCommand = new OleDbCommand(edgeSQL, TestConn);

                //create the datareader object to connect to table
                OleDbDataReader aEdgeReader = aEdgeCommand.ExecuteReader();

                EdgeFromidMap = 0;
                EdgeToidMap = 1;

                while (aEdgeReader.Read())
                {
                    from = aEdgeReader.GetDouble(EdgeFromidMap);
                    to = aEdgeReader.GetDouble(EdgeToidMap);
                    
                    // Add an edge
                    IVertex oFrom = null;
                    IVertex oTo = null;

                    foreach (IVertex oVertex in oVertices)
                    {
                        if (oVertex.Tag.ToString() == from.ToString())
                        {
                            oFrom = oVertex;
                        }

                        if (oVertex.Tag.ToString() == to.ToString())
                        {
                            oTo = oVertex;

                        }


                    }
                    IEdge oEdge1 = oEdges.Add(oFrom, oTo, true);

                }
                aEdgeReader.Close();

                // Perform a layout
                // Apply Layout 
                // ==================================================================

                double xdim;
                double ydim;

                xdim = 5000;
                ydim = xdim;
                string layoutmethod = "Fruchterman/Reingold Layout";
                switch (layoutmethod)
                {
                    case "Circular Layout":
                        ILayout oLayout_cir = new CircleLayout();
                        LayoutContext oLayoutContext_cir = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_cir.LayOutGraph(oGraph, oLayoutContext_cir);
                        break;
                    case "Random Layout":
                        ILayout oLayout_rand = new RandomLayout();
                        LayoutContext oLayoutContext_rand = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_rand.LayOutGraph(oGraph, oLayoutContext_rand);
                        break;
                    case "Sugiyama Layout":
                        ILayout oLayout_Sugi = new SugiyamaLayout();
                        LayoutContext oLayoutContext_Sugi = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_Sugi.LayOutGraph(oGraph, oLayoutContext_Sugi);
                        break;
                    case "Grid Layout":
                        ILayout oLayout_grid = new GridLayout();
                        LayoutContext oLayoutContext_grid = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_grid.LayOutGraph(oGraph, oLayoutContext_grid);
                        break;
                    case "Spiral Layout":
                        ILayout oLayout_spiral = new SpiralLayout();
                        LayoutContext oLayoutContext_spiral = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_spiral.LayOutGraph(oGraph, oLayoutContext_spiral);
                        break;
                    case "Fruchterman/Reingold Layout":
                        ILayout oLayout_Fruch = new FruchtermanReingoldLayout();
                        LayoutContext oLayoutContext_Fruch = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_Fruch.LayOutGraph(oGraph, oLayoutContext_Fruch);
                        break;
                    case "Sinusoid H Layout":
                        ILayout oLayout_SinH = new SinusoidHorizontalLayout();
                        LayoutContext oLayoutContext_SinH = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_SinH.LayOutGraph(oGraph, oLayoutContext_SinH);
                        break;
                    case "Sinusoid V Layout":
                        ILayout oLayout_SinV = new SinusoidVerticalLayout();
                        LayoutContext oLayoutContext_SinV = new LayoutContext(new System.Drawing.Rectangle(0, 0, (int)xdim, (int)ydim));
                        oLayout_SinV.LayOutGraph(oGraph, oLayoutContext_SinV);
                        break;

                }


                // Save the Nodes back out to the Firefly database
                // List the results.
                int xoffset = 0;
                int yoffset = 0;
                int size=10;
                double xx2, yy2,xx,yy;
                
                foreach (IVertex oVertex in oVertices)
                {
                    
                    UniversePadPoint p2 = new UniversePadPoint();

                    p2.PadName = oVertex.Name;
                    xx2 = oVertex.Location.X;
                    yy2 = oVertex.Location.Y;
                    xx2 = xx2 + xoffset;
                    yy2 = yy2 + yoffset;
                 
                    size = 10;
                                       
                    inserts = "insert into Nodes(id, nodename, networkid,x,y,z) values (" + oVertex.Tag.ToString() + ", '" + oVertex.Name.ToString() + "', '" + networkkey + "'," + xx2.ToString() + "," + yy2.ToString() + ",0)";
                    OleDbCommand postnode = new OleDbCommand(inserts, localenginecreate.RepositoryConnection);
                    OleDbDataReader Poster = postnode.ExecuteReader();
                    Poster.Close();

                }

                foreach (IEdge e2 in oEdges)
                {
                    IVertex f1 = e2.BackVertex;
                    IVertex t2 = e2.FrontVertex;
                    xx = f1.Location.X;
                    yy = f1.Location.Y;
                    xx2 = t2.Location.X;
                    yy2 = t2.Location.Y;

                    xx = xx + xoffset;
                    yy = yy + yoffset;
                    xx2 = xx2 + xoffset;
                    yy2 = yy2 + yoffset;

                    inserts = "insert into Edges(fromid, toid, networkid) values (" + f1.Tag.ToString() + ", " + t2.Tag.ToString() + ", '" + networkkey + "')";

                    OleDbCommand postedge = new OleDbCommand(inserts, localenginecreate.RepositoryConnection);
                    OleDbDataReader Poster = postedge.ExecuteReader();
                    Poster.Close();

                }

            }

            //Some usual exception handling
            catch (OleDbException eWriteNodes)
            {
                MessageBox.Show(eWriteNodes.Message);
                
            }
            localenginecreate.Close_Repository();
            MessageBox.Show("Done creating network.");

        }