first commit

This commit is contained in:
2026-09-02 16:31:50 +08:00
commit a461727193
911 changed files with 692450 additions and 0 deletions
@@ -0,0 +1,216 @@
using JSMachine.WMS.Storage.BusinessModules.Views;
using JSMachine.WMS.Common.Mvvm;
using Unity;
using static JSMachine.WMS.Common.EventBus.GlobalEventBus;
using JSMachine.WMS.App.Dto;
namespace JSMachine.WMS.Storage.BusinessModules.ViewModels
{
public class HomePageViewModel : ViewModelBase, IViewLoadedAndUnloadedAware<HomePage>
{
HomePage _homePage;
public HomePageViewModel(IUnityContainer container) : base(container)
{
}
public void OnLoaded(HomePage view)
{
_homePage = view;
//base.OnLoaded(view);
view.Page_Change.Content = new PaperStorageView();
EventAggregator.GetEvent<DeviceConnectionEvent>().Subscribe(UpdateDeviceConnectState);
}
public void OnUnloaded(HomePage view)
{
}
#region PLC通讯状态
/// <summary>
/// PLC通讯状态-连接
/// </summary>
private bool _plcConected;
public bool PLCConected
{
get => _plcConected;
set => SetProperty(ref _plcConected, value);
}
private bool _plcVisible;
public bool PLCVisible
{
get => _plcVisible;
set => SetProperty(ref _plcVisible, value);
}
#endregion
#region DB通讯状态
/// <summary>
/// DB通讯状态-连接
/// </summary>
private bool _dbConected;
public bool DBConected
{
get => _dbConected;
set => SetProperty(ref _dbConected, value);
}
private bool _dbVisible;
public bool DBVisible
{
get => _dbVisible;
set => SetProperty(ref _dbVisible, value);
}
#endregion
#region CodeScnner通讯状态
/// <summary>
/// CS1通讯状态-连接
/// </summary>
private bool _cs1Conected;
public bool CS1Conected
{
get => _cs1Conected;
set => SetProperty(ref _cs1Conected, value);
}
private bool _cs1Visible;
public bool CS1Visible
{
get => _cs1Visible;
set => SetProperty(ref _cs1Visible, value);
}
/// <summary>
/// CS2通讯状态
/// </summary>
private bool _cs2Conected;
public bool CS2Conected
{
get => _cs2Conected;
set => SetProperty(ref _cs2Conected, value);
}
private bool _cs2Visible;
public bool CS2Visible
{
get => _cs2Visible;
set => SetProperty(ref _cs2Visible, value);
}
#endregion
#region ERP通讯状态
/// <summary>
/// ERP通讯状态-连接
/// </summary>
private bool _erpConected;
public bool ERPConected
{
get => _erpConected;
set => SetProperty(ref _erpConected, value);
}
private bool _erpVisible;
public bool ERPVisible
{
get => _erpVisible;
set => SetProperty(ref _erpVisible, value);
}
#endregion
#region ACS通讯状态
/// <summary>
/// ACS通讯状态-连接
/// </summary>
private bool _acsConected;
public bool ACSConected
{
get => _acsConected;
set => SetProperty(ref _acsConected, value);
}
private bool _acsVisible;
public bool ACSVisible
{
get => _acsVisible;
set => SetProperty(ref _acsVisible, value);
}
#endregion
#region WeighBridge通讯状态
/// <summary>
/// 地磅通讯状态-连接
/// </summary>
private bool _wbConected;
public bool WBConected
{
get => _wbConected;
set => SetProperty(ref _wbConected, value);
}
private bool _wbVisible;
public bool WBVisible
{
get => _wbVisible;
set => SetProperty(ref _wbVisible, value);
}
#endregion
#region 印贴一体机通讯状态
/// <summary>
/// 印贴一体机通讯状态-连接
/// </summary>
private bool _printConected;
public bool PrintConected
{
get => _printConected;
set => SetProperty(ref _printConected, value);
}
private bool _printVisible;
public bool PrintVisible
{
get => _printVisible;
set => SetProperty(ref _printVisible, value);
}
#endregion
/// <summary>
/// 设备连接事件
/// </summary>
/// <param name = "deviceStateDto" ></ param >
private void UpdateDeviceConnectState(DeviceStateDto deviceStateDto)
{
#region PLCState
PLCConected = deviceStateDto.PLCConected;
PLCVisible = deviceStateDto.PLCVisible;
#endregion
#region DBState
DBConected = deviceStateDto.DBConected;
DBVisible = deviceStateDto.DBVisible;
#endregion
#region CS1State
CS1Conected = deviceStateDto.CS1Conected;
CS1Visible = deviceStateDto.CS1Visible;
#endregion
#region CS2State
CS2Conected = deviceStateDto.CS2Conected;
CS2Visible = deviceStateDto.CS2Visible;
#endregion
#region ERPState
ERPConected = deviceStateDto.ERPConected;
ERPVisible = deviceStateDto.ERPVisible;
#endregion
#region ACState
ACSConected = deviceStateDto.ACSConected;
ACSVisible = deviceStateDto.ACSVisible;
#endregion
#region WBState
WBConected = deviceStateDto.WBConected;
WBVisible = deviceStateDto.WBVisible;
#endregion
#region PrintState
PrintConected = deviceStateDto.PrintConected;
PrintVisible = deviceStateDto.PrintVisible;
#endregion
}
}
}
@@ -0,0 +1,403 @@
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;
}
}
}
}