更改FTP文件导入
This commit is contained in:
272
FATrace.WPLApp/ViewModels/FactoryInOutboundViewModel.cs
Normal file
272
FATrace.WPLApp/ViewModels/FactoryInOutboundViewModel.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
using FATrace.Model;
|
||||
using FATrace.WPLApp.Core;
|
||||
using FATrace.WPLApp.Services;
|
||||
using FreeSql;
|
||||
using Prism.Commands;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-成品入库与出库 查询 VM(展示 FactoryInOutbound)
|
||||
/// </summary>
|
||||
public class FactoryInOutboundViewModel : NavigationViewModel
|
||||
{
|
||||
private readonly IFreeSql _fsql;
|
||||
private readonly ILogService _log;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="fsql">FreeSql 实例</param>
|
||||
/// <param name="log">日志服务</param>
|
||||
public FactoryInOutboundViewModel(IFreeSql fsql, ILogService log)
|
||||
{
|
||||
_fsql = fsql;
|
||||
_log = log;
|
||||
|
||||
Items = new ObservableCollection<FactoryInOutbound>();
|
||||
|
||||
SearchCommand = new DelegateCommand(async () => await SearchAsync(), () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
ClearCommand = new DelegateCommand(ClearFilters, () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
|
||||
FirstPageCommand = new DelegateCommand(async () => { if (PageIndex == 1) return; PageIndex = 1; await SearchAsync(); }, () => !IsBusy && PageIndex > 1)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex);
|
||||
PrevPageCommand = new DelegateCommand(async () => { if (PageIndex <= 1) return; PageIndex -= 1; await SearchAsync(); }, () => !IsBusy && PageIndex > 1)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex);
|
||||
NextPageCommand = new DelegateCommand(async () => { if (PageIndex >= TotalPages) return; PageIndex += 1; await SearchAsync(); }, () => !IsBusy && PageIndex < TotalPages)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex)
|
||||
.ObservesProperty(() => TotalPages);
|
||||
LastPageCommand = new DelegateCommand(async () => { if (TotalPages <= 0 || PageIndex == TotalPages) return; PageIndex = TotalPages; await SearchAsync(); }, () => !IsBusy && PageIndex < TotalPages)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex)
|
||||
.ObservesProperty(() => TotalPages);
|
||||
}
|
||||
|
||||
#region 查询条件
|
||||
private string? _origin;
|
||||
/// <summary>
|
||||
/// 产地(模糊匹配)
|
||||
/// </summary>
|
||||
public string? Origin { get => _origin; set { _origin = value; RaisePropertyChanged(); } }
|
||||
|
||||
private string? _batch;
|
||||
/// <summary>
|
||||
/// 批号(模糊匹配)
|
||||
/// </summary>
|
||||
public string? Batch { get => _batch; set { _batch = value; RaisePropertyChanged(); } }
|
||||
|
||||
private string? _rawCode;
|
||||
/// <summary>
|
||||
/// 原料代码(模糊匹配)
|
||||
/// </summary>
|
||||
public string? RawCode { get => _rawCode; set { _rawCode = value; RaisePropertyChanged(); } }
|
||||
|
||||
private string? _rawName;
|
||||
/// <summary>
|
||||
/// 原料名称(模糊匹配)
|
||||
/// </summary>
|
||||
public string? RawName { get => _rawName; set { _rawName = value; RaisePropertyChanged(); } }
|
||||
|
||||
private DateTime? _startDate;
|
||||
/// <summary>
|
||||
/// 入库时间起(基于 InTime)
|
||||
/// </summary>
|
||||
public DateTime? StartDate { get => _startDate; set { _startDate = value; RaisePropertyChanged(); } }
|
||||
|
||||
private DateTime? _endDate;
|
||||
/// <summary>
|
||||
/// 入库时间止(基于 InTime,包含当天)
|
||||
/// </summary>
|
||||
public DateTime? EndDate { get => _endDate; set { _endDate = value; RaisePropertyChanged(); } }
|
||||
#endregion
|
||||
|
||||
#region 列表与分页
|
||||
/// <summary>
|
||||
/// 列表数据
|
||||
/// </summary>
|
||||
public ObservableCollection<FactoryInOutbound> Items { get; }
|
||||
|
||||
private bool _isBusy;
|
||||
/// <summary>
|
||||
/// 是否忙碌
|
||||
/// </summary>
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _totalCount;
|
||||
/// <summary>
|
||||
/// 总记录数
|
||||
/// </summary>
|
||||
public int TotalCount { get => _totalCount; set { _totalCount = value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _pageIndex = 1;
|
||||
/// <summary>
|
||||
/// 当前页码
|
||||
/// </summary>
|
||||
public int PageIndex { get => _pageIndex; set { _pageIndex = value < 1 ? 1 : value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _pageSize = 20;
|
||||
/// <summary>
|
||||
/// 页大小
|
||||
/// </summary>
|
||||
public int PageSize
|
||||
{
|
||||
get => _pageSize;
|
||||
set
|
||||
{
|
||||
var v = value <= 0 ? 20 : value;
|
||||
if (_pageSize != v)
|
||||
{
|
||||
_pageSize = v;
|
||||
RaisePropertyChanged();
|
||||
PageIndex = 1;
|
||||
if (!IsBusy) _ = SearchAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _totalPages;
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
public int TotalPages { get => _totalPages; set { _totalPages = value; RaisePropertyChanged(); } }
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
public DelegateCommand SearchCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 清空
|
||||
/// </summary>
|
||||
public DelegateCommand ClearCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 首页
|
||||
/// </summary>
|
||||
public DelegateCommand FirstPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 上一页
|
||||
/// </summary>
|
||||
public DelegateCommand PrevPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下一页
|
||||
/// </summary>
|
||||
public DelegateCommand NextPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 末页
|
||||
/// </summary>
|
||||
public DelegateCommand LastPageCommand { get; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 清空筛选条件
|
||||
/// </summary>
|
||||
private void ClearFilters()
|
||||
{
|
||||
Origin = Batch = RawCode = RawName = string.Empty;
|
||||
StartDate = null;
|
||||
EndDate = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询
|
||||
/// </summary>
|
||||
private async Task SearchAsync()
|
||||
{
|
||||
if (IsBusy) return;
|
||||
try
|
||||
{
|
||||
IsBusy = true;
|
||||
_log.Info("FactoryInOutbound 查询开始");
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
var q = _fsql.Select<FactoryInOutbound>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Origin))
|
||||
q = q.Where(a => a.Origin != null && a.Origin.Contains(Origin));
|
||||
if (!string.IsNullOrWhiteSpace(Batch))
|
||||
q = q.Where(a => a.Batch != null && a.Batch.Contains(Batch));
|
||||
if (!string.IsNullOrWhiteSpace(RawCode))
|
||||
q = q.Where(a => a.RawCode != null && a.RawCode.Contains(RawCode));
|
||||
if (!string.IsNullOrWhiteSpace(RawName))
|
||||
q = q.Where(a => a.RawName != null && a.RawName.Contains(RawName));
|
||||
|
||||
DateTime? start = StartDate;
|
||||
DateTime? end = EndDate;
|
||||
if (start.HasValue)
|
||||
{
|
||||
var s = start.Value.Date;
|
||||
q = q.Where("TRY_CONVERT(datetime, InTime) >= @start", new { start = s });
|
||||
}
|
||||
if (end.HasValue)
|
||||
{
|
||||
var e = end.Value.Date.AddDays(1).AddTicks(-1);
|
||||
q = q.Where("TRY_CONVERT(datetime, InTime) <= @end", new { end = e });
|
||||
}
|
||||
|
||||
q = q.OrderByDescending(a => a.Id);
|
||||
|
||||
var page = PageIndex < 1 ? 1 : PageIndex;
|
||||
var size = PageSize <= 0 ? 20 : PageSize;
|
||||
|
||||
var list = q.Count(out var total)
|
||||
.Page(page, size)
|
||||
.ToList();
|
||||
|
||||
var pages = total <= 0 || size <= 0 ? 0 : (int)Math.Ceiling(total * 1.0 / size);
|
||||
if (pages > 0 && page > pages)
|
||||
{
|
||||
page = pages;
|
||||
list = q.Page(page, size).ToList();
|
||||
}
|
||||
|
||||
return (items: list, total: (int)total, normalizedPage: page, totalPages: pages);
|
||||
});
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
Items.Clear();
|
||||
foreach (var it in data.items) Items.Add(it);
|
||||
TotalCount = data.total;
|
||||
TotalPages = data.totalPages;
|
||||
PageIndex = data.normalizedPage == 0 ? 1 : data.normalizedPage;
|
||||
});
|
||||
|
||||
_log.Info($"FactoryInOutbound 查询完成,记录数: {TotalCount}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"FactoryInOutbound 查询失败: {ex}");
|
||||
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航进入时自动查询
|
||||
/// </summary>
|
||||
/// <param name="navigationContext">导航上下文</param>
|
||||
public override async void OnNavigatedTo(Prism.Regions.NavigationContext navigationContext)
|
||||
{
|
||||
await SearchAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ using System.Windows;
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-入库 数据查询 VM
|
||||
/// 工厂-成品入库 数据查询 VM
|
||||
/// 仅展示从 Excel 导入的 FactoryInbound 数据,支持简单条件与分页。
|
||||
/// </summary>
|
||||
public class FactoryInboundViewModel : NavigationViewModel
|
||||
|
||||
@@ -11,8 +11,8 @@ using System.Windows;
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-出入库 数据查询 VM
|
||||
/// 仅展示从 Excel 导入的 FactoryInventoryTransaction 数据,支持简单条件与分页。
|
||||
/// 工厂-原料出入库 数据查询 VM
|
||||
/// 仅展示从 Excel 导入的 FactoryRawInOutbound 数据,支持简单条件与分页。
|
||||
/// </summary>
|
||||
public class FactoryInventoryTransactionViewModel : NavigationViewModel
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
_fsql = fsql;
|
||||
_log = log;
|
||||
|
||||
Items = new ObservableCollection<FactoryInventoryTransaction>();
|
||||
Items = new ObservableCollection<FactoryRawInOutbound>();
|
||||
|
||||
SearchCommand = new DelegateCommand(async () => await SearchAsync(), () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
@@ -79,7 +79,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
#endregion
|
||||
|
||||
#region 列表与分页
|
||||
public ObservableCollection<FactoryInventoryTransaction> Items { get; }
|
||||
public ObservableCollection<FactoryRawInOutbound> Items { get; }
|
||||
|
||||
private bool _isBusy;
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; RaisePropertyChanged(); } }
|
||||
@@ -133,11 +133,11 @@ namespace FATrace.WPLApp.ViewModels
|
||||
try
|
||||
{
|
||||
IsBusy = true;
|
||||
_log.Info("FactoryInventoryTransaction 查询开始");
|
||||
_log.Info("FactoryRawInOutbound 查询开始");
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
var q = _fsql.Select<FactoryInventoryTransaction>();
|
||||
var q = _fsql.Select<FactoryRawInOutbound>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Origin))
|
||||
q = q.Where(a => a.Origin != null && a.Origin.Contains(Origin));
|
||||
@@ -187,11 +187,11 @@ namespace FATrace.WPLApp.ViewModels
|
||||
PageIndex = data.normalizedPage == 0 ? 1 : data.normalizedPage;
|
||||
});
|
||||
|
||||
_log.Info($"FactoryInventoryTransaction 查询完成,记录数: {TotalCount}");
|
||||
_log.Info($"FactoryRawInOutbound 查询完成,记录数: {TotalCount}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"FactoryInventoryTransaction 查询失败: {ex}");
|
||||
_log.Error($"FactoryRawInOutbound 查询失败: {ex}");
|
||||
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -11,8 +11,8 @@ using System.Windows;
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-领料 数据查询 VM
|
||||
/// 仅展示从 Excel 导入的 FactoryMaterialWithdrawal 数据,支持简单条件与分页。
|
||||
/// 工厂-原料出库 数据查询 VM
|
||||
/// 仅展示从 Excel 导入的 FactoryRawOutbound 数据,支持简单条件与分页。
|
||||
/// </summary>
|
||||
public class FactoryMaterialWithdrawalViewModel : NavigationViewModel
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
_fsql = fsql;
|
||||
_log = log;
|
||||
|
||||
Items = new ObservableCollection<FactoryMaterialWithdrawal>();
|
||||
Items = new ObservableCollection<FactoryRawOutbound>();
|
||||
|
||||
SearchCommand = new DelegateCommand(async () => await SearchAsync(), () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
@@ -79,7 +79,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
#endregion
|
||||
|
||||
#region 列表与分页
|
||||
public ObservableCollection<FactoryMaterialWithdrawal> Items { get; }
|
||||
public ObservableCollection<FactoryRawOutbound> Items { get; }
|
||||
|
||||
private bool _isBusy;
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; RaisePropertyChanged(); } }
|
||||
@@ -133,11 +133,11 @@ namespace FATrace.WPLApp.ViewModels
|
||||
try
|
||||
{
|
||||
IsBusy = true;
|
||||
_log.Info("FactoryMaterialWithdrawal 查询开始");
|
||||
_log.Info("FactoryRawOutbound 查询开始");
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
var q = _fsql.Select<FactoryMaterialWithdrawal>();
|
||||
var q = _fsql.Select<FactoryRawOutbound>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Origin))
|
||||
q = q.Where(a => a.Origin != null && a.Origin.Contains(Origin));
|
||||
@@ -187,11 +187,11 @@ namespace FATrace.WPLApp.ViewModels
|
||||
PageIndex = data.normalizedPage == 0 ? 1 : data.normalizedPage;
|
||||
});
|
||||
|
||||
_log.Info($"FactoryMaterialWithdrawal 查询完成,记录数: {TotalCount}");
|
||||
_log.Info($"FactoryRawOutbound 查询完成,记录数: {TotalCount}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"FactoryMaterialWithdrawal 查询失败: {ex}");
|
||||
_log.Error($"FactoryRawOutbound 查询失败: {ex}");
|
||||
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -11,7 +11,7 @@ using System.Windows;
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-原料生产信息 查询 VM(展示 FactoryProductionRecord)
|
||||
/// 工厂-包袋生产 查询 VM(展示 FactoryProductionRecord)
|
||||
/// </summary>
|
||||
public class FactoryProductionRecordViewModel : NavigationViewModel
|
||||
{
|
||||
@@ -141,7 +141,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
try
|
||||
{
|
||||
IsBusy = true;
|
||||
_log.Info("FactoryProductionRecord 查询开始");
|
||||
_log.Info("FactoryProductionRecord(工厂-包袋生产) 查询开始");
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
@@ -195,11 +195,11 @@ namespace FATrace.WPLApp.ViewModels
|
||||
PageIndex = data.normalizedPage == 0 ? 1 : data.normalizedPage;
|
||||
});
|
||||
|
||||
_log.Info($"FactoryProductionRecord 查询完成,记录数: {TotalCount}");
|
||||
_log.Info($"FactoryProductionRecord(工厂-包袋生产) 查询完成,记录数: {TotalCount}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"FactoryProductionRecord 查询失败: {ex}");
|
||||
_log.Error($"FactoryProductionRecord(工厂-包袋生产) 查询失败: {ex}");
|
||||
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
|
||||
264
FATrace.WPLApp/ViewModels/FactoryRawInboundViewModel.cs
Normal file
264
FATrace.WPLApp/ViewModels/FactoryRawInboundViewModel.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
using FATrace.Model;
|
||||
using FATrace.WPLApp.Core;
|
||||
using FATrace.WPLApp.Services;
|
||||
using FreeSql;
|
||||
using Prism.Commands;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 工厂-原料入库 数据查询 VM(展示 FactoryRawInbound)
|
||||
/// </summary>
|
||||
public class FactoryRawInboundViewModel : NavigationViewModel
|
||||
{
|
||||
private readonly IFreeSql _fsql;
|
||||
private readonly ILogService _log;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="fsql">FreeSql 实例</param>
|
||||
/// <param name="log">日志服务</param>
|
||||
public FactoryRawInboundViewModel(IFreeSql fsql, ILogService log)
|
||||
{
|
||||
_fsql = fsql;
|
||||
_log = log;
|
||||
|
||||
Items = new ObservableCollection<FactoryRawInbound>();
|
||||
|
||||
SearchCommand = new DelegateCommand(async () => await SearchAsync(), () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
ClearCommand = new DelegateCommand(ClearFilters, () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
|
||||
FirstPageCommand = new DelegateCommand(async () => { if (PageIndex == 1) return; PageIndex = 1; await SearchAsync(); }, () => !IsBusy && PageIndex > 1)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex);
|
||||
PrevPageCommand = new DelegateCommand(async () => { if (PageIndex <= 1) return; PageIndex -= 1; await SearchAsync(); }, () => !IsBusy && PageIndex > 1)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex);
|
||||
NextPageCommand = new DelegateCommand(async () => { if (PageIndex >= TotalPages) return; PageIndex += 1; await SearchAsync(); }, () => !IsBusy && PageIndex < TotalPages)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex)
|
||||
.ObservesProperty(() => TotalPages);
|
||||
LastPageCommand = new DelegateCommand(async () => { if (TotalPages <= 0 || PageIndex == TotalPages) return; PageIndex = TotalPages; await SearchAsync(); }, () => !IsBusy && PageIndex < TotalPages)
|
||||
.ObservesProperty(() => IsBusy)
|
||||
.ObservesProperty(() => PageIndex)
|
||||
.ObservesProperty(() => TotalPages);
|
||||
}
|
||||
|
||||
#region 查询条件
|
||||
private string? _origin;
|
||||
/// <summary>
|
||||
/// 产地(模糊匹配)
|
||||
/// </summary>
|
||||
public string? Origin { get => _origin; set { _origin = value; RaisePropertyChanged(); } }
|
||||
|
||||
private string? _rawCode;
|
||||
/// <summary>
|
||||
/// 原料代码(模糊匹配)
|
||||
/// </summary>
|
||||
public string? RawCode { get => _rawCode; set { _rawCode = value; RaisePropertyChanged(); } }
|
||||
|
||||
private string? _rawName;
|
||||
/// <summary>
|
||||
/// 原料名称(模糊匹配)
|
||||
/// </summary>
|
||||
public string? RawName { get => _rawName; set { _rawName = value; RaisePropertyChanged(); } }
|
||||
|
||||
private DateTime? _startDate;
|
||||
/// <summary>
|
||||
/// 登录日期起(基于 LoginDateTime)
|
||||
/// </summary>
|
||||
public DateTime? StartDate { get => _startDate; set { _startDate = value; RaisePropertyChanged(); } }
|
||||
|
||||
private DateTime? _endDate;
|
||||
/// <summary>
|
||||
/// 登录日期止(基于 LoginDateTime,包含当天)
|
||||
/// </summary>
|
||||
public DateTime? EndDate { get => _endDate; set { _endDate = value; RaisePropertyChanged(); } }
|
||||
#endregion
|
||||
|
||||
#region 列表与分页
|
||||
/// <summary>
|
||||
/// 列表数据
|
||||
/// </summary>
|
||||
public ObservableCollection<FactoryRawInbound> Items { get; }
|
||||
|
||||
private bool _isBusy;
|
||||
/// <summary>
|
||||
/// 是否忙碌
|
||||
/// </summary>
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _totalCount;
|
||||
/// <summary>
|
||||
/// 总记录数
|
||||
/// </summary>
|
||||
public int TotalCount { get => _totalCount; set { _totalCount = value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _pageIndex = 1;
|
||||
/// <summary>
|
||||
/// 当前页码
|
||||
/// </summary>
|
||||
public int PageIndex { get => _pageIndex; set { _pageIndex = value < 1 ? 1 : value; RaisePropertyChanged(); } }
|
||||
|
||||
private int _pageSize = 20;
|
||||
/// <summary>
|
||||
/// 页大小
|
||||
/// </summary>
|
||||
public int PageSize
|
||||
{
|
||||
get => _pageSize;
|
||||
set
|
||||
{
|
||||
var v = value <= 0 ? 20 : value;
|
||||
if (_pageSize != v)
|
||||
{
|
||||
_pageSize = v;
|
||||
RaisePropertyChanged();
|
||||
PageIndex = 1;
|
||||
if (!IsBusy) _ = SearchAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _totalPages;
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
public int TotalPages { get => _totalPages; set { _totalPages = value; RaisePropertyChanged(); } }
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
/// <summary>
|
||||
/// 查询命令
|
||||
/// </summary>
|
||||
public DelegateCommand SearchCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 清空命令
|
||||
/// </summary>
|
||||
public DelegateCommand ClearCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 首页
|
||||
/// </summary>
|
||||
public DelegateCommand FirstPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 上一页
|
||||
/// </summary>
|
||||
public DelegateCommand PrevPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下一页
|
||||
/// </summary>
|
||||
public DelegateCommand NextPageCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 末页
|
||||
/// </summary>
|
||||
public DelegateCommand LastPageCommand { get; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 清空筛选条件
|
||||
/// </summary>
|
||||
private void ClearFilters()
|
||||
{
|
||||
Origin = RawCode = RawName = string.Empty;
|
||||
StartDate = null;
|
||||
EndDate = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询
|
||||
/// </summary>
|
||||
private async Task SearchAsync()
|
||||
{
|
||||
if (IsBusy) return;
|
||||
try
|
||||
{
|
||||
IsBusy = true;
|
||||
_log.Info("FactoryRawInbound 查询开始");
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
var q = _fsql.Select<FactoryRawInbound>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Origin))
|
||||
q = q.Where(a => a.Origin != null && a.Origin.Contains(Origin));
|
||||
if (!string.IsNullOrWhiteSpace(RawCode))
|
||||
q = q.Where(a => a.RawCode != null && a.RawCode.Contains(RawCode));
|
||||
if (!string.IsNullOrWhiteSpace(RawName))
|
||||
q = q.Where(a => a.RawName != null && a.RawName.Contains(RawName));
|
||||
|
||||
DateTime? start = StartDate;
|
||||
DateTime? end = EndDate;
|
||||
if (start.HasValue)
|
||||
{
|
||||
var s = start.Value.Date;
|
||||
q = q.Where("TRY_CONVERT(datetime, LoginDateTime) >= @start", new { start = s });
|
||||
}
|
||||
if (end.HasValue)
|
||||
{
|
||||
var e = end.Value.Date.AddDays(1).AddTicks(-1);
|
||||
q = q.Where("TRY_CONVERT(datetime, LoginDateTime) <= @end", new { end = e });
|
||||
}
|
||||
|
||||
q = q.OrderByDescending(a => a.Id);
|
||||
|
||||
var page = PageIndex < 1 ? 1 : PageIndex;
|
||||
var size = PageSize <= 0 ? 20 : PageSize;
|
||||
|
||||
var list = q.Count(out var total)
|
||||
.Page(page, size)
|
||||
.ToList();
|
||||
|
||||
var pages = total <= 0 || size <= 0 ? 0 : (int)Math.Ceiling(total * 1.0 / size);
|
||||
if (pages > 0 && page > pages)
|
||||
{
|
||||
page = pages;
|
||||
list = q.Page(page, size).ToList();
|
||||
}
|
||||
|
||||
return (items: list, total: (int)total, normalizedPage: page, totalPages: pages);
|
||||
});
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
Items.Clear();
|
||||
foreach (var it in data.items) Items.Add(it);
|
||||
TotalCount = data.total;
|
||||
TotalPages = data.totalPages;
|
||||
PageIndex = data.normalizedPage == 0 ? 1 : data.normalizedPage;
|
||||
});
|
||||
|
||||
_log.Info($"FactoryRawInbound 查询完成,记录数: {TotalCount}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"FactoryRawInbound 查询失败: {ex}");
|
||||
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航进入时自动查询
|
||||
/// </summary>
|
||||
/// <param name="navigationContext">导航上下文</param>
|
||||
public override async void OnNavigatedTo(Prism.Regions.NavigationContext navigationContext)
|
||||
{
|
||||
await SearchAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,21 +193,27 @@ namespace FATrace.WPLApp.ViewModels
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FileImportLogView");
|
||||
break;
|
||||
// 工厂/OEM Excel 导入数据查询
|
||||
case "工厂-入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryInboundView");
|
||||
case "工厂-原料入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryRawInboundView");
|
||||
break;
|
||||
case "工厂-领料":
|
||||
case "工厂-原料出库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryMaterialWithdrawalView");
|
||||
break;
|
||||
case "工厂-出入库":
|
||||
case "工厂-原料出入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryInventoryTransactionView");
|
||||
break;
|
||||
case "工厂-原料生产信息":
|
||||
case "工厂-包袋生产":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryProductionRecordView");
|
||||
break;
|
||||
case "工厂-成品入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryInboundView");
|
||||
break;
|
||||
case "工厂-成品出库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryOutboundView");
|
||||
break;
|
||||
case "工厂-成品入库与出库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("FactoryInOutboundView");
|
||||
break;
|
||||
case "OEM-入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("OEMInboundView");
|
||||
break;
|
||||
@@ -217,7 +223,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
case "OEM-出入库":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("OEMInventoryTransactionView");
|
||||
break;
|
||||
case "OEM-原料使用信息":
|
||||
case "OEM-原料使用":
|
||||
this.regionManager.Regions["ContentRegion"].RequestNavigate("OEMRawUsageInfoView");
|
||||
break;
|
||||
case "历史报警":
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
_fsql = fsql;
|
||||
_log = log;
|
||||
|
||||
Items = new ObservableCollection<OEMInventoryTransaction>();
|
||||
Items = new ObservableCollection<OEMInOutbound>();
|
||||
|
||||
SearchCommand = new DelegateCommand(async () => await SearchAsync(), () => !IsBusy)
|
||||
.ObservesProperty(() => IsBusy);
|
||||
@@ -67,7 +67,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
#endregion
|
||||
|
||||
#region 列表与分页
|
||||
public ObservableCollection<OEMInventoryTransaction> Items { get; }
|
||||
public ObservableCollection<OEMInOutbound> Items { get; }
|
||||
|
||||
private bool _isBusy;
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; RaisePropertyChanged(); } }
|
||||
@@ -125,7 +125,7 @@ namespace FATrace.WPLApp.ViewModels
|
||||
|
||||
var data = await Task.Run(() =>
|
||||
{
|
||||
var q = _fsql.Select<OEMInventoryTransaction>();
|
||||
var q = _fsql.Select<OEMInOutbound>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Origin))
|
||||
q = q.Where(a => a.Origin != null && a.Origin.Contains(Origin));
|
||||
|
||||
@@ -11,7 +11,7 @@ using System.Windows;
|
||||
namespace FATrace.WPLApp.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// OEM-原料使用信息 查询 VM(展示 OEMRawUsageInfo)
|
||||
/// OEM-原料使用 查询 VM(展示 OEMRawUsageInfo)
|
||||
/// </summary>
|
||||
public class OEMRawUsageInfoViewModel : NavigationViewModel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user