150 lines
7.9 KiB
C#
150 lines
7.9 KiB
C#
using AyCode.Entities.Users;
|
|
using DevExpress.Blazor;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TIAM.Entities.TransferDestinations;
|
|
|
|
namespace TIAMSharedUI.Pages.Components
|
|
{
|
|
public partial class InputWizard : ComponentBase
|
|
{
|
|
|
|
string FormSubmitResult = "";
|
|
//TestUserData Data { get; set; } = new TestUserData();
|
|
TransferDestination Data { get; set; } = new TransferDestination();
|
|
|
|
string PhoneMask { get; set; } = "(999)000-0000";
|
|
|
|
void HandleValidSubmit()
|
|
{
|
|
FormSubmitResult = "You have been registred successully.";
|
|
}
|
|
void HandleInvalidSubmit()
|
|
{
|
|
FormSubmitResult = "Please correct all errors";
|
|
}
|
|
|
|
public RenderFragment CreateEditFormFields() => formLayoutBuilder =>
|
|
{
|
|
var propertyList = typeof(TransferDestination).GetProperties();
|
|
formLayoutBuilder.OpenComponent<DxFormLayout>(0);
|
|
formLayoutBuilder.AddAttribute(1, "ChildContent", (RenderFragment)((layoutItemBuilder) =>
|
|
{
|
|
int i = 0;
|
|
foreach (var property in propertyList)
|
|
{
|
|
|
|
var attrList = (DataTypeAttribute)property.GetCustomAttributes(typeof(DataTypeAttribute), false).First();
|
|
DisplayAttribute displayLabel = (DisplayAttribute)property.GetCustomAttributes(typeof(DisplayAttribute), false).First();
|
|
layoutItemBuilder.OpenComponent<DxFormLayoutItem>(i++);
|
|
layoutItemBuilder.AddAttribute(i++, "Caption", displayLabel.Name);
|
|
layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12);
|
|
//layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field");
|
|
var access = Expression.Property(Expression.Constant(Data), property.Name);
|
|
var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access);
|
|
layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<Object>)((context) => ((editor) =>
|
|
{
|
|
var j = 0;
|
|
switch (attrList.DataType)
|
|
{
|
|
case DataType.Text:
|
|
{
|
|
editor.OpenComponent<DxTextBox>(j++);
|
|
editor.AddAttribute(j++, "Text", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "TextExpression", lambda);
|
|
editor.AddAttribute(j++, "CssClass", "form-field");
|
|
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
}
|
|
case DataType.Password:
|
|
{
|
|
|
|
editor.OpenComponent<DxTextBox>(j++);
|
|
editor.AddAttribute(j++, "Password", true);
|
|
editor.AddAttribute(j++, "NullText", "Password");
|
|
editor.AddAttribute(j++, "Text", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "TextExpression", lambda);
|
|
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
}
|
|
case DataType.PhoneNumber:
|
|
{
|
|
editor.OpenComponent<DxMaskedInput<String>>(j++);
|
|
editor.AddAttribute(j++, "Value", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "Mask", PhoneMask);
|
|
editor.AddAttribute(j++, "ValueExpression", lambda);
|
|
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
}
|
|
case DataType.Date:
|
|
{
|
|
editor.OpenComponent<DxDateEdit<DateTime>>(j);
|
|
editor.AddAttribute(j++, "Date", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "DateExpression", lambda);
|
|
editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create<System.DateTime>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
|
|
}
|
|
case DataType.Custom:
|
|
{
|
|
editor.OpenComponent<DxComboBox<String, String>>(j);
|
|
editor.AddAttribute(j++, "Data", AdditionalData.Occupations);
|
|
editor.AddAttribute(j++, "Value", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "ValueExpression", lambda);
|
|
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
|
|
}
|
|
case DataType.MultilineText:
|
|
{
|
|
editor.OpenComponent<DxMemo>(j);
|
|
editor.AddAttribute(j++, "Text", property.GetValue(Data));
|
|
editor.AddAttribute(j++, "TextExpression", lambda);
|
|
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
|
|
editor.CloseComponent();
|
|
break;
|
|
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
})));
|
|
|
|
layoutItemBuilder.CloseComponent();
|
|
layoutItemBuilder.OpenElement(i++, "div");
|
|
layoutItemBuilder.AddAttribute(i++, "class", "text-danger");
|
|
layoutItemBuilder.OpenComponent(i++, typeof(ValidationMessage<>).MakeGenericType(property.PropertyType));
|
|
layoutItemBuilder.AddAttribute(i++, "For", lambda);
|
|
layoutItemBuilder.CloseComponent();
|
|
layoutItemBuilder.CloseElement();
|
|
}
|
|
layoutItemBuilder.OpenComponent<DxFormLayoutItem>(i++);
|
|
layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<Object>)((context) => ((editor) =>
|
|
{
|
|
|
|
editor.OpenComponent<DxButton>(i++);
|
|
editor.AddAttribute(i++, "SubmitFormOnClick", true);
|
|
editor.AddAttribute(i++, "Text", "Register");
|
|
editor.CloseComponent();
|
|
})));
|
|
|
|
layoutItemBuilder.CloseComponent();
|
|
}));
|
|
formLayoutBuilder.CloseComponent();
|
|
};
|
|
|
|
}
|
|
}
|