using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Service; using Aucma.Core.PrintTo.Models; using Aucma.Core.PrintTo.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 Aucma.Core.PrintTo.ViewModels { public partial class SupplementPrintPageViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(SupplementPrintPageViewModel)); private readonly IPrintBarCodeServices? _barCodeServices; protected readonly IBaseOrderInfoServices? _baseOrderInfoServices; public SupplementPrintPageViewModel() { } public SupplementPrintPageViewModel(string orderCode, string productCode,string material_code,string materialName) { OrderNo = orderCode; ProductNo = productCode; MaterialCode = material_code; MaterialName = materialName; _barCodeServices = App.ServiceProvider.GetService(); _baseOrderInfoServices = App.ServiceProvider.GetService(); Task.WaitAll(LoadData(productCode, material_code)); } #region 选中订单参数 #region 产品编码 private string _productNo; public string ProductNo { get => _productNo; set => SetProperty(ref _productNo, value); } #endregion #region 订单编码 private string _orderNo; public string OrderNo { get => _orderNo; set => SetProperty(ref _orderNo, value); } #endregion #region 物料编码 private string _materialCode; public string MaterialCode { get => _materialCode; set => SetProperty(ref _materialCode, value); } #endregion #region 物料型号 private string _materialName; public string MaterialName { get => _materialName; set => SetProperty(ref _materialName, value); } #endregion #endregion #region 打印 /// /// 打印 /// [RelayCommand] private void Print(string obj) { if (string.IsNullOrEmpty(obj)) { MessageBox.Show("请选中一行!", "系统提醒"); return; } var productCode = SelectedCells.ProductCode; var materialCode = SelectedCells.MaterialCode; var materialName = SelectedCells.MaterialName; var printName = SelectedCells.PrintName; var barCode = SelectedCells.BarCode; var printType= SelectedCells.PrintType; PrintToDevView printToDev = new PrintToDevView(productCode, materialCode, materialName, 1, printName,printType); printToDev.ShowDialog(); } #endregion #region 查询 /// /// 查询 /// [RelayCommand] private async Task QueryBarCode(string queryStr) { //System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => //{ if (!string.IsNullOrEmpty(queryStr)) { Datalist.Clear(); var list = await _barCodeServices.QueryAsync(d => d.MaterialName.Contains(queryStr) ||d.MaterialBarcode.Equals(ProductNo) || d.OrderCode.Equals(ProductNo)); foreach (var item in list) { Datalist.Add(new BarCodeModel() { ProductCode = ProductNo, MaterialCode= item.MaterialCode, MaterialName=item.MaterialName, BarCode = item.MaterialBarcode, PrintTime = item.PrintTime, SuppleMetNum = item.SupplementMaterial }); } } else { Datalist.Clear(); await LoadData(ProductNo, MaterialCode); } //})); } #endregion #region 加载DataGrid数据 private async Task LoadData(string productCode,string material_code) { var list = await _barCodeServices.QueryAsync(d => d.OrderCode.Contains(productCode)&& d.MaterialCode.Contains(material_code)); if (list == null) return; foreach (var item in list) { Datalist.Add(new BarCodeModel() { ProductCode = ProductNo, MaterialCode = item.MaterialCode, MaterialName = item.MaterialName, 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 } }