using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.DependencyInjection; using SlnMesnac.Business; using SlnMesnac.Model.domain; using SlnMesnac.Model.dto; using SlnMesnac.WPF.MessageTips; using SlnMesnac.WPF.Model; using SqlSugar; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- * 版权所有 (c) 2024 WenJY 保留所有权利。 * CLR版本:4.0.30319.42000 * 机器名称:LAPTOP-E0N2L34V * 命名空间:SlnMesnac.WPF.ViewModel * 唯一标识:14008fcc-0a31-4f1e-bc80-9f9ea84d3de5 * * 创建者:WenJY * 电子邮箱:wenjy@mesnac.com * 创建时间:2024-04-10 16:18:57 * 版本:V1.0.0 * 描述: * *-------------------------------------------------------------------- * 修改人: * 时间: * 修改说明: * * 版本:V1.0.0 *--------------------------------------------------------------------*/ #endregion << 版 本 注 释 >> namespace SlnMesnac.WPF.ViewModel { /// /// 生产统计ViewModel /// internal class ProdStatisticsViewModel : ViewModelBase { private readonly PalletStowBusiness _palletStowBusiness; private readonly ProdCompletionBusiness _prodCompletionBusiness; private readonly ISqlSugarClient sqlClient; public ProdStatisticsViewModel() { _palletStowBusiness = App.ServiceProvider.GetService(); _prodCompletionBusiness = App.ServiceProvider.GetService(); sqlClient = App.ServiceProvider.GetService(); QueryCommand = new RelayCommand(obj => Query(obj)); DeletePalletCommand = new RelayCommand(DeletePallet); BeginDate = DateTime.Now.AddDays(-3); EndDate = DateTime.Now; } #region 时间查询 private async Task Query(object obj) { try { if (EndDate <= BeginDate) { Application.Current.Dispatcher.Invoke(() => { Msg.MsgShow("结束时间要大于开始时间", 2, 3); }); return; } else { await RefreshWmsRawOutstockDetailDataGrid(BeginDate, EndDate); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } #endregion /// /// 刷新原材料出库记录及图表 /// private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate) { List list; list = await sqlClient.AsTenant().GetConnection("mes").Queryable().Where(x => x.WarehouseId==311 && x.OutstockTime >= beginDate && x.OutstockTime <= endDate).OrderBy(t => t.OutstockTime).ToListAsync(); if (list != null && list.Count > 0) { await App.Current.Dispatcher.BeginInvoke((Action)(() => { WmsRawOutstockDetailDataGrid.Clear(); int i = 1; foreach (WmsRawOutstockDetail verify in list) { verify.RawOutstockDetailId = i++; WmsRawOutstockDetailDataGrid.Add(verify); } })); // 刷新图表 // ModelList(list); } } #region 参数定义 private DateTime _BeginDate; public DateTime BeginDate { get { return _BeginDate; } set { if (_BeginDate != value) { _BeginDate = value; RaisePropertyChanged();//属性通知 } } } private DateTime _EndDate; public DateTime EndDate { get { return _EndDate; } set { _EndDate = value; RaisePropertyChanged();//属性通知 } } /// /// 托盘队列DataGrid /// private ObservableCollection wmsRawOutstockDetailDataGrid = new ObservableCollection(); public ObservableCollection WmsRawOutstockDetailDataGrid { get { return wmsRawOutstockDetailDataGrid; } set { wmsRawOutstockDetailDataGrid = value; RaisePropertyChanged(() => WmsRawOutstockDetailDataGrid); } } /// /// 条码队列DataGrid /// private ObservableCollection barCodeTaskDataGrid; public ObservableCollection BarCodeTaskDataGrid { get { return barCodeTaskDataGrid; } set { barCodeTaskDataGrid = value; RaisePropertyChanged(() => BarCodeTaskDataGrid); } } #endregion #region 事件定义 /// /// 时间查询事件 /// public RelayCommand QueryCommand { get; set; } public RelayCommand DeletePalletCommand { get;set; } public RelayCommand DeleteBarCodeCommand { get; set; } #endregion ///// ///// 刷新条码队列信息 ///// ///// //private void RefreshBarCodeTaskDataGrid(List barCodeTasks) //{ // BarCodeTaskDataGrid = new ObservableCollection(); // foreach (var task in barCodeTasks) // { // BarCodeTaskDataGrid.Add(task); // } //} /// /// 移除托盘队列信息 /// /// private void DeletePallet(string palletCode) { _palletStowBusiness.RemovePalletInfo(palletCode); } ///// ///// 移除小包条码队列信息 ///// ///// //private void DeleteBarCode(string barCode) //{ // _prodCompletionBusiness.RemoveBarCode(barCode); //} } }