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.
AUCMA_SCADA/Aucma.Core.SheetMetal/ViewModels/BomMaintenancePageViewModel.cs

186 lines
5.7 KiB
C#

1 year ago
using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Service;
12 months ago
using Aucma.Core.SheetMetal.Business;
1 year ago
using Aucma.Core.SheetMetal.Models;
using Aucma.Core.SheetMetal.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
12 months ago
using System;
1 year ago
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class BomMaintenancePageViewModel : ObservableObject
{
private readonly ISmSyncModelServices _smSyncModelServices;
private readonly ISmSyncModelSubServices _smSyncModelSubServices;
12 months ago
SyncModelHandle handle = new SyncModelHandle();
1 year ago
public BomMaintenancePageViewModel()
{
_smSyncModelServices = App.ServiceProvider.GetService<ISmSyncModelServices>();
_smSyncModelSubServices = App.ServiceProvider.GetService<ISmSyncModelSubServices>();
12 months ago
CorrespondingModelPageViewModel.RefreshSetBomDataGridEvent += Refresh;
1 year ago
OnLoadData();
}
12 months ago
#region 刷新
[RelayCommand]
public void Refresh()
{
OnLoadData();
}
#endregion
#region 初始化加载
1 year ago
public void OnLoadData()
{
12 months ago
SmSyncModelSideDataGrid.Clear();
var list = _smSyncModelServices.QueryAsync().Result;
1 year ago
if (list == null || list.Count() == 0) return;
12 months ago
var sideList= list.OrderBy(d => d.ObjId);
foreach (var item in sideList.Where(d=>d.Category=="0"))
1 year ago
{
12 months ago
SmSyncModelSideDataGrid.Add(item);
1 year ago
}
12 months ago
SmSyncModelBackDataGrid.Clear();
var backList = list.OrderBy(d => d.ObjId);
foreach (var item in backList.Where(d => d.Category == "1"))
1 year ago
{
12 months ago
SmSyncModelBackDataGrid.Add(item);
1 year ago
}
}
12 months ago
#endregion
1 year ago
#region 查询按钮
/// <summary>
/// 查询按钮
/// </summary>
/// <returns></returns>
[RelayCommand]
public async Task QueryModel(string param)
{
var list=await _smSyncModelServices.QueryAsync(d=>d.SmModel.Contains(param));
foreach (var item in list)
{
12 months ago
SmSyncModelSideDataGrid.Add(item);
1 year ago
}
}
#endregion
12 months ago
#region 删除按钮
1 year ago
/// <summary>
12 months ago
/// 删除按钮
1 year ago
/// </summary>
/// <returns></returns>
[RelayCommand]
public async Task DeleteBom(object obj)
{
int id = (int)obj;
12 months ago
var smSyncModelSub = await _smSyncModelSubServices.FirstAsync(d=>d.ObjId==id);
var result = await _smSyncModelSubServices.DeleteByIdAsync(id);
1 year ago
if (result)
{
MessageBox.Show("删除成功!", "系统提醒", MessageBoxButton.OK);
12 months ago
RefreshSetBom(smSyncModelSub.SmProductId);
1 year ago
}
}
#endregion
#region 同步钣金型号按钮
/// <summary>
/// 同步钣金型号按钮
/// </summary>
/// <returns></returns>
[RelayCommand]
12 months ago
public async Task SyncSideModel()
1 year ago
{
12 months ago
Console.WriteLine("手动同步前板型号开始!");
await handle.QuerySidePanelMode();
OnLoadData();
MessageBox.Show("手动同步前板型号结束!");
Console.WriteLine("手动同步前板型号结束!");
}
/// <summary>
/// 同步钣金型号按钮
/// </summary>
/// <returns></returns>
[RelayCommand]
public async Task SyncBackModel()
{
Console.WriteLine("手动同步后板型号开始!");
await handle.QueryBackPanelMode();
OnLoadData();
MessageBox.Show("手动同步后板型号结束!");
Console.WriteLine("手动同步后板型号结束!");
1 year ago
}
#endregion
#region 设置钣金型号对应关系
/// <summary>
/// 设置钣金型号对应关系
/// </summary>
/// <returns></returns>
[RelayCommand]
12 months ago
public Task SetProduct(object obj)
1 year ago
{
12 months ago
string id =Convert.ToInt32(obj).ToString();
1 year ago
//获取PLC设置好的点位 一共四个上料分垛
CorrespondingModelPageView view = new CorrespondingModelPageView(id);
view.ShowDialog();
return Task.FromResult(0);
}
#endregion
#region 初始化datagrid
12 months ago
private ObservableCollection<SmSyncModel> smSyncModelSideDataGrid = new ObservableCollection<SmSyncModel>();
public ObservableCollection<SmSyncModel> SmSyncModelSideDataGrid
1 year ago
{
12 months ago
get { return smSyncModelSideDataGrid; }
1 year ago
set
{
12 months ago
smSyncModelSideDataGrid = value;
1 year ago
OnPropertyChanged();//属性通知
}
}
#endregion
#region 初始化datagrid
12 months ago
private ObservableCollection<SmSyncModel> smSyncModelBackDataGrid = new ObservableCollection<SmSyncModel>();
public ObservableCollection<SmSyncModel> SmSyncModelBackDataGrid
1 year ago
{
12 months ago
get { return smSyncModelBackDataGrid; }
1 year ago
set
{
12 months ago
smSyncModelBackDataGrid = value;
1 year ago
OnPropertyChanged();//属性通知
}
}
#endregion
12 months ago
#region 刷新子控件
public void SelectRow(SmSyncModel sub)
{
RefreshSetBom(sub.SmProductId);
}
public void RefreshSetBom(string smProductId)
{
}
#endregion
1 year ago
}
}