add-设备停机记录添加分页控件,待完善

dev
liuwf 2 days ago
parent 5d9dfb6ce2
commit 49740c4f51

@ -5,7 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page.WindowPage"
xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" x:Class="SlnMesnac.WPF.Page.WindowPage.MachineStopHistoryWindow"
mc:Ignorable="d"
xmlns:ctls="clr-namespace:SlnMesnac.WPF.Templates"
mc:Ignorable="d"
Title="MachineStopHistoryWindow" d:DesignHeight="1080" d:DesignWidth="1920" Height="500" Width="1000" Background="#1254AB" StateChanged="Window_StateChanged">
<Window.Resources>
@ -79,9 +80,15 @@
</DataGrid>
</Border>
</Grid>
<Grid Grid.Row="1">
<Grid Grid.Row="2">
<ctls:Pagination Margin="5" Total="{Binding PagenationModel.Total}" Current="{Binding PagenationModel.Current, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Page="{Binding PagenationModel.Page, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PageSize="{Binding PagenationModel.PageSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PageSizes="{Binding PagenationModel.PageSizes}" PreCommand="{Binding PagenationModel.FindPreCommand}"
NextCommand="{Binding PagenationModel.FindNextCommand}" GoCommand="{Binding PagenationModel.FindTargetCommand}"
>
</ctls:Pagination>
</Grid>
</Grid>
</Window>

@ -42,6 +42,7 @@
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
<PackageReference Include="NPOI" Version="2.7.2" />
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
</ItemGroup>

@ -0,0 +1,102 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.WPF.Templates
{
public class PagenationModel<T> : ObservableObject
{
private long total = 0;
public long Total
{
get => total;
set { total = value; RaisePropertyChanged(() => Total); }
}
private int page;
public int Page
{
get => page;
set { page = value; RaisePropertyChanged(() => Page); }
}
private int current = 1;
public int Current
{
get => current;
set { current = value; RaisePropertyChanged(() => Current); }
}
private List<int> pageSizes = new List<int>() { 10, 20, 30, 40, 50 };
public List<int> PageSizes
{
get => pageSizes;
set { pageSizes = value; RaisePropertyChanged(() => PageSizes); }
}
private int pageSize;
public int PageSize
{
get => pageSize;
set { pageSize = value; RaisePropertyChanged(() => PageSize); }
}
/// <summary>
/// 上一页
/// </summary>
private RelayCommand findPreCommand;
public RelayCommand FindPreCommand
{
get => findPreCommand;
set { findPreCommand = value; RaisePropertyChanged(() => FindPreCommand); }
}
/// <summary>
/// 下一页
/// </summary>
private RelayCommand findNextCommand;
public RelayCommand FindNextCommand
{
get => findNextCommand;
set { findNextCommand = value; RaisePropertyChanged(() => FindNextCommand); }
}
/// <summary>
/// 目标页
/// </summary>
private RelayCommand findTargetCommand;
public RelayCommand FindTargetCommand
{
get => findTargetCommand;
set { findTargetCommand = value; RaisePropertyChanged(() => FindTargetCommand); }
}
private ObservableCollection<T> rows = new ObservableCollection<T>();
public ObservableCollection<T> Rows
{
get => rows;
set { rows = value; RaisePropertyChanged(() => Rows); }
}
public int GetPageNumber()
{
return (current - 1) * PageSize;
}
public void computePage()
{
Page = Convert.ToInt32(Total / PageSize);
if (Total % PageSize != 0)
{
Page += 1;
}
}
}
}

@ -0,0 +1,33 @@
<UserControl x:Class="SlnMesnac.WPF.Templates.Pagination"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SlnMesnac.WPF.Templates"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Background="Transparent" Height="75" Width="880">
<StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Center" >
<TextBlock FontSize="20" Text="共计:" VerticalAlignment="Center" Foreground="White" Background="Transparent" />
<TextBlock FontSize="20" Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Total}" Margin="20,0,0,0"
Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<TextBlock FontSize="20" Text="条数据" Margin="20,0,0,0" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<TextBlock FontSize="20" Text="共" Margin="20,0,0,0" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<TextBlock FontSize="20" Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Page, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,0,0,0"
Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<TextBlock FontSize="20" Text="页" Margin="10,0,0,0" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<TextBox FontSize="20" Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Current, Mode=OneWay}"
Margin="20,0,0,0" Width="60" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<Button FontSize="20" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=GoCommand}"
Content="跳转" Margin="20,0,0,0" Width="100" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<Button FontSize="20" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=PreCommand}"
Content="上一页" Margin="20,0,0,0" Width="100" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<Button FontSize="20" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=NextCommand}"
Content="下一页" Margin="20,0,0,0" Width="100" Foreground="White" Background="Transparent" VerticalAlignment="Center"/>
<ComboBox Width="100" Foreground="Green" Background="Transparent" Margin="30,0,0,0"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=PageSizes}"
SelectedItem="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=PageSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="0"
/>
</StackPanel>
</UserControl>

@ -0,0 +1,147 @@
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SlnMesnac.WPF.Templates
{
/// <summary>
/// Pagination.xaml 的交互逻辑
/// </summary>
public partial class Pagination : UserControl
{
public Pagination()
{
InitializeComponent();
}
#region 分页数据属性
/// <summary>
/// 总条数
/// </summary>
public long Total
{
get { return (long)GetValue(TotalProperty); }
set { SetValue(TotalProperty, value); }
}
public static readonly DependencyProperty TotalProperty =
DependencyProperty.Register("Total", typeof(long), typeof(Pagination), new PropertyMetadata(0l, (s, e) =>
{
((Pagination)s).Total = (long)e.NewValue;
}));
/// <summary>
/// 总页数
/// </summary>
public int Page
{
get { return (int)GetValue(PageProperty); }
set { SetValue(PageProperty, value); }
}
public static readonly DependencyProperty PageProperty =
DependencyProperty.Register("Page", typeof(int), typeof(Pagination),
new PropertyMetadata(0, (o, args) =>
{
((Pagination)o).Page = (int)args.NewValue;
}));
/// <summary>
/// 当前页
/// </summary>
public int Current
{
get { return (int)GetValue(CurrentProperty); }
set { SetValue(CurrentProperty, value); }
}
public static readonly DependencyProperty CurrentProperty =
DependencyProperty.Register("Current", typeof(int), typeof(Pagination), new PropertyMetadata(1, (o, args) =>
{
((Pagination)o).Page = (int)args.NewValue;
}));
/// <summary>
/// 分页大小列表
/// </summary>
public List<int> PageSizes
{
get { return (List<int>)GetValue(PageSizesProperty); }
set { SetValue(PageSizesProperty, value); }
}
public static readonly DependencyProperty PageSizesProperty =
DependencyProperty.Register("PageSizes", typeof(List<int>), typeof(Pagination), new PropertyMetadata(null, (o, args) =>
{
((Pagination)o).PageSizes = (List<int>)args.NewValue;
}));
/// <summary>
/// 分页大小
/// </summary>
public int PageSize
{
get { return (int)GetValue(PageSizeProperty); }
set { SetValue(PageSizeProperty, value); }
}
public static readonly DependencyProperty PageSizeProperty =
DependencyProperty.Register("PageSize", typeof(int), typeof(Pagination), new PropertyMetadata(10, (o, args) =>
{
((Pagination)o).PageSize = (int)args.NewValue;
}));
#endregion
#region 分页事件
/// <summary>
/// 上一页
/// </summary>
public static readonly DependencyProperty FindPreCommandProperty =
DependencyProperty.Register("PreCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
(o, args) =>
{
((Pagination)o).PreCommand = (RelayCommand)args.NewValue;
}));
public RelayCommand PreCommand
{
get { return (RelayCommand)GetValue(FindPreCommandProperty); }
set { SetValue(FindPreCommandProperty, value); }
}
public static readonly DependencyProperty NextCommandProperty =
DependencyProperty.Register("NextCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
(o, args) =>
{
((Pagination)o).NextCommand = (RelayCommand)args.NewValue;
}));
public RelayCommand NextCommand
{
get { return (RelayCommand)GetValue(NextCommandProperty); }
set { SetValue(NextCommandProperty, value); }
}
public static readonly DependencyProperty GoCommandProperty =
DependencyProperty.Register("GoCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
(o, args) =>
{
((Pagination)o).GoCommand = (RelayCommand)args.NewValue;
}));
public RelayCommand GoCommand
{
get { return (RelayCommand)GetValue(GoCommandProperty); }
set { SetValue(GoCommandProperty, value); }
}
#endregion
}
}

@ -1,11 +1,13 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.Formula.Functions;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.WPF.MessageTips;
using SlnMesnac.WPF.Model;
using SlnMesnac.WPF.Templates;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -44,19 +46,50 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary>
/// 生产统计ViewModel
/// </summary>
internal class MachineStopHistoryViewModel : ViewModelBase
public class MachineStopHistoryViewModel : ViewModelBase
{
private readonly ISqlSugarClient? sqlSugarClient;
private Dictionary<int,string> machineNameDic = new Dictionary<int, string>();
public PagenationModel<T> PagenationModel { get; set; }
private Dictionary<int,string> machineNameDic = new Dictionary<int, string>();
public MachineStopHistoryViewModel()
{
PagenationModel = new PagenationModel<T>()
{
PageSize = 20,
FindPreCommand = new RelayCommand(OnPreCommand),
FindNextCommand = new RelayCommand(OnNextCommand),
FindTargetCommand = new RelayCommand(OnGoCommand)
};
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
InitList();
}
#region 事件定义
private void OnPreCommand()
{
// 处理下一页逻辑
Task.Run(async () => await RefreshWcsTaskDataGrid(PagenationModel.Current - 1, PagenationModel.PageSize));
}
private void OnNextCommand()
{
// 处理下一页逻辑
Task.Run(async () => await RefreshWcsTaskDataGrid(PagenationModel.Current + 1, PagenationModel.PageSize));
}
private void OnGoCommand()
{
// 处理跳转到指定页逻辑
}
#endregion
private async void InitList()
{
machineNameDic.Add(1016, "3楼拆包机");
@ -65,7 +98,8 @@ namespace SlnMesnac.WPF.ViewModel
machineNameDic.Add(1019, "2楼烘干机");
machineNameDic.Add(1020, "2楼除尘机");
machineNameDic.Add(1021, "2楼喷码机");
await RefreshWcsTaskDataGrid();
await RefreshWcsTaskDataGrid(PagenationModel.Current, PagenationModel.PageSize);
}
@ -90,7 +124,7 @@ namespace SlnMesnac.WPF.ViewModel
/// 刷新停机记录信息
/// </summary>
/// <param name="palletTasks"></param>
private async Task RefreshWcsTaskDataGrid(int pageNumber=1,int pageSize=20)
private async Task RefreshWcsTaskDataGrid(int pageNumber=1,int pageSize=0)
{
try
{

Loading…
Cancel
Save