public void ParentRefresh() { if (ParentViewModel != null) { ParentViewModel.RefreshData(); } }
//private void ShowValidationError(string message) //{ // GetViewService().ShowDialog(StringResources.Error // , string.Format("{0}{1}{2}", typeof(CustomParam).GetDisplayName() + ":", Environment.NewLine, string.Format(DCL.Resources.StringResources.CpCountValidationFormat, message)) // , MessageBoxButton.OK // , MessageBoxImage.Error // , MessageBoxResult.Yes); //} private void OnEdit(EditableBusinessObject selectedItem) { var modelType = typeof(CustomParamValueTreeViewModel <>).MakeGenericType(_itemType); var model = (ICustomParamValueTreeViewModel)IoC.Instance.Resolve(modelType, null); model.Mode = ObjectListMode.LookUpList3Points; model.AutoExpandAllNodes = true; var cpv = (CustomParamValue)Activator.CreateInstance(_itemType); model.KeyPropertyName = cpv.GetPrimaryKeyPropertyName(); model.ParentIdPropertyName = cpv.ChangePropertyName(CustomParamValue.CPVParentPropertyName); model.CpEntity = SourceNameHelper.Instance.GetSourceName(_parentViewModelSource.GetType()).ToUpper(); model.CpKey = _parentViewModelSource.GetKey().To <string>(); model.ShouldUpdateSeparately = ShouldUpdateSeparately; model.SelectedItem = selectedItem; model.MandantCode = (string)(_parentViewModelSource.ContainsProperty("VMANDANTCODE") ? _parentViewModelSource.GetProperty("VMANDANTCODE") : null); if (_parentViewModelSource != null) { model.ParentViewModelSource = _parentViewModelSource; } if (model.CustomFilters != null) { model.ApplyFilter(null); } var issourceupdated = false; EventHandler onSourceUpdatedHandler = (s, e) => { issourceupdated = true; }; try { model.SourceUpdated += onSourceUpdatedHandler; GetViewService() .ShowDialogWindow(viewModel: model, isRestoredLayout: true, isNotNeededClosingOnOkResult: false, noButtons: true, noActionOnCancelKey: false, height: "50%", width: "65%"); if (issourceupdated) { if (ShouldUpdateSeparately) { if (ParentViewModel != null) { ParentViewModel.RefreshData(); } } else { //TODO: Надо доделывать для этого режима Source = (IList)model.GetSource(); } } } finally { model.SourceUpdated -= onSourceUpdatedHandler; } }
private void OnDelete() { if (!ConnectionManager.Instance.AllowRequest()) { return; } if (!CanDelete()) { return; } try { if (GetViewService().ShowDialog(StringResources.Confirmation , StringResources.ConfirmationDeleteObject , MessageBoxButton.YesNo , MessageBoxImage.Question , MessageBoxResult.Yes) != MessageBoxResult.Yes) { return; } var selectedItem = (CustomParamValue)CurrentItem; var deletes = CpvHelper.GetChildsCpvByParentCpv <CustomParamValue>(Source.Cast <CustomParamValue>(), selectedItem, true); if (ShouldUpdateSeparately) { var uowFactory = IoC.Instance.Resolve <IUnitOfWorkFactory>(); using (var uow = uowFactory.Create(false)) { try { uow.BeginChanges(); var mng = GetManager(_itemType); mng.SetUnitOfWork(uow); foreach (var p in deletes) { mng.Delete(p); } mng.Delete(CurrentItem); uow.CommitChanges(); } catch { uow.RollbackChanges(); throw; } } if (ParentViewModel != null) { ParentViewModel.RefreshData(); } } else { foreach (var p in deletes) { Source.Remove(p); } Source.Remove(CurrentItem); } } catch (Exception ex) { throw new OperationException(ExceptionResources.ItemCantDelete, ex); } }