private static void ShowEntityCard(BusinessEntityDescriptor entityDescr) { Contract.Requires(entityDescr != null); Contract.Requires(!string.IsNullOrEmpty(entityDescr.PrimaryKeyDatatype)); Contract.Requires(!string.IsNullOrEmpty(entityDescr.PrimaryKeyValue)); Contract.Requires(!string.IsNullOrEmpty(entityDescr.EntityType)); switch (entityDescr.EntityType.ToLower()) { case "wmsiwb": ShowEntityCardGeneric <IWB>(entityDescr); break; case "wmsowb": ShowEntityCardGeneric <OWB>(entityDescr); break; default: throw new SystemException("Editing of this EntityType is not supported yet: " + entityDescr.EntityType); } }
private static void ShowEntityCardGeneric <T>(BusinessEntityDescriptor entityDescriptor) { var viewService = IoC.Instance.Resolve <IViewService>(); var viewModel = IoC.Instance.Resolve <IObjectViewModel <T> >(); var mgr = IoC.Instance.Resolve <IBaseManager <T> >(); object id; var pkType = entityDescriptor.PrimaryKeyDatatype.ToLower().Replace("system.", ""); switch (pkType) { case "decimal": id = Convert.ToDecimal(entityDescriptor.PrimaryKeyValue); break; case "string": id = entityDescriptor.PrimaryKeyValue; break; default: throw new SystemException("This pkType is not supported yet: " + entityDescriptor.PrimaryKeyDatatype); } var source = mgr.Get(id, GetModeEnum.Partial); if (source == null) { throw new SystemException("source entity instance cannot be found. entityType: " + entityDescriptor.EntityType + ", pkValue: " + entityDescriptor.PrimaryKeyValue); } viewModel.SetSource(source); viewService.Show(viewModel, new ShowContext { DockingType = DockType.Document, ShowInNewWindow = false }); DispatcherHelper.BeginInvoke(new Action(() => Application.Current.MainWindow.Activate())); }