WorkpieceProcessingRecordPage.razor 2.11 KB
@page "/DataAnalysis/WorkpieceProcessingRecord"
@using System.Text.Json;
@using AntDesign.TableModels
@using System.ComponentModel
@using DataAcquisition.DataAccess
@using DataAcquisition.Models
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;

<Table @ref="table"
       TItem="WorkpieceProcessingRecord"
       Loading="loading"
       DataSource="@dataItems"
       Total="_total"
       @bind-PageIndex="_pageIndex"
       @bind-PageSize="_pageSize"
       OnChange="OnChange"
       Size="TableSize.Small"
       RowKey="x=>x.Id">
    <PropertyColumn Property="c=>c.Id" Hidden />
     <PropertyColumn Title="设备编号" Property="c=>c.EquipmentCode" />
     <PropertyColumn Title="设备名称" Property="c=>c.EquipmentName" />
     <PropertyColumn Title="工件型号" Property="c=>c.WorkpieceCode" />
     <PropertyColumn Title="程序号" Property="c=>c.ProgramNo" />
     <PropertyColumn Title="完成状态" Property="c=>c.IsEnd">
         <Switch @bind-Value="@context.IsEnd" Disabled="true"></Switch>
     </PropertyColumn>
     <PropertyColumn Title="开始时间" Property="c=>c.CreateTime" />
     <PropertyColumn Title="结束时间" Property="c=>c.UpdateTime" />
 </Table>

 @code {
    bool loading = true;

    List<WorkpieceProcessingRecord> dataItems = new List<WorkpieceProcessingRecord>();

    IEnumerable<WorkpieceProcessingRecord> selectedRows = null!;
    ITable table = null!;

    int _pageIndex = 1;
    int _pageSize = 10;
    int _total = 0;

    public async Task OnChange(QueryModel<WorkpieceProcessingRecord> queryModel)
    {
        loading = true;
        using var dbContext = dbContextFactory.CreateDbContext();
        var query = dbContext.WorkpieceProcessingRecords;

        dataItems = await query.OrderByDescending(x => x.Id).Skip(((queryModel.PageIndex - 1) * queryModel.PageSize)).Take(queryModel.PageSize).AsNoTracking().ToListAsync();

        _total = await query.CountAsync();
        loading = false;
    }

    public void RemoveSelection(Guid id)
    {
        var selected = selectedRows.Where(x => x.Id != id);
        selectedRows = selected;
    }
}