VmMaintainerEditor.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. 
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //文件名称: VmMaintainerEditor.cs
  4. //文件描述: 维修商编辑
  5. //创 建 者: xls
  6. //创建日期: 2018/5/24 22:03:44
  7. //版 本 号:1.0.0.0
  8. ////////////////////////////////////////////////////////////////////////////////
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using Com.FirmLib.Bll;
  16. using Com.FirmLib.Entity;
  17. using FWindSoft.DataFramework;
  18. using FWindSoft.MVVM;
  19. using FWindSoft.Wpf;
  20. namespace Com.FirmLib.UI.Maintainer
  21. {
  22. public class VmMaintainerEditor : BaseViewModel
  23. {
  24. public VmMaintainerEditor()
  25. {
  26. Init();
  27. }
  28. private void Init()
  29. {
  30. }
  31. #region 属性相关
  32. /// <summary>
  33. /// 是否管理
  34. /// </summary>
  35. public bool IsManage { get; set; }
  36. /// <summary>
  37. /// 新维修商Id
  38. /// </summary>
  39. public string Id { get; set; }
  40. private string m_Name;
  41. /// <summary>
  42. /// 维修商名称
  43. /// </summary>
  44. public string Name
  45. {
  46. get { return this.m_Name; }
  47. set
  48. {
  49. this.m_Name = value;
  50. RaisePropertyChanged(() => this.Name);
  51. }
  52. }
  53. private string m_Url;
  54. /// <summary>
  55. /// 维修商Url
  56. /// </summary>
  57. public string Url
  58. {
  59. get { return this.m_Url; }
  60. set
  61. {
  62. this.m_Url = value;
  63. RaisePropertyChanged(() => this.Url);
  64. }
  65. }
  66. #endregion
  67. #region 命令相关
  68. /// <summary>
  69. /// 添加工厂完场
  70. /// </summary>
  71. /// <param name="parameter"></param>
  72. [Command]
  73. public void AddCommand(object parameter)
  74. {
  75. try
  76. {
  77. if (!CreateMaintainer())
  78. return;
  79. Window window = parameter as Window;
  80. if (window != null)
  81. window.DialogResult = true;
  82. }
  83. catch (Exception ex)
  84. {
  85. MessageTipEx.Show(ex);
  86. }
  87. }
  88. public bool CanAddCommand(object parameter)
  89. {
  90. return IsValidated;
  91. }
  92. /// <summary>
  93. /// 添加并管理供应商
  94. /// </summary>
  95. /// <param name="parameter"></param>
  96. [Command]
  97. public void AddAndManageCommand(object parameter)
  98. {
  99. try
  100. {
  101. if (!CreateMaintainer())
  102. return;
  103. IsManage = true;
  104. Window window = parameter as Window;
  105. if (window != null)
  106. window.DialogResult = true;
  107. }
  108. catch (Exception ex)
  109. {
  110. MessageTipEx.Show(ex);
  111. }
  112. }
  113. public bool CanAddAndManageCommand(object parameter)
  114. {
  115. return IsValidated;
  116. }
  117. #endregion
  118. /// <summary>
  119. /// 创建供应商
  120. /// </summary>
  121. /// <returns></returns>
  122. private bool CreateMaintainer()
  123. {
  124. MaintainerItem item = new MaintainerItem();
  125. item.Name = this.Name??string.Empty;
  126. item.Website = Url ?? string.Empty;
  127. var result = BllFactory<MaintainerBll>.Instance.Add(item);
  128. if (result)
  129. {
  130. Id = item.Id;
  131. }
  132. else
  133. {
  134. MessageTip.Show(this.GetWindow(), BllFactory<MaintainerBll>.Instance.ErrorMessage ?? string.Empty);
  135. }
  136. return result;
  137. }
  138. }
  139. }