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.

383 lines
13 KiB
C#

using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using Admin.Core.Service;
using Aucma.Core.PrintTo.Models;
using Aucma.Core.PrintTo.Views;
using Castle.Core.Internal;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
/*
* 首页信息
*
*/
namespace Aucma.Core.PrintTo.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
protected readonly IBaseOrderInfoServices _baseOrderInfoServices;
protected readonly IPrintBarCodeServices _printBarCodeServices;
List<BaseBomInfo> treeNodes =new List<BaseBomInfo>();
/// <summary>
/// 打印类型
/// </summary>
public int printType { get; set; }
public IndexPageViewModel()
{
_baseOrderInfoServices = App.ServiceProvider.GetService<IBaseOrderInfoServices>();
_printBarCodeServices = App.ServiceProvider.GetService<IPrintBarCodeServices>();
PrintIsEnabled = "True";
WeakReferenceMessenger.Default.Register<string>(this, Recive);
LoadData();
}
#region 加载DataGrid数据
private async void LoadData()
{
try
{
Datalist.Clear();
List<PrintPlanInfoView> list = await _baseOrderInfoServices.QueryPrintInfo();
if (list == null) return;
list= list.OrderBy(d => d.CreateTime).ToList();
var printBarCode = await _printBarCodeServices.QueryAsync();
foreach (var item in list)
{
OrderInfo order = new OrderInfo();
order.CreatedTime = item.CreateTime;
order.OrderCode = item.OrderCode;
order.ProductCode = item.ProductCode;
order.ProductName = item.ProductName;
order.PlanAmount = item.PlanAmount;
order.CompleteAmount = item.CompleteAmount;
order.MaterialCode = item.MaterialCode;
order.MaterialName = item.MaterialName;
order.StandardAmount = item.StandardAmount;
order.LinerAmount = printBarCode.Where(d => d.OrderCode.Equals(item.OrderCode) && d.MaterialBarcode.Contains("L")).Count();
order.BoxAmount = printBarCode.Where(d=>d.OrderCode.Equals(item.OrderCode)&&d.MaterialBarcode.Contains("B")).Count();
order.ErrorNum = item.ErrorAmount;
order.LinerCodeNum = item.LinerAmount;
order.BoxCodeNum = item.BoxAmount;
order.PrintName = item.PrintName;
datalist.Add(order);
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
private async void LoadData(string queryStr)
{
Datalist.Clear();
List<PrintPlanInfoView> list = await _baseOrderInfoServices.QueryPrintInfo();
if (list.Count() == 0) return;
List<PrintPlanInfoView> pintList = list.Where(d => d.OrderCode.Contains(queryStr) || d.ProductCode.Contains(queryStr) || d.ProductName.Contains(queryStr)).ToList();
foreach (var item in pintList)
{
OrderInfo order = new OrderInfo();
order.CreatedTime = item.CreateTime;
order.OrderCode = item.OrderCode;
order.ProductCode = item.ProductCode;
order.ProductName = item.ProductName;
order.PlanAmount = item.PlanAmount;
order.CompleteAmount = item.CompleteAmount;
order.MaterialCode = item.MaterialCode;
order.MaterialName = item.MaterialName;
order.StandardAmount = item.StandardAmount;
order.LinerAmount = item.LinerAmount;
order.BoxAmount = item.StandardAmount;
order.ErrorNum = item.ErrorAmount;
order.LinerCodeNum = item.LinerAmount;
order.BoxCodeNum = item.BoxAmount;
order.PrintName = item.PrintName;
datalist.Add(order);
}
}
#endregion
#region 查询按钮
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private void QueryString(string queryStr)
{
List<PrintPlanInfoView> orderList = null;
try
{
if (string.IsNullOrEmpty(queryStr))
{
LoadData();
return;
}
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
{
Datalist.Clear();
LoadData(queryStr);
//Datalist.Insert(0, Datalist[Datalist.Count - 1]);
//Datalist.RemoveAt(Datalist.Count - 1);
}));
}
catch (Exception ex)
{
log.Error("QueryString方法出现异常");
}
}
#endregion
#region radio查询按钮
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private void RadioQuery(string type)
{
if (type== "内胆")
{
printType = 500;
}
if (type == "箱体")
{
printType = 400;
}
}
#endregion
#region 打印
/// <summary>
/// 打印
/// </summary>
[RelayCommand]
private async void Print(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中需要打印的产品!","系统提醒");
return;
}
if (string.IsNullOrEmpty(SelectedCells.PrintName))
{
MessageBox.Show("打印名称不可为空!", "系统提醒");
return;
}
if (SelectedCells.PlanAmount == 0)
{
MessageBox.Show("请输入打印数量!", "系统提醒");
return;
}
if (SelectedCells.PlanAmount == 0)
{
MessageBox.Show("请输入打印数量!", "系统提醒");
return;
}
if (printType==0)
{
MessageBox.Show("请选择打印类型!", "系统提醒");
return;
}
try
{
string order_code = SelectedCells.OrderCode;
string product_code = SelectedCells.ProductCode;
string product_name = SelectedCells.ProductName;
//string material_code = SelectedCells.MaterialCode;
//string material_name = SelectedCells.MaterialName;
int standard_amount = SelectedCells.PlanAmount;
string printName = SelectedCells.PrintName;
PrintIsEnabled = "False";
//更新打印名称
var baseOrder=await _baseOrderInfoServices.FirstAsync(d=>d.OrderCode== order_code);
await _baseOrderInfoServices.UpdatePrintName(baseOrder);
PrintToDevView printToDev = new PrintToDevView(order_code,product_code, product_name, standard_amount, printName,printType);
printToDev.ShowDialog();
}
catch (Exception ex)
{
PrintIsEnabled = "True";
log.Error(ex.Message);
}
}
#endregion
#region 补打
/// <summary>
///补打
/// </summary>
[RelayCommand]
private void SupplementPrint(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中要补打的数据!", "系统提醒");
return;
}
string order_code = SelectedCells.OrderCode;
string product_code = SelectedCells.ProductCode;
string product_name = SelectedCells.ProductName;
string material_code = SelectedCells.MaterialCode;
string material_name = SelectedCells.MaterialName;
int standard_amount = SelectedCells.StandardAmount;
SupplementPrintPageView printToDev = new SupplementPrintPageView(order_code,product_code, material_code, material_name);
printToDev.ShowDialog();
}
#endregion
#region 追打
/// <summary>
///追打
/// </summary>
[RelayCommand]
private void AppendPrintPrint(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中需要打印的产品!", "系统提醒");
return;
}
//if (!CheckPrintPassword())
//{
// return;
//}
try
{
string order_code = SelectedCells.OrderCode;
string product_code = SelectedCells.ProductCode;
string product_name = SelectedCells.ProductName;
string material_code = SelectedCells.MaterialCode;
string material_name = SelectedCells.MaterialName;
int standard_amount = SelectedCells.StandardAmount;
string printName = SelectedCells.PrintName;
PrintIsEnabled = "False";
PrintToDevView printToDev = new PrintToDevView(order_code, product_code, product_name, standard_amount, printName, printType);
printToDev.ShowDialog();
}
catch (Exception ex)
{
PrintIsEnabled = "True";
log.Error(ex.Message);
}
}
#endregion
#region 特殊打印
/// <summary>
///特殊打印
/// </summary>
[RelayCommand]
private Task SpecialPrint()
{
try
{
SpecialPrintView print = new SpecialPrintView();
print.ShowDialog();
}
catch (Exception ex)
{
log.Error(ex.Message);
}
return Task.CompletedTask;
}
#endregion
#region 初始化datagrid
private ObservableCollection<OrderInfo> datalist = new ObservableCollection<OrderInfo>();
public ObservableCollection<OrderInfo> Datalist
{
get { return datalist; }
set
{
datalist = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 获取当前行数据 赋值到textbox
private OrderInfo selectedCells;
public OrderInfo SelectedCells
{
get { return selectedCells; }
set
{
selectedCells = value;
SetProperty(ref selectedCells, value);
}
}
#endregion
#region 常规打印按钮状态
private string _printIsEnabled;
public string PrintIsEnabled
{
get { return _printIsEnabled; }
set
{
_printIsEnabled = value;
SetProperty(ref _printIsEnabled, value);//属性通知
}
}
#endregion
#region 刷新列表-其他界面刷新该方法
/// <summary>
/// 刷新列表
/// </summary>
/// <param name="recipient"></param>
/// <param name="message"></param>
private void Recive(object recipient, string message)
{
if (message == "Refresh")
{
PrintIsEnabled = "True";
Datalist.Clear();
LoadData();
}
}
#endregion
#region 递归获取内胆、箱体数量
public static void GetParentID(List<BaseBomInfo> treeNodes, string materialCode)
{
if (string.IsNullOrEmpty(materialCode))
{
return;
}
var query = from c in treeNodes
where c.ParentId == materialCode
select c;
foreach (var item in query)
{
if ( item == null) { }
GetParentID(treeNodes, item.MaterialCode);
treeNodes.Add(item);
}
}
#endregion
}
}