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.

132 lines
4.7 KiB
C#

1 year ago
using Admin.Core.IService;
1 year ago
using Admin.Core.Model.Model_New;
using Admin.Core.Service;
1 year ago
using Aucma.Core.OldBoxFoam.Business;
1 year ago
using Aucma.Core.OldBoxFoam.Models;
1 year ago
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.Tasks;
1 year ago
using System.Timers;
1 year ago
using System.Windows;
namespace Aucma.Core.OldBoxFoam.ViewModels
{
/**
*
*
* */
public partial class RealRoadPageViewModel : ObservableObject
{
protected readonly IBoxFoamPlanServices? _boxFoamPlanServices;
1 year ago
private IOldBoxFoamTypeServices? _oldBoxFoamTypeServices;
1 year ago
System.Timers.Timer timer2 = new System.Timers.Timer(3000);
1 year ago
public RealRoadPageViewModel()
{
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
1 year ago
_oldBoxFoamTypeServices = App.ServiceProvider.GetService<IOldBoxFoamTypeServices>();
1 year ago
//InitData();
1 year ago
Collection.RefreshSpaceEvent += InitData;
1 year ago
timer2.Elapsed += new System.Timers.ElapsedEventHandler(InitData); //到达时间的时候执行事件;
timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
1 year ago
}
1 year ago
public async void InitData(object? sender, ElapsedEventArgs e)
1 year ago
{
1 year ago
List<OldBoxFoamType> list = await _oldBoxFoamTypeServices.QueryAsync();
1 year ago
if (list == null) return;
1 year ago
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
1 year ago
{
1 year ago
ListItems.Clear();
1 year ago
foreach (OldBoxFoamType item in list)
1 year ago
{
1 year ago
ListItems.Add(new OldBoxFoamTypeModel()
{
ObjId = item.ObjId,
Local = item.Local,
1 year ago
Status = item.Storeamount==3?"1":"0",
1 year ago
Storeamount = item.Storeamount,
MaterialCode = item.MaterialCode,
MaterialName = item.MaterialName,
Boxtype = item.Boxtype,
}); ;
}
}));
1 year ago
}
1 year ago
#region 初始化datagrid
private ObservableCollection<OldBoxFoamTypeModel> listItems = new ObservableCollection<OldBoxFoamTypeModel>();
public ObservableCollection<OldBoxFoamTypeModel> ListItems
1 year ago
{
1 year ago
get { return listItems; }
set
{
listItems = value;
OnPropertyChanged();//属性通知
}
1 year ago
}
#endregion
#region 型号统计柱状图X轴日期
/// <summary>
/// 型号统计柱状图X轴日期
/// </summary>
private List<string> materialNameList;
public List<string> MaterialNameList
{
get { return materialNameList; }
set { materialNameList = value; }
}
#endregion
1 year ago
public void InitData(List<SpaceDetailModel> spaceDetailModel)
1 year ago
{
if (spaceDetailModel == null) return;
//List<OldBoxFoamType> list = new List<OldBoxFoamType>();
//var stroreList= await _oldBoxFoamTypeServices.QueryAsync();
//foreach (OldBoxFoamType model in stroreList)
//{
// foreach (var item in spaceDetailModel)
// {
// if (model.ObjId==item.ObjId)
// {
// model.Storeamount = item.StoreAmount;
// model.Boxtype = item.StoreType;
// list.Add(model);
// }
// }
//}
//await _oldBoxFoamTypeServices.UpdateAsync(list);
foreach(var item in spaceDetailModel)
1 year ago
{
var spaceList = _oldBoxFoamTypeServices.Query(x=>x.ObjId == item.ObjId);
if(spaceList != null)
1 year ago
{
if(spaceDetailModel.Count > 0)
1 year ago
{
var spaceInfo = spaceList.FirstOrDefault();
spaceInfo.Storeamount = item.StoreAmount;
spaceInfo.Boxtype = item.StoreType;
_oldBoxFoamTypeServices.UpdateAsync(spaceInfo);
1 year ago
}
}
}
}
1 year ago
}
}