protected void setExtendedProperties(DataTable output, dataUnitPresenter presenter)
 {
     output.ExtendedProperties[templateFieldDataTable.shema_classname] = instanceType.FullName;
     output.ExtendedProperties[templateFieldDataTable.data_tablename]  = presenter.name;
     output.ExtendedProperties[templateFieldDataTable.data_tabledesc]  = presenter.description;
     output.ExtendedProperties[templateFieldDataUnit.map]               = map;
     output.ExtendedProperties[templateFieldDataUnit.complete_Table]    = complete_Table;
     output.ExtendedProperties[templateFieldDataUnit.dataAcquireFlags]  = dataAcquireFlags;
     output.ExtendedProperties[templateFieldDataUnit.dataUnitPresenter] = presenter;
     output.ExtendedProperties[templateFieldDataUnit.previewRowLimit]   = dataAcquireFlags.getPreviewRowLimit();
     output.ExtendedProperties[templateFieldDataUnit.autocountRow]      = dataAcquireFlags.getPreviewRowLimit();
 }
        /// <summary>
        /// Gets the data table fpr presenter
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="presenter">The presenter.</param>
        /// <param name="isPreviewTable">if set to <c>true</c> [is preview table].</param>
        /// <param name="runMonitorCheck">if set to <c>true</c> [run monitor check].</param>
        /// <returns></returns>
        internal virtual DataTable getDataTable(IEnumerable items, dataUnitPresenter presenter, bool isPreviewTable, bool runMonitorCheck = false)
        {
            if (presenter == complete_Table)
            {
                if (tableShema.Columns.Count == 0)
                {
                    tableShema = buildDataTableShema(presenter);
                }
            }

            DataTable output = selectDataTableShema(tableShema, presenter);

            if (runMonitorCheck)
            {
                map.monitor.prepare();
            }
            int rowLimit = -1;

            if (isPreviewTable)
            {
                rowLimit = output.ExtendedProperties.getProperInt32(-1, templateFieldDataUnit.previewRowLimit);
            }
            int c = 0;

            foreach (object item in items)
            {
                DataRow dr = output.NewRow();
                if (runMonitorCheck)
                {
                    map.monitor.runFunctions(item);
                }
                foreach (DataColumn dc in output.Columns)
                {
                    settingsPropertyEntryWithContext sce = dc.ExtendedProperties.getProperField(templateFieldDataTable.col_propertyInfo) as settingsPropertyEntryWithContext;

                    dr[dc] = sce.pi.GetValue(item, null);
                }
                if (runMonitorCheck)
                {
                    map.monitor.unlock();
                }
                output.Rows.Add(dr);

                c++;
                if ((rowLimit > 0) && (c > rowLimit))
                {
                    break;
                }
            }

            return(output);
        }
        /// <summary>
        /// Builds the data table shema.
        /// </summary>
        /// <param name="presenter">The presenter.</param>
        /// <returns></returns>
        public virtual DataTable buildDataTableShema(dataUnitPresenter presenter = null)
        {
            if (presenter == null)
            {
                presenter = complete_Table;
            }

            DataTable output = new DataTable(presenter.name);

            setExtendedProperties(output, presenter);

            bool insertCountRow = dataAcquireFlags.HasFlag(dataDeliveryAcquireEnum.insertCountRow);

            foreach (settingsPropertyEntryWithContext sce in map.columns)
            {
                if (insertCountRow)
                {
                    DataColumn dci = output.Columns.Add("i", typeof(int));
                    dci.Caption    = "#";
                    dci.Expression = "Count(" + sce.pi.Name + ")";
                    insertCountRow = false;
                }

                DataColumn dc = output.Columns.Add(sce.pi.Name, sce.pi.PropertyType);
                dc.Caption = sce.displayName;
                if (!sce.expression.isNullOrEmpty())
                {
                    dc.Expression = sce.expression;
                }
                if (!sce.escapeValueString)
                {
                    dc.ExtendedProperties[templateFieldDataTable.col_directAppend] = true;
                }
                dc.ExtendedProperties[templateFieldDataTable.col_caption]       = sce.displayName;
                dc.ExtendedProperties[templateFieldDataTable.col_desc]          = sce.description;
                dc.ExtendedProperties[templateFieldDataTable.col_format]        = sce.format;
                dc.ExtendedProperties[templateFieldDataTable.col_group]         = sce.categoryName;
                dc.ExtendedProperties[templateFieldDataTable.col_imbattributes] = sce.attributes;
                dc.ExtendedProperties[templateFieldDataTable.col_propertyInfo]  = sce;
                dc.ExtendedProperties[templateFieldDataTable.col_priority]      = sce.priority;
                dc.ExtendedProperties[imbAttributeName.viewPriority]            = sce.priority;
                dc.ExtendedProperties[templateFieldDataTable.col_type]          = sce.pi.PropertyType;
                output.ExtendedProperties[imbAttributeName.measure_important]   = sce.importance;
            }

            return(output);
        }
        protected virtual DataColumn addStandardColumnShema(DataTable shema, dataUnitPresenter presenter, PropertyEntryColumn pec)
        {
            string name = pec.toColumnCaption(false);
            string desc = pec.getDescriptionForKey();

            DataColumn dc = shema.Columns.Add(pec.toStringSafe());

            dc.ColumnName = pec.toStringSafe();
            dc.Caption    = name;
            dc.DataType   = pec.toColumnType();

            dc.ExtendedProperties[templateFieldDataTable.col_caption]  = name;
            dc.ExtendedProperties[templateFieldDataTable.col_desc]     = desc;
            dc.ExtendedProperties[templateFieldDataTable.col_format]   = "";
            dc.ExtendedProperties[templateFieldDataTable.col_group]    = "";
            dc.ExtendedProperties[templateFieldDataTable.col_priority] = pec.toColumnPriority();
            dc.ExtendedProperties[templateFieldDataTable.col_type]     = typeof(string);

            return(dc);
        }
        /// <summary>
        /// Selects the data table shema.
        /// </summary>
        /// <param name="shema">The shema.</param>
        /// <param name="presenter">The presenter.</param>
        /// <returns></returns>
        protected virtual DataTable selectDataTableShema(DataTable shema, dataUnitPresenter presenter)
        {
            if (presenter == null)
            {
                presenter = complete_Table;
            }
            DataTable output = new DataTable();

            output.TableName = presenter.name;
            output.ExtendedProperties.copyInto(shema.ExtendedProperties); // = presenter.name;

            foreach (string cns in map.fieldsByNeedle[presenter.key])
            {
                DataColumn dcShema = shema.Columns[cns];
                DataColumn dcTable = output.Columns.Add(dcShema.ColumnName);
                dcTable.Caption    = dcShema.Caption;
                dcTable.Expression = dcShema.Expression;
                dcTable.DataType   = dcShema.DataType;
                dcTable.ExtendedProperties.copyInto(dcTable.ExtendedProperties); // = dcShema.DataType;
            }
            return(output);
        }
        protected void buildMap()
        {
            map = dataUnitMap.getDataUnitMap(instanceType, unitType);
            var unitProps = unitType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);

            presenters = new dataUnitPresenterDictionary();

            foreach (PropertyInfo pi in unitProps)
            {
                if (pi.PropertyType == typeof(dataUnitPresenter))
                {
                    dataUnitPresenter presObj = pi.GetValue(this, null) as dataUnitPresenter;
                    if (presObj != null)
                    {
                        if (!presenters.items.ContainsKey(presObj.key))
                        {
                            presenters.items.Add(presObj.key, presObj);
                        }
                        presObj.parent = this;
                    }
                }
            }
        }
        /// <summary>
        /// Builds the custom data table.
        /// </summary>
        /// <param name="instance_items">The instance items.</param>
        /// <param name="presenter">The presenter.</param>
        /// <param name="isPreviewTable">if set to <c>true</c> [is preview table].</param>
        /// <returns></returns>
        public DataTable buildCustomDataTable(IEnumerable instance_items, dataUnitPresenter presenter, bool isPreviewTable)
        {
            if (presenter == complete_Table)
            {
                if (tableShema.Columns.Count == 0)
                {
                    tableShema = buildDataTableShema(presenter);
                }
            }
            DataTable selectedShema = selectDataTableShema(tableShema, presenter);
            DataTable output        = selectedShema;

            switch (presenter.presentationType)
            {
            case dataDeliveryPresenterTypeEnum.tableVertical:

                output = new DataTable(presenter.name);
                output.ExtendedProperties.copyInto(selectedShema.ExtendedProperties);

                List <DataColumn>          value_columns = new List <DataColumn>();
                List <PropertyEntryColumn> extra_columns = new List <PropertyEntryColumn>();
                //addStandardColumnShema(output, presenter, PropertyEntryColumn.entry_name);

                PropertyCollectionExtended pce = null;
                int i = 0;
                foreach (object instance in instance_items)
                {
                    pce = new PropertyCollectionExtended();
                    pce.setFromObject(instance);

                    var dc = addStandardColumnShema(output, presenter, PropertyEntryColumn.entry_value);

                    if (instance is IObjectWithName)
                    {
                        IObjectWithName input_IObjectWithName = (IObjectWithName)instance;
                        dc.Caption = input_IObjectWithName.name;
                    }

                    if (instance is IObjectWithDescription)
                    {
                        IObjectWithDescription instanceIObjectWithDescription = (IObjectWithDescription)instance;
                        dc.ExtendedProperties[templateFieldDataTable.col_desc] = instanceIObjectWithDescription.description;
                    }

                    dc.ExtendedProperties[imbAttributeName.menuRelevance] = dataPointImportance.important;
                    dc.ExtendedProperties[imbAttributeName.metaData]      = pce;

                    dc.ColumnName = "value_" + i.ToString();
                    value_columns.Add(dc);

                    i++;
                }

                addStandardColumnShema(output, presenter, PropertyEntryColumn.entry_description);

                foreach (PropertyEntryColumn epec in presenter.extraColumns.getEnumListFromFlags <PropertyEntryColumn>())
                {
                    if ((epec != PropertyEntryColumn.entry_name) && (epec != PropertyEntryColumn.entry_description))
                    {
                        extra_columns.Add(epec);
                        addStandardColumnShema(output, presenter, epec);
                    }
                }

                // <----------------------------------- izgradnja redova

                foreach (string cns in map.fieldsByNeedle[presenter.key])
                {
                    DataColumn dcShema = null;

                    if (selectedShema.Columns.Contains(cns))
                    {
                        dcShema = selectedShema.Columns[cns];
                    }

                    DataRow dr = output.NewRow();

                    // dr[output.Columns[PropertyEntryColumn.entry_name.ToString()]] = dcShema.Caption;

                    int    vi  = 0;
                    object val = null;
                    foreach (object instance in instance_items)
                    {
                        var dc = value_columns[vi];
                        dr[dc] = instance.imbGetPropertySafe(cns, "--");

                        if (dr[dc] != null)
                        {
                            val = dr[dc];
                        }

                        vi++;
                    }

                    //dr[output.Columns[PropertyEntryColumn.entry_description.ToString()]] = dcShema.ExtendedProperties[templateFieldDataTable.col_desc];

                    if (extra_columns.Any())
                    {
                        foreach (PropertyEntryColumn epec in extra_columns)
                        {
                            dr[output.Columns[epec.ToString()]] = pce[output.Columns[epec.ToString()]];
                        }
                    }
                }

                break;

            case dataDeliveryPresenterTypeEnum.tableTwoColumnParam:
                object ins = instance_items.imbGetItemAt(0);

                PropertyCollectionExtended pc2 = new PropertyCollectionExtended();     // instance.buildPropertyCollection(true, true, "");
                                                                                       //pc2.setFromObject(ins);

                // pc2 = ins.buildPropertyCollection<PropertyCollectionExtended>(doOnlyWithDisplayName:false, doInherited:true, filedName_prefix:"", output:null, fieldsOrCategoriesToShow:map.fieldsByNeedle[presenter.key]);

                foreach (var pairs in pc2.entries)
                {
                }

                break;

            case dataDeliveryPresenterTypeEnum.lineGraph:
            case dataDeliveryPresenterTypeEnum.pieGraph:
            case dataDeliveryPresenterTypeEnum.barGraph:
            case dataDeliveryPresenterTypeEnum.tableHorizontal:

                output = getDataTable(instance_items, presenter, isPreviewTable, false);
                break;
            }

            return(output);
        }
 public DataTable GetTableWith(dataUnitPresenter presenter, bool isPreview = false)
 {
     return(buildCustomDataTable(items, presenter, isPreview));
 }