You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.PrintTo/ViewModels/SupplementPrintPageViewMode...

193 lines
6.5 KiB
C#

using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Service;
using Admin.Core.Service.Service_New;
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;
protected readonly IPrintSuppleMentBarCodeServices _printSuppleMentBarCodeServices;
public SupplementPrintPageViewModel() {
_printSuppleMentBarCodeServices = App.ServiceProvider.GetService<IPrintSuppleMentBarCodeServices>();
_baseOrderInfoServices = App.ServiceProvider.GetService<IBaseOrderInfoServices>();
Task.WaitAll(LoadData());
}
#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 打印
/// <summary>
/// 打印
/// </summary>
/// <param name="obj">主键</param>
[RelayCommand]
private async void Print(string obj)
{
if (obj== "0")
{
MessageBox.Show("请选中要补打的条码!", "系统提醒");
return;
}
var orderCode = SelectedCells.OrderCode;
var materialCode = SelectedCells.MaterialCode;
var materialName = SelectedCells.MaterialName;
var barCode = SelectedCells.BarCode;
var printName = SelectedCells.PrintName;
var baseOrderInfo=await _baseOrderInfoServices.FirstAsync(d => d.OrderCode == orderCode);
if (baseOrderInfo!=null)
{
int Id = Convert.ToInt32(obj);
SupplementView printToDev = new SupplementView(Id);
printToDev.ShowDialog();
}
}
#endregion
#region 查询
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private async Task QueryBarCode(string queryStr)
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
{
if (!string.IsNullOrEmpty(queryStr))
{
Datalist.Clear();
var list = await _printSuppleMentBarCodeServices.QueryAsync(d => d.MaterialName.Contains(queryStr) || d.MaterialBarCode.Equals(ProductNo) || d.OrderCode.Equals(ProductNo));
foreach (var item in list)
{
Datalist.Add(new BarCodeModel()
{
OrderCode = item.OrderCode,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
BarCode = item.MaterialBarCode,
PrintTime = item.PrintTime
});
}
}
else
{
Datalist.Clear();
await LoadData(ProductNo, MaterialCode);
}
}));
}
#endregion
#region 加载DataGrid数据
private async Task LoadData(string materialCode, string materialName)
{
var list = await _printSuppleMentBarCodeServices.QueryAsync(d=>d.MaterialBarCode.Contains(materialCode)|| d.MaterialBarCode.Contains(materialName));
if (list == null) return;
foreach (var item in list)
{
Datalist.Add(new BarCodeModel() {
OrderCode = item.OrderCode,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
BarCode = item.MaterialBarCode,
PrintName = item.PrintName,
PrintTime = item.PrintTime
});
}
}
private async Task LoadData()
{
var list = await _printSuppleMentBarCodeServices.QueryAsync();
if (list == null) return;
foreach (var item in list)
{
Datalist.Add(new BarCodeModel()
{
ID = item.ObjId,
OrderCode = item.OrderCode,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
BarCode = item.MaterialBarCode,
PrintName = item.PrintName,
PrintTime = item.PrintTime
});
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<BarCodeModel> datalist = new ObservableCollection<BarCodeModel>();
public ObservableCollection<BarCodeModel> 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
}
}