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.

209 lines
7.0 KiB
C#

using Admin.Core.IService;
using Admin.Core.Model.Sys;
using Admin.Core.Model;
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 MaterialDesignThemes.Wpf;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Metrics;
using System.Drawing.Imaging;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using Admin.Core.Common;
/*
* 首页信息
*
*/
namespace Admin.Core.Wpf.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
protected readonly IProductPlanInfoServices? _productPlanInfoServices;
public IndexPageViewModel()
{
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
_=LoadData();
}
#region 加载DataGrid数据
private async Task LoadData()
{
var list= await _productPlanInfoServices.QueryAsync(d=>d.ProductLineCode== "1001");
foreach(var item in list)
{
Datalist.Add(new OrderInfo() { plan_code= item.PlanCode, created_time = item.BeginTime.ToString(), order_code=item.OrderCode, material_code = item.MaterialCode, material_name = item.MaterialName, plan_amount =item.PlanAmount });
}
}
#endregion
#region 查询按钮
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private void QueryString(string queryStr)
{
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));
//}
var list = await _productPlanInfoServices.QueryAsync(d => d.PlanCode.Contains(queryStr) || d.OrderCode.Contains(queryStr) || d.MaterialCode.Contains(queryStr) || d.MaterialName.Contains(queryStr));
var orderList=list.Where(d => d.ProductLineCode == "1001");
foreach (var item in orderList)
{
Datalist.Add(new OrderInfo() { plan_code = item.PlanCode, created_time = item.BeginTime.ToString(), order_code = item.OrderCode, material_code = item.MaterialCode, material_name = item.MaterialName, plan_amount =item.PlanAmount== item.PlanAmount ? item.PlanAmount :0 });
}
}
else
{
Datalist.Clear();
_ = LoadData();
}
//Datalist.Insert(0, Datalist[Datalist.Count - 1]);
//Datalist.RemoveAt(Datalist.Count - 1);
}));
}
#endregion
#region radio查询按钮
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private async Task RadioQuery(object queryStr)
{
try
{
string materialName= string.Empty;
string query = queryStr as string;
if (string.IsNullOrEmpty(query)) materialName = "内胆";
if (query == "Liner") materialName = "内胆";
if (query== "BoxShell") materialName = "箱壳";
var list = await _productPlanInfoServices.QueryAsync(d => d.ProductLineCode == "1001" && d.MaterialName.Contains(materialName));
Datalist.Clear();
foreach (var item in list)
{
Datalist.Add(new OrderInfo() { plan_code = item.PlanCode, created_time = item.BeginTime.ToString(), order_code = item.OrderCode, material_code = item.MaterialCode, material_name = item.MaterialName, plan_amount = Convert.ToInt32(item.PlanAmount) });
}
}
catch (Exception ex)
{
log.Error("查询数据异常", ex);
}
}
#endregion
#region 打印
/// <summary>
/// 打印
/// </summary>
[RelayCommand]
private void Print(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中一行!","系统提醒");
return;
}
string plan_code = SelectedCells.plan_code;
string order_code = SelectedCells.order_code;
string material_name = SelectedCells.material_name;
int plan_amount = SelectedCells.plan_amount;
PrintToDevView printToDev= new PrintToDevView(plan_code, order_code, material_name, plan_amount);
printToDev.ShowDialog();
}
#endregion
#region 补打
/// <summary>
///补打
/// </summary>
[RelayCommand]
private void SupplementPrint(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中要补打的数据!", "系统提醒");
return;
}
string plan_code = SelectedCells.plan_code;
string order_code = SelectedCells.order_code;
string material_name = SelectedCells.material_name;
int plan_amount = SelectedCells.plan_amount;
SupplementPrintPageView printToDev = new SupplementPrintPageView(plan_code, order_code, material_name);
printToDev.ShowDialog();
}
#endregion
#region 续打
/// <summary>
///续打
/// </summary>
[RelayCommand]
private void ContinuedPrint()
{
MessageBox.Show("续打");
// OrderInfo info = new OrderInfo();
}
#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
}
}