using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MJTop.Data { /// /// 表触发器 /// public class TableTrigger { /// /// 表对应执行的Action集合 /// internal IgCaseDictionary> ExecActions { get; set; } private DB Db { get; set; } internal TableTrigger(DB db) { this.Db = db; this.ExecActions = new IgCaseDictionary>(); } /// /// 添加 表对应要执行的Action /// /// 表名 /// 多个Action,object:方法执行后传入的值 public void Add(string tableName, params Action[] actions) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException("表名不能为空!"); } this.Db.CheckTabStuct(tableName); this.ExecActions.AddRange(tableName, actions); } /// /// 删除 表对应执行的Action集合数据 /// /// 表名 /// 是否删除成功 public bool Remove(string tableName) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException("表名不能为空!"); } Db.CheckTabStuct(tableName); return this.ExecActions.Remove(tableName); } /// /// 清除 所有表的Action集合 /// public void Clear() { this.ExecActions.Clear(); } /// /// 获取当前表的Action集合 /// /// /// 当前表的Action集合 public List GetActions(string tableName) { if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException("表名不能为空!"); } List lstAct = null; if (this.ExecActions.TryGetValue(tableName, out lstAct)) { return lstAct; } else { return new List(); } } } }