VmManufacturerEditor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. 
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //文件名称: VmManufacturerEditor.cs
  4. //文件描述: 生产厂商编辑
  5. //创 建 者: xls
  6. //创建日期: 2018/5/27 10:52:53
  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.Manufacturer
  21. {
  22. public class VmManufacturerEditor : BaseViewModel
  23. {
  24. public VmManufacturerEditor()
  25. {
  26. Init();
  27. }
  28. private void Init()
  29. {
  30. }
  31. public void Init(LoadParameter parameter)
  32. {
  33. //todo 根据参数加载项目信息
  34. }
  35. #region 属性相关
  36. private string m_Name;
  37. /// <summary>
  38. /// 厂商名称
  39. /// </summary>
  40. public string Name
  41. {
  42. get { return this.m_Name; }
  43. set
  44. {
  45. this.m_Name = value;
  46. RaisePropertyChanged(() => this.Name);
  47. }
  48. }
  49. #endregion
  50. /// <summary>
  51. /// 关联Id新厂商Id
  52. /// </summary>
  53. public string Id { get;private set; }
  54. /// <summary>
  55. /// 管理厂商库
  56. /// </summary>
  57. public bool ManagerManufacturer { get; private set; }
  58. #region 命令相关
  59. /// <summary>
  60. /// 添加工厂
  61. /// </summary>
  62. /// <param name="parameter"></param>
  63. [Command]
  64. public void AddCommand(object parameter)
  65. {
  66. try
  67. {
  68. if (!CreateManufacturer())
  69. return;
  70. ManagerManufacturer = false;
  71. Window window = parameter as Window;
  72. if (window != null)
  73. window.DialogResult = true;
  74. }
  75. catch (Exception ex)
  76. {
  77. MessageTipEx.Show(ex);
  78. }
  79. }
  80. public bool CanAddCommand(object parameter)
  81. {
  82. return IsValidated;
  83. }
  84. /// <summary>
  85. /// 添加并管理工厂
  86. /// </summary>
  87. /// <param name="parameter"></param>
  88. [Command]
  89. public void AddAndManage(object parameter)
  90. {
  91. try
  92. {
  93. if (!CreateManufacturer())
  94. return;
  95. ManagerManufacturer = true;
  96. Window window = parameter as Window;
  97. if (window != null)
  98. window.DialogResult = true;
  99. }
  100. catch (Exception ex)
  101. {
  102. MessageTipEx.Show(ex);
  103. }
  104. }
  105. public bool CanAddAndManage(object parameter)
  106. {
  107. return IsValidated;
  108. }
  109. #endregion
  110. /// <summary>
  111. /// 创建厂商库,返回是否成功创建
  112. /// </summary>
  113. /// <returns></returns>
  114. private bool CreateManufacturer()
  115. {
  116. ManufacturerItem item = new ManufacturerItem();
  117. item.Name = this.Name;
  118. var result = BllFactory<ManufacturerBll>.Instance.Add(item);
  119. if (result)
  120. {
  121. Id = item.Id;
  122. }
  123. else
  124. {
  125. MessageTip.Show(this.GetWindow(), BllFactory<ManufacturerBll>.Instance.ErrorMessage ?? string.Empty);
  126. }
  127. return result;
  128. }
  129. }
  130. }