using Admin.Core.IService; using Admin.Core.Service; using Admin.Core.Wpf.Models; using Admin.Core.Wpf.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using log4net; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Admin.Core.Wpf.ViewModels { public partial class SupplementPrintPageViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(SupplementPrintPageViewModel)); private readonly IPrintBarCodeServices? _barCodeServices; protected readonly IProductPlanInfoServices? _productPlanInfoServices; public SupplementPrintPageViewModel() { } public SupplementPrintPageViewModel(string planCode, string orderNo, string materialName) { PlanCode = planCode; OrderNo = orderNo; MaterialName = materialName; _barCodeServices = App.ServiceProvider.GetService(); _productPlanInfoServices = App.ServiceProvider.GetService(); LoadData(planCode, orderNo); } #region 选中订单参数 #region 计划编码 private string _planCode; public string PlanCode { get => _planCode; set => SetProperty(ref _planCode, value); } #endregion #region 订单编码 private string _orderNo; public string OrderNo { get => _orderNo; set => SetProperty(ref _orderNo, value); } #endregion #region 物料型号 private string _materialName; public string MaterialName { get => _materialName; set => SetProperty(ref _materialName, value); } #endregion #endregion #region 打印 /// /// 打印 /// [RelayCommand] private async void Print() { //if (string.IsNullOrEmpty(obj)) //{ // MessageBox.Show("请选中一行!", "系统提醒"); // return; //} var barCode = SelectedCells.BarCode; var list = await _productPlanInfoServices.QueryAsync(d => d.PlanCode == PlanCode && d.OrderCode == OrderNo); ; var barCodeObj = list.FirstOrDefault(); PrintToDevView printToDev = new PrintToDevView(barCodeObj.PlanCode, barCodeObj.OrderCode, barCodeObj.MaterialCode, 1,barCode); printToDev.ShowDialog(); } #endregion #region 加载DataGrid数据 private async void LoadData(string planCode,string orderNo) { var b = await _barCodeServices.QueryAsync(); var list = await _barCodeServices.QueryAsync(d => d.OrderCode.Contains(orderNo)); foreach (var item in list) { Datalist.Add(new BarCodeModel() { PlanCode = planCode, BarCode = item.MaterialBarcode, PrintTime = item.PrintTime, SuppleMetNum = item.SupplementMaterial}); } } #endregion #region 初始化datagrid private ObservableCollection datalist = new ObservableCollection(); public ObservableCollection Datalist { get { return datalist; } set { datalist = value; OnPropertyChanged("datalist");//属性通知 } } #endregion #region 获取当前行数据 赋值到textbox private BarCodeModel selectedCells; public BarCodeModel SelectedCells { get { return selectedCells; } set { selectedCells = value; SetProperty(ref selectedCells, value); } } #endregion } }