终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

82 satır
3.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using BPA.Helper;
  9. namespace BPASmartClient.SmallBatchingSystem.ViewModels
  10. {
  11. public class NewSiloViewModel : BaseModel
  12. {
  13. public NewSiloViewModel()
  14. {
  15. CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SiloClose"); });
  16. SaveCommand = new RelayCommand(() =>
  17. {
  18. if (Index >= 0 && Index < Json<ConfigInfoModel>.Data.SiloInfoModels.Count)
  19. {
  20. var array = Json<ConfigInfoModel>.Data.SiloInfoModels.ToArray();
  21. var res = Array.FindIndex(array, p => p.SiloName == SiloInfoModelObj.SiloName);
  22. if (res >= 0 && res != Index)
  23. {
  24. ErrorInfo = "料仓名称已经存在!";
  25. return;
  26. }
  27. var temp = Array.FindIndex(array, p => p.SiloLoc == SiloInfoModelObj.SiloLoc);
  28. if (temp >= 0 && temp != Index)
  29. {
  30. ErrorInfo = "料仓位置已存在!";
  31. return;
  32. }
  33. Json<ConfigInfoModel>.Data.SiloInfoModels.ElementAt(Index).SiloName = SiloInfoModelObj.SiloName;
  34. Json<ConfigInfoModel>.Data.SiloInfoModels.ElementAt(Index).SiloLoc = SiloInfoModelObj.SiloLoc;
  35. Control.GetInstance.OperationLog($"{SiloInfoModelObj.SiloName} 编辑完成");
  36. }
  37. else
  38. {
  39. var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == SiloInfoModelObj.SiloName);
  40. if (res != null)
  41. {
  42. ErrorInfo = "料仓名称已经存在!";
  43. return;
  44. }
  45. var temp = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == SiloInfoModelObj.SiloLoc);
  46. if (temp != null)
  47. {
  48. ErrorInfo = "料仓位置已存在!";
  49. return;
  50. }
  51. Json<ConfigInfoModel>.Data.SiloInfoModels.Add(new SiloInfoModel()
  52. {
  53. SiloLoc = SiloInfoModelObj.SiloLoc,
  54. SiloName = SiloInfoModelObj.SiloName,
  55. });
  56. Control.GetInstance.OperationLog($"{SiloInfoModelObj.SiloName} 添加成功");
  57. }
  58. ActionManage.GetInstance.Send("SiloClose");
  59. });
  60. ActionManage.GetInstance.Register(new Action<object>((o) =>
  61. {
  62. if (o != null && o is SiloInfoModel tempSilo)
  63. {
  64. SiloInfoModelObj.SiloLoc = tempSilo.SiloLoc;
  65. SiloInfoModelObj.SiloName = tempSilo.SiloName;
  66. Index = Array.FindIndex(Json<ConfigInfoModel>.Data.SiloInfoModels.ToArray(), p => p.SiloName == tempSilo.SiloName);
  67. }
  68. }), "OpenNewSilo", true);
  69. }
  70. public SiloInfoModel SiloInfoModelObj { get { return _mSiloInfoModelObj; } set { _mSiloInfoModelObj = value; OnPropertyChanged(); } }
  71. private SiloInfoModel _mSiloInfoModelObj = new SiloInfoModel();
  72. }
  73. }