using DbCommon.Enties.DbModels; using Mapster; using MaterialDesignThemes.Wpf; using Prism.Commands; using Prism.Services.Dialogs; using ProjectManagementSystem.Common.Extenions; using ProjectManagementSystem.Common.Service; using ProjectManagementSystemView.Infrastructure; using ProjectManagementSystemView.Infrastructure.Models; using PropertyChanged; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProjectManagementSystemView.ViewModels.Dialogs { [AddINotifyPropertyChangedInterface] public class ModifyWmsViewModel : IDialogHostAware { public ObservableCollection StatusCollection { get; set; } public ObservableCollection MaterialIdCollection { get; set; } public VmLocationProperty Model { get; set; } public string DialogHostName { get; set; } public DelegateCommand SaveCommand { get; set; } public DelegateCommand CancelCommand { get; set; } public ModifyWmsViewModel() { Model = new VmLocationProperty(); StatusCollection = new ObservableCollection(); MaterialIdCollection = new ObservableCollection(); StatusCollection.Add(new { Value = LocationStatus.None, Display = LocationStatus.None.ToStatusString() }); StatusCollection.Add(new { Value = LocationStatus.Filled, Display = LocationStatus.Filled.ToStatusString() }); StatusCollection.Add(new { Value = LocationStatus.Empty, Display = LocationStatus.Empty.ToStatusString() }); if (Crms.PmsTaskService is PmsTaskServiceSWms) { var goodsList = Crms.SWmsApi.GetAllGoods(); if (goodsList != null) { goodsList.ForEach(d => MaterialIdCollection.Add(d.goodsCode)); } } else { MaterialIdCollection.Add("默认货物"); MaterialIdCollection.Add("空料车"); MaterialIdCollection.Add("满料车"); } MaterialIdCollection.Add(""); SaveCommand = new DelegateCommand(Save); CancelCommand = new DelegateCommand(Cancel); } /// /// 取消 /// private void Cancel() { if (DialogHost.IsDialogOpen(DialogHostName)) DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No)); //取消返回NO告诉操作结束 } /// /// 确定 /// private void Save() { if (DialogHost.IsDialogOpen(DialogHostName)) { //确定时,把编辑的实体返回并且返回OK DialogParameters param = new DialogParameters(); param.Add("Value", Model); DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param)); } } public void OnDialogOpend(IDialogParameters parameters) { if (parameters.ContainsKey("Value")) { var data = parameters.GetValue("Value"); data?.Adapt(Model); } } } }