DtBaseQcm.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using Core.Mes.Client.Comm.Tool;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Reflection;
  7. using System.Windows.Forms;
  8. //Create By Cx 2015年1月9日 18:35:02
  9. namespace Core.StlMes.Client.Qcm
  10. {
  11. public abstract class DtBaseQcm
  12. {
  13. protected delegate bool ActionDelegate();
  14. protected delegate void QueryDelegate();
  15. private Dictionary<ActionType, ActionDelegate> _dicAction = new Dictionary<ActionType, ActionDelegate>();
  16. private Dictionary<string, QueryDelegate> _dicQuery = new Dictionary<string, QueryDelegate>();
  17. //private ArrayList[] _parms;
  18. //public ArrayList[] Parms
  19. //{
  20. // get { return _parms; }
  21. // set { _parms = value; }
  22. //}
  23. private ArrayList _parm;
  24. public ArrayList Parm
  25. {
  26. get { return _parm; }
  27. set { _parm = value; }
  28. }
  29. private string _defaultQueryKey = "DefaultQuery";
  30. public string DefaultQueryKey
  31. {
  32. get { return _defaultQueryKey; }
  33. set { _defaultQueryKey = value; }
  34. }
  35. private string _msg;
  36. public DtBaseQcm()
  37. {
  38. //RegistQuery(Query, "DefaultQuery");
  39. //RegistAction(Add, ActionType.Add);
  40. //RegistAction(Modify, ActionType.Modify);
  41. //RegistAction(Save, ActionType.Save);
  42. //RegistAction(Delete, ActionType.Delete);
  43. //RegistAction(Resume, ActionType.Resume);
  44. //RegistAction(SubMitAudit, ActionType.SubMitAudit);
  45. //RegistAction(Audit, ActionType.Audit);
  46. //RegistAction(Group, ActionType.Group);
  47. ExceptionHelper.RegistException();
  48. }
  49. /// <summary>
  50. /// 注册非查询
  51. /// </summary>
  52. /// <param name="action">非查询方法</param>
  53. /// <param name="actionType">操作类型</param>
  54. protected void RegistAction(ActionDelegate action, ActionType actionType)
  55. {
  56. _dicAction.Add(actionType, action);
  57. }
  58. /// <summary>
  59. /// 注册查询
  60. /// </summary>
  61. /// <param name="query">查询方法</param>
  62. /// <param name="strKey">查询Key</param>
  63. protected void RegistQuery(QueryDelegate query, string strKey)
  64. {
  65. _dicQuery.Add(strKey, query);
  66. }
  67. /// <summary>
  68. /// 根据操作类型执行对应的非查询
  69. /// </summary>
  70. /// <param name="actionType">操作类型</param>
  71. /// <returns></returns>
  72. public bool DoAction(ActionType actionType)
  73. {
  74. bool result = false;
  75. if (IsSelectData(actionType, out _msg) == false)
  76. {
  77. if (string.IsNullOrEmpty(_msg) == true)
  78. {
  79. MessageUtil.ShowWarning("请选择一条记录后再进行操作!");
  80. }
  81. else
  82. {
  83. MessageUtil.ShowWarning(_msg);
  84. }
  85. return false;
  86. }
  87. if (CheckData(actionType, out _parm, out _msg) == false)
  88. {
  89. if (string.IsNullOrEmpty(_msg) == false)
  90. {
  91. MessageUtil.ShowWarning(_msg);
  92. }
  93. return false;
  94. }
  95. DialogResult msgResult = MessageUtil.ShowYesNoAndQuestion(GetSubmitMsg(actionType));
  96. if (msgResult == DialogResult.Yes)
  97. {
  98. result = _dicAction[actionType].Invoke();
  99. }
  100. if (result == true)
  101. {
  102. MessageUtil.ShowTips(GetSuccessMsg(actionType));
  103. DoQuery(_defaultQueryKey);
  104. }
  105. return result;
  106. }
  107. /// <summary>
  108. /// 根据Key值执行对应查询方法。
  109. /// </summary>
  110. /// <param name="strKey">注册查询时的Key值</param>
  111. public void DoQuery(string strKey)
  112. {
  113. _dicQuery[strKey].Invoke();
  114. }
  115. ///// <summary>
  116. ///// 查询
  117. ///// </summary>
  118. //protected abstract void Query();
  119. ///// <summary>
  120. ///// 新增
  121. ///// </summary>
  122. ///// <returns></returns>
  123. //protected abstract bool Add();
  124. ///// <summary>
  125. ///// 修改
  126. ///// </summary>
  127. ///// <returns></returns>
  128. //protected abstract bool Modify();
  129. ///// <summary>
  130. ///// 保存
  131. ///// </summary>
  132. ///// <returns></returns>
  133. //protected abstract bool Save();
  134. ///// <summary>
  135. ///// 作废
  136. ///// </summary>
  137. ///// <returns></returns>
  138. //protected abstract bool Delete();
  139. ///// <summary>
  140. ///// 恢复
  141. ///// </summary>
  142. ///// <returns></returns>
  143. //protected abstract bool Resume();
  144. ///// <summary>
  145. ///// 提交审核
  146. ///// </summary>
  147. ///// <returns></returns>
  148. //protected abstract bool SubMitAudit();
  149. ///// <summary>
  150. ///// 审核
  151. ///// </summary>
  152. ///// <returns></returns>
  153. //protected abstract bool Audit();
  154. ///// <summary>
  155. ///// 分组
  156. ///// </summary>
  157. ///// <returns></returns>
  158. //protected abstract bool Group();
  159. /// <summary>
  160. /// 检验数据
  161. /// </summary>
  162. /// <returns></returns>
  163. protected abstract bool CheckData(ActionType actionType, out ArrayList parm, out string msg);
  164. ///// <summary>
  165. ///// 获取参数
  166. ///// </summary>
  167. ///// <param name="actionType"></param>
  168. ///// <returns></returns>
  169. //protected abstract ArrayList[] GetParms(ActionType actionType);
  170. /// <summary>
  171. /// 是否有选择记录
  172. /// </summary>
  173. /// <returns></returns>
  174. protected abstract bool IsSelectData(ActionType actionType, out string msg);
  175. private string GetSubmitMsg(ActionType actionType)
  176. {
  177. Type type = typeof(ActionType);
  178. FieldInfo fieldInfo = type.GetField(Enum.GetName(type, actionType));
  179. object[] objs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
  180. if (objs.Length > 0)
  181. {
  182. DescriptionAttribute descAttribute = (DescriptionAttribute)objs[0];
  183. return "是否" + descAttribute.Description + "数据?";
  184. }
  185. return "";
  186. }
  187. private string GetSuccessMsg(ActionType actionType)
  188. {
  189. Type type = typeof(ActionType);
  190. FieldInfo fieldInfo = type.GetField(Enum.GetName(type, actionType));
  191. object[] objs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
  192. if (objs.Length > 0)
  193. {
  194. DescriptionAttribute descAttribute = (DescriptionAttribute)objs[0];
  195. return descAttribute.Description + "成功!";
  196. }
  197. return "";
  198. }
  199. }
  200. }