using System; using System.Collections.Generic; using System.Collections; using System.Text; using BP.DA; namespace BP.WF { /// /// 消息类型 /// public enum SendReturnMsgType { /// /// 消息 /// Info, /// /// 系统消息 /// SystemMsg } /// /// 消息标记 /// public class SendReturnMsgFlag { /// /// 符合工作流程完成条件 /// public const string MacthFlowOver = "MacthFlowOver"; /// /// 当前工作[{0}]已经完成 /// public const string CurrWorkOver = "CurrWorkOver"; /// /// 符合完成条件,流程完成 /// public const string FlowOverByCond = "FlowOverByCond"; /// /// 到人员 /// public const string ToEmps = "ToEmps"; /// /// 到人员的扩展信息 /// public const string ToEmpExt = "ToEmpExt"; /// /// 分配任务 /// public const string AllotTask = "AllotTask"; /// /// 合流结束 /// public const string HeLiuOver = "HeLiuOver"; /// /// 工作报告 /// public const string WorkRpt = "WorkRpt"; /// /// 启动节点 /// public const string WorkStartNode = "WorkStartNode"; /// /// 工作启动 /// public const string WorkStart = "WorkStart"; /// /// 流程结束 /// public const string FlowOver = "FlowOver"; /// /// 发送成功后的事件异常 /// public const string SendSuccessMsgErr = "SendSuccessMsgErr"; /// /// 发送成功信息 /// public const string SendSuccessMsg = "SendSuccessMsg"; /// /// 分流程信息 /// public const string FenLiuInfo = "FenLiuInfo"; /// /// 抄送消息 /// public const string CCMsg = "CCMsg"; /// /// 编辑接受者 /// public const string EditAccepter = "EditAccepter"; /// /// 新建流程 /// public const string NewFlowUnSend = "NewFlowUnSend"; /// /// 撤销发送 /// public const string UnSend = "UnSend"; /// /// 报表 /// public const string Rpt = "Rpt"; /// /// 发送时 /// public const string SendWhen = "SendWhen"; /// /// 当前流程结束 /// public const string End = "End"; /// /// 当前流程完成 /// public const string OverCurr = "OverCurr"; /// /// 流程方向信息 /// public const string CondInfo = "CondInfo"; /// /// 一个节点完成 /// public const string OneNodeSheetver = "OneNodeSheetver"; /// /// 单据信息 /// public const string BillInfo = "BillInfo"; /// /// 文本信息(系统不会生成) /// public const string MsgOfText = "MsgOfText"; /// /// 消息收听信息 /// public const string ListenInfo = "ListenInfo"; #region 系统变量 /// /// 流程是否结束? /// public const string IsStopFlow = "IsStopFlow"; /// /// 工作ID /// public const string VarWorkID = "VarWorkID"; /// /// 当前节点ID /// public const string VarCurrNodeID = "VarCurrNodeID"; /// /// 当前节点名称 /// public const string VarCurrNodeName = "VarCurrNodeName"; /// /// 到达节点ID /// public const string VarToNodeID = "VarToNodeID"; /// /// 到达的节点集合 /// public const string VarToNodeIDs = "VarToNodeIDs"; /// /// 到达节点名称 /// public const string VarToNodeName = "VarToNodeName"; /// /// 接受人集合的名称(用逗号分开) /// public const string VarAcceptersName = "VarAcceptersName"; /// /// 接受人集合的ID(用逗号分开) /// public const string VarAcceptersID = "VarAcceptersID"; /// /// 接受人集合的ID Name(用逗号分开) /// public const string VarAcceptersNID = "VarAcceptersNID"; /// /// 子线程的WorkIDs /// public const string VarTreadWorkIDs = "VarTreadWorkIDs"; #endregion 系统变量 } /// /// 工作发送返回对象 /// public class SendReturnObj { /// /// 消息标记 /// public string MsgFlag = null; /// /// 消息标记描述 /// public string MsgFlagDesc { get { if (MsgFlag == null) throw new Exception("@没有标记"); switch (MsgFlag) { case SendReturnMsgFlag.VarAcceptersID: return "接受人ID"; case SendReturnMsgFlag.VarAcceptersName: return "接受人名称"; case SendReturnMsgFlag.VarAcceptersNID: return "接受人ID集合"; case SendReturnMsgFlag.VarCurrNodeID: return "当前节点ID"; case SendReturnMsgFlag.VarCurrNodeName: return "接受人集合的名称(用逗号分开)"; case SendReturnMsgFlag.VarToNodeID: return "到达节点ID"; case SendReturnMsgFlag.VarToNodeName: return "到达节点名称"; case SendReturnMsgFlag.VarTreadWorkIDs: return "子线程的WorkIDs"; case SendReturnMsgFlag.BillInfo: return "单据信息"; case SendReturnMsgFlag.CCMsg: return "抄送信息"; case SendReturnMsgFlag.CondInfo: return "条件信息"; case SendReturnMsgFlag.CurrWorkOver: return "当前的工作已经完成"; case SendReturnMsgFlag.EditAccepter: return "编辑接受者"; case SendReturnMsgFlag.End: return "当前的流程已经结束"; case SendReturnMsgFlag.FenLiuInfo: return "分流信息"; case SendReturnMsgFlag.FlowOver: return "当前流程已经完成"; case SendReturnMsgFlag.FlowOverByCond: return "符合完成条件,流程完成."; case SendReturnMsgFlag.HeLiuOver: return "分流完成"; case SendReturnMsgFlag.MacthFlowOver: return "符合工作流程完成条件"; case SendReturnMsgFlag.NewFlowUnSend: return "新建流程"; case SendReturnMsgFlag.OverCurr: return "当前流程完成"; case SendReturnMsgFlag.Rpt: return "报表"; case SendReturnMsgFlag.SendSuccessMsg: return "发送成功信息"; case SendReturnMsgFlag.SendSuccessMsgErr: return "发送错误"; case SendReturnMsgFlag.SendWhen: return "发送时"; case SendReturnMsgFlag.ToEmps: return "到达人员"; case SendReturnMsgFlag.UnSend: return "撤消发送"; case SendReturnMsgFlag.ToEmpExt: return "到人员的扩展信息"; case SendReturnMsgFlag.VarWorkID: return "工作ID"; case SendReturnMsgFlag.IsStopFlow: return "流程是否结束"; case SendReturnMsgFlag.WorkRpt: return "工作报告"; case SendReturnMsgFlag.WorkStartNode: return "启动节点"; case SendReturnMsgFlag.AllotTask: return "分配任务"; default: return "信息:" + MsgFlag; // throw new Exception("@没有判断的标记..."); } } } /// /// 消息类型 /// public SendReturnMsgType HisSendReturnMsgType = SendReturnMsgType.Info; /// /// 消息内容 /// public string MsgOfText = null; /// /// 消息内容Html /// public string MsgOfHtml = null; /// /// 发送消息 /// public SendReturnObj() { } } /// /// 工作发送返回对象集合. /// public class SendReturnObjs : System.Collections.CollectionBase { #region 获取系统变量. public Int64 VarWorkID { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarWorkID) return Int64.Parse(item.MsgOfText); } return 0; } } public bool ItIsStopFlow { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.IsStopFlow) { if (item.MsgOfText == "1") return true; else return false; } } //throw new Exception("@没有找到系统变量IsStopFlow"); return false; } } /// /// 到达节点ID /// public int VarToNodeID { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarToNodeID) return int.Parse(item.MsgOfText); } return 0; } } /// /// 到达节点IDs /// public string VarToNodeIDs { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarToNodeIDs) return item.MsgOfText; } return null; } } /// /// 到达节点名称 /// public string VarToNodeName { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarToNodeName) return item.MsgOfText; } return "没有找到变量."; } } /// /// 到达的节点名称 /// public string VarCurrNodeName { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarCurrNodeName) return item.MsgOfText; } return null; } } public int VarCurrNodeID { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarCurrNodeID) return int.Parse(item.MsgOfText); } return 0; } } /// /// 接受人 /// public string VarAcceptersName { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarAcceptersName) return item.MsgOfText; } return null; } } /// /// 接受人IDs /// public string VarAcceptersID { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarAcceptersID) return item.MsgOfText; } return null; } } /// /// 文本提示信息. /// public string MsgOfText { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.MsgOfText) return item.MsgOfText; } return null; } } /// /// 分流向子线程发送时产生的子线程的WorkIDs, 多个有逗号分开. /// public string VarTreadWorkIDs { get { foreach (SendReturnObj item in this) { if (item.MsgFlag == SendReturnMsgFlag.VarTreadWorkIDs) return item.MsgOfText; } return null; } } #endregion /// /// 构造 /// public SendReturnObjs() { } /// /// 根据指定格式的字符串生成一个事例获取相关变量 /// /// 指定格式的字符串 public SendReturnObjs(string specText) { this.LoadSpecText(specText); } /// /// 输出text消息 /// public string OutMessageText = null; /// /// 输出html信息 /// public string OutMessageHtml = null; /// /// 增加消息 /// /// 消息标记 /// 文本消息 /// html消息 /// 消息类型 public void AddMsg(string msgFlag, string msg, string msgOfHtml, SendReturnMsgType type) { SendReturnObj obj = new SendReturnObj(); obj.MsgFlag = msgFlag; obj.MsgOfText = msg; obj.MsgOfHtml = msgOfHtml; obj.HisSendReturnMsgType = type; foreach (SendReturnObj item in this) { if (item.MsgFlag == msgFlag) { item.MsgFlag = msgFlag; item.MsgOfText = msg; item.MsgOfHtml = msgOfHtml; item.HisSendReturnMsgType = type; return; } } this.InnerList.Add(obj); } /// /// 转化成特殊的格式 /// /// public string ToMsgOfSpecText() { string msg = ""; foreach (SendReturnObj item in this) { if (item.MsgOfText != null) { msg += "$" + item.MsgFlag + "^" + (int)item.HisSendReturnMsgType + "^" + item.MsgOfText; } } //增加上 text信息。 msg += "$MsgOfText^" + (int)SendReturnMsgType.Info + "^" + this.ToMsgOfText(); msg.Replace("@@", "@"); return msg; } /// /// 装载指定的文本,生成这个对象。 /// /// 指定格式的文本 public void LoadSpecText(string text) { string[] strs = text.Split('$'); foreach (string str in strs) { string[] sp = str.Split('^'); this.AddMsg(sp[0], sp[2], null, (SendReturnMsgType)int.Parse(sp[1])); } } /// /// 转化成text方式的消息,以方便识别不出来html的设备输出. /// /// public string ToMsgOfText() { if (this.OutMessageText != null) return this.OutMessageText; string msg = ""; foreach (SendReturnObj item in this) { if (item.HisSendReturnMsgType == SendReturnMsgType.SystemMsg) continue; //特殊判断. if (item.MsgFlag == SendReturnMsgFlag.IsStopFlow) { msg += "@" + item.MsgOfHtml; continue; } if (item.MsgOfText != null) { if (item.MsgOfText.Contains("<")) { #warning 不应该出现. // Log.DefaultLogWriteLineWarning("@文本信息里面有html标记:" + item.MsgOfText); continue; } msg += "@" + item.MsgOfText; continue; } } msg.Replace("@@", "@"); return msg; } public string ToJson() { Hashtable ht = new Hashtable(); foreach (SendReturnObj item in this) { string nodeID = null; if (item.MsgFlag.Equals(SendReturnMsgFlag.VarCurrNodeID)) nodeID = item.MsgOfText; if (item.MsgFlag.Equals(SendReturnMsgFlag.VarToNodeID)) nodeID = item.MsgOfText; if (nodeID != null) { ht.Add(item.MsgFlag, item.MsgOfText); nodeID = DBAccess.RunSQLReturnStringIsNull("SELECT Mark FROM WF_Node WHERE NodeID=" + nodeID, nodeID); ht.Add(item.MsgFlag + "NodeMark", nodeID); continue; } if (item.MsgFlag.Equals(SendReturnMsgFlag.VarToNodeIDs)) { ht.Add(item.MsgFlag, item.MsgOfText); string ids = ""; string[] strs = item.MsgOfText.Split(','); foreach (string str in strs) { ids += DBAccess.RunSQLReturnStringIsNull("SELECT Mark FROM WF_Node WHERE NodeID=" + nodeID, nodeID) + ","; } ht.Add(item.MsgFlag + "NodeMark", ids); continue; } ht.Add(item.MsgFlag, item.MsgOfText); } return BP.Tools.Json.ToJson(ht); } /// /// 转化成html方式的消息,以方便html的信息输出. /// /// public string ToMsgOfHtml() { if (this.OutMessageHtml != null) return this.OutMessageHtml; string msg = ""; foreach (SendReturnObj item in this) { if (item.HisSendReturnMsgType != SendReturnMsgType.Info) continue; if (item.MsgOfHtml != null) { msg += "@" + item.MsgOfHtml; continue; } if (item.MsgOfText != null) { msg += "@" + item.MsgOfText; continue; } } msg = msg.Replace("@@", "@"); msg = msg.Replace("@@", "@"); if (msg == "@") return "@流程已经完成."; return msg; } } }