Files
moadiran/TaxPayerFull/Layout/LTable.razor
mmrbnjd eddbc54c4c ...
2024-06-08 21:48:26 +03:30

104 lines
5.8 KiB
Plaintext

@using System.Reflection
@using System.ComponentModel.DataAnnotations
@using Shared.DTOs
@typeparam T
<div class="row">
<div class="col-md-12">
<div class="mb-4">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="table-responsive text-nowrap">
<table class="table">
<thead class="table-light">
<tr>
@{
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (var item in properties)
{
if (item.GetCustomAttributes(typeof(DisplayAttribute), false).Length > 0)
{
<th>
@item.CustomAttributes.Where(w => w.AttributeType.Name == "DisplayAttribute").Select(s => s.NamedArguments.Where(w => w.MemberName == "Name").Select(ss => ss.TypedValue.Value).First()).First().ToString()
</th>
}
}
<th>عملیات</th>
}
</tr>
</thead>
<tbody class="table-border-bottom-0">
@{
foreach (var item in ModelinComponent)
{
<tr>
@{
properties = item.GetType().GetProperties();
int id = 0;
foreach (PropertyInfo property in properties)
{
if (property.Name.ToLower() == "id")
id = Convert.ToInt32(property.GetValue(item, null));
if (property.CustomAttributes.Any(w => w.AttributeType.Name == "DisplayAttribute"))
{
if (property.PropertyType == typeof(Nullable<System.Decimal>) || property.PropertyType == typeof(System.Decimal))
{
<td>
@decimal.Parse(property.GetValue(item, null).ToString()).ToString("N0") ريال
</td>
}
else if (property.Name.ToLower() == "id")
{
if (id > 0)
{
<td><button @onclick="()=>OnMultipleOfThree.InvokeAsync(Convert.ToInt32(id))" type="button" class="btn btn-link">@property.GetValue(item, null)</button></td>
}
else
{
<td><button type="button" class="btn btn-link disabled">@property.GetValue(item, null)</button></td>
}
}
else
{
<td>@property.GetValue(item, null)</td>
}
}
}
if (id > 0)
{
<td><button @onclick="()=>OnMultipleOfThree.InvokeAsync(Convert.ToInt32(id))" type="button" class="btn btn-link">ویرایش</button></td>
}
else
{
<td><button type="button" class="btn btn-link disabled">ویرایش</button></td>
}
}
</tr>
}
}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@code {
[Parameter]
public List<T> ModelinComponent { get; set; } = new List<T>();
[Parameter] public EventCallback<int> OnMultipleOfThree { get; set; }
}