예제 #1
0
        private void LoadDataFromDB(MySqlConnection connection, int rootId, Unit unit, string tableName, List <NodeTable> refTables)
        {
            tableName = tableName + "_" + unit.Key;

            var leaves = unit.Children.Where(x => x.Leaf);
            var trunks = unit.Children.Where(x => !x.Leaf);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("SELECT `ParentIndex`, `NodeIndex`");
            foreach (var leaf in leaves)
            {
                sb.AppendFormat(", `{0}`", leaf.Key);
            }
            sb.AppendFormat(" FROM `{0}` WHERE `RootId` = @RootId ORDER BY `ParentIndex`, `NodeIndex`;", tableName);

            var table = new NodeTable(tableName);

            using (var cmd = connection.CreateCommand())
            {
                cmd.CommandText = sb.ToString();
                cmd.Parameters.AddWithValue("@RootId", rootId);
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        NodeRow row = new NodeRow((int)reader["ParentIndex"], (int)reader["NodeIndex"]);
                        foreach (var leaf in leaves)
                        {
                            row.AddColumn(leaf.Key, reader[leaf.Key]);
                        }
                        table.AddRow(row);
                    }
                }
            }
            refTables.Add(table);

            foreach (var trunk in trunks)
            {
                LoadDataFromDB(connection, rootId, trunk, tableName, refTables);
            }
        }
예제 #2
0
파일: NodeRow.cs 프로젝트: hotjk/unno
 public void AddRow(NodeRow row)
 {
     this.Rows.Add(row);
 }