179 lines
5.6 KiB
Plaintext
179 lines
5.6 KiB
Plaintext
@using System.Reflection
|
|
|
|
@inherits BaseForm
|
|
<EditForm OnValidSubmit="Success" Model="model">
|
|
|
|
<div>
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
@foreach (var p in Properties)
|
|
{
|
|
@if (p.PropertyType.Name == "Int32")
|
|
{
|
|
<DynamicBinder T="int"
|
|
Getter="@(() => GetProperty<int>(p))"
|
|
Setter="@(v => p.SetValue(model, v))">
|
|
<ChildContent Context="item">
|
|
|
|
<div class="form-floating mb-3">
|
|
<InputNumber TValue="int" class="form-control"
|
|
id="@nameof(p.Name)"
|
|
Value="@item.Value"
|
|
ValueChanged="@(v => item.SetValue(v))"
|
|
ValueExpression="@(() => item.Value)" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
</ChildContent>
|
|
</DynamicBinder>
|
|
}
|
|
else if (p.PropertyType.Name == "String")
|
|
{
|
|
<DynamicBinder T="string"
|
|
Getter="@(() => GetProperty<string>(p))"
|
|
Setter="@(v => p.SetValue(model, v))">
|
|
<ChildContent Context="item">
|
|
|
|
<div class="form-floating mb-3">
|
|
<InputText class="form-control"
|
|
id="@nameof(p.Name)"
|
|
Value="@item.Value"
|
|
ValueChanged="@(v => item.SetValue(v))"
|
|
ValueExpression="@(() => item.Value)" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
</ChildContent>
|
|
</DynamicBinder>
|
|
}
|
|
else if (p.PropertyType.Name == "DateTime")
|
|
{
|
|
<DynamicBinder T="DateTime"
|
|
Getter="@(() => GetProperty<DateTime>(p))"
|
|
Setter="@(v => p.SetValue(model, v))">
|
|
<ChildContent Context="item">
|
|
<div class="form-floating mb-3">
|
|
<Cdate TValue="DateTime" class="form-control"
|
|
id="@nameof(p.Name)"
|
|
Value="@item.Value"
|
|
ValueChanged="@(v => item.SetValue(v))"
|
|
ValueExpression="@(() => item.Value)" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
</ChildContent>
|
|
</DynamicBinder>
|
|
}
|
|
|
|
|
|
@* else if (p.PropertyType == typeof(Nullable<int>))
|
|
{
|
|
<div class="form-floating mb-3">
|
|
<InputNumber id="@nameof(p.Name)" @bind-Value="n_intValues.Where(v => v.PName == p.Name).Single().Value" placeholder="placeholder" class="form-control" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
}
|
|
|
|
else if (p.PropertyType.Name == "DateTime")
|
|
{
|
|
<div class="form-floating mb-3">
|
|
<input id="@nameof(p.Name)" @bind="DateTimeValues.Where(v => v.PName == p.Name).Single().Value" placeholder="placeholder" class="form-control" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
}
|
|
|
|
else if (p.PropertyType.Name == "Boolean")
|
|
{
|
|
<div class="form-floating mb-3">
|
|
<input id="@nameof(p.Name)" @bind="BoolValues.Where(v => v.PName == p.Name).Single().Value" placeholder="placeholder" class="form-control" />
|
|
<label for="@nameof(p.Name)">@p.GetDisplayName()</label>
|
|
</div>
|
|
} *@
|
|
|
|
}
|
|
</div>
|
|
<button class='btn btn-sm @((IsUpdate)? "btn-warning" : "btn-success")'>ثبت</button>
|
|
</EditForm>
|
|
|
|
|
|
@code {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
public Type Type { get; set; } /* = typeof(SubAsil.Models.Users.User); */
|
|
|
|
[Parameter]
|
|
public object Data { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<object> OnChange { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<object> OnDone { get; set; }
|
|
|
|
|
|
//public object DynamicInstance { get; set; } = new();
|
|
|
|
public List<PropertyInfo> Properties { get; set; } = new();
|
|
|
|
object model = new object();
|
|
|
|
bool IsUpdate = false;
|
|
|
|
|
|
T? GetProperty<T>(PropertyInfo prop)
|
|
{
|
|
return (T)prop.GetValue(model)!;
|
|
}
|
|
|
|
void SetValue<T>(PropertyInfo prop, T value)
|
|
{
|
|
prop.SetValue(model, value);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
model = Activator.CreateInstance(Type);
|
|
if (Data != null)
|
|
{
|
|
model = Data;
|
|
//IsUpdate = true;
|
|
}
|
|
|
|
var sssss = (BaseEntity)model;
|
|
|
|
// sssss.CreateDate = DateTime.Now;
|
|
|
|
model = sssss;
|
|
|
|
Properties = Type.GetProperties().ToList();
|
|
Properties = Properties.Where(p => !PropertyFilters.Any(pp => pp == p.Name)).ToList();
|
|
}
|
|
|
|
|
|
|
|
[Inject]
|
|
public IJSRuntime Js { get; set; }
|
|
|
|
async void Success()
|
|
{
|
|
await OnDone.InvokeAsync(model);
|
|
//await OnChange.InvokeAsync(model);
|
|
}
|
|
public int GetNumber(PropertyInfo property)
|
|
{
|
|
return Properties.IndexOf(property);
|
|
}
|
|
public class Mmodel<T>
|
|
{
|
|
public T Value { get; set; }
|
|
|
|
public string PName { get; set; }
|
|
}
|
|
|
|
public List<string> PropertyFilters = new List<string> { /* "CreateDate", "UpdateDate" */ };
|
|
}
|
|
|