예제 #1
0
        /// <summary>
        /// Adds the grid columns.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        private void AddGridColumns(DataTable dataTable)
        {
            bool showColumns = bool.Parse(GetAttributeValue("ShowColumns"));
            var  columnList  = GetAttributeValue("Columns").SplitDelimitedValues().ToList();

            int rowsToEval = 10;

            if (dataTable.Rows.Count < 10)
            {
                rowsToEval = dataTable.Rows.Count;
            }

            gReport.Columns.Clear();

            if (!string.IsNullOrWhiteSpace(gReport.PersonIdField))
            {
                gReport.Columns.Add(new SelectField());
            }

            foreach (DataColumn dataTableColumn in dataTable.Columns)
            {
                if (columnList.Count > 0 &&
                    ((showColumns && !columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase)) ||
                     (!showColumns && columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase))))
                {
                    continue;
                }

                BoundField bf = new BoundField();

                if (dataTableColumn.DataType == typeof(bool))
                {
                    bf = new BoolField();
                }

                if (dataTableColumn.DataType == typeof(DateTime))
                {
                    bf = new DateField();

                    for (int i = 0; i < rowsToEval; i++)
                    {
                        object dateObj = dataTable.Rows[i][dataTableColumn];
                        if (dateObj is DateTime)
                        {
                            DateTime dateTime = (DateTime)dateObj;
                            if (dateTime.TimeOfDay.Seconds != 0)
                            {
                                bf = new DateTimeField();
                                break;
                            }
                        }
                    }
                }

                bf.DataField      = dataTableColumn.ColumnName;
                bf.SortExpression = dataTableColumn.ColumnName;
                bf.HeaderText     = dataTableColumn.ColumnName.SplitCase();
                gReport.Columns.Add(bf);
            }
        }
예제 #2
0
        public void Test_NullBoolEvalsToFalse_27122(string test)
        {
            string typeName = Guid.NewGuid().ToString();

            test = test.Replace("TestBool27122", typeName);

            EntityType type = new EntityType();

            type.Name = typeName;
            type.Save();

            Resource instance = Entity.Create(type.Id).As <Resource>();

            instance.Name = "TestInstance";
            instance.Save();

            // Retrospectively add a bool field
            BoolField field = new BoolField();

            field.Name = "BoolField";
            type.Fields.Add(field.As <Field>());
            type.Save();

            TestHelper.Test(test);
        }
예제 #3
0
파일: Bullet.cs 프로젝트: preetum/archive
        public Bullet(Actor actor)
        {
            _parentActor = actor;

            field    = _parentActor.ParentLevel.levelField;
            position = _parentActor.Position;
        }
예제 #4
0
        private bool ParseCheckbox(Element el)
        {
            bool val        = false;
            bool hasDefault = Boolean.TryParse(el.defaultValue, out val);

            BoolField field = new BoolField
            {
                Label                 = el.label,
                DefaultValue          = val,
                DefaultValueSpecified = true,
                ReadOnly              = el.readOnly,
                Required              = el.required,
                Searchable            = el.searchable,
                ModifyEnabled         = el.modifyEnable,
                HiddenField           = el.hiddenField,
                ClientId              = el.clientId,
                ColumnName            = Utils.SafeSQLName(el.label),
                Layout                = new LayoutPosition
                {
                    PanelId   = el.columns.ToString(),
                    ColNumber = el.columns,
                    RowNumber = el.rows
                }
            };

            sections.AddCtrl(field);
            return(true);
        }
예제 #5
0
        /// <summary>
        /// Adds the grid columns.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        private void AddGridColumns(object item)
        {
            Type oType = item.GetType();

            gReport.Columns.Clear();

            foreach (var prop in oType.GetProperties())
            {
                BoundField bf = new BoundField();

                if (prop.PropertyType == typeof(bool) ||
                    prop.PropertyType == typeof(bool?))
                {
                    bf = new BoolField();
                }

                if (prop.PropertyType == typeof(DateTime) ||
                    prop.PropertyType == typeof(DateTime? ))
                {
                    bf = new DateTimeField();
                }

                bf.DataField      = prop.Name;
                bf.SortExpression = prop.Name;
                bf.HeaderText     = prop.Name.SplitCase();
                gReport.Columns.Add(bf);
            }
        }
예제 #6
0
파일: Bullet.cs 프로젝트: preetum/archive
        public Bullet(Actor actor, bool playerOriginated)
        {
            _parentActor = actor;

            field    = _parentActor.ParentLevel.levelField;
            position = _parentActor.Position;
            this.playerOriginated = playerOriginated;
        }
        /// <summary>
        /// Gets the grid field.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override DataControlField GetGridField(Type entityType, string selection)
        {
            BoundField boundField;

            var settings = new SelectSettings(selection);

            var entityFields = GetGroupMemberAttributeEntityFields();

            var entityField = entityFields.FirstOrDefault(f => f.UniqueName == settings.AttributeKey);

            if (entityField == null)
            {
                // This shouldn't happe, but if searching by UniqueName didn't work, search by Name instead
                entityField = entityFields.FirstOrDefault(f => f.Name == settings.AttributeKey);
            }

            if (entityField == null)
            {
                // should't happen, but just in case
                return(new BoundField());
            }

            if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.BOOLEAN.AsGuid()))
            {
                boundField = new BoolField();
            }
            else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()))
            {
                boundField = new DateField();
            }
            else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE_TIME.AsGuid()))
            {
                boundField = new DateTimeField();
            }
            else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid()))
            {
                boundField = new DefinedValueField();
            }
            else
            {
                boundField = new BoundField();
            }

            boundField.SortExpression = boundField.DataField;

            if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) ||
                entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()) ||
                entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.FILTER_DATE.AsGuid()))
            {
                boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                boundField.ItemStyle.HorizontalAlign   = HorizontalAlign.Right;
            }

            return(boundField);
        }
예제 #8
0
 private void SetBoolField(BoolField field, bool value)
 {
     if (value)
     {
         _boolFieldStore |= field;
     }
     else
     {
         _boolFieldStore &= (~field);
     }
 }
예제 #9
0
        /// <summary>
        /// A field that can contain a bool from a BoolField object. A BoolField exists inside a BoolList object.
        /// </summary>
        /// <param name="boolField">The BoolField object that contains the bool that appears in the field.</param>
        /// <param name="index">The slot assigned to the BoolField in its BoolList object.</param>
        /// <returns>The BoolField assigned to the field.</returns>
        public static bool BoolListField(BoolField boolField, int index)
        {
            int  bodyWidth = 15;
            int  height    = 20;
            bool value     = boolField.value;

            BeginHorizontal();
            bool result = EditorGUILayout.Toggle("", value, GUILayout.Width(bodyWidth), GUILayout.Height(height));

            EndHorizontal();

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Gets the grid field.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override DataControlField GetGridField(Type entityType, string selection)
        {
            BoundField boundField;

            var attributeGuid = selection.AsGuid();

            var groupAttributeEntityFields = GetGroupAttributeEntityFields();

            var entityField = groupAttributeEntityFields.FirstOrDefault(f => f.AttributeGuid == attributeGuid);

            if (entityField != null)
            {
                if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.BOOLEAN.AsGuid()))
                {
                    boundField = new BoolField();
                }
                else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()))
                {
                    boundField = new DateField();
                }
                else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE_TIME.AsGuid()))
                {
                    boundField = new DateTimeField();
                }
                else if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid()))
                {
                    boundField = new DefinedValueField();
                }
                else
                {
                    boundField = new BoundField();
                }

                boundField.SortExpression = boundField.DataField;

                if (entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) ||
                    entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()) ||
                    entityField.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.FILTER_DATE.AsGuid()))
                {
                    boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                    boundField.ItemStyle.HorizontalAlign   = HorizontalAlign.Right;
                }

                return(boundField);
            }

            return(null);
        }
예제 #11
0
        private void DrawFields(Type type, ComponentSystemBase effectiveInstance)
        {
            foreach (var field in cachedFields)
            {
                if (field.FieldType == typeof(System.Int32))
                {
                    IntField.Draw(type, field, effectiveInstance);
                }
                else if (field.FieldType == typeof(System.Single))
                {
                    FloatField.Draw(type, field, effectiveInstance);
                }
                else if (field.FieldType == typeof(System.String))
                {
                    StringField.Draw(type, field, effectiveInstance);
                }
                else if (field.FieldType == typeof(System.Boolean))
                {
                    BoolField.Draw(type, field, effectiveInstance);
                }
                else if (field.FieldType.IsEnum)
                {
                    var underlyingType = Enum.GetUnderlyingType(field.FieldType);
                    if (underlyingType == typeof(short))
                    {
                        MaskField.Draw(type, field, effectiveInstance);
                    }
                    else
                    {
                        EnumField.Draw(type, field, effectiveInstance);
                    }
                }
                else
                {
                    // monobehaviours
                    switch (field.FieldType.ToString())
                    {
                    case "UnityEngine.Mesh":
                        MeshField.Draw(type, field, effectiveInstance);
                        break;

                    case "UnityEngine.Material":
                        MaterialField.Draw(type, field, effectiveInstance);
                        break;
                    }
                }
            }
        }
예제 #12
0
    private void OnValidate()
    {
        Player player = GetComponent <Player>();

        if (player)
        {
            playerId = player.Id;
            if (player.Score)
            {
                playerScore = player.Score;
            }
            if (player.GetIsFireballActive)
            {
                isFireballActive = player.GetIsFireballActive;
            }
        }
    }
예제 #13
0
        /// <summary>
        /// Adds the grid columns.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        private void AddGridColumns(DataTable dataTable)
        {
            int rowsToEval = 10;

            if (dataTable.Rows.Count < 10)
            {
                rowsToEval = dataTable.Rows.Count;
            }

            gReport.Columns.Clear();
            foreach (DataColumn dataTableColumn in dataTable.Columns)
            {
                BoundField bf = new BoundField();

                if (dataTableColumn.DataType == typeof(bool))
                {
                    bf = new BoolField();
                }

                if (dataTableColumn.DataType == typeof(DateTime))
                {
                    bf = new DateField();

                    for (int i = 0; i < rowsToEval; i++)
                    {
                        object dateObj = dataTable.Rows[i][dataTableColumn];
                        if (dateObj is DateTime)
                        {
                            DateTime dateTime = (DateTime)dateObj;
                            if (dateTime.TimeOfDay.Seconds != 0)
                            {
                                bf = new DateTimeField();
                                break;
                            }
                        }
                    }
                }

                bf.DataField      = dataTableColumn.ColumnName;
                bf.SortExpression = dataTableColumn.ColumnName;
                bf.HeaderText     = dataTableColumn.ColumnName.SplitCase();
                gReport.Columns.Add(bf);
            }
        }
예제 #14
0
 private void SetBoolField(BoolField field, bool value)
 {
     if (value)
     {
         _tabItemBoolFieldStore |= field;
     }
     else
     {
         _tabItemBoolFieldStore &= (~field);
     }
 }
예제 #15
0
 private static void SetBoolField(UIElement element, BoolField field, bool value)
 {
     if (value)
     {
         element.SetValue(BooleanFieldStoreProperty, ((BoolField)element.GetValue(BooleanFieldStoreProperty)) | field);
     }
     else
     {
         element.SetValue(BooleanFieldStoreProperty, ((BoolField)element.GetValue(BooleanFieldStoreProperty)) & (~field));
     }
 }
예제 #16
0
        protected override void ConstructFields()
        {
            SupportsNotificationBinding = false;
            NoBuildCrosschecks          = true;
            FieldValidationSuspended    = true;

            TableName = "TBL_TESTPERSON";
            StoreFlag = StoreFlag.LoadAndStore;

            m_fldName = new StringField()
            {
                Owner     = this,
                FieldName = "PERSON_NAME",
                Required  = true,
                Size      = 50
            };


            m_fldRating = new IntField()
            {
                Owner          = this,
                FieldName      = "RATING",
                MinMaxChecking = true,
                MinValue       = 0,
                MaxValue       = 10
            };

            m_fldRegistered = new BoolField()
            {
                Owner     = this,
                FieldName = "IS_REGISTERED",
                Required  = true
            };

            m_fldDOB = new DateTimeField()
            {
                Owner     = this,
                FieldName = "DOB"
            };


            m_fldScore = new DoubleField()
            {
                Owner     = this,
                FieldName = "SCORE"
            };


            m_fldData1 = new StringField()
            {
                Owner     = this,
                FieldName = "Data1"
            };

            m_fldData2 = new StringField()
            {
                Owner     = this,
                FieldName = "Data2"
            };

            m_fldData3 = new StringField()
            {
                Owner     = this,
                FieldName = "Data3"
            };

            m_fldData4 = new IntField()
            {
                Owner     = this,
                FieldName = "Data4"
            };

            m_fldData5 = new IntField()
            {
                Owner     = this,
                FieldName = "Data5"
            };

            m_fldData6 = new IntField()
            {
                Owner     = this,
                FieldName = "Data6"
            };

            m_fldData7 = new BoolField()
            {
                Owner     = this,
                FieldName = "Data7"
            };

            m_fldData8 = new BoolField()
            {
                Owner     = this,
                FieldName = "Data8"
            };

            m_fldData9 = new BoolField()
            {
                Owner     = this,
                FieldName = "Data9"
            };

            m_fldData10 = new DoubleField()
            {
                Owner     = this,
                FieldName = "Data10"
            };
        }
예제 #17
0
 public void BoolField(BoolField field, bool value)
 {
     SimpleField(field, value);
 }
예제 #18
0
 private static bool GetBoolField(UIElement element, BoolField field)
 {
     return (((BoolField)element.GetValue(BooleanFieldStoreProperty)) & field) != 0;
 }
예제 #19
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 internal BoolFieldHelper(BoolField fieldEntity)
 {
     _field = fieldEntity;
 }
예제 #20
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="gReport">The g report.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="dataViewFilterOverrides">The data view filter overrides.</param>
        /// <param name="databaseTimeoutSeconds">The database timeout seconds.</param>
        /// <param name="isCommunication">if set to <c>true</c> [is communication].</param>
        /// <param name="errorMessage">The error message.</param>
        public static void BindGrid(Report report, Grid gReport, Person currentPerson, DataViewFilterOverrides dataViewFilterOverrides, int?databaseTimeoutSeconds, bool isCommunication, out string errorMessage)
        {
            errorMessage = null;
            if (report != null)
            {
                var errors = new List <string>();

                if (!report.EntityTypeId.HasValue)
                {
                    gReport.Visible = false;
                    return;
                }

                var rockContext = new RockContext();

                if (!report.IsAuthorized(Authorization.VIEW, currentPerson))
                {
                    gReport.Visible = false;
                    return;
                }

                Type entityType = EntityTypeCache.Get(report.EntityTypeId.Value, rockContext).GetEntityType();
                if (entityType == null)
                {
                    errorMessage = string.Format("Unable to determine entityType for {0}", report.EntityType);
                    return;
                }

                gReport.EntityTypeId = report.EntityTypeId;

                bool isPersonDataSet = report.EntityTypeId == EntityTypeCache.Get(typeof(Rock.Model.Person), true, rockContext).Id;

                if (isPersonDataSet)
                {
                    gReport.PersonIdField = "Id";
                    gReport.DataKeyNames  = new string[] { "Id" };
                }
                else
                {
                    gReport.PersonIdField = null;
                }

                if (report.EntityTypeId.HasValue)
                {
                    gReport.RowItemText = EntityTypeCache.Get(report.EntityTypeId.Value, rockContext).FriendlyName;
                }

                List <EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields(entityType, true, false);

                var selectedEntityFields = new Dictionary <int, EntityField>();
                var selectedAttributes   = new Dictionary <int, AttributeCache>();
                var selectedComponents   = new Dictionary <int, ReportField>();

                // if there is a selectField, keep it to preserve which items are checked
                var selectField = gReport.Columns.OfType <SelectField>().FirstOrDefault();
                gReport.Columns.Clear();
                int columnIndex = 0;

                if (!string.IsNullOrWhiteSpace(gReport.PersonIdField))
                {
                    // if we already had a selectField, use it (to preserve checkbox state)
                    gReport.Columns.Add(selectField ?? new SelectField());
                    columnIndex++;
                }

                var reportFieldSortExpressions = new Dictionary <Guid, string>();

                gReport.CommunicateMergeFields = new List <string>();
                gReport.CommunicationRecipientPersonIdFields = new List <string>();

                foreach (var reportField in report.ReportFields.OrderBy(a => a.ColumnOrder))
                {
                    bool mergeField     = reportField.IsCommunicationMergeField.HasValue && reportField.IsCommunicationMergeField.Value;
                    bool recipientField = reportField.IsCommunicationRecipientField.HasValue && reportField.IsCommunicationRecipientField.Value;

                    columnIndex++;
                    if (reportField.ReportFieldType == ReportFieldType.Property)
                    {
                        var entityField = entityFields.FirstOrDefault(a => a.Name == reportField.Selection);
                        if (entityField != null)
                        {
                            selectedEntityFields.Add(columnIndex, entityField);

                            BoundField boundField = entityField.GetBoundFieldType();
                            boundField.DataField      = string.Format("Entity_{0}_{1}", entityField.Name, columnIndex);
                            boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? entityField.Title : reportField.ColumnHeaderText;
                            boundField.SortExpression = boundField.DataField;
                            reportFieldSortExpressions.AddOrReplace(reportField.Guid, boundField.SortExpression);
                            boundField.Visible = reportField.ShowInGrid;
                            gReport.Columns.Add(boundField);

                            if (mergeField)
                            {
                                gReport.CommunicateMergeFields.Add($"{boundField.DataField}|{boundField.HeaderText.RemoveSpecialCharacters()}");
                            }
                            if (recipientField)
                            {
                                gReport.CommunicationRecipientPersonIdFields.Add(boundField.DataField);
                            }
                        }
                    }
                    else if (reportField.ReportFieldType == ReportFieldType.Attribute)
                    {
                        Guid?attributeGuid = reportField.Selection.AsGuidOrNull();
                        if (attributeGuid.HasValue)
                        {
                            var attribute = AttributeCache.Get(attributeGuid.Value, rockContext);
                            if (attribute != null && attribute.IsActive)
                            {
                                selectedAttributes.Add(columnIndex, attribute);

                                BoundField boundField;

                                if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.BOOLEAN.AsGuid()))
                                {
                                    boundField = new BoolField();
                                }
                                else if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid()))
                                {
                                    boundField = new DefinedValueField();
                                }
                                else
                                {
                                    boundField            = new CallbackField();
                                    boundField.HtmlEncode = false;
                                    (boundField as CallbackField).OnFormatDataValue += (sender, e) => {
                                        string resultHtml = null;
                                        if (e.DataValue != null)
                                        {
                                            bool condensed = true;
                                            resultHtml = attribute.FieldType.Field.FormatValueAsHtml(gReport, e.DataValue.ToString(), attribute.QualifierValues, condensed);
                                        }

                                        e.FormattedValue = resultHtml ?? string.Empty;
                                    };
                                }

                                boundField.DataField      = string.Format("Attribute_{0}_{1}", attribute.Id, columnIndex);
                                boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? attribute.Name : reportField.ColumnHeaderText;
                                boundField.SortExpression = boundField.DataField;
                                reportFieldSortExpressions.AddOrReplace(reportField.Guid, boundField.SortExpression);

                                if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) ||
                                    attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()) ||
                                    attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.FILTER_DATE.AsGuid()))
                                {
                                    boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                                    boundField.ItemStyle.HorizontalAlign   = HorizontalAlign.Right;
                                }

                                boundField.Visible = reportField.ShowInGrid;

                                gReport.Columns.Add(boundField);

                                if (mergeField)
                                {
                                    gReport.CommunicateMergeFields.Add($"{boundField.DataField}|{boundField.HeaderText.RemoveSpecialCharacters()}");
                                }
                                if (recipientField)
                                {
                                    gReport.CommunicationRecipientPersonIdFields.Add(boundField.DataField);
                                }
                            }
                        }
                    }
                    else if (reportField.ReportFieldType == ReportFieldType.DataSelectComponent)
                    {
                        selectedComponents.Add(columnIndex, reportField);

                        DataSelectComponent selectComponent = DataSelectContainer.GetComponent(reportField.DataSelectComponentEntityType.Name);
                        if (selectComponent != null)
                        {
                            try
                            {
                                DataControlField columnField = selectComponent.GetGridField(entityType, reportField.Selection ?? string.Empty);
                                string           fieldId     = $"{selectComponent.ColumnPropertyName}_{columnIndex}";

                                if (columnField is BoundField)
                                {
                                    (columnField as BoundField).DataField = $"Data_{fieldId}";
                                    var  customSortProperties = selectComponent.SortProperties(reportField.Selection ?? string.Empty);
                                    bool sortReversed         = selectComponent.SortReversed(reportField.Selection ?? string.Empty);
                                    if (customSortProperties != null)
                                    {
                                        if (customSortProperties == string.Empty)
                                        {
                                            // disable sorting if customSortExpression set to string.empty
                                            columnField.SortExpression = string.Empty;
                                        }
                                        else
                                        {
                                            columnField.SortExpression = customSortProperties.Split(',').Select(a => string.Format("Sort_{0}_{1}", a, columnIndex)).ToList().AsDelimited(",");
                                        }
                                    }
                                    else
                                    {
                                        // use default sorting if customSortExpression was null
                                        columnField.SortExpression = (columnField as BoundField).DataField;
                                    }

                                    if (sortReversed == true && !string.IsNullOrWhiteSpace(columnField.SortExpression))
                                    {
                                        columnField.SortExpression = columnField.SortExpression + " DESC";
                                    }
                                }

                                columnField.HeaderText = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? selectComponent.ColumnHeaderText : reportField.ColumnHeaderText;
                                if (!string.IsNullOrEmpty(columnField.SortExpression))
                                {
                                    reportFieldSortExpressions.AddOrReplace(reportField.Guid, columnField.SortExpression);
                                }

                                columnField.Visible = reportField.ShowInGrid;
                                gReport.Columns.Add(columnField);

                                if (mergeField)
                                {
                                    gReport.CommunicateMergeFields.Add($"Data_{fieldId}|{columnField.HeaderText.RemoveSpecialCharacters()}");
                                }
                                if (recipientField)
                                {
                                    string fieldName = (selectComponent is IRecipientDataSelect) ? $"Recipient_{fieldId}" : $"Data_{fieldId}";
                                    gReport.CommunicationRecipientPersonIdFields.Add(fieldName);
                                }
                            }
                            catch (Exception ex)
                            {
                                ExceptionLogService.LogException(ex, HttpContext.Current);
                                errors.Add(string.Format("{0} - {1}", selectComponent, ex.Message));
                            }
                        }
                    }
                }

                // if no fields are specified, show the default fields (Previewable/All) for the EntityType
                var dataColumns = gReport.Columns.OfType <object>().Where(a => a.GetType() != typeof(SelectField));
                if (dataColumns.Count() == 0)
                {
                    // show either the Previewable Columns or all (if there are no previewable columns)
                    bool showAllColumns = !entityFields.Any(a => a.FieldKind == FieldKind.Property && a.IsPreviewable);
                    foreach (var entityField in entityFields.Where(a => a.FieldKind == FieldKind.Property))
                    {
                        columnIndex++;
                        selectedEntityFields.Add(columnIndex, entityField);

                        BoundField boundField = entityField.GetBoundFieldType();

                        boundField.DataField      = string.Format("Entity_{0}_{1}", entityField.Name, columnIndex);
                        boundField.HeaderText     = entityField.Name;
                        boundField.SortExpression = boundField.DataField;
                        boundField.Visible        = showAllColumns || entityField.IsPreviewable;
                        gReport.Columns.Add(boundField);
                    }
                }

                try
                {
                    gReport.Visible        = true;
                    gReport.ExportFilename = report.Name;
                    SortProperty sortProperty = gReport.SortProperty;
                    if (sortProperty == null)
                    {
                        var reportSort  = new SortProperty();
                        var sortColumns = new Dictionary <string, SortDirection>();
                        foreach (var reportField in report.ReportFields.Where(a => a.SortOrder.HasValue).OrderBy(a => a.SortOrder.Value))
                        {
                            if (reportFieldSortExpressions.ContainsKey(reportField.Guid))
                            {
                                var sortField = reportFieldSortExpressions[reportField.Guid];
                                if (!string.IsNullOrWhiteSpace(sortField))
                                {
                                    sortColumns.Add(sortField, reportField.SortDirection);
                                }
                            }
                        }

                        if (sortColumns.Any())
                        {
                            reportSort.Property = sortColumns.Select(a => a.Key + (a.Value == SortDirection.Descending ? " desc" : string.Empty)).ToList().AsDelimited(",");
                            sortProperty        = reportSort;
                        }
                    }

                    var qryErrors = new List <string>();
                    System.Data.Entity.DbContext reportDbContext;
                    dynamic qry = report.GetQueryable(entityType, selectedEntityFields, selectedAttributes, selectedComponents, sortProperty, dataViewFilterOverrides, databaseTimeoutSeconds ?? 180, isCommunication, out qryErrors, out reportDbContext);
                    errors.AddRange(qryErrors);

                    if (!string.IsNullOrEmpty(report.QueryHint) && reportDbContext is RockContext)
                    {
                        using (new QueryHintScope(reportDbContext as RockContext, report.QueryHint))
                        {
                            gReport.SetLinqDataSource(qry);
                        }
                    }
                    else
                    {
                        gReport.SetLinqDataSource(qry);
                    }

                    gReport.DataBind();
                }
                catch (Exception ex)
                {
                    Exception exception = ex;
                    ExceptionLogService.LogException(ex, HttpContext.Current);
                    while (exception != null)
                    {
                        if (exception is System.Data.SqlClient.SqlException)
                        {
                            // if there was a SQL Server Timeout, have the warning be a friendly message about that.
                            if ((exception as System.Data.SqlClient.SqlException).Number == -2)
                            {
                                errorMessage = "This report did not complete in a timely manner. You can try again or adjust the timeout setting of this block.";
                                return;
                            }
                            else
                            {
                                errors.Add(exception.Message);
                                exception = exception.InnerException;
                            }
                        }
                        else
                        {
                            errors.Add(exception.Message);
                            exception = exception.InnerException;
                        }
                    }
                }

                if (errors.Any())
                {
                    errorMessage = "WARNING: There was a problem with one or more of the report's data components...<br/><br/> " + errors.AsDelimited("<br/>");
                }
            }
        }
예제 #21
0
        protected override void ConstructFields()
        {
            TableName = "TBL_PATIENT";

               m_fldID = new StringField()
               {
             Owner = this,
             FieldName = "PATIENT_ID",
             Description = "ID",
             Size = 12,
             Required = true,
             KeyField = true
               };

               m_fldFirstName = new StringField(){
              Owner = this,
              FieldName = "FIRST_NAME",
              Description = "First Name",
              Size = 50,
              Required = true
               };

               m_fldLastName = new StringField()
               {
             Owner = this,
             FieldName = "LAST_NAME",
             Description = "Last Name",
             Size = 50,
             Required = true
               };

               m_fldContactPhone = new StringField()
               {
             Owner = this,
             FieldName = "PHONE_CONTACT",
             Description = "Contact Phone#",
             DataEntryFormat = DataEntryFormat.Phone,
             Size = 25
               };

               m_fldDOB = new DateTimeField()
               {
             Owner = this,
             FieldName = "DOB",
             Description = "Date of Birth",
             Required = true
               };

               m_fldAdmissionDate = new DateTimeField()
               {
             Owner = this,
             FieldName = "ADM_DATE",
             Description = "Admission Date"
               };

               m_fldMonthlyCost = new DecimalField()
               {
             Owner = this,
             FieldName = "MONTHLY_COST",
             Description = "Monthly Cost",
             MinValue = 0,
             DisplayFormat = "C"
               };

               m_fldClassification = new StringField()
               {
             Owner = this,
             FieldName = "ATTITUDE_CLASSIFICATION",
             Description = "Classification",
             Required = true,
             Size = 3,
             LookupType = LookupType.Dictionary,
             DataEntryType = DataEntryType.Lookup,

             HasDefaultValue = true,
             DefaultValue = "BUD"
               };

               m_fldClassification.LookupDictionary.Add("MRX, Marxist",
                                                     "CAP, Capitalist",
                                                     "NEH, Nehilist",
                                                     "BUD, Buddhist");

               m_fldReligious = new BoolField()
               {
             Owner = this,
             FieldName = "IS_RELIGIOUS",
             Description = "Religious",
             Required = true,
             DefaultValue = false,
             HasDefaultValue = true
               };
        }
예제 #22
0
        private Element CreateFieldElement(FieldBaseType obj)
        {
            if (obj.GetType() == typeof(EnumField))
            {
                EnumField field     = obj as EnumField;
                Element   enumField = new Element
                {
                    ctrlType           = ctlEnum,
                    label              = field.Label,
                    enumOptions        = field.Options,
                    defaultValue       = field.DefaultValue ?? "",
                    defaultSearchValue = field.DefaultSearchValue ?? "",
                    readOnly           = field.ReadOnly,
                    required           = field.Required,
                    columnName         = field.ColumnName,
                    searchable         = field.Searchable,
                    modifyEnable       = field.ModifyEnabled,
                    hiddenField        = field.HiddenField,
                    clientId           = field.ClientId,
                    resultVisibility   = field.ResultVisibility,
                    resultPosition     = field.ResultPosition,
                    multipleValues     = field.MultipleValues
                };
                if (field.Layout != null)
                {
                    enumField.rows    = field.Layout.RowNumber;
                    enumField.columns = field.Layout.ColNumber;
                }

                return(enumField);
            }

            if (obj.GetType() == typeof(StatusField))
            {
                StatusField field       = obj as StatusField;
                Element     statusField = new Element
                {
                    ctrlType           = ctlStatus,
                    label              = field.Label,
                    statusType         = field.Options,
                    defaultValue       = field.DefaultValue ?? "",
                    defaultSearchValue = field.DefaultSearchValue ?? "",
                    readOnly           = field.ReadOnly,
                    required           = field.Required,
                    columnName         = field.ColumnName,
                    searchable         = field.Searchable,
                    modifyEnable       = field.ModifyEnabled,
                    hiddenField        = field.HiddenField,
                    clientId           = field.ClientId,
                    resultVisibility   = field.ResultVisibility,
                    resultPosition     = field.ResultPosition
                };
                if (field.Layout != null)
                {
                    statusField.rows    = field.Layout.RowNumber;
                    statusField.columns = field.Layout.ColNumber;
                }

                return(statusField);
            }

            if (obj.GetType() == typeof(TextField))
            {
                TextField field     = obj as TextField;
                Element   textField = new Element
                {
                    ctrlType           = ctlText,
                    label              = field.Label,
                    multiLine          = field.Multiline,
                    HTMLEnable         = field.HTMLEnable,
                    defaultValue       = field.DefaultValue ?? "",
                    defaultSearchValue = field.DefaultSearchValue ?? "",
                    readOnly           = field.ReadOnly,
                    required           = field.Required,
                    columnName         = field.ColumnName,
                    searchable         = field.Searchable,
                    modifyEnable       = field.ModifyEnabled,
                    hiddenField        = field.HiddenField,
                    clientId           = field.ClientId,
                    resultVisibility   = field.ResultVisibility,
                    resultPosition     = field.ResultPosition
                };
                if (field.Layout != null)
                {
                    textField.rows    = field.Layout.RowNumber;
                    textField.columns = field.Layout.ColNumber;
                }

                return(textField);
            }

            if (obj.GetType() == typeof(DateField))
            {
                DateField field   = obj as DateField;
                Element   element = new Element
                {
                    ctrlType           = ctlDate,
                    label              = field.Label,
                    defaultSearchValue = field.DefaultSearchValue.ToString("dd/MM/yyyy") ?? "",
                    restrictedYear     = field.RestrictedYear,
                    enableDefaultDate  = field.DefaultTodayEnabled,
                    readOnly           = field.ReadOnly,
                    required           = field.Required,
                    columnName         = field.ColumnName,
                    searchable         = field.Searchable,
                    modifyEnable       = field.ModifyEnabled,
                    hiddenField        = field.HiddenField,
                    clientId           = field.ClientId,
                    resultVisibility   = field.ResultVisibility,
                    resultPosition     = field.ResultPosition
                };

                element.defaultValue = "";
                if (field.DefaultValueSpecified && field.DefaultValue != DateTime.MinValue)
                {
                    element.defaultValue = field.DefaultValue.ToString("dd/MM/yyyy");
                }

                if (field.Layout != null)
                {
                    element.rows    = field.Layout.RowNumber;
                    element.columns = field.Layout.ColNumber;
                }

                return(element);
            }

            if (obj.GetType() == typeof(NumberField))
            {
                NumberField field       = obj as NumberField;
                Element     numberField = new Element
                {
                    ctrlType     = ctlNumber,
                    label        = field.Label,
                    defaultValue = field.DefaultValueSpecified == true?field.DefaultValue.ToString() : "",
                                       readOnly         = field.ReadOnly,
                                       required         = field.Required,
                                       columnName       = field.ColumnName,
                                       searchable       = field.Searchable,
                                       modifyEnable     = field.ModifyEnabled,
                                       hiddenField      = field.HiddenField,
                                       clientId         = field.ClientId,
                                       resultVisibility = field.ResultVisibility,
                                       resultPosition   = field.ResultPosition,
                                       format           = field.Format
                };
                if (field.MinValueSpecified)
                {
                    numberField.minValue = field.MinValue;
                }
                if (field.MaxValueSpecified)
                {
                    numberField.maxValue = field.MaxValue;
                }
                if (field.Layout != null)
                {
                    numberField.rows    = field.Layout.RowNumber;
                    numberField.columns = field.Layout.ColNumber;
                }
                return(numberField);
            }

            if (obj.GetType() == typeof(BoolField))
            {
                BoolField field     = obj as BoolField;
                Element   boolField = new Element
                {
                    ctrlType         = ctlCheckbox,
                    label            = field.Label,
                    defaultValue     = field.DefaultValue == true && field.DefaultValueSpecified ? "True" : "",
                    readOnly         = field.ReadOnly,
                    required         = field.Required,
                    columnName       = field.ColumnName,
                    searchable       = field.Searchable,
                    modifyEnable     = field.ModifyEnabled,
                    hiddenField      = field.HiddenField,
                    clientId         = field.ClientId,
                    resultVisibility = field.ResultVisibility,
                    resultPosition   = field.ResultPosition
                };
                if (field.Layout != null)
                {
                    boolField.rows    = field.Layout.RowNumber;
                    boolField.columns = field.Layout.ColNumber;
                }
                return(boolField);
            }

            if (obj.GetType() == typeof(LookupField))
            {
                LookupField field  = obj as LookupField;
                Element     lookup = new Element
                {
                    ctrlType             = ctlLookup,
                    label                = field.Label,
                    required             = field.Required,
                    columnName           = field.ColumnName,
                    lookupRepositoryName = field.LookupArchiveName,
                    lookupFieldName      = field.LookupArchiveColumnName == "_subject" ? "Oggetto" : field.LookupArchiveColumnName,
                    searchable           = field.Searchable,
                    modifyEnable         = field.ModifyEnabled,
                    hiddenField          = field.HiddenField,
                    clientId             = field.ClientId,
                    resultVisibility     = field.ResultVisibility,
                    resultPosition       = field.ResultPosition,
                    multipleValues       = field.MultipleValues
                };
                if (field.Layout != null)
                {
                    lookup.rows    = field.Layout.RowNumber;
                    lookup.columns = field.Layout.ColNumber;
                }
                return(lookup);
            }

            return(null);
        }
예제 #23
0
        protected void AddDynamicControls(ContentChannel channel)
        {
            // Remove all columns
            gContentChannelItems.Columns.Clear();
            phAttributeFilters.Controls.Clear();

            if (channel != null)
            {
                // Add Title column
                var titleField = new BoundField();
                titleField.DataField      = "Title";
                titleField.HeaderText     = "Title";
                titleField.SortExpression = "Title";
                gContentChannelItems.Columns.Add(titleField);

                // Add Attribute columns
                int    entityTypeId  = EntityTypeCache.Read(typeof(Rock.Model.ContentChannelItem)).Id;
                string channelId     = channel.Id.ToString();
                string channelTypeId = channel.ContentChannelTypeId.ToString();
                foreach (var attribute in AvailableAttributes)
                {
                    var control = attribute.FieldType.Field.FilterControl(attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter);
                    if (control != null)
                    {
                        if (control is IRockControl)
                        {
                            var rockControl = (IRockControl)control;
                            rockControl.Label = attribute.Name;
                            rockControl.Help  = attribute.Description;
                            phAttributeFilters.Controls.Add(control);
                        }
                        else
                        {
                            var wrapper = new RockControlWrapper();
                            wrapper.ID    = control.ID + "_wrapper";
                            wrapper.Label = attribute.Name;
                            wrapper.Controls.Add(control);
                            phAttributeFilters.Controls.Add(wrapper);
                        }

                        string savedValue = gfFilter.GetUserPreference(MakeKeyUniqueToChannel(channel.Id, attribute.Key));
                        if (!string.IsNullOrWhiteSpace(savedValue))
                        {
                            try
                            {
                                var values = JsonConvert.DeserializeObject <List <string> >(savedValue);
                                attribute.FieldType.Field.SetFilterValues(control, attribute.QualifierValues, values);
                            }
                            catch
                            {
                                // intentionally ignore
                            }
                        }
                    }

                    string dataFieldExpression = attribute.Key;
                    bool   columnExists        = gContentChannelItems.Columns.OfType <AttributeField>().FirstOrDefault(a => a.DataField.Equals(dataFieldExpression)) != null;
                    if (!columnExists)
                    {
                        AttributeField boundField = new AttributeField();
                        boundField.DataField   = dataFieldExpression;
                        boundField.AttributeId = attribute.Id;
                        boundField.HeaderText  = attribute.Name;
                        boundField.ItemStyle.HorizontalAlign = attribute.FieldType.Field.AlignValue;
                        gContentChannelItems.Columns.Add(boundField);
                    }
                }

                if (channel.ContentChannelType.IncludeTime)
                {
                    // Add Start column
                    var startField = new DateTimeField();
                    startField.DataField      = "StartDateTime";
                    startField.HeaderText     = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date";
                    startField.SortExpression = "StartDateTime";
                    gContentChannelItems.Columns.Add(startField);

                    // Expire column
                    if (channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange)
                    {
                        var expireField = new DateTimeField();
                        expireField.DataField      = "ExpireDateTime";
                        expireField.HeaderText     = "Expire";
                        expireField.SortExpression = "ExpireDateTime";
                        gContentChannelItems.Columns.Add(expireField);
                    }
                }
                else
                {
                    // Add Start column
                    var startField = new DateField();
                    startField.DataField      = "StartDateTime";
                    startField.HeaderText     = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date";
                    startField.SortExpression = "StartDateTime";
                    gContentChannelItems.Columns.Add(startField);

                    // Expire column
                    if (channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange)
                    {
                        var expireField = new DateField();
                        expireField.DataField      = "ExpireDateTime";
                        expireField.HeaderText     = "Expire";
                        expireField.SortExpression = "ExpireDateTime";
                        gContentChannelItems.Columns.Add(expireField);
                    }
                }

                // Priority column
                var priorityField = new BoundField();
                priorityField.DataField                 = "Priority";
                priorityField.HeaderText                = "Priority";
                priorityField.SortExpression            = "Priority";
                priorityField.DataFormatString          = "{0:N0}";
                priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                gContentChannelItems.Columns.Add(priorityField);


                // Status column
                if (channel.RequiresApproval)
                {
                    var statusField = new BoundField();
                    gContentChannelItems.Columns.Add(statusField);
                    statusField.DataField      = "Status";
                    statusField.HeaderText     = "Status";
                    statusField.SortExpression = "Status";
                    statusField.HtmlEncode     = false;
                }

                // Add occurrences Count column
                var occurrencesField = new BoolField();
                occurrencesField.DataField  = "Occurrences";
                occurrencesField.HeaderText = "Event Occurrences";
                gContentChannelItems.Columns.Add(occurrencesField);

                // Add Created By column
                var createdByPersonNameField = new BoundField();
                createdByPersonNameField.DataField  = "CreatedByPersonName";
                createdByPersonNameField.HeaderText = "Created By";
                createdByPersonNameField.HtmlEncode = false;
                gContentChannelItems.Columns.Add(createdByPersonNameField);

                bool canEditChannel = channel.IsAuthorized(Rock.Security.Authorization.EDIT, CurrentPerson);
                gContentChannelItems.Actions.ShowAdd = canEditChannel;
                gContentChannelItems.IsDeleteEnabled = canEditChannel;
                if (canEditChannel)
                {
                    var deleteField = new DeleteField();
                    gContentChannelItems.Columns.Add(deleteField);
                    deleteField.Click += gContentChannelItems_Delete;
                }
            }
        }
예제 #24
0
        internal static BaseField CreateField(FieldType type)
        {
            BaseField field = null;

            switch (type)
            {
            case FieldType.ObjectKey:
                field = new ObjectKeyField();
                break;

            case FieldType.BigInt:
                field = new BigIntField();
                break;

            case FieldType.Bool:
                field = new BoolField();
                break;

            case FieldType.Date:
                field = new DateField();
                break;

            case FieldType.DateTime:
                field = new DateTimeField();
                break;

            case FieldType.Decimal:
                field = new DecimalField();
                break;

            case FieldType.Image:
                field = new ImageField();
                break;

            case FieldType.Integer:
                field = new IntegerField();
                break;

            case FieldType.LongText:
                field = new LongTextField();
                break;

            case FieldType.Password:
                field = new PasswordField();
                break;

            case FieldType.MonataryAmount:
                field = new DecimalField();
                break;

            case FieldType.Html:
                field = new HtmlField();
                break;

            case FieldType.Xml:
                field = new XmlField();
                break;

            case FieldType.Json:
                field = new JsonField();
                break;

            case FieldType.Email:
                field = new EmailField();
                break;

            case FieldType.Phone:
                field = new PhoneField();
                break;

            case FieldType.ObjectLink:
                field = new ObjectLinkField();
                break;

            case FieldType.MultiObjectLink:
                field = new MultiObjectLinkField();
                break;

            case FieldType.Select:
                field = new SelectField();
                break;

            case FieldType.MultiSelect:
                field = new MultiSelectField();
                break;

            case FieldType.FilterField:
                field = new FilterField();
                break;

            case FieldType.OneToMany:
                field = new OneToManyField();
                break;

            default:
                field = new StringField();
                break;
            }
            return(field);
        }
예제 #25
0
        private ObjectDataFieldControl CreateControl(long typeId, int member, ObjectInfo objInfo)
        {
            ObjectDataFieldControl c = null;

            Safir.Dob.Typesystem.MemberType memberType;
            long   complexType;
            int    typeSize;
            bool   isArray;
            int    arrLength;
            string memberName = Safir.Dob.Typesystem.Members.GetInfo(typeId, member, out memberType, out complexType, out typeSize, out isArray, out arrLength);

            switch (memberType)
            {
            case Safir.Dob.Typesystem.MemberType.EnumerationMemberType:
            {
                c = new EnumField(objInfo, member, complexType, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.BooleanMemberType:
            {
                c = new BoolField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.Int32MemberType:
            {
                c = new Int32Field(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.Int64MemberType:
            {
                c = new Int64Field(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.ChannelIdMemberType:
            {
                c = new ChannelIdField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.HandlerIdMemberType:
            {
                c = new HandlerIdField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.EntityIdMemberType:
            {
                c = new EntityIdField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.InstanceIdMemberType:
            {
                c = new InstanceIdField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.StringMemberType:
            {
                c = new StringField(objInfo, member, memberName, arrLength, typeSize);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.TypeIdMemberType:
            {
                c = new TypeIdField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.ObjectMemberType:
            {
                c = new ObjectField(objInfo, member, complexType, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.BinaryMemberType:
            {
                c = new BinaryField(objInfo, member, memberName, arrLength);
                break;
            }

            case Safir.Dob.Typesystem.MemberType.Float32MemberType:
            case Safir.Dob.Typesystem.MemberType.Ampere32MemberType:
            case Safir.Dob.Typesystem.MemberType.CubicMeter32MemberType:
            case Safir.Dob.Typesystem.MemberType.Hertz32MemberType:
            case Safir.Dob.Typesystem.MemberType.Joule32MemberType:
            case Safir.Dob.Typesystem.MemberType.Kelvin32MemberType:
            case Safir.Dob.Typesystem.MemberType.Kilogram32MemberType:
            case Safir.Dob.Typesystem.MemberType.Meter32MemberType:
            case Safir.Dob.Typesystem.MemberType.MeterPerSecond32MemberType:
            case Safir.Dob.Typesystem.MemberType.MeterPerSecondSquared32MemberType:
            case Safir.Dob.Typesystem.MemberType.Newton32MemberType:
            case Safir.Dob.Typesystem.MemberType.Pascal32MemberType:
            case Safir.Dob.Typesystem.MemberType.Radian32MemberType:
            case Safir.Dob.Typesystem.MemberType.RadianPerSecond32MemberType:
            case Safir.Dob.Typesystem.MemberType.RadianPerSecondSquared32MemberType:
            case Safir.Dob.Typesystem.MemberType.Second32MemberType:
            case Safir.Dob.Typesystem.MemberType.SquareMeter32MemberType:
            case Safir.Dob.Typesystem.MemberType.Steradian32MemberType:
            case Safir.Dob.Typesystem.MemberType.Volt32MemberType:
            case Safir.Dob.Typesystem.MemberType.Watt32MemberType:
            {
                c = new Float32Field(objInfo, member, memberName, arrLength,
                                     Safir.Dob.Typesystem.Members.GetTypeName(typeId, member));
                break;
            }

            case Safir.Dob.Typesystem.MemberType.Float64MemberType:
            case Safir.Dob.Typesystem.MemberType.Ampere64MemberType:
            case Safir.Dob.Typesystem.MemberType.CubicMeter64MemberType:
            case Safir.Dob.Typesystem.MemberType.Hertz64MemberType:
            case Safir.Dob.Typesystem.MemberType.Joule64MemberType:
            case Safir.Dob.Typesystem.MemberType.Kelvin64MemberType:
            case Safir.Dob.Typesystem.MemberType.Kilogram64MemberType:
            case Safir.Dob.Typesystem.MemberType.Meter64MemberType:
            case Safir.Dob.Typesystem.MemberType.MeterPerSecond64MemberType:
            case Safir.Dob.Typesystem.MemberType.MeterPerSecondSquared64MemberType:
            case Safir.Dob.Typesystem.MemberType.Newton64MemberType:
            case Safir.Dob.Typesystem.MemberType.Pascal64MemberType:
            case Safir.Dob.Typesystem.MemberType.Radian64MemberType:
            case Safir.Dob.Typesystem.MemberType.RadianPerSecond64MemberType:
            case Safir.Dob.Typesystem.MemberType.RadianPerSecondSquared64MemberType:
            case Safir.Dob.Typesystem.MemberType.Second64MemberType:
            case Safir.Dob.Typesystem.MemberType.SquareMeter64MemberType:
            case Safir.Dob.Typesystem.MemberType.Steradian64MemberType:
            case Safir.Dob.Typesystem.MemberType.Volt64MemberType:
            case Safir.Dob.Typesystem.MemberType.Watt64MemberType:
            {
                c = new Float64Field(objInfo, member, memberName, arrLength,
                                     Safir.Dob.Typesystem.Members.GetTypeName(typeId, member));
                break;
            }
            }
            if (c != null)
            {
                c.ParentObjectEditPanel = this;
            }
            return(c);
        }
        public static string GetUDSValue(FieldBaseType field)
        {
            string ret = string.Empty;

            if (field is StatusField)
            {
                StatusField rField = field as StatusField;
                if (!string.IsNullOrEmpty(rField.Value))
                {
                    ret = rField.Value;
                }
                return(ret);
            }
            if (field is LookupField)
            {
                LookupField rField = field as LookupField;
                if (!string.IsNullOrEmpty(rField.Value))
                {
                    ret = string.Join(", ", JsonConvert.DeserializeObject <string[]>(rField.Value));
                }
                return(ret);
            }
            if (field is EnumField)
            {
                EnumField rField = field as EnumField;
                if (!string.IsNullOrEmpty(rField.Value))
                {
                    ret = string.Join(", ", JsonConvert.DeserializeObject <string[]>(rField.Value));
                }
                return(ret);
            }
            if (field is NumberField)
            {
                NumberField rField = field as NumberField;
                if (rField.Value != double.MinValue)
                {
                    ret = rField.Value.ToString(rField.Format);
                }
                return(ret);
            }
            if (field is BoolField)
            {
                BoolField rField = field as BoolField;
                ret = rField.Value ? "vero" : "falso";
                return(ret);
            }
            if (field is DateField)
            {
                DateField rField = field as DateField;
                if (rField.Value != DateTime.MinValue)
                {
                    ret = rField.Value.ToLongDateString();
                    if (rField.RestrictedYear)
                    {
                        ret = rField.Value.Year.ToString();
                    }
                }
                return(ret);
            }
            if (field is TextField)
            {
                TextField rField = field as TextField;
                ret = rField.Value;
            }
            return(ret);
        }
예제 #27
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="gReport">The g report.</param>
        /// <param name="bindGridOptions">The bind grid options.</param>
        /// <exception cref="ArgumentNullException">Report must be specified</exception>
        /// <exception cref="Rock.Reporting.RockReportingException">Unable to determine EntityType type for {report.EntityType}</exception>
        public static void BindGrid(Report report, Grid gReport, BindGridOptions bindGridOptions)
        {
            if (report == null)
            {
                throw new ArgumentNullException("Report must be specified");
            }

            if (!report.EntityTypeId.HasValue)
            {
                gReport.Visible = false;
                return;
            }

            var currentPerson = bindGridOptions?.CurrentPerson;

            var rockContext = new RockContext();

            if (!report.IsAuthorized(Authorization.VIEW, currentPerson))
            {
                gReport.Visible = false;
                return;
            }

            Type entityType = EntityTypeCache.Get(report.EntityTypeId.Value, rockContext).GetEntityType();

            if (entityType == null)
            {
                throw new RockReportException(report, $"Unable to determine EntityType type for {report.EntityType} ");
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            gReport.EntityTypeId = report.EntityTypeId;

            bool isPersonDataSet = report.EntityTypeId == EntityTypeCache.Get(typeof(Rock.Model.Person), true, rockContext).Id;

            if (isPersonDataSet)
            {
                gReport.PersonIdField = "Id";
                gReport.DataKeyNames  = new string[] { "Id" };
            }
            else
            {
                gReport.PersonIdField = null;
            }

            if (report.EntityTypeId.HasValue)
            {
                gReport.RowItemText = EntityTypeCache.Get(report.EntityTypeId.Value, rockContext).FriendlyName;
            }

            List <EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields(entityType, true, false);

            var selectedEntityFields = new Dictionary <int, EntityField>();
            var selectedAttributes   = new Dictionary <int, AttributeCache>();
            var selectedComponents   = new Dictionary <int, ReportField>();

            // if there is a selectField, keep it to preserve which items are checked
            var selectField = gReport.Columns.OfType <SelectField>().FirstOrDefault();

            gReport.Columns.Clear();
            int columnIndex = 0;

            if (!string.IsNullOrWhiteSpace(gReport.PersonIdField))
            {
                // if we already had a selectField, use it (to preserve checkbox state)
                gReport.Columns.Add(selectField ?? new SelectField());
                columnIndex++;
            }

            var reportFieldSortExpressions = new Dictionary <Guid, string>();

            gReport.CommunicateMergeFields = new List <string>();
            gReport.CommunicationRecipientPersonIdFields = new List <string>();

            foreach (var reportField in report.ReportFields.OrderBy(a => a.ColumnOrder))
            {
                bool isMergeField     = reportField.IsCommunicationMergeField.HasValue && reportField.IsCommunicationMergeField.Value;
                bool isRecipientField = reportField.IsCommunicationRecipientField.HasValue && reportField.IsCommunicationRecipientField.Value;

                columnIndex++;
                if (reportField.ReportFieldType == ReportFieldType.Property)
                {
                    var entityField = entityFields.FirstOrDefault(a => a.Name == reportField.Selection);

                    if (entityField == null)
                    {
                        // if the reportField selection refers to a non-existant entityField, ignore this field
                        continue;
                    }

                    selectedEntityFields.Add(columnIndex, entityField);

                    BoundField boundField = entityField.GetBoundFieldType();
                    boundField.DataField      = string.Format("Entity_{0}_{1}", entityField.Name, columnIndex);
                    boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? entityField.Title : reportField.ColumnHeaderText;
                    boundField.SortExpression = boundField.DataField;
                    reportFieldSortExpressions.AddOrReplace(reportField.Guid, boundField.SortExpression);
                    boundField.Visible = reportField.ShowInGrid;
                    gReport.Columns.Add(boundField);

                    if (isMergeField)
                    {
                        gReport.CommunicateMergeFields.Add($"{boundField.DataField}|{boundField.HeaderText.RemoveSpecialCharacters()}");
                    }

                    if (isRecipientField)
                    {
                        gReport.CommunicationRecipientPersonIdFields.Add(boundField.DataField);
                    }
                }
                else if (reportField.ReportFieldType == ReportFieldType.Attribute)
                {
                    Guid?attributeGuid = reportField.Selection.AsGuidOrNull();
                    if (attributeGuid == null)
                    {
                        // if an attribute guid is not specified, just ignore this field
                        continue;
                    }

                    var attribute = AttributeCache.Get(attributeGuid.Value, rockContext);
                    if (attribute == null || !attribute.IsActive)
                    {
                        // if the attribute doesn't exist (or no longer exists), or if the active is not active, just ignore this field
                        continue;
                    }

                    selectedAttributes.Add(columnIndex, attribute);

                    BoundField boundField;

                    if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.BOOLEAN.AsGuid()))
                    {
                        boundField = new BoolField();
                    }
                    else if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid()))
                    {
                        boundField = new DefinedValueField();
                    }
                    else
                    {
                        boundField            = new CallbackField();
                        boundField.HtmlEncode = false;
                        (boundField as CallbackField).OnFormatDataValue += (sender, e) =>
                        {
                            string resultHtml     = null;
                            var    attributeValue = e.DataValue ?? attribute.DefaultValueAsType;
                            if (attributeValue != null)
                            {
                                bool condensed = true;
                                resultHtml = attribute.FieldType.Field.FormatValueAsHtml(gReport, attributeValue.ToString(), attribute.QualifierValues, condensed);
                            }

                            e.FormattedValue = resultHtml ?? string.Empty;
                        };
                    }

                    boundField.DataField      = string.Format("Attribute_{0}_{1}", attribute.Id, columnIndex);
                    boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? attribute.Name : reportField.ColumnHeaderText;
                    boundField.SortExpression = boundField.DataField;
                    reportFieldSortExpressions.AddOrReplace(reportField.Guid, boundField.SortExpression);

                    if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) ||
                        attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()) ||
                        attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.FILTER_DATE.AsGuid()))
                    {
                        boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                        boundField.ItemStyle.HorizontalAlign   = HorizontalAlign.Right;
                    }

                    boundField.Visible = reportField.ShowInGrid;

                    gReport.Columns.Add(boundField);

                    if (isMergeField)
                    {
                        gReport.CommunicateMergeFields.Add($"{boundField.DataField}|{boundField.HeaderText.RemoveSpecialCharacters()}");
                    }

                    if (isRecipientField)
                    {
                        gReport.CommunicationRecipientPersonIdFields.Add(boundField.DataField);
                    }
                }
                else if (reportField.ReportFieldType == ReportFieldType.DataSelectComponent)
                {
                    selectedComponents.Add(columnIndex, reportField);

                    DataSelectComponent selectComponent = DataSelectContainer.GetComponent(reportField.DataSelectComponentEntityType.Name);
                    if (selectComponent == null)
                    {
                        throw new RockReportFieldExpressionException(reportField, $"Unable to determine select component for {reportField.DataSelectComponentEntityType.Name}");
                    }

                    DataControlField columnField = selectComponent.GetGridField(entityType, reportField.Selection ?? string.Empty);
                    string           fieldId     = $"{selectComponent.ColumnPropertyName}_{columnIndex}";

                    if (columnField is BoundField)
                    {
                        (columnField as BoundField).DataField = $"Data_{fieldId}";
                        var  customSortProperties = selectComponent.SortProperties(reportField.Selection ?? string.Empty);
                        bool sortReversed         = selectComponent.SortReversed(reportField.Selection ?? string.Empty);
                        if (customSortProperties != null)
                        {
                            if (customSortProperties == string.Empty)
                            {
                                // disable sorting if customSortExpression set to string.empty
                                columnField.SortExpression = string.Empty;
                            }
                            else
                            {
                                columnField.SortExpression = customSortProperties.Split(',').Select(a => string.Format("Sort_{0}_{1}", a, columnIndex)).ToList().AsDelimited(",");
                            }
                        }
                        else
                        {
                            // use default sorting if customSortExpression was null
                            columnField.SortExpression = (columnField as BoundField).DataField;
                        }

                        if (sortReversed == true && !string.IsNullOrWhiteSpace(columnField.SortExpression))
                        {
                            columnField.SortExpression = columnField.SortExpression + " DESC";
                        }
                    }

                    columnField.HeaderText = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? selectComponent.ColumnHeaderText : reportField.ColumnHeaderText;
                    if (!string.IsNullOrEmpty(columnField.SortExpression))
                    {
                        reportFieldSortExpressions.AddOrReplace(reportField.Guid, columnField.SortExpression);
                    }

                    columnField.Visible = reportField.ShowInGrid;
                    gReport.Columns.Add(columnField);

                    if (isMergeField)
                    {
                        gReport.CommunicateMergeFields.Add($"Data_{fieldId}|{columnField.HeaderText.RemoveSpecialCharacters()}");
                    }
                    if (isRecipientField)
                    {
                        string fieldName = (selectComponent is IRecipientDataSelect) ? $"Recipient_{fieldId}" : $"Data_{fieldId}";
                        gReport.CommunicationRecipientPersonIdFields.Add(fieldName);
                    }
                }
            }

            // if no fields are specified, show the default fields (Previewable/All) for the EntityType
            var dataColumns = gReport.Columns.OfType <object>().Where(a => a.GetType() != typeof(SelectField));

            if (dataColumns.Count() == 0)
            {
                // show either the Previewable Columns or all (if there are no previewable columns)
                bool showAllColumns = !entityFields.Any(a => a.FieldKind == FieldKind.Property && a.IsPreviewable);
                foreach (var entityField in entityFields.Where(a => a.FieldKind == FieldKind.Property))
                {
                    columnIndex++;
                    selectedEntityFields.Add(columnIndex, entityField);

                    BoundField boundField = entityField.GetBoundFieldType();

                    boundField.DataField      = string.Format("Entity_{0}_{1}", entityField.Name, columnIndex);
                    boundField.HeaderText     = entityField.Name;
                    boundField.SortExpression = boundField.DataField;
                    boundField.Visible        = showAllColumns || entityField.IsPreviewable;
                    gReport.Columns.Add(boundField);
                }
            }

            try
            {
                gReport.Visible        = true;
                gReport.ExportFilename = report.Name;
                SortProperty sortProperty = gReport.SortProperty;
                if (sortProperty == null)
                {
                    var reportSort  = new SortProperty();
                    var sortColumns = new Dictionary <string, SortDirection>();
                    foreach (var reportField in report.ReportFields.Where(a => a.SortOrder.HasValue).OrderBy(a => a.SortOrder.Value))
                    {
                        if (reportFieldSortExpressions.ContainsKey(reportField.Guid))
                        {
                            var sortField = reportFieldSortExpressions[reportField.Guid];
                            if (!string.IsNullOrWhiteSpace(sortField))
                            {
                                sortColumns.Add(sortField, reportField.SortDirection);
                            }
                        }
                    }

                    if (sortColumns.Any())
                    {
                        reportSort.Property = sortColumns.Select(a => a.Key + (a.Value == SortDirection.Descending ? " desc" : string.Empty)).ToList().AsDelimited(",");
                        sortProperty        = reportSort;
                    }
                }

                var qryErrors       = new List <string>();
                var reportDbContext = bindGridOptions?.ReportDbContext;
                if (reportDbContext == null)
                {
                    reportDbContext = Reflection.GetDbContextForEntityType(entityType);
                }

                ReportGetQueryableArgs reportGetQueryableArgs = new ReportGetQueryableArgs
                {
                    ReportDbContext         = reportDbContext as Rock.Data.DbContext,
                    EntityFields            = selectedEntityFields,
                    Attributes              = selectedAttributes,
                    SelectComponents        = selectedComponents,
                    SortProperty            = sortProperty,
                    DataViewFilterOverrides = bindGridOptions?.DataViewFilterOverrides,
                    DatabaseTimeoutSeconds  = bindGridOptions?.DatabaseTimeoutSeconds ?? 180,
                    IsCommunication         = bindGridOptions?.IsCommunication ?? false
                };

                dynamic qry = report.GetQueryable(reportGetQueryableArgs);

                if (!string.IsNullOrEmpty(report.QueryHint) && reportDbContext is RockContext)
                {
                    using (new QueryHintScope(reportDbContext as RockContext, report.QueryHint))
                    {
                        gReport.SetLinqDataSource(qry);
                    }
                }
                else
                {
                    gReport.SetLinqDataSource(qry);
                }

                gReport.DataBind();
                stopwatch.Stop();

                ReportService.AddRunReportTransaction(report.Id, Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds));
            }
            catch (Exception ex)
            {
                Exception exception = ex;
                ExceptionLogService.LogException(ex, HttpContext.Current);

                // recursively find if there was a SQL timeout exception.
                // A SQL Timeout would be something we might expect, so we'll give that a friendly error message.
                var sqlTimeoutException = FindSqlTimeoutException(ex);

                if (sqlTimeoutException != null)
                {
                    // if there was a SQL Server Timeout, have the warning be a friendly message about that.
                    throw new RockReportException(report, "This report did not complete in a timely manner. You can try again or adjust the timeout setting of this block.", ex);
                }

                // if there isn't a SQL Exception, we'll throw the original exception (since it would be an exception that we wouldn't expect)
                throw;
            }
        }
예제 #28
0
 public static bool IsTrue(BoolField field)
 {
     return(field && field.Value);
 }
예제 #29
0
파일: PersonRecord.cs 프로젝트: mjaric/nfx
        protected override void ConstructFields()
        {
            TableName = "TBL_TESTPERSON";
            StoreFlag = StoreFlag.LoadAndStore;

            m_fldName = new StringField()
            {
                Owner     = this,
                FieldName = "PERSON_NAME",
                Required  = true,
                Size      = 50
            };

            m_fldSex = new StringField()
            {
                Owner         = this,
                FieldName     = "SEX",
                Required      = true,
                Size          = 1,
                DataEntryType = DataEntryType.DirectEntryOrLookupWithValidation,
                LookupType    = LookupType.Dictionary
            };
            m_fldSex.LookupDictionary.AddRange(new string[] { "M,Male", "F,Female", "U,Unspecified" });

            m_fldRating = new IntField()
            {
                Owner          = this,
                FieldName      = "RATING",
                MinMaxChecking = true,
                MinValue       = 0,
                MaxValue       = 10
            };

            m_fldRegistered = new BoolField()
            {
                Owner     = this,
                FieldName = "IS_REGISTERED",
                Required  = true
            };

            m_fldDOB = new DateTimeField()
            {
                Owner     = this,
                FieldName = "DOB"
            };

            m_fldSalary = new DecimalField()
            {
                Owner          = this,
                FieldName      = "PAYROLL_VOLUME",
                MinMaxChecking = true,
                MinValue       = 0M,
                MaxValue       = Decimal.MaxValue
            };

            //calculated field returns salary * 10 years
            m_fldDecadeSalary = new DecimalField()
            {
                Owner         = this,
                FieldName     = "DECADE_SALARY",
                StoreFlag     = StoreFlag.None,
                DataEntryType = DataEntryType.None,
                Calculated    = true,
                Formula       = "850-10 +(::PAYROLL_VOLUME * 10)"
            };

            m_fldScore = new DoubleField()
            {
                Owner     = this,
                FieldName = "SCORE"
            };


            m_fldMovieNames = new ListField <string>()
            {
                Owner     = this,
                FieldName = "MOVIES",
                Required  = true
            };


            //ths is business logic-driven computed column for GUI
            m_fldBusinessCode = new StringField()
            {
                Owner         = this,
                FieldName     = "BUSINESS_CODE",
                StoreFlag     = StoreFlag.None,
                DataEntryType = DataEntryType.None
            };
        }
예제 #30
0
 private bool GetBoolField(BoolField field)
 {
     return((_boolFieldStore & field) != 0);
 }
예제 #31
0
        protected override void ConstructFields()
        {
            TableName = "TBL_TESTPERSON";
               StoreFlag = StoreFlag.LoadAndStore;

               m_fldName = new StringField()
               {
             Owner = this,
             FieldName = "PERSON_NAME",
             Required = true,
             Size = 50
               };

               m_fldSex = new StringField()
               {
             Owner = this,
             FieldName = "SEX",
             Required = true,
             Size = 1,
             DataEntryType = DataEntryType.DirectEntryOrLookupWithValidation,
             LookupType = LookupType.Dictionary
               };
               m_fldSex.LookupDictionary.AddRange(new string[]{"M,Male", "F,Female", "U,Unspecified"});

               m_fldRating = new IntField()
               {
             Owner = this,
             FieldName = "RATING",
             MinMaxChecking = true,
             MinValue = 0,
             MaxValue = 10
               };

               m_fldRegistered = new BoolField()
               {
             Owner = this,
             FieldName = "IS_REGISTERED",
             Required = true
               };

               m_fldDOB = new DateTimeField()
               {
             Owner = this,
             FieldName = "DOB"
               };

               m_fldSalary = new DecimalField()
               {
             Owner = this,
             FieldName = "PAYROLL_VOLUME",
             MinMaxChecking = true,
             MinValue = 0M,
             MaxValue = Decimal.MaxValue
               };

               //calculated field returns salary * 10 years
               m_fldDecadeSalary = new DecimalField()
               {
             Owner = this,
             FieldName = "DECADE_SALARY",
             StoreFlag = StoreFlag.None,
             DataEntryType = DataEntryType.None,
             Calculated = true,
             Formula = "850-10 +(::PAYROLL_VOLUME * 10)"
               };

               m_fldScore = new DoubleField()
               {
             Owner = this,
             FieldName = "SCORE"
               };

               m_fldMovieNames = new ListField<string>()
               {
             Owner = this,
             FieldName = "MOVIES",
             Required = true
               };

               //ths is business logic-driven computed column for GUI
               m_fldBusinessCode = new StringField()
               {
             Owner = this,
             FieldName = "BUSINESS_CODE",
             StoreFlag = StoreFlag.None,
             DataEntryType = DataEntryType.None
               };
        }
예제 #32
0
        //-------------------------------------------------------------------
        //
        //  Private Fields
        //
        //-------------------------------------------------------------------

        #region Private Fields

        private bool GetBoolField(BoolField field)
        {
            return (_tabItemBoolFieldStore & field) != 0;
        }
예제 #33
0
        public static IFieldHelper ConvertToFieldHelper(IEntity fieldEntity)
        {
            if (fieldEntity == null)
            {
                throw new ArgumentNullException("fieldEntity");
            }

            // Ensure we have the specific type of field in question.
            IEntity field = Entity.AsNative(fieldEntity);

            if (field == null)
            {
                throw new Exception("Assert false");
            }

            StringField stringField = field as StringField;

            if (stringField != null)
            {
                return(new StringFieldHelper(stringField));
            }

            AliasField aliasField = field as AliasField;

            if (aliasField != null)
            {
                return(new AliasFieldHelper(aliasField));
            }

            AutoNumberField autoNumberField = field as AutoNumberField;

            if (autoNumberField != null)
            {
                return(new AutoNumberFieldHelper(autoNumberField));
            }

            BoolField boolField = field as BoolField;

            if (boolField != null)
            {
                return(new BoolFieldHelper(boolField));
            }

            CurrencyField currencyField = field as CurrencyField;

            if (currencyField != null)
            {
                return(new CurrencyFieldHelper(currencyField));
            }

            DateField dateField = field as DateField;

            if (dateField != null)
            {
                return(new DateFieldHelper(dateField));
            }

            DateTimeField dateTimeField = field as DateTimeField;

            if (dateTimeField != null)
            {
                return(new DateTimeFieldHelper(dateTimeField));
            }

            DecimalField decimalField = field as DecimalField;

            if (decimalField != null)
            {
                return(new DecimalFieldHelper(decimalField));
            }

            IntField intField = field as IntField;

            if (intField != null)
            {
                return(new IntFieldHelper(intField));
            }

            TimeField timeField = field as TimeField;

            if (timeField != null)
            {
                return(new TimeFieldHelper(timeField));
            }

            GuidField guidField = field as GuidField;

            if (guidField != null)
            {
                return(new GuidFieldHelper(guidField));
            }

            XmlField xmlField = field as XmlField;

            if (xmlField != null)
            {
                return(new XmlFieldHelper(xmlField));
            }

            throw new Exception("Entity is not a valid field type: " + field.GetType().ToString());
        }
예제 #34
0
        protected override void ConstructFields()
        {
            SupportsNotificationBinding = false;
               NoBuildCrosschecks = true;
               FieldValidationSuspended = true;

               TableName = "TBL_TESTPERSON";
               StoreFlag = StoreFlag.LoadAndStore;

               m_fldName = new StringField()
               {
             Owner = this,
             FieldName = "PERSON_NAME",
             Required = true,
             Size = 50
               };

               m_fldRating = new IntField()
               {
               Owner = this,
               FieldName = "RATING",
               MinMaxChecking = true,
               MinValue = 0,
               MaxValue = 10
               };

               m_fldRegistered = new BoolField()
               {
               Owner = this,
               FieldName = "IS_REGISTERED",
               Required = true
               };

               m_fldDOB = new DateTimeField()
               {
               Owner = this,
               FieldName = "DOB"
               };

               m_fldScore = new DoubleField()
               {
               Owner = this,
               FieldName = "SCORE"
               };

               m_fldData1 = new StringField()
               {
               Owner = this,
               FieldName = "Data1"
               };

               m_fldData2 = new StringField()
               {
               Owner = this,
               FieldName = "Data2"
               };

               m_fldData3 = new StringField()
               {
               Owner = this,
               FieldName = "Data3"
               };

               m_fldData4 = new IntField()
               {
               Owner = this,
               FieldName = "Data4"
               };

               m_fldData5 = new IntField()
               {
               Owner = this,
               FieldName = "Data5"
               };

               m_fldData6 = new IntField()
               {
               Owner = this,
               FieldName = "Data6"
               };

               m_fldData7 = new BoolField()
               {
               Owner = this,
               FieldName = "Data7"
               };

               m_fldData8 = new BoolField()
               {
               Owner = this,
               FieldName = "Data8"
               };

               m_fldData9 = new BoolField()
               {
               Owner = this,
               FieldName = "Data9"
               };

               m_fldData10 = new DoubleField()
               {
               Owner = this,
               FieldName = "Data10"
               };
        }
        /// <summary>
        /// Adds the grid columns.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        private void AddGridColumns(Grid grid, DataTable dataTable)
        {
            bool showColumns     = GetAttributeValue("ShowColumns").AsBoolean();
            var  columnList      = GetAttributeValue("Columns").SplitDelimitedValues().ToList();
            var  encryptedFields = GetAttributeValue("EncryptedFields").SplitDelimitedValues().ToList();

            int rowsToEval = 10;

            if (dataTable.Rows.Count < 10)
            {
                rowsToEval = dataTable.Rows.Count;
            }

            grid.Columns.Clear();

            if (!string.IsNullOrWhiteSpace(grid.PersonIdField))
            {
                grid.Columns.Add(new SelectField());
            }

            GridFilterColumnLookup = new Dictionary <Control, string>();

            foreach (DataColumn dataTableColumn in dataTable.Columns)
            {
                if (columnList.Count > 0 &&
                    ((showColumns && !columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase)) ||
                     (!showColumns && columnList.Contains(dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase))))
                {
                    continue;
                }

                BoundField bf            = new BoundField();
                var        splitCaseName = dataTableColumn.ColumnName.SplitCase();

                if (dataTableColumn.DataType == typeof(bool))
                {
                    bf = new BoolField();

                    if (GridFilter != null)
                    {
                        var id = "ddl" + dataTableColumn.ColumnName.RemoveSpecialCharacters();

                        var filterControl = new RockDropDownList()
                        {
                            Label = splitCaseName,
                            ID    = id
                        };

                        GridFilterColumnLookup.Add(filterControl, dataTableColumn.ColumnName);

                        filterControl.Items.Add(BoolToString(null));
                        filterControl.Items.Add(BoolToString(true));
                        filterControl.Items.Add(BoolToString(false));
                        GridFilter.Controls.Add(filterControl);

                        var value = GridFilter.GetUserPreference(id);

                        if (value != null)
                        {
                            filterControl.SetValue(value);
                        }
                    }
                }
                else if (dataTableColumn.DataType == typeof(DateTime))
                {
                    bf = new DateField();

                    for (int i = 0; i < rowsToEval; i++)
                    {
                        object dateObj = dataTable.Rows[i][dataTableColumn];
                        if (dateObj is DateTime)
                        {
                            DateTime dateTime = ( DateTime )dateObj;
                            if (dateTime.TimeOfDay.Seconds != 0)
                            {
                                bf = new DateTimeField();
                                break;
                            }
                        }
                    }

                    if (GridFilter != null)
                    {
                        var id = "drp" + dataTableColumn.ColumnName.RemoveSpecialCharacters();

                        var filterControl = new DateRangePicker()
                        {
                            Label = splitCaseName,
                            ID    = id,
                        };

                        GridFilterColumnLookup.Add(filterControl, dataTableColumn.ColumnName);

                        GridFilter.Controls.Add(filterControl);

                        var value = GridFilter.GetUserPreference(id);

                        if (value != null)
                        {
                            DateTime upper;
                            DateTime lower;

                            if (DateRangePicker.TryParse(value, out lower, out upper))
                            {
                                filterControl.LowerValue = lower;
                                filterControl.UpperValue = upper;
                            }
                        }
                    }
                }
                else
                {
                    if (encryptedFields.Contains(dataTableColumn.ColumnName))
                    {
                        bf = new EncryptedField();
                    }

                    bf.HtmlEncode = false;

                    if (GridFilter != null)
                    {
                        var id            = "tb" + dataTableColumn.ColumnName.RemoveSpecialCharacters();
                        var filterControl = new RockTextBox()
                        {
                            Label = splitCaseName,
                            ID    = id
                        };

                        GridFilterColumnLookup.Add(filterControl, dataTableColumn.ColumnName);

                        GridFilter.Controls.Add(filterControl);
                        var key   = filterControl.ID;
                        var value = GridFilter.GetUserPreference(key);

                        if (value != null)
                        {
                            filterControl.Text = value;
                        }
                    }
                }

                bf.DataField      = dataTableColumn.ColumnName;
                bf.SortExpression = dataTableColumn.ColumnName;
                bf.HeaderText     = splitCaseName;
                grid.Columns.Add(bf);
            }
        }
예제 #36
0
        protected override void ConstructFields()
        {
            TableName = "TBL_PATIENT";

            m_fldID = new StringField()
            {
                Owner       = this,
                FieldName   = "PATIENT_ID",
                Description = "ID",
                Size        = 12,
                Required    = true,
                KeyField    = true
            };

            m_fldFirstName = new StringField()
            {
                Owner       = this,
                FieldName   = "FIRST_NAME",
                Description = "First Name",
                Size        = 50,
                Required    = true
            };

            m_fldLastName = new StringField()
            {
                Owner       = this,
                FieldName   = "LAST_NAME",
                Description = "Last Name",
                Size        = 50,
                Required    = true
            };

            m_fldContactPhone = new StringField()
            {
                Owner           = this,
                FieldName       = "PHONE_CONTACT",
                Description     = "Contact Phone#",
                DataEntryFormat = DataEntryFormat.Phone,
                Size            = 25
            };

            m_fldDOB = new DateTimeField()
            {
                Owner       = this,
                FieldName   = "DOB",
                Description = "Date of Birth",
                Required    = true
            };

            m_fldAdmissionDate = new DateTimeField()
            {
                Owner       = this,
                FieldName   = "ADM_DATE",
                Description = "Admission Date"
            };

            m_fldMonthlyCost = new DecimalField()
            {
                Owner         = this,
                FieldName     = "MONTHLY_COST",
                Description   = "Monthly Cost",
                MinValue      = 0,
                DisplayFormat = "C"
            };

            m_fldClassification = new StringField()
            {
                Owner         = this,
                FieldName     = "ATTITUDE_CLASSIFICATION",
                Description   = "Classification",
                Required      = true,
                Size          = 3,
                LookupType    = LookupType.Dictionary,
                DataEntryType = DataEntryType.Lookup,

                HasDefaultValue = true,
                DefaultValue    = "BUD"
            };

            m_fldClassification.LookupDictionary.Add("MRX, Marxist",
                                                     "CAP, Capitalist",
                                                     "NEH, Nehilist",
                                                     "BUD, Buddhist");

            m_fldReligious = new BoolField()
            {
                Owner           = this,
                FieldName       = "IS_RELIGIOUS",
                Description     = "Religious",
                Required        = true,
                DefaultValue    = false,
                HasDefaultValue = true
            };
        }
예제 #37
0
        /// <summary>
        /// Shows the preview.
        /// </summary>
        /// <param name="entityTypeId">The entity type id.</param>
        /// <param name="filter">The filter.</param>
        private void BindGrid(Report report)
        {
            if (report != null && report.DataView != null)
            {
                var errors = new List <string>();

                if (!report.EntityTypeId.HasValue)
                {
                    return;
                }

                Type entityType = EntityTypeCache.Read(report.EntityTypeId.Value).GetEntityType();
                List <EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields(entityType);

                var selectedEntityFields = new Dictionary <int, EntityField>();
                var selectedAttributes   = new Dictionary <int, AttributeCache>();
                var selectedComponents   = new Dictionary <int, ReportField>();

                gReport.Columns.Clear();
                int columnIndex = 0;
                foreach (var reportField in report.ReportFields.OrderBy(a => a.Order))
                {
                    columnIndex++;
                    if (reportField.ReportFieldType == ReportFieldType.Property)
                    {
                        var entityField = entityFields.FirstOrDefault(a => a.Name == reportField.Selection);
                        if (entityField != null)
                        {
                            selectedEntityFields.Add(columnIndex, entityField);

                            if (reportField.ShowInGrid)
                            {
                                BoundField boundField;
                                if (entityField.DefinedTypeId.HasValue)
                                {
                                    boundField = new DefinedValueField();
                                }
                                else
                                {
                                    boundField = Grid.GetGridField(entityField.PropertyType);
                                }

                                boundField.DataField      = string.Format("Entity_{0}_{1}", entityField.Name, columnIndex);
                                boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? entityField.Title : reportField.ColumnHeaderText;
                                boundField.SortExpression = entityField.Name;
                                gReport.Columns.Add(boundField);
                            }
                        }
                    }
                    else if (reportField.ReportFieldType == ReportFieldType.Attribute)
                    {
                        int?attributeId = reportField.Selection.AsInteger(false);
                        if (attributeId.HasValue)
                        {
                            var attribute = AttributeCache.Read(attributeId.Value);
                            selectedAttributes.Add(columnIndex, attribute);

                            if (reportField.ShowInGrid)
                            {
                                BoundField boundField;

                                if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.BOOLEAN.AsGuid()))
                                {
                                    boundField = new BoolField();
                                }
                                else
                                {
                                    boundField = new BoundField();
                                }

                                boundField.DataField      = string.Format("Attribute_{0}_{1}", attribute.Id, columnIndex);
                                boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? attribute.Name : reportField.ColumnHeaderText;
                                boundField.SortExpression = null;

                                if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) ||
                                    attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DATE.AsGuid()))
                                {
                                    boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                                    boundField.ItemStyle.HorizontalAlign   = HorizontalAlign.Right;
                                }

                                // NOTE:  Additional formatting for attributes is done in the gReport_RowDataBound event
                                gReport.Columns.Add(boundField);
                            }
                        }
                    }
                    else if (reportField.ReportFieldType == ReportFieldType.DataSelectComponent)
                    {
                        selectedComponents.Add(columnIndex, reportField);
                        if (reportField.ShowInGrid)
                        {
                            DataSelectComponent selectComponent = DataSelectContainer.GetComponent(reportField.DataSelectComponentEntityType.Name);
                            if (selectComponent != null)
                            {
                                var boundField = Grid.GetGridField(selectComponent.ColumnFieldType);
                                boundField.DataField      = string.Format("Data_{0}_{1}", selectComponent.ColumnPropertyName, columnIndex);
                                boundField.HeaderText     = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? selectComponent.ColumnHeaderText : reportField.ColumnHeaderText;
                                boundField.SortExpression = null;
                                gReport.Columns.Add(boundField);
                            }
                        }
                    }
                }

                gReport.DataSource = report.GetDataSource(new RockContext(), entityType, selectedEntityFields, selectedAttributes, selectedComponents, gReport.SortProperty, out errors);

                if (errors.Any())
                {
                    nbEditModeMessage.Text = "INFO: There was a problem with one or more of the report's data components...<br/><br/> " + errors.AsDelimited("<br/>");
                }

                gReport.DataBind();
            }
        }