using ATC_MaterialBind.Entity; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Models; using SlnMesnac.Common; using SlnMesnac.Config; using SlnMesnac.Model.domain; using SlnMesnac.Repository; using SlnMesnac.Repository.service; using SlnMesnac.WPF.Attribute; using SlnMesnac.WPF.Model; using SqlSugar; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Forms; using TouchSocket.Sockets; namespace SlnMesnac.WPF.ViewModel.IndexPage { [RegisterAsSingletonAttribute] public partial class HistorySearchViewModel : ObservableObject { private ILogger _logger; private Isys_dict_dataService _dataService; private AppsettingsConfig _appSettings = new AppsettingsConfig(); public Action Action; public delegate void RefreshDataInfo(Real_DataInfo real_Data); private ISqlSugarClient? sqlSugarClient; public event RefreshDataInfo? RefreshDataInfoEvent; public HistorySearchViewModel() { sqlSugarClient = App.ServiceProvider.GetService(); GetOrderInfoCommand = new RelayCommand(t=> RefreshData(t)); BeginDate = DateTime.Now.Date; // 当天的 0:00:00 EndDate = DateTime.Now.Date.AddDays(2).AddSeconds(-1); // 当天的 23:59:59 RefreshHistoryData(); } private async Task RefreshHistoryData() { try { await RefreshData(null); } catch (Exception ex) { MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } public RelayCommand GetOrderInfoCommand { get; set; } /// /// 从MES获取订单信息 /// /// /// [RelayCommand] private async Task RefreshData(object? parameter) { string mesOrderNo = MesOrderNo; string rfidCount = RfidCount; DateTime dateTime = BeginDate; DateTime dateTime1 = EndDate; Expression> exp = (real_readdata s1) => true; if (!string.IsNullOrEmpty(MesOrderNo.Trim())) { exp = exp.And(x => x.orderno == mesOrderNo); } if (!string.IsNullOrEmpty(QueryIsCheck.Content.ToString().Trim())) { exp = exp.And(x => x.writestatus == QueryIsCheck.Content.ToString()); } //查询记录 List real_readdataInfos = sqlSugarClient.Queryable().Where(exp ).ToList(); if (real_readdataInfos.Count > 0) { App.Current.Dispatcher.Invoke(() => { realreaddata.Clear(); foreach (var item in real_readdataInfos) { realreaddata.Add(item); } }); } else { realreaddata.Clear(); } } private ComboBoxItem _QueryIsCheck = new ComboBoxItem() { Content = "" }; public ComboBoxItem QueryIsCheck { get { return _QueryIsCheck; } set { _QueryIsCheck = value; if (_QueryIsCheck != value) { SetProperty(ref _QueryIsCheck, value); } } } private DateTime _BeginDate; public DateTime BeginDate { get { return _BeginDate; } set { if (_BeginDate != value) { _BeginDate = value; if (_BeginDate != value) { SetProperty(ref _BeginDate, value); } } } } private DateTime _EndDate; public DateTime EndDate { get { return _EndDate; } set { _EndDate = value; if (_EndDate != value) { SetProperty(ref _EndDate, value); } } } private string _MesOrderNo = ""; public string MesOrderNo { get { return _MesOrderNo; } set { if (_MesOrderNo != value) { SetProperty(ref _MesOrderNo, value); } } } private string _RfidCount = ""; public string RfidCount { get { return _RfidCount; } set { if (_RfidCount != value) { SetProperty(ref _RfidCount, value); } } } private ObservableCollection _realreaddata = new ObservableCollection(); public ObservableCollection realreaddata { get => _realreaddata; set => SetProperty(ref _realreaddata, value); } } }