internal override bool Perform() { DataGridViewRow changedRow = _dgvCategories.Rows[_eventArgs.RowIndex]; VarConfig.CategoryRow categoryRow = changedRow.Tag as VarConfig.CategoryRow; string newValue = changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString(); if (_eventArgs.ColumnIndex == _dgvCategories.Columns.IndexOf(_variablesForm.colCategoryValue)) { if (categoryRow.Value == newValue) { return(false); //only change if different } if (!EM_Helpers.IsNumeric(newValue)) { if (Tools.UserInfoHandler.GetInfo(newValue + " is not numeric.\n\nUndo change?", MessageBoxButtons.YesNo) == DialogResult.Yes) { _variablesForm._acronymManager.FillCategoriesList(_variablesForm.treeAcronyms.FocusedNode); return(false); } } categoryRow.Value = newValue; } else if (_eventArgs.ColumnIndex == _dgvCategories.Columns.IndexOf(_variablesForm.colCategoryDescription)) { if (categoryRow.Description == newValue) { return(false); //only change if different } categoryRow.Description = 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 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 (_dgvCategories.SelectedRows.Count == 0) { return(false); } categStateChanged = _dgvCategories.Rows.Count == _dgvCategories.SelectedRows.Count; foreach (DataGridViewRow row in _dgvCategories.SelectedRows) { VarConfig.CategoryRow categoryRow = row.Tag as VarConfig.CategoryRow; categoryRow.Delete(); } _acronymManager.FillCategoriesList(_treeAcronyms.FocusedNode); 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; } } }
internal void CopyCategoryRow(VarConfig.CategoryRow originalCategory, VarConfig.AcronymRow parentAcronym) { _varConfig.Category.AddCategoryRow(parentAcronym, originalCategory.Value, originalCategory.Description); }