예제 #1
0
        /// <summary>
        /// Exposes to the user a data editor, for the the supplied Detail Table, Designator and Custom-Look, and returns indication of change.
        /// </summary>
        public static bool Edit(Table DetailTable, TableDetailDesignator Designator, TableAppearance CustomLook = null, bool ForceSingleRecord = false)
        {
            if (DetailTable.Definition.FieldDefinitions.Count < 1)
            {
                if (Display.DialogMessage("Warning!", "No declared fields in the '" + DetailTable.Definition.Name + "' Table-Structure.\n\n" +
                                          "Do you want to declare them for " + (Designator.Owner.IsGlobal ? "all Ideas of type '" : "the Idea '") +
                                          ((IIdentifiableElement)Designator.Owner.Owner).Name + "' ?",
                                          EMessageType.Warning, MessageBoxButton.YesNo)
                    != MessageBoxResult.Yes)
                {
                    return(false);
                }

                var EditResult = DomainServices.EditDetailDesignator(Designator, Designator.Owner.IsGlobal, Designator.EditEngine);
                if (!EditResult.Item1.IsTrue())
                {
                    return(false);
                }
            }

            var WorkTable = DetailTable.CreateClone(ECloneOperationScope.Deep, null);
            var Editor    = new DetailTableEditor(WorkTable, Designator, CustomLook.NullDefault(new TableAppearance()), ForceSingleRecord);

            DialogOptionsWindow EditingWindow = null;   // Do not declare as static to allow multiple dialogs open!
            var Changed = Display.OpenContentDialogWindow <DetailTableEditor>(ref EditingWindow, "Edit data of table '" + WorkTable.Designation.Name + "'", Editor).IsTrue();

            if (Editor.ApplyChanges)
            {
                DetailTable.UpdateContentFrom(WorkTable);
            }

            return(Editor.ApplyChanges); //? || Changed);
        }
예제 #2
0
        public DetailTableEditor(Table SourceTable, TableDetailDesignator SourceDesignator, TableAppearance SourceCustomLook, bool ForceSingleRecord = false)
            : this()
        {
            this.SourceTable      = SourceTable;
            this.SourceDesignator = SourceDesignator;
            this.SourceCustomLook = SourceCustomLook;

            // Operations: Append-Record and Reset-Records...
            Tuple <Action <TableRecord>, Action> RecordOperations = null;

            if (this.SourceCustomLook.IsMultiRecord && !ForceSingleRecord)
            {
                RecordOperations = SetMultiRecordEditor();
            }
            else
            {
                RecordOperations = SetSingleRecordEditor();
            }

            var ImportWidget = DomainServices.CreateTransferWidget(SourceDesignator, SourceTable.OwnerIdea, false, false,
                                                                   (compatdef, datarecords, append) =>
            {
                if (compatdef == null)
                {
                    Display.DialogMessage("Attention", "Cannot load data with incomptaible table-structure.",
                                          EMessageType.Warning);
                    return;
                }

                if (!append)
                {
                    RecordOperations.Item2();           // Reset-Records
                }
                foreach (var datarecord in datarecords)
                {
                    RecordOperations.Item1(new TableRecord(SourceTable, datarecord));           // Append-Record
                }
            },
                                                                   this.SourceTable);

            ImportWidget.MaxWidth            = 300;
            ImportWidget.HorizontalAlignment = HorizontalAlignment.Left;
            DockPanel.SetDock(ImportWidget, Dock.Left);
            this.BottomPanel.Children.Add(ImportWidget);
        }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        public bool AppendPastedDetail(Idea Target, string DetailName, string MimeType, byte[] DetailContent)
        {
            if (DetailName.IsAbsent() || MimeType.IsAbsent() || DetailContent == null || DetailContent.Length < 1)
            {
                return(false);
            }

            ContainedDetail Detail = null;

            if (MimeType.StartsWith("text/"))
            {
                var Owner   = Ownership.Create <IdeaDefinition, Idea>(Target);
                var Content = DetailContent.BytesToString();
                if (Content.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase))
                {
                    var NewLink = new ResourceLink(Target, new Assignment <DetailDesignator>(
                                                       DomainServices.CreateLinkDesignation(
                                                           Owner,
                                                           DetailName),
                                                       true));
                    NewLink.TargetLocation = Content;
                    Detail = NewLink;
                }
                else
                if (MimeType.EndsWith("/tsv") || MimeType.EndsWith("/csv"))
                {
                    var Delimiter = (MimeType.EndsWith("/csv")
                                         ? General.GetCurrentTextListDelimiter()
                                         : "\t");
                    var TextRecords = General.LoadStreamDelimitedIntoStrings(Content.StringToStream(), Delimiter);

                    var TypingResult = DomainServices.GenerateTypedRecordsList(TextRecords.Item1);

                    var TableDef = DomainServices.CreateCompatibleTableDefinition(Target.OwnerComposition.CompositeContentDomain,
                                                                                  DetailName + " - TableDef",
                                                                                  TypingResult.Item2, TextRecords.Item2);
                    var Designator = new TableDetailDesignator(Owner, TableDef, true, DetailName, DetailName.TextToIdentifier());
                    var NewTable   = new Table(Target, Designator.Assign <DetailDesignator>(true));
                    foreach (var DataRecord in TypingResult.Item1)
                    {
                        NewTable.Add(new TableRecord(NewTable, DataRecord));
                    }

                    Detail = NewTable;
                }
            }

            if (Detail == null)
            {
                var Route = new Uri(DetailName, UriKind.RelativeOrAbsolute);
                Detail = this.CreateIdeaDetailAttachment(Ownership.Create <IdeaDefinition, Idea>(Target),
                                                         Target, DetailName, Route, DetailContent, MimeType);
                if (Detail == null)
                {
                    return(false);
                }
            }

            Target.Details.AddNew(Detail);

            return(true);
        }
예제 #4
0
        public TableDetailDesignatorStructSubform(TableDetailDesignator SourceDesignator, FrameworkElement AssociatedImportWidget = null, bool DirectApply = false)
            : this()
        {
            this.SourceDesignator       = SourceDesignator;
            this.AssociatedImportWidget = AssociatedImportWidget;

            this.DirectApply = DirectApply;

            this.PnlButtons.SetVisible(DirectApply);

            // Clone for detect changes
            this.InitialTableDefinitionClone = (this.SourceDesignator.DeclaringTableDefinition == null ? null :
                                                this.SourceDesignator.DeclaringTableDefinition.CreateClone(ECloneOperationScope.DeepAndEquivalent, null));

            this.RelatedDomain = this.SourceDesignator.OwnerDomain;

            this.AvailabeTableStructures = this.RelatedDomain.TableDefinitions.Where(tdef => tdef.Alterability != EAlterability.System);;

            if (this.SourceDesignator.TableDefIsOwned)
            {
                this.OwnedTableDefinition = this.SourceDesignator.DeclaringTableDefinition;
            }

            if (this.OwnedTableDefinition == null)
            {
                var LocalName = this.SourceDesignator.AssignerOwnerName + " - " + this.SourceDesignator.Name;
                this.OwnedTableDefinition = new TableDefinition(this.RelatedDomain, LocalName, LocalName.TextToIdentifier());
                this.OwnedTableDefinition.Alterability = EAlterability.Definition;  // This prevents the table-def to be edited from the Domain.
            }

            this.FrmTableStructEditor.SetSourceTableDef(this.OwnedTableDefinition);
            TableDefinitionMaintainer.SetFieldDefinitionsMaintainer(this.FrmTableStructEditor.FieldsMaintainer);    // Don't forget to assign the new maintainer
            this.FrmTableStructEditor.FieldsMaintainer.VisualControl.CanEditItemsDirectly = false;

            this.CbxCopySourceTableStruct.ItemsSource = this.AvailabeTableStructures;

            if (this.AvailabeTableStructures != null && this.AvailabeTableStructures.Any())
            {
                this.CbxReferencedTableStruct.ItemsSource = this.AvailabeTableStructures;

                if (this.SourceDesignator.DeclaringTableDefinition != null &&
                    this.AvailabeTableStructures.Contains(this.SourceDesignator.DeclaringTableDefinition) &&
                    !this.SourceDesignator.TableDefIsOwned)
                {
                    this.CbxReferencedTableStruct.SelectedItem = this.SourceDesignator.DeclaringTableDefinition;
                }
                else
                {
                    this.CbxReferencedTableStruct.SelectedItem = this.AvailabeTableStructures.First();
                }
            }
            else
            {
                this.RbReferenced.IsEnabled             = false;
                this.TxbReferencedTableStruct.IsEnabled = false;
                this.CbxReferencedTableStruct.IsEnabled = false;
            }

            if (this.SourceDesignator.TableDefIsOwned || !this.RbReferenced.IsEnabled)
            {
                this.RbOwned.IsChecked = true;
            }
            else
            {
                this.RbReferenced.IsChecked = true;
            }
        }