예제 #1
0
        public static void AppendComplexType <T, TProperty>(RenderTreeBuilder pBuilder, IMPropertyInfo pPropertyInfo, T pModel, Guid pId, IMForm pParent, MComplexPropertyField <T, TProperty> pComplexField,
                                                            MFormGridContext pGridContext)
        {
            if (pComplexField.Template == null)
            {
                ShowNotSupportedType(pBuilder, pPropertyInfo, pModel, pId, pParent);
                return;
            }

            MComplexPropertyFieldContext <TProperty> context = new MComplexPropertyFieldContext <TProperty>();

            TProperty value = (TProperty)pPropertyInfo.GetValue(pModel);

#pragma warning disable BL0005 // Component parameter should not be set outside of its component.
            context.Row              = pModel;
            context.InputId          = pId;
            context.Value            = value;
            context.MFormGridContext = pGridContext;

            context.ValueChanged = RuntimeHelpers.CreateInferredEventCallback <TProperty>(pParent, async __value =>
            {
                pPropertyInfo.SetValue(pModel, __value);
                await pParent.OnInputValueChanged(pComplexField, pPropertyInfo, __value);
            }, value);

            context.ValueExpression = GetValueExpression <TProperty>(pPropertyInfo, pModel);

#pragma warning restore BL0005 // Component parameter should not be set outside of its component.

            pBuilder.AddContent(42, pComplexField.Template?.Invoke(context));
        }
예제 #2
0
        private static async Task InvokeValueChanged(IMForm pParent, IMPropertyInfo pPropertyInfo, IMField pField, object pModel, object pNewValue)
        {
            lock (pModel)
            {
                if (pPropertyInfo.GetCustomAttribute <DateAttribute>() != null)
                {
                    var dateTime = pNewValue as DateTime?;

                    if (dateTime != null && dateTime.Value.Kind == DateTimeKind.Unspecified)
                    {
                        pNewValue = DateTime.SpecifyKind(dateTime.Value, DateTimeKind.Utc);
                    }
                }

                pPropertyInfo.SetValue(pModel, pNewValue);
            }

            await pParent.OnInputValueChanged(pField, pPropertyInfo, pNewValue);
        }
예제 #3
0
        public static void AppendComplexType <T, TProperty>(RenderTreeBuilder pBuilder, IMPropertyInfo pPropertyInfo, T pModel, Guid pId, IMForm pParent, MComplexPropertyField <TProperty> pComplexField,
                                                            MFormGridContext pGridContext)
        {
            if (pComplexField.Template == null)
            {
                ShowNotSupportedType(pBuilder, pPropertyInfo, pModel, pId);
                return;
            }

            TProperty value = (TProperty)pPropertyInfo.GetValue(pModel);

            var context = new MComplexPropertyFieldContext <TProperty>
            {
                Row              = pModel,
                InputId          = pId.ToString(),
                FormId           = pParent.Id.ToString(),
                Form             = pParent,
                Value            = value,
                MFormGridContext = pGridContext,

                ValueChanged = RuntimeHelpers.CreateInferredEventCallback <TProperty>(pParent, async __value =>
                {
                    pPropertyInfo.SetValue(pModel, __value);
                    await pParent.OnInputValueChanged(pComplexField, pPropertyInfo, __value);
                }, value),

                ValueExpression = GetValueExpression <TProperty>(pPropertyInfo, pModel)
            };

            pBuilder.AddContent(263, pComplexField.Template?.Invoke(context));

            if (pParent.EnableValidation)
            {
                pBuilder.OpenComponent <ValidationMessage <TProperty> >(236);
                pBuilder.AddAttribute(237, "For", context.ValueExpression);
                pBuilder.CloseComponent();
            }
        }
예제 #4
0
        public static void AppendInput <T>(RenderTreeBuilder pBuilder, IMPropertyInfo pPropertyInfo, object pModel, Guid pId, IMForm pParent, bool pIsInFilterRow, IMField pField)
        {
            try
            {
                if (!IsTypeSupported(typeof(T)) || IsPropertyHolderNull(pPropertyInfo, pModel))
                {
                    ShowNotSupportedType(pBuilder, pPropertyInfo, pModel, pId, pParent);
                    return;
                }

                T    value = (T)(pPropertyInfo.GetValue(pModel) ?? default(T));
                Type tType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);

                bool isReadOnly = pPropertyInfo.IsReadOnly || pPropertyInfo.GetCustomAttribute(typeof(ReadOnlyAttribute)) != null;

                if (mNumberTypes.Contains(tType))
                {
                    pBuilder.OpenComponent <InputNumber <T> >(0);
                }
                else if (tType == typeof(DateTime) || tType == typeof(DateTimeOffset))
                {
                    if (pPropertyInfo.GetCustomAttribute(typeof(TimeAttribute)) != null)
                    {
                        pBuilder.OpenComponent <InputTime <T> >(0);
                    }
                    else if (pPropertyInfo.GetCustomAttribute(typeof(DateTimeAttribute)) != null)
                    {
                        pBuilder.OpenComponent <InputDateTime <T> >(0);
                    }
                    else
                    {
                        pBuilder.OpenComponent <InputDate <T> >(0);
                    }
                }
                else if (typeof(T) == typeof(bool))
                {
                    pBuilder.OpenComponent <MInputCheckbox>(0);
                }
                else if (typeof(T) == typeof(bool?))
                {
                    pBuilder.OpenComponent <MSelect <T> >(0);
                    if (pIsInFilterRow)
                    {
                        pBuilder.AddAttribute(10, "NullValueDescription", "\u200b");
                    }
                }
                else if (tType == typeof(Guid))
                {
                    pBuilder.OpenComponent <InputGuid <T> >(0);
                }
                else if (tType.IsEnum)
                {
                    pBuilder.OpenComponent <MSelect <T> >(0);
                    if (pIsInFilterRow)
                    {
                        pBuilder.AddAttribute(10, "NullValueDescription", "\u200b");
                    }
                }
                else
                {
                    if (pPropertyInfo.GetCustomAttribute(typeof(TextAreaAttribute)) != null)
                    {
                        pBuilder.OpenComponent <InputTextArea>(0);
                    }
                    else
                    {
                        pBuilder.OpenComponent <InputText>(0);
                    }
                }

                if (pPropertyInfo.GetCustomAttribute(typeof(PasswordAttribute)) != null)
                {
                    pBuilder.AddAttribute(33, "type", "password");
                }

                if (pField.AdditionalAttributes != null)
                {
                    pBuilder.AddMultipleAttributes(17, pField.AdditionalAttributes
                                                   .Where(a => a.Key != Extensions.MFORM_IN_TABLE_ROW_TD_STYLE_ATTRIBUTE)
                                                   .Where(a => a.Key != nameof(IMGridColumn))
                                                   .ToDictionary(a => a.Key, a => a.Value));
                }

                pBuilder.AddAttribute(1, "id", pId);
                pBuilder.AddAttribute(2, "Value", value);

                pBuilder.AddAttribute(23, "ValueChanged", RuntimeHelpers.CreateInferredEventCallback <T>(pParent, async __value =>
                {
                    pPropertyInfo.SetValue(pModel, __value);
                    await pParent.OnInputValueChanged(pField, pPropertyInfo, __value);
                }, value));

                pBuilder.AddAttribute(23, "onkeyup", EventCallback.Factory.Create <KeyboardEventArgs>(pParent, (a) =>
                {
                    pParent.OnInputKeyUp(a);
                }));

                var valueExpression = GetValueExpression <T>(pPropertyInfo, pModel);

                pBuilder.AddAttribute(4, "ValueExpression", valueExpression);

                string cssClass = "m-form-control";

                if (isReadOnly)
                {
                    pBuilder.AddAttribute(33, "disabled", string.Empty);
                    pBuilder.AddAttribute(33, "IsDisabled", true);
                }

                pBuilder.AddAttribute(10, "class", cssClass);

                if (typeof(T) == typeof(bool?))
                {
                    IEnumerable <bool?> options = new bool?[] { true, false };
                    pBuilder.AddAttribute(10, "Options", options);
                }

                pBuilder.CloseComponent();

                if (pParent.EnableValidation)
                {
                    pBuilder.OpenComponent <ValidationMessage <T> >(60);
                    pBuilder.AddAttribute(61, "For", valueExpression);
                    pBuilder.CloseComponent();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }