internal VarConfig.AcronymRow AddAcronymRow(VarConfig.AcronymLevelRow parentRow, string acronym = "", string description = "") { string guid = Guid.NewGuid().ToString(); _guidsOfNewRows.Add(guid); return(_varConfig.Acronym.AddAcronymRow(guid, parentRow, acronym, description)); }
VarConfig.AcronymLevelRow GetAddAferLevel(VarConfig.AcronymTypeRow internalType, VarConfig.AcronymLevelRow externalLevel) {//find the level after which to insert the new level //first collect all levels before the new level in the external type ... List <VarConfig.AcronymLevelRow> preRows = new List <VarConfig.AcronymLevelRow>(); foreach (VarConfig.AcronymLevelRow externalSiblingLevel in externalLevel.AcronymTypeRow.GetAcronymLevelRows()) { if (externalSiblingLevel.Index < externalLevel.Index) { preRows.Add(externalSiblingLevel); } } preRows = (from preRow in preRows select preRow).OrderBy(preRow => preRow.Index).ToList(); //... and order them by index //then try to find the (equivalent of the) new level's direct predecessor in the internal type, //if found - this is the level where to add the new one after, if not found - try with the next to the direct predecessor, and so on VarConfig.AcronymLevelRow addAfterLevel = null; for (int index = preRows.Count - 1; index >= 0; --index) { foreach (VarConfig.AcronymLevelRow internalSiblingLevel in internalType.GetAcronymLevelRows()) { if (internalSiblingLevel.Name.ToLower() == preRows.ElementAt(index).Name.ToLower()) { addAfterLevel = internalSiblingLevel; break; } } if (addAfterLevel != null) { break; } } return(addAfterLevel); }
internal override bool Perform() { if (_treeAcronyms.FocusedNode == null) { return(false); } TreeListNode addAfterNode = null; TreeListNode parentNode = null; //assess where level should be inserted with respect to which node is focused ... if (AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode)) { parentNode = _treeAcronyms.FocusedNode; //... type node: insert as first level } else if (AcronymManager.IsLevelNode(_treeAcronyms.FocusedNode)) { addAfterNode = _treeAcronyms.FocusedNode; //... (other) level node: insert after this level parentNode = addAfterNode.ParentNode; } else if (AcronymManager.IsAcronymNode(_treeAcronyms.FocusedNode)) { addAfterNode = _treeAcronyms.FocusedNode.ParentNode; //... acronym node: insert after the level of the acronym parentNode = addAfterNode.ParentNode; } //first append the new node ... TreeListNode node = _treeAcronyms.AppendNode(null, parentNode); VarConfig.AcronymLevelRow addAfterRow = null; if (addAfterNode != null) { addAfterRow = addAfterNode.Tag as VarConfig.AcronymLevelRow; } node.Tag = _varConfigFacade.AddAcronymLevelRow(parentNode.Tag as VarConfig.AcronymTypeRow, addAfterRow); //... then move ... int pos = -1; if (addAfterNode == null) { pos = 0; //... at front, if type node was selected } else if (addAfterNode.NextNode != null) //... after the focused node, if level- or acronym-node selected { pos = addAfterNode.ParentNode.Nodes.IndexOf(addAfterNode.NextNode); } if (pos >= 0) { _treeAcronyms.SetNodeIndex(node, pos); } parentNode.Expanded = true; return(true); }
TreeListNode AcronymTree_AddNode(TreeListNode parentNode, object nodeTag, string action = "") { TreeListNode node = treeAcronyms.AppendNode(null, parentNode); if (action == string.Empty) { node.SetValue(colPerformAcronyms, string.Empty); //do not show check box if just "header", e.g. type containing added/deleted/changed acronyms/levels, but not changed itself } else { node.SetValue(colPerformAcronyms, _actionDefaultPerform); } node.SetValue(colActionAcronyms, action); node.SetValue(colInfoAcronyms, string.Empty); node.Tag = nodeTag; //somewhat unelegant procedure, which serves only to determin the content of colAcronym string acronymText = string.Empty; VarConfig.AcronymTypeRow typeRow = null; VarConfig.AcronymLevelRow levelRow = null; VarConfig.AcronymRow acronymRow = null; bool tagIsDictionary = action == _actionChange || action == string.Empty; if (parentNode == null) { typeRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymTypeRow : (nodeTag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0); } else if (parentNode != null && parentNode.ParentNode == null) { levelRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymLevelRow : (nodeTag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0); } else { acronymRow = !tagIsDictionary ? nodeTag as VarConfig.AcronymRow : (nodeTag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Keys.ElementAt(0); } if (typeRow != null) { acronymText = typeRow.ShortName.ToUpper() + " (" + typeRow.LongName + ")"; } if (levelRow != null) { acronymText = levelRow.Name; } if (acronymRow != null) { acronymText = acronymRow.Name + " (" + acronymRow.Description + ")"; } node.SetValue(colAcronym, acronymText); return(node); }
internal static bool IsLevelNode(TreeListNode node) { if (node == null || node.Tag == null) { return(false); } VarConfig.AcronymLevelRow levelRow = node.Tag as VarConfig.AcronymLevelRow; return(levelRow != null); }
void PerformAddAcronym(VarConfig.AcronymLevelRow internalLevel, VarConfig.AcronymRow externalAcronym) { VarConfig.AcronymRow internalAcronym = _varConfigFacade.AddAcronymRow(internalLevel, externalAcronym.Name, externalAcronym.Description); foreach (VarConfig.CategoryRow externalCategory in externalAcronym.GetCategoryRows()) { _varConfigFacade.AddCategoryRow(internalAcronym, externalCategory.Value, externalCategory.Description); } _varConfigFacade.Commit(); }
VarConfig.AcronymLevelRow PerformAddLevel(VarConfig.AcronymTypeRow internalType, VarConfig.AcronymLevelRow externalLevel, VarConfig.AcronymLevelRow addAfterRow) { VarConfig.AcronymLevelRow internalLevel = _varConfigFacade.AddAcronymLevelRow(internalType, addAfterRow, externalLevel.Name); //todo: null is not correct foreach (VarConfig.AcronymRow externalAcronym in externalLevel.GetAcronymRows()) { PerformAddAcronym(internalLevel, externalAcronym); } _varConfigFacade.Commit(); return(internalLevel); }
void PerformAddType(VarConfig.AcronymTypeRow externalType) { VarConfig.AcronymTypeRow internalType = _varConfigFacade.AddAcronymTypeRow(externalType.LongName, externalType.ShortName); VarConfig.AcronymLevelRow addAfterRow = null; foreach (VarConfig.AcronymLevelRow externalLevel in _importVariablesForm._externalVarConfigFacade.GetAcronymLevelsSortedByIndex(externalType)) { addAfterRow = PerformAddLevel(internalType, externalLevel, addAfterRow); } _varConfigFacade.Commit(); }
void DisplayUnusedAcronyms(bool expand) //... as assessed in CheckForUnusedAcronyms { treeAcronyms.BeginUnboundLoad(); //store which nodes are expanded, the focused node and the first visible node List <string> expandedNodesIDs = new List <string>(); string focusedNodeID = string.Empty; string topVisibleNodeID = string.Empty; AcronymManager.StoreNodeStates(treeAcronyms, ref expandedNodesIDs, ref focusedNodeID, ref topVisibleNodeID); treeAcronyms.Nodes.Clear(); TreeListNode typeNode = null; TreeListNode levelNode = null; foreach (VarConfig.AcronymRow acroRow in _acronymsToDisplay) { VarConfig.AcronymTypeRow typeRow = acroRow.AcronymLevelRow.AcronymTypeRow; if (typeNode == null || !(typeNode.Tag as VarConfig.AcronymTypeRow).Equals(typeRow)) { typeNode = treeAcronyms.AppendNode(null, null); typeNode.SetValue(colAcronym, typeRow.LongName.ToUpper() + " (" + typeRow.ShortName.ToUpper() + ")"); typeNode.Tag = typeRow; } VarConfig.AcronymLevelRow levelRow = acroRow.AcronymLevelRow; if (levelNode == null || !(levelNode.Tag as VarConfig.AcronymLevelRow).Equals(levelRow)) { levelNode = treeAcronyms.AppendNode(null, typeNode); levelNode.SetValue(colAcronym, levelRow.Name); levelNode.Tag = levelRow; } TreeListNode acroNode = treeAcronyms.AppendNode(null, levelNode); acroNode.SetValue(colAcronym, acroRow.Description + " (" + acroRow.Name.ToUpper() + ")"); acroNode.SetValue(colDeleteAcronyms, true); acroNode.Tag = acroRow; } //restore collapse/expanded, focused and first visible node states AcronymManager.RestoreNodeStates(treeAcronyms, expandedNodesIDs, focusedNodeID, topVisibleNodeID); treeAcronyms.EndUnboundLoad(); colAcronym.BestFit(); colDeleteAcronyms.BestFit(); if (expand) { treeAcronyms.ExpandAll(); //initially, i.e. if called from btnLoad_Click, expand all nodes } }
internal override bool Perform() { string newValue = _eventArgs.Value.ToString(); VarConfig.AcronymLevelRow levelRow = _eventArgs.Node.Tag as VarConfig.AcronymLevelRow; if (newValue == levelRow.Name) { return(false); //only change if different } levelRow.Name = newValue; return(true); }
short AssessAcroLevel(string ID, bool local, out DataRow dataRow, List <string> allIDs = null) { VarConfigFacade _vcFac = local ? _vcFacLocal : _vcFacRemote; dataRow = _vcFac.GetAcronymTypeByID(ID); if (dataRow != null) { return(LEVEL_ACROTYPE); } VarConfig.AcronymLevelRow acroLevel = _vcFac.GetAcronymLevelByID(ID); if (acroLevel != null) { if (allIDs != null && allIDs.Contains(acroLevel.AcronymTypeRow.ID)) { return(LEVEL_INVALID); //the level is already taken into account, by the action on type-level (e.g. deleted via the type instead of individually) } dataRow = acroLevel; return(LEVEL_ACROLEVEL); } VarConfig.AcronymRow acro = _vcFac.GetAcronymByID(ID); if (acro != null) { if (allIDs != null && (allIDs.Contains(acro.AcronymLevelRow.ID) || allIDs.Contains(acro.AcronymLevelRow.AcronymTypeRow.ID))) { return(LEVEL_INVALID); //see comment above } dataRow = acro; return(LEVEL_ACRO); } if (!ID.Contains("#")) { return(LEVEL_INVALID); } string catValue = ID.Split(new string[] { "#" }, StringSplitOptions.None)[0]; string acroID = ID.Split(new string[] { "#" }, StringSplitOptions.None)[1]; VarConfig.CategoryRow categ = _vcFac.GetCategoryByKey(acroID, catValue); if (categ != null) { if (allIDs != null && (allIDs.Contains(categ.AcronymRow.ID) || allIDs.Contains(categ.AcronymRow.AcronymLevelRow.ID) || allIDs.Contains(categ.AcronymRow.AcronymLevelRow.AcronymTypeRow.ID))) { return(LEVEL_INVALID); //see comment above } dataRow = categ; return(LEVEL_ACROCAT); } dataRow = null; return(LEVEL_INVALID); }
void PerformClean() { try { //delete checked variables foreach (DataGridViewRow variableRow in dgvVariables.Rows) { if (EM_Helpers.SaveConvertToBoolean(variableRow.Cells[colDeleteVariables.Name].Value) == true) { (variableRow.Tag as VarConfig.VariableRow).Delete(); } } _varConfigFacade.Commit(); //delete checked acronyms foreach (TreeListNode typeNode in treeAcronyms.Nodes) { foreach (TreeListNode levelNode in typeNode.Nodes) { foreach (TreeListNode acroNode in levelNode.Nodes) { if (EM_Helpers.SaveConvertToBoolean(acroNode.GetValue(colDeleteAcronyms))) { (acroNode.Tag as VarConfig.AcronymRow).Delete(); } } _varConfigFacade.Commit(); VarConfig.AcronymLevelRow levelRow = levelNode.Tag as VarConfig.AcronymLevelRow; if (levelRow.GetAcronymRows().Count() == 0) { levelRow.Delete(); //delete level if all contained acronyms were deleted } } _varConfigFacade.Commit(); VarConfig.AcronymTypeRow typeRow = typeNode.Tag as VarConfig.AcronymTypeRow; if (typeRow.GetAcronymLevelRows().Count() == 0) { typeRow.Delete(); //delete type if all contained levels (and acronyms) were deleted (not very likely to happen) } _varConfigFacade.Commit(); } } catch (Exception exception) { Tools.UserInfoHandler.ShowException(exception); } }
void AddAcros(bool local) { List <string> addIDs = GetRelevantIDs(_mcAcronyms, local, true); foreach (string ID in addIDs) { DataRow dataRow; switch (AssessAcroLevel(ID, false, out dataRow)) { case LEVEL_INVALID: continue; //should not happen case LEVEL_ACROTYPE: VarConfig.AcronymTypeRow acroType = dataRow as VarConfig.AcronymTypeRow; _vcFacLocal.CopyAcronymTypeRow(acroType); //note: this copies without content (i.e. without included levels, their acronyms and their categories (which may have been refused)) break; case LEVEL_ACROLEVEL: VarConfig.AcronymLevelRow acroLevel = dataRow as VarConfig.AcronymLevelRow; VarConfig.AcronymTypeRow parentType = _vcFacLocal.GetAcronymTypeByID(acroLevel.AcronymTypeRow.ID); if (parentType != null) //possible though non-sense (see comment below) { _vcFacLocal.CopyAcronymLevelRow(acroLevel, parentType); //see note above (i.e. included acronyms and their categories are not copied) } break; case LEVEL_ACRO: VarConfig.AcronymRow acro = dataRow as VarConfig.AcronymRow; VarConfig.AcronymLevelRow parentLevel = _vcFacLocal.GetAcronymLevelByID(acro.AcronymLevelRow.ID); if (parentLevel != null) //possible though non-sense (see comment below) { _vcFacLocal.CopyAcronymRow(acro, parentLevel); //see note above (i.e. included categories are not copied) } break; case LEVEL_ACROCAT: VarConfig.CategoryRow categ = dataRow as VarConfig.CategoryRow; VarConfig.AcronymRow parentAcro = _vcFacLocal.GetAcronymByID(categ.AcronymRow.ID); if (parentAcro != null) //may happen if (though non-sense) copying acro was refused while copying category was accepted { _vcFacLocal.CopyCategoryRow(categ, parentAcro); } break; } } _vcFacLocal.GetVarConfig().AcceptChanges(); }
internal override bool Perform() { if (!AcronymManager.IsLevelNode(_treeAcronyms.FocusedNode)) { return(false); } VarConfig.AcronymLevelRow levelRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymLevelRow; string usage = string.Empty; List <VarConfig.AcronymRow> usedAcronymRows = new List <VarConfig.AcronymRow>(); foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(levelRow.AcronymTypeRow.ShortName)) { if (levelRow.Name.ToLower() != acronymRow.AcronymLevelRow.Name.ToLower()) { continue; } string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, levelRow.AcronymTypeRow.ShortName); if (usingVariables != string.Empty) { usedAcronymRows.Add(acronymRow); usage += acronymRow.Name + " used by " + usingVariables + "\n"; } } if (usage != string.Empty) { if (Tools.UserInfoHandler.GetInfo("The following acronyms of this level are used:\n" + usage + "\nCancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes) { return(false); } foreach (VarConfig.AcronymRow usedAcronymRow in usedAcronymRows) { usedAcronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels } _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronymRows); } levelRow.Delete(); return(true); }
void ChangeAcros(bool local) { foreach (MergeControl.NodeInfo nodeInfo in local ? _mcAcronyms.GetNodeInfoLocal() : _mcAcronyms.GetNodeInfoRemote()) { if (nodeInfo.changeType != MergeControl.ChangeType.changed || nodeInfo.changeHandling == (local ? MergeControl.ChangeHandling.accept : MergeControl.ChangeHandling.reject)) { continue; //not relevant, because neither changed nor locally accepted nor remotely rejected } const string NOT_CHANGED = "NOT_CHANGED"; MergeControl.CellInfo cellInfo = nodeInfo.cellInfo.First(); MergeControl.CellInfo cellInfoRemote = local ? _mcAcronyms.GetTwinCellInfo(cellInfo) : cellInfo; string changedName = (cellInfo.isChanged && (local ? !cellInfo.acceptChange : cellInfo.acceptChange)) //if name is changed and remotely accepted or locally rejected ? cellInfoRemote.text : NOT_CHANGED; //change to remote name (otherwise mark not changed) cellInfo = nodeInfo.cellInfo.Last(); cellInfoRemote = local ? _mcAcronyms.GetTwinCellInfo(cellInfo) : cellInfo; string changedDesc = (cellInfo.isChanged && (local ? !cellInfo.acceptChange : cellInfo.acceptChange)) //if description is changed and remotely accepted or locally rejected ? cellInfoRemote.text : NOT_CHANGED; //change to remote description (otherwise mark not changed) DataRow dataRow; switch (AssessAcroLevel(nodeInfo.ID, true, out dataRow)) { case LEVEL_INVALID: continue; //should not happen case LEVEL_ACROTYPE: VarConfig.AcronymTypeRow acroType = dataRow as VarConfig.AcronymTypeRow; if (changedName != NOT_CHANGED) { acroType.ShortName = changedName; } if (changedDesc != NOT_CHANGED) { acroType.LongName = changedDesc; } break; case LEVEL_ACROLEVEL: VarConfig.AcronymLevelRow acroLevel = dataRow as VarConfig.AcronymLevelRow; if (changedName != NOT_CHANGED) { acroLevel.Index = Convert.ToInt32(changedName); //probably not relevant } if (changedDesc != NOT_CHANGED) { acroLevel.Name = changedDesc; } break; case LEVEL_ACRO: VarConfig.AcronymRow acro = dataRow as VarConfig.AcronymRow; if (changedName != NOT_CHANGED) { acro.Name = changedName; } if (changedDesc != NOT_CHANGED) { acro.Description = changedDesc; } break; case LEVEL_ACROCAT: VarConfig.CategoryRow categ = dataRow as VarConfig.CategoryRow; if (changedName != NOT_CHANGED) { categ.Value = changedName; } if (changedDesc != NOT_CHANGED) { categ.Description = changedDesc; } break; } } }
void PerformChangeLevel(VarConfig.AcronymLevelRow internalLevel, VarConfig.AcronymLevelRow externalLevel) { //this type of change does not exist (currently) }
void PerformImportNode(TreeListNode node, short nodeType) { string action = node.GetValue(_importVariablesForm.colActionAcronyms).ToString(); bool perform = false; if (action != string.Empty) { perform = EM_Helpers.SaveConvertToBoolean(node.GetValue(_importVariablesForm.colPerformAcronyms)); } if (!perform) { return; } switch (nodeType) { case _typeNode: switch (action) { case ImportVariablesForm._actionAdd: PerformAddType(node.Tag as VarConfig.AcronymTypeRow); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymTypeRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeType((node.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Values.ElementAt(0)); break; } break; case _levelNode: switch (action) { case ImportVariablesForm._actionAdd: VarConfig.AcronymTypeRow internalType = (node.ParentNode.Tag as Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>).Keys.ElementAt(0); VarConfig.AcronymLevelRow externalLevel = node.Tag as VarConfig.AcronymLevelRow; PerformAddLevel(internalType, externalLevel, GetAddAferLevel(internalType, externalLevel)); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymLevelRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeLevel((node.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Values.ElementAt(0)); break; } break; case _acronymNode: switch (action) { case ImportVariablesForm._actionAdd: PerformAddAcronym((node.ParentNode.Tag as Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>).Keys.ElementAt(0), node.Tag as VarConfig.AcronymRow); break; case ImportVariablesForm._actionDelete: (node.Tag as VarConfig.AcronymRow).Delete(); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: PerformChangeAcronym((node.Tag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Keys.ElementAt(0), (node.Tag as Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>).Values.ElementAt(0), node.GetValue(_importVariablesForm.colInfoAcronyms).ToString()); break; } break; } }
internal void CopyAcronymRow(VarConfig.AcronymRow originalAcronym, VarConfig.AcronymLevelRow parentLevel) { _varConfig.Acronym.AddAcronymRow(originalAcronym.ID, parentLevel, originalAcronym.Name, originalAcronym.Description); }
internal void CopyAcronymLevelRow(VarConfig.AcronymLevelRow originalLevel, VarConfig.AcronymTypeRow parentType) { _varConfig.AcronymLevel.AddAcronymLevelRow(originalLevel.ID, originalLevel.Index, parentType, originalLevel.Name); }
internal VarConfig.AcronymLevelRow AddAcronymLevelRow(VarConfig.AcronymTypeRow parentRow, VarConfig.AcronymLevelRow addAfterRow = null, string name = "") { int indexAfter = 0; if (addAfterRow != null) { indexAfter = addAfterRow.Index; } foreach (VarConfig.AcronymLevelRow acronymLevelRow in parentRow.GetAcronymLevelRows()) { if (acronymLevelRow.Index > indexAfter) { ++acronymLevelRow.Index; } } string guid = Guid.NewGuid().ToString(); _guidsOfNewRows.Add(guid); return(_varConfig.AcronymLevel.AddAcronymLevelRow(guid, indexAfter + 1, parentRow, name)); }
internal List <VarConfig.AcronymRow> GetAcronymsOfLevelSortedByName(VarConfig.AcronymLevelRow levelRow) { return((from acronym in levelRow.GetAcronymRows() select acronym).OrderBy(acronym => acronym.Name).ToList()); }
internal static void StoreNodeStates(TreeList treeAcronyms, ref List <string> expandedNodesIDs, ref string focusedNodeID, ref string topVisibleNodeID) { foreach (TreeListNode typeNode in treeAcronyms.Nodes) { VarConfig.AcronymTypeRow typeRow = typeNode.Tag as VarConfig.AcronymTypeRow; if (typeRow.RowState != System.Data.DataRowState.Unchanged) { continue; //happens if tree is redrawn because of an undo action } string typeID = typeRow.ID; if (typeNode.Expanded == true) { expandedNodesIDs.Add(typeID); } if (typeNode.Focused == true) { focusedNodeID = typeID; } if (treeAcronyms.GetVisibleIndexByNode(typeNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = typeID; } foreach (TreeListNode levelNode in typeNode.Nodes) { VarConfig.AcronymLevelRow levelRow = levelNode.Tag as VarConfig.AcronymLevelRow; if (levelRow.RowState != System.Data.DataRowState.Unchanged) { continue; } string levelID = levelRow.ID; if (levelNode.Expanded == true) { expandedNodesIDs.Add(levelID); } if (levelNode.Focused == true) { focusedNodeID = levelID; } if (treeAcronyms.GetVisibleIndexByNode(levelNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = levelID; } foreach (TreeListNode acroNode in levelNode.Nodes) { VarConfig.AcronymRow acroRow = acroNode.Tag as VarConfig.AcronymRow; if (acroRow.RowState != System.Data.DataRowState.Unchanged) { continue; } string acroID = acroRow.ID; if (acroNode.Focused == true) { focusedNodeID = acroID; } if (treeAcronyms.GetVisibleIndexByNode(acroNode) == treeAcronyms.TopVisibleNodeIndex) { topVisibleNodeID = acroID; } } } } }
void FillAcronymsList() { //(1) ACRONYM TYPES: search for elements existing only in one version as well as elements with different descriptions and/or content List <VarConfig.AcronymTypeRow> internalTypes = _internalVarConfigFacade.GetAcronymTypesSortedByShortName(); List <VarConfig.AcronymTypeRow> externalTypes = _externalVarConfigFacade.GetAcronymTypesSortedByShortName(); List <string> internalIDs = (from internalType in internalTypes select internalType.ShortName).ToList(); List <string> externalIDs = (from externalType in externalTypes select externalType.ShortName).ToList(); Dictionary <int, int> compareTypeIndexList = new Dictionary <int, int>(); List <int> addIndexList = new List <int>(); List <int> deleteIndexList = new List <int>(); AnalyseLists(internalIDs, externalIDs, ref compareTypeIndexList, ref addIndexList, ref deleteIndexList); //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(null, externalTypes.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(null, internalTypes.ElementAt(deleteIndex), _actionDelete); } foreach (int internalTypeIndex in compareTypeIndexList.Keys) //elements existent in both version: still have to check for different description and/or content { int externalTypeIndex = compareTypeIndexList[internalTypeIndex]; VarConfig.AcronymTypeRow internalType = internalTypes.ElementAt(internalTypeIndex); VarConfig.AcronymTypeRow externalType = externalTypes.ElementAt(externalTypeIndex); Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow> typeTag = new Dictionary <VarConfig.AcronymTypeRow, VarConfig.AcronymTypeRow>(); typeTag.Add(internalType, externalType); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode typeNode = null; //check for different description (LongName) if (internalType.LongName != externalType.LongName) { typeNode = AcronymTree_AddNode(null, typeTag, _actionChange); typeNode.SetValue(colInfoAcronyms, _infoNewDescription + externalType.LongName); } //check for differnet content, i.e.: //(2) ACRONYM LEVELS: search for elements existing only in one version as well as elements with different content List <VarConfig.AcronymLevelRow> internalLevels = _internalVarConfigFacade.GetAcronymLevelsSortedByName(internalType); List <VarConfig.AcronymLevelRow> externalLevels = _externalVarConfigFacade.GetAcronymLevelsSortedByName(externalType); internalIDs = (from internalLevel in internalLevels select internalLevel.Name).ToList(); externalIDs = (from externalLevel in externalLevels select externalLevel.Name).ToList(); Dictionary <int, int> compareLevelIndexList = new Dictionary <int, int>(); addIndexList.Clear(); deleteIndexList.Clear(); AnalyseLists(internalIDs, externalIDs, ref compareLevelIndexList, ref addIndexList, ref deleteIndexList); if (typeNode == null && (addIndexList.Count != 0 || deleteIndexList.Count != 0)) { typeNode = AcronymTree_AddNode(null, typeTag); //generate parent node if necessary } //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(typeNode, externalLevels.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(typeNode, internalLevels.ElementAt(deleteIndex), _actionDelete); } foreach (int internalLevelIndex in compareLevelIndexList.Keys) //elements existent in both version: still have to check for different content { int externalLevelIndex = compareLevelIndexList[internalLevelIndex]; VarConfig.AcronymLevelRow internalLevel = internalLevels.ElementAt(internalLevelIndex); VarConfig.AcronymLevelRow externalLevel = externalLevels.ElementAt(externalLevelIndex); Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow> levelTag = new Dictionary <VarConfig.AcronymLevelRow, VarConfig.AcronymLevelRow>(); levelTag.Add(internalLevel, externalLevel); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode levelNode = null; //check for differnet content, i.e.: //(3) ACRONYMS: search for elements existing only in one version as well as elements with different description List <VarConfig.AcronymRow> internalAcronyms = _internalVarConfigFacade.GetAcronymsOfLevelSortedByName(internalLevel); List <VarConfig.AcronymRow> externalAcronyms = _externalVarConfigFacade.GetAcronymsOfLevelSortedByName(externalLevel); internalIDs = (from internalAcronym in internalAcronyms select internalAcronym.Name).ToList(); externalIDs = (from externalAcronym in externalAcronyms select externalAcronym.Name).ToList(); Dictionary <int, int> compareAcronymIndexList = new Dictionary <int, int>(); addIndexList.Clear(); deleteIndexList.Clear(); AnalyseLists(internalIDs, externalIDs, ref compareAcronymIndexList, ref addIndexList, ref deleteIndexList); if (addIndexList.Count != 0 || deleteIndexList.Count != 0) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } } //fill the found differences into the tree-control foreach (int addIndex in addIndexList) //elements only existent in external version { AcronymTree_AddNode(levelNode, externalAcronyms.ElementAt(addIndex), _actionAdd); } foreach (int deleteIndex in deleteIndexList) //elements only existent in internal version { AcronymTree_AddNode(levelNode, internalAcronyms.ElementAt(deleteIndex), _actionDelete); } foreach (int internalAcronymIndex in compareAcronymIndexList.Keys) //elements existent in both version: still have to check for different description { int externalAcronymIndex = compareAcronymIndexList[internalAcronymIndex]; VarConfig.AcronymRow internalAcronym = internalAcronyms.ElementAt(internalAcronymIndex); VarConfig.AcronymRow externalAcronym = externalAcronyms.ElementAt(externalAcronymIndex); Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow> acronymTag = new Dictionary <VarConfig.AcronymRow, VarConfig.AcronymRow>(); acronymTag.Add(internalAcronym, externalAcronym); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values TreeListNode acronymNode = null; //check for different description if (internalAcronym.Description != externalAcronym.Description) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } acronymNode = AcronymTree_AddNode(levelNode, acronymTag, _actionChange); acronymNode.SetValue(colInfoAcronyms, _infoNewDescription + externalAcronym.Description); } //check for different categories bool equal = internalAcronym.GetCategoryRows().Count() == externalAcronym.GetCategoryRows().Count(); if (equal) { foreach (VarConfig.CategoryRow internalCategory in internalAcronym.GetCategoryRows()) { bool found = false; foreach (VarConfig.CategoryRow externalCategory in externalAcronym.GetCategoryRows()) { if (internalCategory.Value == externalCategory.Value && internalCategory.Description == externalCategory.Description) { found = true; break; } } if (!found) { equal = false; break; //if one category different, acronym needs to be marked as changed - no need to check all categories here } } } if (!equal) { if (typeNode == null) //generate parent nodes if necessary { typeNode = AcronymTree_AddNode(null, typeTag); } if (levelNode == null) { levelNode = AcronymTree_AddNode(typeNode, levelTag); } string info = _infoChangeCategory; if (acronymNode == null) { acronymNode = AcronymTree_AddNode(levelNode, acronymTag, _actionChange); } else { info = acronymNode.GetDisplayText(colInfoAcronyms) + " + " + _infoChangeCategory; } acronymNode.SetValue(colInfoAcronyms, info); } } } } colPerformAcronyms.BestFit(); colAcronym.BestFit(); colActionAcronyms.BestFit(); colInfoAcronyms.BestFit(); treeAcronyms.ExpandAll(); }