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.
340 lines
12 KiB
C#
340 lines
12 KiB
C#
using Admin.Core.IService;
|
|
using Admin.Core.Model.ViewModels;
|
|
using Aucma.Core.PrintTo.Models;
|
|
using Aucma.Core.PrintTo.Views;
|
|
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;
|
|
|
|
public IndexPageViewModel()
|
|
{
|
|
_baseOrderInfoServices = App.ServiceProvider.GetService<IBaseOrderInfoServices>();
|
|
|
|
PrintIsEnabled = "True";
|
|
WeakReferenceMessenger.Default.Register<string>(this, Recive);
|
|
|
|
//Task.WaitAll(LoadData());
|
|
}
|
|
|
|
#region 加载DataGrid数据
|
|
private async Task LoadData()
|
|
{
|
|
Datalist.Clear();
|
|
var list = await _baseOrderInfoServices.QueryPrintInfo();
|
|
foreach (var item in list)
|
|
{
|
|
Datalist.Add(new OrderInfo()
|
|
{
|
|
CreatedTime = item.CreateTime,
|
|
OrderCode = item.OrderCode,
|
|
ProductCode = item.ProductCode,
|
|
ProductName = item.ProductName,
|
|
PlanAmount = item.PlanAmount,
|
|
CompleteAmount = item.CompleteAmount,
|
|
MaterialCode = item.MaterialCode,
|
|
MaterialName = item.MaterialName,
|
|
StandardAmount = item.StandardAmount,
|
|
LinerAmount = item.LinerAmount,
|
|
BoxAmount = item.StandardAmount,
|
|
ErrorNum = item.ErrorAmount,
|
|
LinerCodeNum = item.LinerAmount,
|
|
BoxCodeNum = item.BoxAmount
|
|
});
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 查询按钮
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
[RelayCommand]
|
|
private async void QueryString(string queryStr)
|
|
{
|
|
List<PrintPlanInfoView> orderList = null;
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(queryStr))
|
|
{
|
|
var list = await _baseOrderInfoServices.QueryPrintInfo();
|
|
orderList = list.Where(d => d.OrderCode.Contains(queryStr) || d.ProductCode.Contains(queryStr) || d.ProductName.Contains(queryStr) || d.MaterialCode.Contains(queryStr) || d.MaterialName.Contains(queryStr)).ToList();
|
|
|
|
}
|
|
|
|
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
|
|
{
|
|
if (!string.IsNullOrEmpty(queryStr))
|
|
{
|
|
Datalist.Clear();
|
|
|
|
//Expression<Func<OrderInfo, bool>> whereExpression = x => (bool)x.DelFlag == false;
|
|
//if (queryStr.IsNotEmptyOrNull())
|
|
//{
|
|
// whereExpression = whereExpression.And(x => x.PLAN_CODE.Contains(queryStr));
|
|
//}
|
|
|
|
foreach (var item in orderList)
|
|
{
|
|
OrderInfo info = new OrderInfo();
|
|
info.CreatedTime = item.CreateTime;
|
|
info.OrderCode = item.OrderCode;
|
|
info.ProductCode = item.ProductCode;
|
|
info.ProductName = item.ProductName;
|
|
info.PlanAmount = item.PlanAmount;
|
|
info.CompleteAmount = item.CompleteAmount;
|
|
info.MaterialCode = item.MaterialCode;
|
|
info.MaterialName = item.MaterialName;
|
|
info.StandardAmount = item.StandardAmount;
|
|
info.ErrorNum = item.ErrorAmount;
|
|
info.LinerCodeNum = item.LinerAmount;
|
|
info.BoxCodeNum = item.BoxAmount;
|
|
Datalist.Add(info);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Datalist.Clear();
|
|
await LoadData();
|
|
}
|
|
//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 async Task RadioQuery(string query)
|
|
{
|
|
try
|
|
{
|
|
string materialName= string.Empty;
|
|
//if (string.IsNullOrEmpty(query)) materialName = "内胆";
|
|
//if (query == "Liner") materialName = "内胆";
|
|
//if (query== "UShell") materialName = "U壳";
|
|
|
|
Datalist.Clear();
|
|
var list = await _baseOrderInfoServices.QueryPrintInfo();
|
|
var orderList = list.Where(d => d.MaterialName.Contains(query) );
|
|
foreach (var item in orderList)
|
|
{
|
|
OrderInfo info = new OrderInfo();
|
|
info.CreatedTime = item.CreateTime;
|
|
info.OrderCode = item.OrderCode;
|
|
info.ProductCode = item.ProductCode;
|
|
info.ProductName = item.ProductName;
|
|
info.PlanAmount = item.PlanAmount;
|
|
info.CompleteAmount = item.CompleteAmount;
|
|
info.MaterialCode = item.MaterialCode;
|
|
info.MaterialName = item.MaterialName;
|
|
info.StandardAmount = item.StandardAmount;
|
|
info.ErrorNum = item.ErrorAmount;
|
|
info.LinerCodeNum = item.LinerAmount;
|
|
info.BoxCodeNum = item.BoxAmount;
|
|
Datalist.Add(info);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("查询数据异常", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 打印
|
|
/// <summary>
|
|
/// 打印
|
|
/// </summary>
|
|
[RelayCommand]
|
|
private void Print(string obj)
|
|
{
|
|
if (string.IsNullOrEmpty(obj))
|
|
{
|
|
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.StandardAmount;
|
|
PrintIsEnabled = "False";
|
|
PrintToDevView printToDev = new PrintToDevView(product_code, material_code, material_name, standard_amount);
|
|
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;
|
|
PrintIsEnabled = "False";
|
|
PrintToDevView printToDev = new PrintToDevView(product_code, material_code, material_name, standard_amount);
|
|
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, object message)
|
|
{
|
|
PrintIsEnabled = "True";
|
|
Datalist.Clear();
|
|
_=LoadData();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|