public IEnumerable <NodePairs> ListAllNodePairss() { try { sqlite_conn.Open(); SqliteDataReader sqlite_datareader; SqliteCommand sqlite_cmd; sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "SELECT * FROM nodePairs"; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { NodePairs item = new NodePairs() { ParentId = Convert.ToInt32(sqlite_datareader["parentNodeId"]), ChildId = Convert.ToInt32(sqlite_datareader["childNodeId"]) }; nodepairs.Add(item); } sqlite_conn.Close(); return(nodepairs); } catch (System.Exception exception) { System.Console.WriteLine(exception); return(null); } }
public IEnumerable <NodePairs> GetNodePairById(int id) { List <NodePairs> childernNodes = new List <NodePairs>(); try { sqlite_conn.Open(); SqliteDataReader sqlite_datareader; SqliteCommand sqlite_cmd; sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "SELECT * FROM nodepairs where parentNodeId = '" + id + "'"; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { NodePairs item = new NodePairs() { ParentId = Convert.ToInt32(sqlite_datareader["parentNodeId"]), ChildId = Convert.ToInt32(sqlite_datareader["childNodeId"]) }; childernNodes.Add(item); } return(childernNodes); } catch (System.Exception exception) { System.Console.WriteLine(exception); return(null); } }
public int UpdateNodePairById(int id, [FromBody] NodePairs value) { try { sqlite_conn.Open(); SqliteCommand sqlite_cmd; sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "UPDATE nodepairs SET childNodeId = @childNodeId where parentNodeId = '" + id + "'"; sqlite_cmd.Parameters.AddWithValue("@childNodeId", value.ChildId); int rowAffected = sqlite_cmd.ExecuteNonQuery(); return(rowAffected); } catch (System.Exception exception) { System.Console.WriteLine(exception); return(0); } }
public int PostNode([FromBody] NodePairs value) { try { sqlite_conn.Open(); SqliteCommand sqlite_cmd; sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "INSERT INTO nodePairs (parentNodeId, childNodeId) VALUES (@parentNodeId, @childNodeId);"; sqlite_cmd.Parameters.AddWithValue("@parentNodeId", value.ParentId); sqlite_cmd.Parameters.AddWithValue("@childNodeId", value.ChildId); int rowAffected = sqlite_cmd.ExecuteNonQuery(); sqlite_conn.Close(); return(rowAffected); } catch (System.Exception exception) { System.Console.WriteLine(exception); return(0); } }
/// <summary> /// Formats the line input into the UnitCell object. It converts the list of lines into /// a list of unique nodes and unique node pairs, ignoring duplicates. /// </summary> private void ExtractTopology(List <Line> lines) { double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; CellTools.FixIntersections(ref lines); // Iterate through list of lines foreach (Line line in lines) { // Get line, and it's endpoints Point3d[] pts = new Point3d[] { line.From, line.To }; List <int> nodeIndices = new List <int>(); // Loop over end points, being sure to not create the same node twice foreach (Point3d pt in pts) { int closestIndex = this.Nodes.ClosestIndex(pt); // find closest node to current pt // If node already exists if (this.Nodes.Count != 0 && this.Nodes[closestIndex].EpsilonEquals(pt, tol)) { nodeIndices.Add(closestIndex); } // If it doesn't exist, add it else { this.Nodes.Add(pt); nodeIndices.Add(this.Nodes.Count - 1); } } IndexPair nodePair = new IndexPair(nodeIndices[0], nodeIndices[1]); // If not duplicate strut, save it if (this.NodePairs.Count == 0 || !NodePairs.Contains(nodePair)) { this.NodePairs.Add(nodePair); } } }