403 lines
14 KiB
C#
403 lines
14 KiB
C#
using FastReport;
|
|
using HandyControl.Controls;
|
|
using JSMachine.WMS.App.Dto;
|
|
using JSMachine.WMS.App.Dto.Enum;
|
|
using JSMachine.WMS.App.IService;
|
|
using JSMachine.WMS.Common;
|
|
using JSMachine.WMS.Common.Globalization;
|
|
using JSMachine.WMS.Common.Mvvm;
|
|
using JSMachine.WMS.Domain.Entity;
|
|
using JSMachine.WMS.Infrastructure.Extensions;
|
|
using JSMachine.WMS.Infrastructure.Helper;
|
|
using JSMachine.WMS.Storage.BusinessModules.Views;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using SqlSugar;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using Unity;
|
|
using static JSMachine.WMS.Common.EventBus.GlobalEventBus;
|
|
using static JSMachine.WMS.Common.EventBus.JobEvent;
|
|
|
|
namespace JSMachine.WMS.Storage.BusinessModules.ViewModels
|
|
{
|
|
public class PaperStorageViewModel : ViewModelBase, IViewLoadedAndUnloadedAware<PaperStorageView>
|
|
{
|
|
#region Command
|
|
|
|
/// <summary>
|
|
/// 自动打印标签
|
|
/// </summary>
|
|
public ICommand IAtuoPrintCmd { get; set; }
|
|
|
|
/// <summary>
|
|
/// 手动打印标签
|
|
/// </summary>
|
|
public ICommand IHandPrintCmd { get; set; }
|
|
|
|
#endregion Command
|
|
|
|
#region Search Condition
|
|
|
|
private DateTime? _startTime;
|
|
|
|
/// <summary>
|
|
/// 订单开始时间起点
|
|
/// </summary>
|
|
public DateTime? StartTime
|
|
{
|
|
get => _startTime;
|
|
set => SetProperty(ref _startTime, value);
|
|
}
|
|
|
|
private DateTime? _endTime;
|
|
|
|
/// <summary>
|
|
/// 订单结束时间终点
|
|
/// </summary>
|
|
public DateTime? EndTime
|
|
{
|
|
get => _endTime;
|
|
set => SetProperty(ref _endTime, value);
|
|
}
|
|
|
|
private string _paperLabel;
|
|
|
|
/// <summary>
|
|
/// 原纸卷标
|
|
/// </summary>
|
|
public string PaperLabel
|
|
{
|
|
get => _paperLabel;
|
|
set => SetProperty(ref _paperLabel, value);
|
|
}
|
|
|
|
private string _supplier;
|
|
|
|
/// <summary>
|
|
/// 供应商
|
|
/// </summary>
|
|
public string Supplier
|
|
{
|
|
get => _supplier;
|
|
set => SetProperty(ref _supplier, value);
|
|
}
|
|
|
|
private string _paperCode;
|
|
|
|
/// <summary>
|
|
/// 纸质
|
|
/// </summary>
|
|
public string PaperCode
|
|
{
|
|
get => _paperCode;
|
|
set => SetProperty(ref _paperCode, value);
|
|
}
|
|
|
|
private string _paperWidth;
|
|
|
|
/// <summary>
|
|
/// 门幅
|
|
/// </summary>
|
|
public string PaperWidth
|
|
{
|
|
get => _paperWidth;
|
|
set => SetProperty(ref _paperWidth, value);
|
|
}
|
|
|
|
#endregion Search Condition
|
|
|
|
#region DataSource
|
|
|
|
private List<PaperNewStockInDto> _paperNewStockIns;
|
|
|
|
/// <summary>
|
|
/// 新卷入库数据集合
|
|
/// </summary>
|
|
public List<PaperNewStockInDto> PaperNewStockIns
|
|
{
|
|
get { return _paperNewStockIns; }
|
|
set { SetProperty(ref _paperNewStockIns, value); }
|
|
}
|
|
|
|
private PaperNewStockInDto _selectedPaperNewStockIn;
|
|
|
|
/// <summary>
|
|
/// 当前选中新卷入库信息
|
|
/// </summary>
|
|
public PaperNewStockInDto SelectedPaperNewStockIn
|
|
{
|
|
get { return _selectedPaperNewStockIn; }
|
|
set { SetProperty(ref _selectedPaperNewStockIn, value); }
|
|
}
|
|
|
|
#endregion DataSource
|
|
|
|
#region Page Search Condition
|
|
|
|
/// <summary>
|
|
/// 分页查询条件
|
|
/// </summary>
|
|
private PageQueryConditionDto _pageQueryCondtion = new()
|
|
{
|
|
CurrentPage = 1,
|
|
PageSize = 11,
|
|
OrderByFiled = nameof(PaperNewStockInDto.CreationTime),
|
|
OrderByType = OrderByType.Asc,
|
|
Filters = new()
|
|
};
|
|
|
|
#endregion Page Search Condition
|
|
|
|
#region Structure Function
|
|
|
|
private IPaperNewStockInService _paperNewStockInService;
|
|
private IEventAggregator _eventAggregator;
|
|
|
|
public PaperStorageViewModel(IUnityContainer container, IPaperNewStockInService paperNewStockInService, IEventAggregator eventAggregator) : base(container)
|
|
{
|
|
IAtuoPrintCmd = new DelegateCommand(OnAutoPrint);
|
|
IHandPrintCmd = new DelegateCommand(OnHandPrint);
|
|
_paperNewStockInService = paperNewStockInService;
|
|
_eventAggregator = eventAggregator;
|
|
StartTime = DateTime.Now.GetTodayBegin();
|
|
EndTime = DateTime.Now.GetTodayEnd();
|
|
_eventAggregator.GetEvent<PaperStorageBaseDataEvent>().Subscribe(OnSearchClick); //自动写入新卷入库之后,自动刷新页面
|
|
}
|
|
|
|
#endregion Structure Function
|
|
|
|
/// <summary>
|
|
/// 自动打印
|
|
/// </summary>
|
|
private async void OnAutoPrint()
|
|
{
|
|
try
|
|
{
|
|
//未打印的记录
|
|
PaperNewStockIns = await _paperNewStockInService.GetListByExpression(p => p.PrintState == 0);
|
|
if (!PaperNewStockIns.Any())
|
|
{
|
|
Growl.Error("没有需要自动打印的标签", PaperMesConst.MainWindow);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
Report fPrewControlReport = new Report();//报表预览
|
|
foreach (var item in PaperNewStockIns)
|
|
{
|
|
LoadFrxAndData(fPrewControlReport, Environment.CurrentDirectory + Global.AppSettings.LabelReportFilePathStr);
|
|
fPrewControlReport.SetParameterValue("companyname", "京山轻机");
|
|
fPrewControlReport.SetParameterValue("papercode", item.PaperCode);
|
|
fPrewControlReport.SetParameterValue("supplier", item.Supplier);
|
|
fPrewControlReport.SetParameterValue("paperwidth", item.PaperWidth);
|
|
fPrewControlReport.SetParameterValue("weight", Convert.ToInt32(item.InWeight));
|
|
fPrewControlReport.SetParameterValue("paperlabel", item.PaperLabel);
|
|
fPrewControlReport.SetParameterValue("paperlength", Convert.ToInt32(item.MeterLength));
|
|
fPrewControlReport.SetParameterValue("unitweight", item.PaperUnitWeight);
|
|
FastReport.Utils.Config.ReportSettings.ShowProgress = false;
|
|
fPrewControlReport.PrintSettings.Printer = "Doro PDF Writer";
|
|
fPrewControlReport.PrintSettings.ShowDialog = false;
|
|
fPrewControlReport.Print();
|
|
}
|
|
await GetPageData(1);
|
|
//更新自动打印时间
|
|
await Task.Delay(500).ContinueWith(async task =>
|
|
{
|
|
foreach (var item in PaperNewStockIns)
|
|
{
|
|
item.PrintTime = DateTime.Now;
|
|
item.PrintState = 1;
|
|
}
|
|
await _paperNewStockInService.EditBatch(PaperNewStockIns);
|
|
});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error($"新卷入库:自动打印标签出错: {ex.Message} \n {ex.StackTrace}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 载入报表路径和报表数据
|
|
/// </summary>
|
|
private void LoadFrxAndData(FastReport.Report report, string filePathStr)
|
|
{
|
|
//1 编辑指定路径下的frx,先load frx
|
|
report.Load(filePathStr);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动打印
|
|
/// </summary>
|
|
private void OnHandPrint()
|
|
{
|
|
try
|
|
{
|
|
PrintLabelWindow printLabelWindow = new PrintLabelWindow
|
|
{
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen,//窗体居中
|
|
Owner = Application.Current.MainWindow,
|
|
};
|
|
printLabelWindow.SelectedPaperNewStockIn = SelectedPaperNewStockIn;
|
|
_eventAggregator.GetEvent<PrintLabelEvent>().Publish(PrintType.NewStock);
|
|
printLabelWindow.ShowDialog();//打开原生的xaml文件,不使用prism,report用在prism的框架下无法正常使用
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error($"新卷入库:手动打印弹窗出错: {ex.Message} \n {ex.StackTrace}");
|
|
}
|
|
}
|
|
|
|
public async void OnLoaded(PaperStorageView view)
|
|
{
|
|
_eventAggregator.GetEvent<SearchStorageEvent>().Subscribe(OnSearchClick);
|
|
await GetPageData(1);
|
|
}
|
|
|
|
public void OnUnloaded(PaperStorageView view)
|
|
{
|
|
}
|
|
|
|
private async void OnSearchClick()
|
|
{
|
|
await GetPageData(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取数据
|
|
/// </summary>
|
|
public override async Task GetPageData(int pageIndex)
|
|
{
|
|
_pageQueryCondtion.Filters = new();
|
|
|
|
if (EndTime < StartTime)
|
|
{
|
|
Growl.Error(Localizations.GetStringValueByKey("CompletionRecordViewModel_Growl_ErrorThree"), PaperMesConst.MainWindow);
|
|
return;
|
|
}
|
|
|
|
if (StartTime != null)
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.CreationTime) ,
|
|
ConditionalType=ConditionalType.GreaterThanOrEqual,
|
|
FieldValue=StartTime.ToString()}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
if (EndTime != null)
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.CreationTime) ,
|
|
ConditionalType=ConditionalType.LessThanOrEqual,
|
|
FieldValue=EndTime.ToString()}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(PaperLabel))
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.PaperLabel) ,
|
|
ConditionalType=ConditionalType.Like,
|
|
FieldValue=PaperLabel}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Supplier))
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.Supplier) ,
|
|
ConditionalType=ConditionalType.Like,
|
|
FieldValue=Supplier}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(PaperCode))
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.PaperCode) ,
|
|
ConditionalType=ConditionalType.Like,
|
|
FieldValue=PaperCode}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(PaperWidth))
|
|
{
|
|
_pageQueryCondtion.Filters.Add(new ConditionalCollections()
|
|
{
|
|
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>
|
|
{
|
|
new KeyValuePair<WhereType, ConditionalModel> (
|
|
WhereType.And,
|
|
new ConditionalModel
|
|
{
|
|
FieldName= nameof(PaperNewStockInDto.PaperWidth) ,
|
|
ConditionalType=ConditionalType.Like,
|
|
FieldValue=PaperWidth}
|
|
)
|
|
}
|
|
});
|
|
}
|
|
|
|
_pageQueryCondtion.CurrentPage = pageIndex;
|
|
|
|
PagedResult<PaperNewStockInDto> pageData = await _paperNewStockInService.QueryByPage(_pageQueryCondtion);
|
|
if (pageData != null)
|
|
{
|
|
base.PageIndex = pageData.PageNumber;
|
|
base.PageCount = pageData.TotalPages;
|
|
base.PageSize = pageData.PageSize;
|
|
base.TotalCount = pageData.TotalRecords;
|
|
|
|
PaperNewStockIns = pageData.PageData;
|
|
}
|
|
}
|
|
}
|
|
} |