/// <summary> /// Создание начальных записей в левой колонке. /// </summary> public void CreateInitData() { if (DBInterface != null && DBInterface.TableType != null) { MemberInits.Clear(); Type initType = DBInterface.TableType; int recordCount = 0; PropertyInfoExs infos1 = GetProperties(initType); foreach (PropertyInfoEx prInfo1 in infos1) { TableMemberInfo tmInfo2 = AnalisProperty(prInfo1, null, ref recordCount); if (tmInfo2 == null) { break; } MemberInits.Add(tmInfo2); PropertyInfoExs prInfos2 = GetProperties(prInfo1); CreateInitData(prInfos2, tmInfo2, ref recordCount, 1); } lblTotalCount.Caption = string.Format("Всего: {0}", recordCount); treeInit.DataSource = null; treeInit.DataSource = MemberInits; } }
private void btnDelete_Click(object sender, EventArgs e) { TableMemberInfos deletings = new TableMemberInfos(rewriteParent: false); foreach (TreeListNode node in treeExist.Selection) { TableMemberInfo info = treeExist.GetDataRecordByNode(node) as TableMemberInfo; if (info != null && info.Item != null) { DBInterface.DestroyInstance(info.Item); UnuseInitTable(info); EraseExistDate(info); deletings.Add(info); } } // Удаление записей foreach (TableMemberInfo infoInter in deletings) { MemberExists.RemoveEx(infoInter); } }
/// <summary> /// Рекурсивный перебор всех элементов дерева. /// </summary> public void CreateInitData(PropertyInfoExs infos, TableMemberInfo info, ref int recordCount, int level) { if (level < LevelMax) { foreach (PropertyInfoEx prInfo in infos) { if (!(prInfo.IsXPCollection && prInfo.Parent != null && prInfo.Parent.IsXPBaseObject)) { TableMemberInfo tmInfo2 = AnalisProperty(prInfo, info, ref recordCount); if (tmInfo2 == null) { break; } PropertyInfoExs prInfos2 = GetProperties(prInfo); CreateInitData(prInfos2, tmInfo2, ref recordCount, level + 1); } else { } } } }
/// <summary> /// Рекурсивный метод очистки записей. /// </summary> private void EraseExistDate(TableMemberInfo tmInfo, int level) { foreach (TableMemberInfo item in tmInfo.Items) { UnuseInitTable(item); EraseExistDate(item, level + 1); } }
/// <summary> /// Очистка записи. /// </summary> public void UnuseInitTable(TableMemberInfo tmInfo) { TableMemberInfo infoInit = MemberInits.FindInfo(tmInfo); if (infoInit != null) { infoInit.IsUsed = false; } }
private void btnAddInit_Click(object sender, EventArgs e) { foreach (TreeListNode node in treeInit.Selection) { TableMemberInfo info = treeInit.GetDataRecordByNode(node) as TableMemberInfo; CreateInstance(info); } treeExist.ExpandAll(); }
private void treeInit_GetStateImage(object sender, GetStateImageEventArgs e) { TableMemberInfo info = treeInit.GetDataRecordByNode(e.Node) as TableMemberInfo; if (info != null) { e.NodeImageIndex = info.ImageIndex; } }
/// <summary> /// Анализ PropertyInfoEx объекта и добавление полученных данных в объект TableMemberInfo. /// </summary> public TableMemberInfo AnalisProperty(PropertyInfoEx propertyInfo, TableMemberInfo tableInfo, ref int recordCount) { TableMemberInfo result = new TableMemberInfo(); result.FieldName = propertyInfo.PropertyInfo.Name; result.Caption = PropertyInfoEx.GetDisplayNameAttribute(propertyInfo.PropertyInfo); result.PropertyType = propertyInfo.PropertyInfo.PropertyType; if (propertyInfo.IsXPCollection) { result.PropertyTypeCollection = propertyInfo.PropertyInfoCollection.PropertyType; } result.IsXPBaseObject = propertyInfo.IsXPBaseObject; result.IsXPCollection = propertyInfo.IsXPCollection; if (result.IsXPBaseObject || result.IsXPCollection) { string name = ""; if (result.IsXPBaseObject) { name = DBAttribute.GetIconFile(result.PropertyType); } if (result.IsXPCollection) { name = DBAttribute.GetIconFile(result.PropertyTypeCollection); } string dir = DBInterface.GetImageFullName(name); if (dir != "" && File.Exists(dir) && !ImageEx.IsExist(imgInit, name)) { imgInit.AddImage(Image.FromFile(dir), name); } result.ImageIndex = ImageEx.GetImageIndex(imgInit, name); result.ImageName = name; } if (tableInfo != null) { tableInfo.Add(result); } if (MemberExists.FindInfo(result) != null) { result.IsUsed = true; } // Ограничение по количеству записей recordCount++; if (recordCount >= RecordCountMax) { return(null); } else { return(result); } }
private void treeInit_MouseDoubleClick(object sender, MouseEventArgs e) { TreeListNode node = GetTreeListNode(treeInit, e.Location); if (node != null) { TableMemberInfo info = treeInit.GetDataRecordByNode(node) as TableMemberInfo; CreateInstance(info); } }
/// <summary> /// Рекурсивный метод обновления записей уже созданных записей. /// </summary> private void CreateExistData(DBInterfaceItemXPComplex itemComplex, TableMemberInfos infos, int level) { foreach (DBInterfaceItemBase item in itemComplex.Items) { TableMemberInfo tmInfo = DBInterface.PrintExistData(treeExist, item, infos); if (item is DBInterfaceItemXPComplex) { CreateExistData((DBInterfaceItemXPComplex)item, tmInfo.Items, level + 1); } } }
/// <summary> /// Принадлежит ли тип к XPObject. /// </summary> public static bool isXPBaseObject(TableMemberInfo tmInfo) { if (!tmInfo.IsXPCollection && isXPBaseObject(tmInfo.PropertyType)) { return(true); } else { return(false); } }
private void treeExist_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e) { TableMemberInfo tmInfo = treeExist.GetDataRecordByNode(e.Node) as TableMemberInfo; SelectedExistInfo = tmInfo; if (tmInfo != null && tmInfo.Item != null) { proExist.SelectedObject = tmInfo.Item; UpdateExistButtons(); } }
/// <summary> /// Рекурсивный метод определения уровня положения записи. /// </summary> private int GetLevel(TableMemberInfo info, int level) { if (info.Parent != null) { return(GetLevel(info.Parent, level + 1)); } else { return(level); } }
/// <summary> /// Обновление визуального представление кнопок "Выше" и "Ниже". /// </summary> public void UpdateExistButtons() { TableMemberInfo info = SelectedExistInfo; if (info != null) { btnExistUp.Enabled = !info.Item.IsFirst(); btnExistDown.Enabled = !info.Item.IsLast(); } else { btnExistUp.Enabled = false; btnExistDown.Enabled = false; } }
/// <summary> /// Обновления дерева уже созданных записей. /// </summary> public void UpdateExistData() { MemberExists.Clear(); foreach (DBInterfaceItemBase item in DBInterface.Items) { TableMemberInfo info = DBInterface.PrintExistData(treeExist, item, MemberExists); if (item is DBInterfaceItemXPComplex) { CreateExistData((DBInterfaceItemXPComplex)item, info.Items, 1); } } treeExist.ExpandAll(); UpdateExistButtons(); DBInterface.ItemsSeq.CorrectImageIndex(); }
private void treeExist_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { Point point = treeExist.PointToClient(Control.MousePosition); TreeListNode node = GetTreeListNode(treeExist, point); if (node != null) { TableMemberInfo tmInfo = treeExist.GetDataRecordByNode(node) as TableMemberInfo; if (tmInfo != null) { MemberExists.Remove(tmInfo); } } } }
/// <summary> /// Рекурсивный метод обновления надписей и иконок.. /// </summary> private void UpdateExistCaptionAndIcon(TableMemberInfos infos, int level) { foreach (TableMemberInfo info in infos) { TableMemberInfo infoExist = MemberExists.FindInfo(info); if (infoExist != null) { infoExist.Caption = info.Caption; DBInterface.CreateIcon(infoExist.Item, info); if (info.Items.Count > 0) { UpdateExistCaptionAndIcon(info.Items, level + 1); } } } }
/// <summary> /// Рекурсивный метод поиска старшего родителя записи. /// </summary> private TableMemberInfo GetParent(TableMemberInfo info, int level, int limit = 9999) { if (level < limit) { if (info.Parent != null) { return(GetParent(info.Parent, level + 1, limit)); } else { return(info); } } else { return(info); } }
/// <summary> /// Обновления надписей и иконок. /// </summary> public void UpdateExistCaptionAndIcon() { foreach (TableMemberInfo info in MemberInits) { TableMemberInfo infoExist = MemberExists.FindInfo(info); if (infoExist != null) { infoExist.Caption = info.Caption; DBInterface.CreateIcon(infoExist.Item, info); if (info.Items.Count > 0) { UpdateExistCaptionAndIcon(info.Items, 1); } } } DBInterface.TableCaption = DBAttribute.GetCaption(DBInterface.TableType); }
/// <summary> /// Автоматическое создание элемента коллекции. /// </summary> public DBInterfaceItemBase CreateInstance(TableMemberInfo tmInfo) { DBInterfaceItemBase item = null; TableMemberInfo infoParent = null; TableMemberInfo infoSelect = null; int level = tmInfo.GetLevel(); for (int i = 0; i < level; i++) { infoParent = tmInfo.GetParent(level - i); infoSelect = MemberExists.FindInfo(infoParent.Parent); if (MemberExists.FindInfo(infoParent) == null) { item = DBInterface.CreateInstance(infoParent.PropertyType, infoParent, infoSelect, treeExist, MemberExists); } } return(item); }
/// <summary> /// Изменение позиции записи в дереве. /// </summary> private void SetNodeIndex(int inc) { if (treeExist.Selection.Count > 0) { TreeListNode node = treeExist.Selection[0]; int index = treeExist.GetNodeIndex(node); treeExist.SetNodeIndex(node, index + inc); TableMemberInfo tmInfo = treeExist.GetDataRecordByNode(node) as TableMemberInfo; if (tmInfo != null && tmInfo.Item != null) { DBInterfaceItemBases dbItems = tmInfo.Item.Owner; if (0 <= index + inc && index + inc < dbItems.Count) { DBInterfaceItemBases dbBuffs = new DBInterfaceItemBases(); dbItems.CopyTo(dbBuffs); dbItems.Clear(); dbBuffs.Change(index, index + inc); dbBuffs.CopyTo(dbItems); //dbItems.CorrectVisibleIndex(); } } } }
/// <summary> /// Добавление дочерней записи. /// </summary> public void Add(TableMemberInfo item) { Items.Add(item); }
/// <summary> /// Очистка всех вложеннных записей. /// </summary> private void EraseExistDate(TableMemberInfo tmInfo) { EraseExistDate(tmInfo, 1); }