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.

187 lines
6.1 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Aucma.Core.SheetMetal.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Admin.Core.IService;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using Admin.Core.Model;
using Castle.Core.Internal;
using Admin.Core.Service;
using Admin.Core.Model.Model_New;
using Admin.Core.Common;
using CommunityToolkit.Mvvm.Messaging;
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class SplitPlanViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
protected readonly IProductPlanInfoServices? _productPlanInfoServices;
protected readonly ISmTaskExecutionServices? _smTaskExecutionServices;
public SplitPlanViewModel()
{
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
_smTaskExecutionServices = App.ServiceProvider.GetService<ISmTaskExecutionServices>();
LoadData();
}
#region 加载DataGrid数据
private async void LoadData()
{
int i = 1;
List<PlanMaintenanceView> list = await _productPlanInfoServices.QueryPlanInfo();
foreach (var item in list)
{
MaterialDataGrid.Add(new PlanMaintenanceModel()
{
No = i,
PlanCode= item.PlanCode,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
OrderCode = item.OrderCode,
PlanAmount = item.PlanAmount,
ResidueAmount = item.ResidueAmount,
StartDate = item.StartDate
});
i++;
}
}
private async void LoadData(string obj)
{
int i = 1;
List<PlanMaintenanceView> list = await _productPlanInfoServices.QueryPlanInfo();
var queryList = list.Where(d=>d.PlanCode.Contains(obj)|| d.OrderCode.Contains(obj)|| d.MaterialCode.Contains(obj) || d.MaterialName.Contains(obj));
foreach (var item in queryList)
{
MaterialDataGrid.Add(new PlanMaintenanceModel()
{
No = i,
PlanCode = item.PlanCode,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
OrderCode = item.OrderCode,
PlanAmount = item.PlanAmount,
ResidueAmount = item.ResidueAmount,
StartDate = item.StartDate
});
i++;
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<PlanMaintenanceModel> materialDataGrid = new ObservableCollection<PlanMaintenanceModel>();
public ObservableCollection<PlanMaintenanceModel> MaterialDataGrid
{
get { return materialDataGrid; }
set
{
materialDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 查询
/// <summary>
/// 查询
/// </summary>
[RelayCommand]
private void QueryPlan(string obj)
{
if (obj.IsNullOrEmpty())
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
MaterialDataGrid.Clear();
LoadData();
}));
return;
}
MaterialDataGrid.Clear();
LoadData(obj);
}
#endregion
#region 创建任务
/// <summary>
/// 创建任务
/// </summary>
[RelayCommand]
private async Task CreateTask(string obj)
{
if (string.IsNullOrEmpty(obj))
{
MessageBox.Show("请选中一行!", "系统提醒");
return;
}
var list = await _smTaskExecutionServices.QueryAsync();
string plan_code = SelectedCells.PlanCode;
string order_code = SelectedCells.OrderCode;
string material_code = SelectedCells.MaterialCode;
string material_name = SelectedCells.MaterialName;
int plan_amount = SelectedCells.PlanAmount;
SmTaskExecution task=new SmTaskExecution();
task.PlanCode = plan_code;
task.OrderCode = order_code;
task.MaterialCode = material_code;
task.MaterialName = material_name;
task.TaskAmount = plan_amount;
task.CompleteAmount = 0;
if (list.Count == 0)
{
task.TaskSort = 1;
task.ObjId = 1;
}
if (list.Count != 0)
{
task.ObjId = list.Max(d => d.ObjId) + 1;
task.TaskSort = list.Max(d => d.TaskSort) + 1;
}
task.IsExec = 0;
task.CreateTime = DateTime.Now;
var result = await _smTaskExecutionServices.AddAsync(task);
if (result==0)
{
CloseWindow();
MaterialDataGrid.Clear();
LoadData();
}
}
#endregion
#region 获取当前行数据 赋值到textbox
private PlanMaintenanceModel selectedCells;
public PlanMaintenanceModel SelectedCells
{
get { return selectedCells; }
set
{
selectedCells = value;
SetProperty(ref selectedCells, value);
}
}
#endregion
#region 关闭当前窗口
/// <summary>
/// 关闭当前窗口
/// </summary>
public void CloseWindow()
{
WeakReferenceMessenger.Default.Send<object>("close");
}
#endregion
}
}