终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

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