using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using Aucma.Core.SheetMetal.Models; using Aucma.Core.SheetMetal.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; 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; public BomMaintenancePageViewModel() { _smSyncModelServices = App.ServiceProvider.GetService(); _smSyncModelSubServices = App.ServiceProvider.GetService(); CorrespondingModelPageViewModel.RefreshSetBomDataGridEvent += RefreshSetBom; //SmSyncModel model=new SmSyncModel(); //model.ObjId = 1; //model.SmProductId = "1"; //model.SmModel = "BC/BD-310NF"; //SmSyncModelDataGrid.Add(model); OnLoadData(); } public void OnLoadData() { var list = _smSyncModelServices.QueryAsync().Result; if (list == null || list.Count() == 0) return; foreach (var item in list) { SmSyncModelDataGrid.Add(item); } var obj=list.First(); var smSyncModelSubList = _smSyncModelSubServices.QueryAsync(d=>d.SmProductId== obj.SmProductId).Result; if (smSyncModelSubList == null || smSyncModelSubList.Count == 0) return; int i = 1; foreach (var item in smSyncModelSubList) { item.ObjId = i; smSyncModelDateilDataGrid.Add(item); i++; } } public void RefreshSetBom(string smProductId) { var smSyncModelSubList = _smSyncModelSubServices.QueryAsync(d => d.SmProductId == smProductId).Result; if (smSyncModelSubList == null || smSyncModelSubList.Count == 0) return; int i = 1; foreach (var item in smSyncModelSubList) { item.ObjId = i; smSyncModelDateilDataGrid.Add(item); i++; } } #region 查询按钮 /// /// 查询按钮 /// /// [RelayCommand] public async Task QueryModel(string param) { var list=await _smSyncModelServices.QueryAsync(d=>d.SmModel.Contains(param)); foreach (var item in list) { SmSyncModelDataGrid.Add(item); } } #endregion #region 查询按钮 /// /// 查询按钮 /// /// [RelayCommand] public async Task DeleteBom(object obj) { int id = (int)obj; var result = await _smSyncModelServices.DeleteByIdAsync(id); if (result) { MessageBox.Show("删除成功!", "系统提醒", MessageBoxButton.OK); } } #endregion #region 同步钣金型号按钮 /// /// 同步钣金型号按钮 /// /// [RelayCommand] public Task SyncModel() { //获取PLC设置好的点位 一共四个上料分垛 return Task.FromResult(0); } #endregion #region 设置钣金型号对应关系 /// /// 设置钣金型号对应关系 /// /// [RelayCommand] public Task SetProduct(string id) { //获取PLC设置好的点位 一共四个上料分垛 CorrespondingModelPageView view = new CorrespondingModelPageView(id); view.ShowDialog(); return Task.FromResult(0); } #endregion #region 初始化datagrid private ObservableCollection smSyncModelDataGrid = new ObservableCollection(); public ObservableCollection SmSyncModelDataGrid { get { return smSyncModelDataGrid; } set { smSyncModelDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 初始化datagrid private ObservableCollection smSyncModelDateilDataGrid = new ObservableCollection(); public ObservableCollection SmSyncModelDateilDataGrid { get { return smSyncModelDateilDataGrid; } set { smSyncModelDateilDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion } }