void MaterialRDEControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var mat = DataContext as RDEMaterialViewModel; if (mat != null) { this.IsEnabled = true; if (_currentMaterial != null) { // although the database actions are registered for new/modified traits, we need to keep track of them so we can // redisplay them as the user flips around the different material. _currentMaterial.Traits = _traits.GetModel(); _currentMaterial.Multimedia = _multimedia.GetModel(); } _traits.BindModel(mat.Traits, mat); _currentMaterial = mat; _multimedia.BindModel(mat.Multimedia, mat); grpSubParts.Items = _currentMaterial.SubParts; _subpartsFull.SetModel(_currentMaterial, _currentMaterial.SubParts); _associates.SetModel(_currentMaterial, _currentMaterial.Associates); } else { this.IsEnabled = false; } }
private ObservableCollection<ViewModelBase> CreateMaterialViewModels(IEnumerable<RDEMaterial> material, RDESiteVisitViewModel siteVisit) { var supportService = new SupportService(User); siteVisit.Material.Clear(); return new ObservableCollection<ViewModelBase>(material.Select(m => { var vm = new RDEMaterialViewModel(m); vm.Traits = supportService.GetTraits(TraitCategoryType.Material.ToString(), vm.MaterialID); vm.Multimedia = supportService.GetMultimediaItems(TraitCategoryType.Material.ToString(), vm.MaterialID); vm.DataChanged += MaterialViewModelDataChanged; vm.SiteVisit = siteVisit; vm.SiteVisitID = siteVisit.SiteVisitID; siteVisit.Material.Add(vm); vm.Locked = !User.HasPermission(PermissionCategory.SPARC_MATERIAL, PERMISSION_MASK.UPDATE) || _startLockMode; return (ViewModelBase)vm; })); }
private void LoadMaterialTemplate(int templateId) { var supportService = new SupportService(User); var service = new MaterialService(User); var list = service.GetRDEMaterial(new[] { templateId }); if (list != null && list.Count > 0) { _materialTemplate = new RDEMaterialViewModel(list[0]); _materialTemplate.Traits = supportService.GetTraits(TraitCategoryType.Material.ToString(), _materialTemplate.MaterialID); // need to get associates and subparts... var subparts = service.GetMaterialParts(templateId); var associates = supportService.GetAssociates(TraitCategoryType.Material.ToString(), templateId); foreach (Associate assoc in associates) { var vm = new AssociateViewModel(assoc); _materialTemplate.Associates.Add(vm); } foreach (MaterialPart part in subparts) { var vm = new MaterialPartViewModel(part); _materialTemplate.SubParts.Add(vm); } } if (_materialTemplate != null) { mnuSetMaterialTemplate.Header = String.Format("Set _Material Template ({0}) ...", _materialTemplate.MaterialName); Config.SetProfile(User, ConfigMaterialTemplateId, templateId); } else { mnuSetMaterialTemplate.Header = "Set _Material Template..."; Config.SetProfile(User, ConfigMaterialTemplateId, -1); } }
private RDEMaterialViewModel AddNewMaterial(RDESiteVisitViewModel siteVisit) { if (siteVisit != null) { // create the new material... List<Trait> traits; List<Associate> associates; List<MaterialPart> subparts; var material = CreateNewMaterial(out traits, out associates, out subparts); var materialViewModel = new RDEMaterialViewModel(material); RegisterPendingChange(new InsertRDEMaterialCommand(material, siteVisit.Model)); RegisterUniquePendingChange(new UpdateRDEMaterialCommand(material) { SuccessAction = () => { materialViewModel.MaterialName = material.MaterialName; } }); if (traits != null && traits.Count > 0) { foreach (Trait t in traits) { materialViewModel.Traits.Add(t); RegisterPendingChange(new UpdateTraitDatabaseCommand(t, materialViewModel)); } } if (associates != null && associates.Count > 0) { foreach (Associate a in associates) { var vm = new AssociateViewModel(a); vm.DataChanged += AssociateDataChanged; materialViewModel.Associates.Add(vm); RegisterPendingChange(new InsertAssociateCommand(a, materialViewModel)); } } if (subparts != null && subparts.Count > 0) { foreach (MaterialPart subpart in subparts) { var vm = new MaterialPartViewModel(subpart); vm.DataChanged +=SubPartDataChanged; materialViewModel.SubParts.Add(vm); RegisterPendingChange(new InsertMaterialPartCommand(subpart, materialViewModel)); } } else { // Add one subpart... var subpart = new MaterialPartViewModel(new MaterialPart()) {MaterialPartID = -1, PartName = "<New>"}; materialViewModel.SubParts.Add(subpart); RegisterPendingChange(new InsertMaterialPartCommand(subpart.Model, materialViewModel)); } materialViewModel.SiteVisit = siteVisit; materialViewModel.SiteVisitID = siteVisit.SiteVisitID; siteVisit.Material.Add(materialViewModel); materialViewModel.DataChanged +=MaterialViewModelDataChanged; return materialViewModel; } return null; }