| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using Core.Mes.Client.Comm.Tool;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Reflection;
- using System.Windows.Forms;
- //Create By Cx 2015年1月9日 18:35:02
- namespace Core.StlMes.Client.Qcm
- {
- public abstract class DtBaseQcm
- {
- protected delegate bool ActionDelegate();
- protected delegate void QueryDelegate();
- private Dictionary<ActionType, ActionDelegate> _dicAction = new Dictionary<ActionType, ActionDelegate>();
- private Dictionary<string, QueryDelegate> _dicQuery = new Dictionary<string, QueryDelegate>();
- //private ArrayList[] _parms;
- //public ArrayList[] Parms
- //{
- // get { return _parms; }
- // set { _parms = value; }
- //}
- private ArrayList _parm;
- public ArrayList Parm
- {
- get { return _parm; }
- set { _parm = value; }
- }
- private string _defaultQueryKey = "DefaultQuery";
- public string DefaultQueryKey
- {
- get { return _defaultQueryKey; }
- set { _defaultQueryKey = value; }
- }
- private string _msg;
- public DtBaseQcm()
- {
- //RegistQuery(Query, "DefaultQuery");
- //RegistAction(Add, ActionType.Add);
- //RegistAction(Modify, ActionType.Modify);
- //RegistAction(Save, ActionType.Save);
- //RegistAction(Delete, ActionType.Delete);
- //RegistAction(Resume, ActionType.Resume);
- //RegistAction(SubMitAudit, ActionType.SubMitAudit);
- //RegistAction(Audit, ActionType.Audit);
- //RegistAction(Group, ActionType.Group);
- ExceptionHelper.RegistException();
- }
- /// <summary>
- /// 注册非查询
- /// </summary>
- /// <param name="action">非查询方法</param>
- /// <param name="actionType">操作类型</param>
- protected void RegistAction(ActionDelegate action, ActionType actionType)
- {
- _dicAction.Add(actionType, action);
- }
- /// <summary>
- /// 注册查询
- /// </summary>
- /// <param name="query">查询方法</param>
- /// <param name="strKey">查询Key</param>
- protected void RegistQuery(QueryDelegate query, string strKey)
- {
- _dicQuery.Add(strKey, query);
- }
- /// <summary>
- /// 根据操作类型执行对应的非查询
- /// </summary>
- /// <param name="actionType">操作类型</param>
- /// <returns></returns>
- public bool DoAction(ActionType actionType)
- {
- bool result = false;
- if (IsSelectData(actionType, out _msg) == false)
- {
- if (string.IsNullOrEmpty(_msg) == true)
- {
- MessageUtil.ShowWarning("请选择一条记录后再进行操作!");
- }
- else
- {
- MessageUtil.ShowWarning(_msg);
- }
- return false;
- }
- if (CheckData(actionType, out _parm, out _msg) == false)
- {
- if (string.IsNullOrEmpty(_msg) == false)
- {
- MessageUtil.ShowWarning(_msg);
- }
- return false;
- }
- DialogResult msgResult = MessageUtil.ShowYesNoAndQuestion(GetSubmitMsg(actionType));
- if (msgResult == DialogResult.Yes)
- {
- result = _dicAction[actionType].Invoke();
- }
- if (result == true)
- {
- MessageUtil.ShowTips(GetSuccessMsg(actionType));
- DoQuery(_defaultQueryKey);
- }
- return result;
- }
- /// <summary>
- /// 根据Key值执行对应查询方法。
- /// </summary>
- /// <param name="strKey">注册查询时的Key值</param>
- public void DoQuery(string strKey)
- {
- _dicQuery[strKey].Invoke();
- }
- ///// <summary>
- ///// 查询
- ///// </summary>
- //protected abstract void Query();
- ///// <summary>
- ///// 新增
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Add();
- ///// <summary>
- ///// 修改
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Modify();
- ///// <summary>
- ///// 保存
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Save();
- ///// <summary>
- ///// 作废
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Delete();
- ///// <summary>
- ///// 恢复
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Resume();
- ///// <summary>
- ///// 提交审核
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool SubMitAudit();
- ///// <summary>
- ///// 审核
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Audit();
- ///// <summary>
- ///// 分组
- ///// </summary>
- ///// <returns></returns>
- //protected abstract bool Group();
- /// <summary>
- /// 检验数据
- /// </summary>
- /// <returns></returns>
- protected abstract bool CheckData(ActionType actionType, out ArrayList parm, out string msg);
- ///// <summary>
- ///// 获取参数
- ///// </summary>
- ///// <param name="actionType"></param>
- ///// <returns></returns>
- //protected abstract ArrayList[] GetParms(ActionType actionType);
- /// <summary>
- /// 是否有选择记录
- /// </summary>
- /// <returns></returns>
- protected abstract bool IsSelectData(ActionType actionType, out string msg);
- private string GetSubmitMsg(ActionType actionType)
- {
- Type type = typeof(ActionType);
- FieldInfo fieldInfo = type.GetField(Enum.GetName(type, actionType));
- object[] objs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (objs.Length > 0)
- {
- DescriptionAttribute descAttribute = (DescriptionAttribute)objs[0];
- return "是否" + descAttribute.Description + "数据?";
- }
- return "";
- }
- private string GetSuccessMsg(ActionType actionType)
- {
- Type type = typeof(ActionType);
- FieldInfo fieldInfo = type.GetField(Enum.GetName(type, actionType));
- object[] objs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (objs.Length > 0)
- {
- DescriptionAttribute descAttribute = (DescriptionAttribute)objs[0];
- return descAttribute.Description + "成功!";
- }
- return "";
- }
- }
- }
|