ivr流程编辑器

GlobalController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using HySoft.IVRFlowEditor.IVRControlUtility;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. using System.Reflection;
  9. using System.ComponentModel;
  10. using System.IO;
  11. using IVRFlowEditor;
  12. using HySoft.FlowEditor;
  13. using HySoft.IVRFlowEditor.Model;
  14. using IVRFlowEditor.IVRControlUtility;
  15. namespace HySoft.IVRFlowEditor.Utility
  16. {
  17. public class GlobalController
  18. {
  19. static GlobalController()
  20. {
  21. IVRCancas =new Dictionary<string,IVRCanvas>();
  22. SetIVRControl();
  23. }
  24. #region 绘制控件
  25. /// <summary>
  26. /// 即将绘制的流程图形
  27. /// </summary>
  28. private static IVRControlBase ChartFlowIng
  29. { get; set; }
  30. /// <summary>
  31. ///
  32. /// </summary>
  33. public static Dictionary<string, Type> IVRControls;
  34. /// <summary>
  35. /// 缓存全部IVR控件,在做导入时判断以及实例化IVR控件
  36. /// </summary>
  37. private static void SetIVRControl()
  38. {
  39. IVRControls = new Dictionary<string, Type>();
  40. IVRControls.Add("CELL_AUDIODTMF", typeof(IVRAudioDTMF));
  41. IVRControls.Add("CELL_BRANCH", typeof(IVRBranch));
  42. IVRControls.Add("CELL_CALCULATE", typeof(IVRCalculate));
  43. IVRControls.Add("CELL_CANCELQUEUE", typeof(IVRCancelQueue));
  44. IVRControls.Add("CELL_COMPARE", typeof(IVRCompare));
  45. IVRControls.Add("CELL_CONTINUEQUEUE", typeof(IVRContinueQueue));
  46. IVRControls.Add("IVRDefaultVar", typeof(IVRDefaultVar));
  47. IVRControls.Add("CELL_DEFINEVAR", typeof(IVRDefinevar));
  48. IVRControls.Add("DefVar", typeof(IVRDefinevarDefVar));
  49. IVRControls.Add("CELL_END", typeof(IVREndNode));
  50. IVRControls.Add("CELL_HANGUP", typeof(IVRHangUp));
  51. IVRControls.Add("CELL_LEAVEWORD", typeof(IVRLeaveWord));
  52. IVRControls.Add("CELL_CALL", typeof(IVROutbound));
  53. IVRControls.Add("CELL_QUEUE", typeof(IVRQueue));
  54. IVRControls.Add("CELL_RECORDSET", typeof(IVRRecordSet));
  55. IVRControls.Add("CELL_RECVFAX", typeof(IVRRecvfax));
  56. IVRControls.Add("CELL_SENDFAX", typeof(IVRSendfax));
  57. IVRControls.Add("CELL_SQL", typeof(IVRSql));
  58. IVRControls.Add("CELL_START", typeof(IVRStartNode));
  59. IVRControls.Add("CELL_STRINGOP", typeof(IVRStringop));
  60. IVRControls.Add("CELL_SUBFLOW", typeof(IVRSubflow));
  61. IVRControls.Add("CELL_TIMER", typeof(IVRTimer));
  62. IVRControls.Add("CELL_TRANSFEROUT", typeof(IVRTransfeOut));
  63. IVRControls.Add("CELL_TURNAGENT", typeof(IVRTurnagent));
  64. IVRControls.Add("CELL_SOCKET", typeof(IVRSocket));
  65. }
  66. /// <summary>
  67. /// 检查工具菜单是否按下(按下代表即将创建节点控件)
  68. /// </summary>
  69. /// <returns></returns>
  70. public static bool CheckCreateNode()
  71. {
  72. if (ChartFlowIng != null)
  73. return true;
  74. else
  75. return false;
  76. }
  77. /// <summary>
  78. /// 创建节点
  79. /// </summary>
  80. /// <param name="node"></param>
  81. /// <param name="imageName"></param>
  82. public static void SetCreateNodeType(IVRControlBase node,string imageName)
  83. {
  84. ChartFlowIng = node;
  85. ChartFlowIng.Image =ControlImageList.Images[imageName];
  86. ChartFlowIng.SelectedImage = ControlImageList.Images[imageName];
  87. }
  88. /// <summary>
  89. /// 为绑定ComboBox
  90. /// </summary>
  91. /// <returns></returns>
  92. public static List<IVRControlBase> GetComBoBoxofIVR()
  93. {
  94. try
  95. {
  96. List<IVRControlBase> list = IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowNode;
  97. if (list.Where(a => a.Pos == "0").Count() == 0)
  98. {
  99. list.Add(new IVRControlBase() { Pos = "0", Name = "请选择" });
  100. }
  101. return list.Where(a => a != _SelectCanvas.SelectedNodes.Last()).OrderBy(a => a.Pos).ToList();
  102. }
  103. catch(Exception ex)
  104. {
  105. MessageBox.Show("获取下拉列表参数失败!详细信息" + ex.Message);
  106. return null;
  107. }
  108. }
  109. /// <summary>
  110. /// 为绑定ComboBox
  111. /// </summary>
  112. /// <returns></returns>
  113. public static List<IVRFlowInfo> GetComBoBoxofIVRFlow()
  114. {
  115. try
  116. {
  117. List<IVRFlowInfo> list = IVRCancas[_SelectTabControl.Name].IVRFlows.Where(a => a.Value.FlowID != _SelectCanvas.Name).Select(a=>a.Value).ToList();
  118. if (list.Where(a => a.FlowName == "请选择").Count() == 0)
  119. {
  120. list.Add(new IVRFlowInfo() { FlowID = "-1", FlowName = "请选择" });
  121. }
  122. return list.Where(a => a.FlowID != _SelectCanvas.Name).ToList();
  123. }
  124. catch (Exception ex)
  125. {
  126. MessageBox.Show("获取下拉列表参数失败!详细信息" + ex.Message);
  127. return null;
  128. }
  129. }
  130. /// <summary>
  131. /// 把变量节点中定义的变量缓存
  132. /// </summary>
  133. // public static List<IVRDefinevarDefVar> DefVar = new List<IVRDefinevarDefVar>();
  134. public static void SetFlowVar(List<IVRDefinevarDefVar> var)
  135. {
  136. IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowVar=(var);
  137. }
  138. public static List<IVRDefinevarDefVar> GetFlowVar()
  139. {
  140. try
  141. {
  142. return IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowVar;
  143. }
  144. catch (Exception ex)
  145. {
  146. MessageBox.Show("添加控件到全局变量中出现异常!详细信息:" + ex.Message);
  147. return null;
  148. }
  149. }
  150. public static void SetCurrentCancasIVRControlBase(IVRControlBase con)
  151. {
  152. try
  153. {
  154. IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowNode.Add(con);
  155. }
  156. catch (Exception ex)
  157. {
  158. MessageBox.Show("添加控件到全局变量中出现异常!详细信息:" + ex.Message);
  159. }
  160. }
  161. /// <summary>
  162. ///
  163. /// </summary>
  164. public static Dictionary<string ,IVRCanvas> IVRCancas;
  165. /// <summary>
  166. /// 当前选中的画布,在FrmMain中赋值
  167. /// </summary>
  168. public static FlowEditorCanvas _SelectCanvas;
  169. /// <summary>
  170. /// 当前选中的TabControl
  171. /// </summary>
  172. public static TabControl _SelectTabControl;
  173. /// <summary>
  174. /// 创建一个节点
  175. /// </summary>
  176. /// <param name="id">节点编号</param>
  177. /// <returns></returns>
  178. public static IVRControlBase CreateNode(string id)
  179. {
  180. try
  181. {
  182. if (ChartFlowIng != null)
  183. {
  184. ChartFlowIng.Pos = id;
  185. ChartFlowIng.SelectedImage = new Bitmap(@"pic\Selected.png");
  186. ChartFlowIng.Image = new Bitmap(@"pic\NoSelect.png");
  187. }
  188. return ChartFlowIng;
  189. }
  190. finally
  191. {
  192. ChartFlowIng = null;
  193. }
  194. }
  195. #endregion
  196. #region 保存当前缓存对象
  197. #endregion
  198. #region 绑定ComBoBox
  199. /// <summary>
  200. /// 根据枚举DescriptionAttribute 特性绑定ComboBox要显示的数据
  201. /// </summary>
  202. /// <param name="com"></param>
  203. /// <param name="obj"></param>
  204. public static void BindComBoBoxOfEnumDesc(ComboBox com, object obj)
  205. {
  206. try
  207. {
  208. List<string> source = new List<string>();
  209. foreach (FieldInfo f in obj.GetType().GetFields())
  210. {
  211. var v = f.GetCustomAttributes(typeof(DescriptionAttribute), false);
  212. if (v != null && v.Count() > 0)
  213. source.Add((v[0] as DescriptionAttribute).Description);
  214. }
  215. com.DataSource = source;
  216. if (Enum.GetName(obj.GetType(), obj) != null && obj.GetType().GetField(Enum.GetName(obj.GetType(), obj)).GetCustomAttributes(typeof(DescriptionAttribute), false).Count() != 0)
  217. {
  218. var o = obj.GetType().GetField(Enum.GetName(obj.GetType(), obj)).GetCustomAttributes(typeof(DescriptionAttribute), false)[0] as DescriptionAttribute;
  219. com.Text = o.Description;
  220. }
  221. else
  222. {
  223. com.Text = source.First();
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. MessageBox.Show(ex.ToString());
  229. }
  230. }
  231. /// <summary>
  232. /// 根据Type是具体值还是变量绑定Com
  233. /// </summary>
  234. /// <param name="com">要重新绑定的ComboBox</param>
  235. /// <param name="type">绑定类型</param>
  236. public static void BindComboBoxOFVar(ComboBox com, NumberType type)
  237. {
  238. switch (type)
  239. {
  240. case NumberType.变量:
  241. com.DataSource = GlobalController.GetFlowVar().ToList();
  242. com.DisplayMember = "VarName";
  243. com.ValueMember = "VarVal";
  244. break;
  245. case NumberType.具体值:
  246. com.DataSource = null;
  247. break;
  248. }
  249. }
  250. /// <summary>
  251. /// 返回ComboBox选中的enum信息
  252. /// </summary>
  253. /// <typeparam name="T"></typeparam>
  254. /// <param name="value"></param>
  255. /// <returns></returns>
  256. public static T GetEnumByComBoBoxValueOFDesc<T>(string value)
  257. {
  258. object obj= default(T);
  259. foreach (FieldInfo f in obj.GetType().GetFields())
  260. {
  261. var descs = f.GetCustomAttributes(typeof(DescriptionAttribute), false);
  262. if (descs != null)
  263. {
  264. foreach (DescriptionAttribute d in descs)
  265. {
  266. if (value == d.Description)
  267. {
  268. return(T)Enum.Parse(obj.GetType(),f.Name);
  269. }
  270. }
  271. }
  272. }
  273. return (T)obj;
  274. }
  275. #endregion
  276. #region 序列化处理
  277. /// <summary>
  278. /// 缓存序列化对象
  279. /// </summary>
  280. private static IVRFlowSerializer _IVRFlowSerializer;
  281. /// <summary>
  282. /// 获取序列化对象
  283. /// </summary>
  284. /// <returns></returns>
  285. public static IVRFlowSerializer GetSerializerHandle()
  286. {
  287. if (_IVRFlowSerializer == null)
  288. _IVRFlowSerializer = new IVRFlowSerializer();
  289. return _IVRFlowSerializer;
  290. }
  291. #endregion
  292. /// <summary>
  293. /// 缓存菜单图片
  294. /// </summary>
  295. public static System.Windows.Forms.ImageList ControlImageList;
  296. }
  297. }