ModifyWmsViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using DbCommon.Enties.DbModels;
  2. using Mapster;
  3. using MaterialDesignThemes.Wpf;
  4. using Prism.Commands;
  5. using Prism.Services.Dialogs;
  6. using ProjectManagementSystem.Common.Extenions;
  7. using ProjectManagementSystem.Common.Service;
  8. using ProjectManagementSystemView.Infrastructure;
  9. using ProjectManagementSystemView.Infrastructure.Models;
  10. using PropertyChanged;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace ProjectManagementSystemView.ViewModels.Dialogs
  18. {
  19. [AddINotifyPropertyChangedInterface]
  20. public class ModifyWmsViewModel : IDialogHostAware
  21. {
  22. public ObservableCollection<object> StatusCollection { get; set; }
  23. public ObservableCollection<string> MaterialIdCollection { get; set; }
  24. public VmLocationProperty Model { get; set; }
  25. public string DialogHostName { get; set; }
  26. public DelegateCommand SaveCommand { get; set; }
  27. public DelegateCommand CancelCommand { get; set; }
  28. public ModifyWmsViewModel()
  29. {
  30. Model = new VmLocationProperty();
  31. StatusCollection = new ObservableCollection<object>();
  32. MaterialIdCollection = new ObservableCollection<string>();
  33. StatusCollection.Add(new { Value = LocationStatus.None, Display = LocationStatus.None.ToStatusString() });
  34. StatusCollection.Add(new { Value = LocationStatus.Filled, Display = LocationStatus.Filled.ToStatusString() });
  35. StatusCollection.Add(new { Value = LocationStatus.Empty, Display = LocationStatus.Empty.ToStatusString() });
  36. if (Crms.PmsTaskService is PmsTaskServiceSWms)
  37. {
  38. var goodsList = Crms.SWmsApi.GetAllGoods();
  39. if (goodsList != null)
  40. {
  41. goodsList.ForEach(d => MaterialIdCollection.Add(d.goodsCode));
  42. }
  43. }
  44. else
  45. {
  46. MaterialIdCollection.Add("默认货物");
  47. MaterialIdCollection.Add("空料车");
  48. MaterialIdCollection.Add("满料车");
  49. }
  50. MaterialIdCollection.Add("");
  51. SaveCommand = new DelegateCommand(Save);
  52. CancelCommand = new DelegateCommand(Cancel);
  53. }
  54. /// <summary>
  55. /// 取消
  56. /// </summary>
  57. private void Cancel()
  58. {
  59. if (DialogHost.IsDialogOpen(DialogHostName))
  60. DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No)); //取消返回NO告诉操作结束
  61. }
  62. /// <summary>
  63. /// 确定
  64. /// </summary>
  65. private void Save()
  66. {
  67. if (DialogHost.IsDialogOpen(DialogHostName))
  68. {
  69. //确定时,把编辑的实体返回并且返回OK
  70. DialogParameters param = new DialogParameters();
  71. param.Add("Value", Model);
  72. DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param));
  73. }
  74. }
  75. public void OnDialogOpend(IDialogParameters parameters)
  76. {
  77. if (parameters.ContainsKey("Value"))
  78. {
  79. var data = parameters.GetValue<VmLocationProperty>("Value");
  80. data?.Adapt(Model);
  81. }
  82. }
  83. }
  84. }