internal static void StoreInfo(QTable qt, QHierarchy h, string comment, QData data) { data.AddInfo(qt, h, new QField { Name = "Value", NoNameCs = true, Type = QType.Date, Prefix = null, Comment = comment }); }
/// <summary> /// Add description of class. Should by called recursively for child classes. /// </summary> /// <param name="tab">description of table in db (without fields)</param> /// <param name="h">description of hierarchy of class</param> /// <param name="fields">description of fields with simple types</param> public void AddInfo(QTable tab, QHierarchy h, params QField[] fields) { if (string.IsNullOrWhiteSpace(tab.Name)) { throw new Exception("Table name can not be empty"); } foreach (var f in fields) { if (string.IsNullOrWhiteSpace(f.Name)) { throw new Exception("Name of field can not be empty for table: " + tab.Name); } if (string.IsNullOrEmpty(f.Prefix)) { f.Prefix = tab.Prefix; } if (h != null && string.IsNullOrEmpty(h.Name)) { throw new Exception("Name not set in hierarchy for table: " + tab.Name); } f.Hierarchy = h; } if (!_tabs.ContainsKey(tab.Name)) { _tabs[tab.Name] = tab; tab.Fields.AddRange(fields); } else { var t = _tabs[tab.Name]; if (string.IsNullOrEmpty(t.Comment)) { t.Comment = tab.Comment; } t.Fields.AddRange(fields); } if (h == null) { if (_root.Table == null) { _root.Table = tab; } else if (_root.Table.Name != tab.Name) { throw new Exception("For root node table name was " + _root.Table.Name + ", new table name: " + tab.Name); } _root.Fields.AddRange(fields); } else { var ehParent = h.Parent == null ? _root : FindParent(h.Parent, _root); if (ehParent == null) { throw new Exception("Parent not found for table: " + tab.Name + ", hierarchy: " + h.Path); } bool found = false; foreach (var ehChild in ehParent.Children) { if (ehChild.Hierarchy.Name == h.Name) { if (ehChild.Hierarchy.Type != h.Type) { throw new Exception("Different types for one name: " + h.Name + ", parent: " + ehParent.Hierarchy.Path); } ehChild.Fields.AddRange(fields); found = true; } } if (!found) { var eh = new QExtHierarchy(); eh.Hierarchy = h; eh.Table = tab; eh.Fields.AddRange(fields); ehParent.Children.Add(eh); } } var checkUnique = new Dictionary <string, QHierarchy>(); foreach (var f in tab.Fields) { string fname = f.FullName; if (checkUnique.ContainsKey(fname.ToLower())) { throw new Exception("Table " + tab.Name + " has multiple columns with name: '" + fname + "' in " + (f.Hierarchy != null ? f.Hierarchy.Path : "parent") + " and " + checkUnique[fname.ToLower()].Path); } checkUnique.Add(fname.ToLower(), f.Hierarchy ?? new QHierarchy("Root", QHType.Member, null)); } }