Esempio n. 1
0
        public static DataView AsDataView(this CremaDataTable table)
        {
            var view = table.InternalObject.AsDataView();

            view.Sort = string.Join(",", table.Columns.Select(item => item.ColumnName));
            return(view);
        }
Esempio n. 2
0
        public InternalDataTable(CremaDataTable target, string name, string categoryPath)
            : base(name, categoryPath)
        {
            this.childList2 = new ReadOnlyObservableCollection <InternalDataTable>(this.childList);
            if (base.ChildItems is INotifyCollectionChanged childTables)
            {
                childTables.CollectionChanged += ChildTables_CollectionChanged;
            }

            this.attributeTag = new InternalAttribute(CremaSchema.Tags, typeof(string))
            {
                AllowDBNull  = false,
                DefaultValue = TagInfo.All.ToString(),
            };
            this.Columns.Add(this.attributeTag);

            this.attributeEnable = new InternalAttribute(CremaSchema.Enable, typeof(bool))
            {
                AllowDBNull  = false,
                DefaultValue = true,
            };
            this.Columns.Add(this.attributeEnable);

            base.Target = target ?? new CremaDataTable(this);
            this.Columns.CollectionChanged     += Columns_CollectionChanged;
            this.Constraints.CollectionChanged += Constraints_CollectionChanged;
            this.creationInfo = this.modificationInfo = this.SignatureDateProvider.Provide();
        }
Esempio n. 3
0
        public TableInfo Filter(TagInfo tags)
        {
            var tableInfo = this;

            tableInfo.Columns   = tableInfo.Columns.Where(item => (item.DerivedTags & tags) != TagInfo.Unused).ToArray();
            tableInfo.HashValue = CremaDataTable.GenerateHashValue(tableInfo.Columns);
            return(tableInfo);
        }
Esempio n. 4
0
        public static CremaDataTable ReadSchema(XmlReader reader, ItemName itemName)
        {
            var dataTable    = new CremaDataTable();
            var schemaReader = new CremaSchemaReader(dataTable, itemName);

            schemaReader.Read(reader);
            return(dataTable);
        }
Esempio n. 5
0
        internal void CopyTo(CremaDataTable dest)
        {
            foreach (CremaDataColumn item in this.Columns)
            {
                item.CopyTo(dest.Columns[item.ColumnName]);
            }

            dest.CategoryPath = this.CategoryPath;
        }
Esempio n. 6
0
        public CremaDataRow[] GetChildRows(CremaDataTable childTable)
        {
            if (childTable.Parent != this.Table)
            {
                return(null);
            }

            var relationName = InternalSetBase.GenerateRelationName(this.Table.TableName, childTable.TableName, this.Table.Namespace);

            return(this.row.GetChildRows(relationName).Select(item => (item as InternalDataRow).Target).ToArray());
        }
Esempio n. 7
0
        public static string GetTableName(object component)
        {
            if (component is DataRowView == false)
            {
                throw new ArgumentException();
            }

            var rowView = component as DataRowView;

            return(CremaDataTable.GetTableName(rowView.Row.Table.TableName));
        }
Esempio n. 8
0
        public CremaTemplate(CremaDataTable targetTable)
        {
            if (targetTable == null)
            {
                throw new ArgumentNullException(nameof(targetTable));
            }
            if (targetTable.TemplateNamespace != string.Empty)
            {
                throw new ArgumentException(Resources.Exception_CannotEditInheritedTable, nameof(targetTable));
            }

            this.builder  = new CremaTemplateColumnBuilder(this);
            this.template = new InternalTemplate(this, this.builder)
            {
                TargetTable = (InternalDataTable)targetTable
            };
            this.attributes = new CremaAttributeCollection(this.template);
            this.columns    = new CremaTemplateColumnCollection(this.template);

            this.AttachEventHandlers();
        }
Esempio n. 9
0
        public CremaDataTable Copy(ItemName itemName, bool copyData)
        {
            this.ValidateCopy(itemName);

            var schema = this.GetXmlSchema();
            var xml    = copyData == true?this.GetXml() : null;

            if (this.DataSet != null)
            {
                this.DataSet.ReadXmlSchemaString(schema, itemName);
                if (xml != null)
                {
                    this.DataSet.ReadXmlString(xml, itemName);
                }

                var dataTable     = this.DataSet.Tables[itemName.Name, itemName.CategoryPath];
                var signatureDate = this.SignatureDateProvider.Provide();
                dataTable.DetachTemplatedParent();
                foreach (var item in EnumerableUtility.Friends(dataTable, dataTable.childs))
                {
                    item.InternalTableID = Guid.NewGuid();
                    item.CreationInfo    = signatureDate;
                }
                dataTable.UpdateRevision(this.Revision);
                return(dataTable);
            }

            using (var sr = new StringReader(schema))
                using (var reader = XmlReader.Create(sr))
                {
                    var dataTable = CremaDataTable.ReadSchema(reader, itemName);
                    if (xml != null)
                    {
                        dataTable.ReadXmlString(xml);
                    }

                    dataTable.UpdateRevision(this.Revision);
                    return(dataTable);
                }
        }
Esempio n. 10
0
        public CremaDataSet Filter(CremaDataSet srcDataSet, CremaDataSet destDataSet, TagInfo tags)
        {
            CremaDataTable parentDestDataTable = null;

            if (this.Parent != null)
            {
                parentDestDataTable = new CremaDataTable(this.ParentName, this.Parent.CategoryPath);
                destDataSet.Tables.Add(parentDestDataTable);
            }

            var destDataTable = new CremaDataTable(this.TableName, this.CategoryPath);

            destDataSet.Tables.Add(destDataTable);
            destDataTable.Parent = parentDestDataTable;

            foreach (var column in this.Columns)
            {
                if ((column.DerivedTags & tags) != TagInfo.Unused)
                {
                    var newColumn = new CremaDataColumn(column.ColumnName, column.DataType);
                    destDataTable.Columns.Add(newColumn);
                }
            }

            var columns = destDataTable.Columns.ToArray();

            foreach (var row in this.Rows)
            {
                if ((row.DerivedTags & tags) == TagInfo.Unused)
                {
                    continue;
                }

                destDataTable.AddRow(row.Filter(columns, tags));
            }

            return(destDataSet);
        }
Esempio n. 11
0
 internal CremaDataTableClearEventArgs(DataTableClearEventArgs e)
 {
     this.table          = (e.Table as InternalDataTable).Target;
     this.tableName      = e.TableName;
     this.tableNamespace = e.TableNamespace;
 }
Esempio n. 12
0
 internal void AttachTemplatedParent(CremaDataTable templatedParent)
 {
     this.TemplatedParent = templatedParent;
 }
Esempio n. 13
0
        public static CremaTemplate CreateChild(CremaDataTable parentTable)
        {
            var dataTable = parentTable.Childs.Add();

            return(new CremaTemplate(dataTable));
        }
Esempio n. 14
0
 public void AttachTemplatedParent(CremaDataTable templatedParent)
 {
     this.TemplatedParent = templatedParent;
 }
Esempio n. 15
0
 internal CremaDataRowBuilder(CremaDataTable table)
 {
     this.table = table;
 }