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.
272 lines
9.4 KiB
C#
272 lines
9.4 KiB
C#
using Admin.Core.IService;
|
|
using Admin.Core.Model;
|
|
using Admin.Core.Service;
|
|
using Aucma.Core.OldBoxFoam.Business;
|
|
using Aucma.Core.OldBoxFoam.Models;
|
|
using Aucma.Core.OldBoxFoam.Views;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Aucma.Core.OldBoxFoam.ViewModels
|
|
{
|
|
/**
|
|
* 发泡计划
|
|
*
|
|
* */
|
|
public partial class FoamPlanPageViewModel : ObservableObject
|
|
{
|
|
protected readonly IBoxFoamPlanServices? _boxFoamPlanServices;
|
|
private readonly ICurrentTeamTimeServices _currentTeamTimeServices;
|
|
|
|
private Collection collection = new Collection();
|
|
|
|
public FoamPlanPageViewModel()
|
|
{
|
|
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
|
|
_currentTeamTimeServices = App.ServiceProvider.GetService<ICurrentTeamTimeServices>();
|
|
WeakReferenceMessenger.Default.Register<string>(this, Recive);
|
|
//InitData();
|
|
|
|
Task.Run(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
|
{
|
|
InitData();
|
|
}));
|
|
|
|
Thread.Sleep(1000 * 5);
|
|
};
|
|
});
|
|
|
|
}
|
|
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
[RelayCommand]
|
|
public void DeletePlan(object ObjId)
|
|
{
|
|
MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
|
|
if (MessageBoxResult.Yes == msg)
|
|
{
|
|
int id = (int)ObjId;
|
|
_boxFoamPlanServices.DeleteByIdAsync(id).Wait();
|
|
InitData();
|
|
MessageBox.Show("执行计划删除成功", "系统信息");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void InitData()
|
|
{
|
|
ListItems1.Clear();
|
|
ListItems.Clear();
|
|
int count = 0;
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
// 判断当前是否是白班时间段
|
|
if (now.Hour >= 8 && now.Hour < 20)
|
|
{
|
|
List<BoxFoamPlan> list = _boxFoamPlanServices.QueryAsync(d => d.StationCode == "1105" && d.ShiftType == 1).Result;
|
|
if (list == null) return;
|
|
foreach (BoxFoamPlan item in list)
|
|
{
|
|
BoxFoamPlanModel model = new BoxFoamPlanModel();
|
|
model.No = ++count;
|
|
model.MaterialCode = item.MaterialCode;
|
|
model.MaterialName = item.MaterialName;
|
|
model.PlanAmount = item.PlanAmount;
|
|
model.ComplateAmount = item.CompleteAmount;
|
|
model.DifferenceValue = item.PlanAmount - item.CompleteAmount;
|
|
model.ObjId = item.ObjId;
|
|
ListItems.Add(model);
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<BoxFoamPlan> list = _boxFoamPlanServices.QueryAsync(d => d.ShiftType == 1).Result;
|
|
if (list == null) return;
|
|
foreach (BoxFoamPlan item in list)
|
|
{
|
|
BoxFoamPlanModel model = new BoxFoamPlanModel();
|
|
model.No = ++count;
|
|
model.MaterialCode = item.MaterialCode;
|
|
model.MaterialName = item.MaterialName;
|
|
model.PlanAmount = item.PlanAmount;
|
|
model.ComplateAmount = item.CompleteAmount;
|
|
model.DifferenceValue = item.PlanAmount - item.CompleteAmount;
|
|
model.ObjId = item.ObjId;
|
|
|
|
ListItems1.Add(model);
|
|
}
|
|
}
|
|
}catch(Exception ex)
|
|
{
|
|
Console.WriteLine($"计划信息实时刷新异常:{ex.Message}");
|
|
}
|
|
|
|
#region 原逻辑 Delete By wenjy 2024-01-07 12:24:00
|
|
//DateTime now=DateTime.Now;
|
|
//CurrentTeamTime time = _currentTeamTimeServices.FirstAsync(d => d.StartTime <= now && d.EndTime >= now).Result;
|
|
//if (time == null) return;
|
|
//if (time.TeamName.Equals("早班"))
|
|
//{
|
|
// List<BoxFoamPlan> list = _boxFoamPlanServices.QueryAsync(d=>d.ShiftType==1).Result;
|
|
// if (list == null) return;
|
|
// foreach (BoxFoamPlan item in list)
|
|
// {
|
|
// BoxFoamPlanModel model = new BoxFoamPlanModel();
|
|
// model.No = ++count;
|
|
// model.MaterialCode = item.MaterialCode;
|
|
// model.MaterialName = item.MaterialName;
|
|
// model.PlanAmount = item.PlanAmount;
|
|
// model.ComplateAmount = item.CompleteAmount;
|
|
// model.DifferenceValue = item.PlanAmount - item.CompleteAmount;
|
|
// model.ObjId = item.ObjId;
|
|
// ListItems.Add(model);
|
|
|
|
// }
|
|
//}
|
|
//if (time.TeamName.Equals("晚班"))
|
|
//{
|
|
|
|
// List<BoxFoamPlan> list = _boxFoamPlanServices.QueryAsync(d => d.ShiftType == 1).Result;
|
|
// if (list == null) return;
|
|
// foreach (BoxFoamPlan item in list)
|
|
// {
|
|
// BoxFoamPlanModel model = new BoxFoamPlanModel();
|
|
// model.No = ++count;
|
|
// model.MaterialCode = item.MaterialCode;
|
|
// model.MaterialName = item.MaterialName;
|
|
// model.PlanAmount = item.PlanAmount;
|
|
// model.ComplateAmount = item.CompleteAmount;
|
|
// model.DifferenceValue = item.PlanAmount - item.CompleteAmount;
|
|
// model.ObjId = item.ObjId;
|
|
|
|
// ListItems1.Add(model);
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
public void AddPlan(string objId)
|
|
{
|
|
int shiftType = 1;//当班是1
|
|
SplitPlanView plan = new SplitPlanView(objId, shiftType,"","");
|
|
plan.Show();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async void ClearPlan(string objId)
|
|
{
|
|
int id=int.Parse(objId);
|
|
var obj=await _boxFoamPlanServices.FirstAsync(d=>d.ObjId== id);
|
|
obj.MaterialCode = "";
|
|
obj.MaterialName = "";
|
|
obj.PlanAmount = 0;
|
|
var result= await _boxFoamPlanServices.UpdateAsync(obj);
|
|
if (result)
|
|
{
|
|
ClearData();
|
|
MessageBox.Show("清除计划成功!", "系统提醒");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("清除计划失败!", "系统提醒");
|
|
}
|
|
}
|
|
|
|
#region 初始化datagrid
|
|
/// <summary>
|
|
/// 白班
|
|
/// </summary>
|
|
private ObservableCollection<BoxFoamPlanModel> listItems = new ObservableCollection<BoxFoamPlanModel>();
|
|
public ObservableCollection<BoxFoamPlanModel> ListItems
|
|
{
|
|
get => listItems;
|
|
set => SetProperty(ref listItems, value);
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化datagrid
|
|
/// <summary>
|
|
/// 夜班
|
|
/// </summary>
|
|
private ObservableCollection<BoxFoamPlanModel> listItems1 = new ObservableCollection<BoxFoamPlanModel>();
|
|
public ObservableCollection<BoxFoamPlanModel> ListItems1
|
|
{
|
|
get => listItems1;
|
|
set => SetProperty(ref listItems1, value);
|
|
}
|
|
#endregion
|
|
|
|
private void Recive(object recipient, string message)
|
|
{
|
|
if (message == "RefreshTask")
|
|
{
|
|
ClearData();
|
|
}
|
|
}
|
|
|
|
#region 清空数据
|
|
public void ClearData()
|
|
{
|
|
Id.Clear();
|
|
MaterialCode.Clear();
|
|
MaterialName.Clear();
|
|
PlanAmount.Clear();
|
|
InitData();
|
|
}
|
|
#endregion
|
|
|
|
#region MyRegion
|
|
private ObservableCollection<int> _id = new ObservableCollection<int>();
|
|
public ObservableCollection<int> Id
|
|
{
|
|
get => _id;
|
|
set => SetProperty(ref _id, value);
|
|
}
|
|
private ObservableCollection<string> _materialCode = new ObservableCollection<string>();
|
|
public ObservableCollection<string> MaterialCode
|
|
{
|
|
get => _materialCode;
|
|
set => SetProperty(ref _materialCode, value);
|
|
}
|
|
private ObservableCollection<string> _materialName = new ObservableCollection<string>();
|
|
public ObservableCollection<string> MaterialName
|
|
{
|
|
get => _materialName;
|
|
set => SetProperty(ref _materialName, value);
|
|
}
|
|
private ObservableCollection<int> _planAmount = new ObservableCollection<int>();
|
|
public ObservableCollection<int> PlanAmount
|
|
{
|
|
get => _planAmount;
|
|
set => SetProperty(ref _planAmount, value);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|