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 _dicAction = new Dictionary(); private Dictionary _dicQuery = new Dictionary(); //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(); } /// /// 注册非查询 /// /// 非查询方法 /// 操作类型 protected void RegistAction(ActionDelegate action, ActionType actionType) { _dicAction.Add(actionType, action); } /// /// 注册查询 /// /// 查询方法 /// 查询Key protected void RegistQuery(QueryDelegate query, string strKey) { _dicQuery.Add(strKey, query); } /// /// 根据操作类型执行对应的非查询 /// /// 操作类型 /// 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; } /// /// 根据Key值执行对应查询方法。 /// /// 注册查询时的Key值 public void DoQuery(string strKey) { _dicQuery[strKey].Invoke(); } ///// ///// 查询 ///// //protected abstract void Query(); ///// ///// 新增 ///// ///// //protected abstract bool Add(); ///// ///// 修改 ///// ///// //protected abstract bool Modify(); ///// ///// 保存 ///// ///// //protected abstract bool Save(); ///// ///// 作废 ///// ///// //protected abstract bool Delete(); ///// ///// 恢复 ///// ///// //protected abstract bool Resume(); ///// ///// 提交审核 ///// ///// //protected abstract bool SubMitAudit(); ///// ///// 审核 ///// ///// //protected abstract bool Audit(); ///// ///// 分组 ///// ///// //protected abstract bool Group(); /// /// 检验数据 /// /// protected abstract bool CheckData(ActionType actionType, out ArrayList parm, out string msg); ///// ///// 获取参数 ///// ///// ///// //protected abstract ArrayList[] GetParms(ActionType actionType); /// /// 是否有选择记录 /// /// 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 ""; } } }