public void AddRole(object button) { var info = GridPopupMenuBase.GetGridMenuInfo((DependencyObject)button) as GridMenuInfo; string roleName = string.Empty; var bulkEditStringsViewModel = BulkEditStringsViewModel.Create(roleName); if (AddRoleDialogService.ShowDialog(MessageButton.OKCancel, "Add new role", "BulkEditStrings", bulkEditStringsViewModel) == MessageResult.OK) { if (bulkEditStringsViewModel.EditValue != null) { roleName = (string)bulkEditStringsViewModel.EditValue; } ROLE newROLE = new ROLE() { NAME = roleName, SORTORDER = 0, PARENTGUID = Guid.Empty }; string errorMessage = string.Empty; if (ROLECollection.IsValidEntity(newROLE, ref errorMessage)) { ROLECollection.Save(newROLE); } else { MessageBoxService.ShowMessage(errorMessage + " already exists", "Error", MessageButton.OK, MessageIcon.Error); } } }
public void AutoPopulate(object button) { MainViewModel.EntitiesUndoRedoManager.PauseActionId(); var info = GridPopupMenuBase.GetGridMenuInfo((DependencyObject)button) as GridMenuInfo; string departmentFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DEPARTMENT); string disciplineFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DISCIPLINE); string docTypeFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DOCTYPE); string areaFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_AREA); string workpackFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_WORKPACK); string internalNumberFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().INTERNAL_NUM); List <BASELINE_ITEMProjection> entitiesToSave = new List <BASELINE_ITEMProjection>(); if (info.Column.FieldName == internalNumberFieldName) { foreach (BASELINE_ITEMProjection entity in MainViewModel.SelectedEntities) { entity.BASELINE_ITEM.INTERNAL_NUM = string.Empty; } } foreach (BASELINE_ITEMProjection entity in MainViewModel.SelectedEntities) { WORKPACK entityWORKPACK = WORKPACKCollection.FirstOrDefault(x => x.GUID == entity.BASELINE_ITEM.GUID_WORKPACK); if (info.Column.FieldName == internalNumberFieldName) { string internalNum = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(loadPROJECT, MainViewModel.Entities, entity.BASELINE_ITEM.AREA, entity.BASELINE_ITEM.DISCIPLINE, entity.BASELINE_ITEM.DOCTYPE, entity.GUID); MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, internalNum); entitiesToSave.Add(entity); } else if (info.Column.FieldName == departmentFieldName || info.Column.FieldName == disciplineFieldName || info.Column.FieldName == docTypeFieldName || info.Column.FieldName == areaFieldName) { if (entityWORKPACK == null) { continue; } if (info.Column.FieldName == departmentFieldName) { MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDEPARTMENT); } else if (info.Column.FieldName == disciplineFieldName) { MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDISCIPLINE); } else if (info.Column.FieldName == docTypeFieldName) { MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDOCTYPE); } else if (info.Column.FieldName == areaFieldName) { MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DAREA); } entitiesToSave.Add(entity); } else if (info.Column.FieldName == workpackFieldName) { if (entity.BASELINE_ITEM.GUID_DISCIPLINE == Guid.Empty || entity.BASELINE_ITEM.GUID_DEPARTMENT == Guid.Empty || entity.BASELINE_ITEM.GUID_DOCTYPE == Guid.Empty || entity.BASELINE_ITEM.GUID_AREA == Guid.Empty) { continue; } WORKPACK findWORKPACK = WORKPACKCollection.FirstOrDefault(x => x.GUID_DDEPARTMENT == entity.BASELINE_ITEM.GUID_DEPARTMENT && x.GUID_DDISCIPLINE == entity.BASELINE_ITEM.GUID_DISCIPLINE); if (findWORKPACK == null) { WORKPACK newWORKPACK = new WORKPACK(); newWORKPACK.GUID_PROJECT = loadPROJECT.GUID; newWORKPACK.GUID_DAREA = (Guid)entity.BASELINE_ITEM.GUID_AREA; if (entity.BASELINE_ITEM.GUID_PHASE != null) { newWORKPACK.GUID_DPHASE = entity.BASELINE_ITEM.GUID_PHASE; } newWORKPACK.GUID_DDISCIPLINE = (Guid)entity.BASELINE_ITEM.GUID_DISCIPLINE; newWORKPACK.GUID_DDEPARTMENT = (Guid)entity.BASELINE_ITEM.GUID_DEPARTMENT; newWORKPACK.GUID_DDOCTYPE = (Guid)entity.BASELINE_ITEM.GUID_DOCTYPE; newWORKPACK.INTERNAL_NAME1 = BluePrintDataUtils.WORKPACK_Generate_InternalNumber1(loadPROJECT, newWORKPACK, WORKPACKCollection, loaderCollection.GetViewModel <AREA>(), loaderCollection.GetViewModel <DISCIPLINE>(), loaderCollection.GetViewModel <DOCTYPE>()); newWORKPACK.INTERNAL_NAME2 = BluePrintDataUtils.WORKPACK_Generate_InternalNumber2(loadPROJECT, newWORKPACK, WORKPACKCollection, loaderCollection.GetViewModel <AREA>(), loaderCollection.GetViewModel <DISCIPLINE>(), loaderCollection.GetViewModel <PHASE>()); newWORKPACK.STARTDATE = DateTime.Now; newWORKPACK.ENDDATE = BluePrintDataUtils.WORKPACK_Calculate_EndDate(newWORKPACK.STARTDATE, loadPROJECT); DateTime reviewStartDate = newWORKPACK.STARTDATE; DateTime reviewEndDate = newWORKPACK.ENDDATE; BluePrintDataUtils.WORKPACK_Calculate_ReviewPeriod(ref reviewStartDate, ref reviewEndDate, loadPROJECT, false); newWORKPACK.REVIEWSTARTDATE = reviewStartDate; newWORKPACK.REVIEWENDDATE = reviewEndDate; newWORKPACK.AUTOGENERATED = true; ((CollectionViewModel <WORKPACK, WORKPACK, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <WORKPACK>()).Save(newWORKPACK); MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, newWORKPACK.GUID); } else { MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, findWORKPACK.GUID); } entitiesToSave.Add(entity); } } MainViewModel.BulkSave(entitiesToSave); MainViewModel.EntitiesUndoRedoManager.UnpauseActionId(); }