| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using HySoft.IVRFlowEditor.IVRControlUtility;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Reflection;
- using System.ComponentModel;
- using System.IO;
- using IVRFlowEditor;
- using HySoft.FlowEditor;
- using HySoft.IVRFlowEditor.Model;
- using IVRFlowEditor.IVRControlUtility;
- namespace HySoft.IVRFlowEditor.Utility
- {
-
- public class GlobalController
- {
- static GlobalController()
- {
- IVRCancas =new Dictionary<string,IVRCanvas>();
- SetIVRControl();
- }
- #region 绘制控件
- /// <summary>
- /// 即将绘制的流程图形
- /// </summary>
- private static IVRControlBase ChartFlowIng
- { get; set; }
- /// <summary>
- ///
- /// </summary>
- public static Dictionary<string, Type> IVRControls;
- /// <summary>
- /// 缓存全部IVR控件,在做导入时判断以及实例化IVR控件
- /// </summary>
- private static void SetIVRControl()
- {
- IVRControls = new Dictionary<string, Type>();
- IVRControls.Add("CELL_AUDIODTMF", typeof(IVRAudioDTMF));
- IVRControls.Add("CELL_BRANCH", typeof(IVRBranch));
- IVRControls.Add("CELL_CALCULATE", typeof(IVRCalculate));
- IVRControls.Add("CELL_CANCELQUEUE", typeof(IVRCancelQueue));
- IVRControls.Add("CELL_COMPARE", typeof(IVRCompare));
- IVRControls.Add("CELL_CONTINUEQUEUE", typeof(IVRContinueQueue));
- IVRControls.Add("IVRDefaultVar", typeof(IVRDefaultVar));
- IVRControls.Add("CELL_DEFINEVAR", typeof(IVRDefinevar));
- IVRControls.Add("DefVar", typeof(IVRDefinevarDefVar));
- IVRControls.Add("CELL_END", typeof(IVREndNode));
- IVRControls.Add("CELL_HANGUP", typeof(IVRHangUp));
- IVRControls.Add("CELL_LEAVEWORD", typeof(IVRLeaveWord));
- IVRControls.Add("CELL_CALL", typeof(IVROutbound));
- IVRControls.Add("CELL_QUEUE", typeof(IVRQueue));
- IVRControls.Add("CELL_RECORDSET", typeof(IVRRecordSet));
- IVRControls.Add("CELL_RECVFAX", typeof(IVRRecvfax));
- IVRControls.Add("CELL_SENDFAX", typeof(IVRSendfax));
- IVRControls.Add("CELL_SQL", typeof(IVRSql));
- IVRControls.Add("CELL_START", typeof(IVRStartNode));
- IVRControls.Add("CELL_STRINGOP", typeof(IVRStringop));
- IVRControls.Add("CELL_SUBFLOW", typeof(IVRSubflow));
- IVRControls.Add("CELL_TIMER", typeof(IVRTimer));
- IVRControls.Add("CELL_TRANSFEROUT", typeof(IVRTransfeOut));
- IVRControls.Add("CELL_TURNAGENT", typeof(IVRTurnagent));
- IVRControls.Add("CELL_SOCKET", typeof(IVRSocket));
- }
- /// <summary>
- /// 检查工具菜单是否按下(按下代表即将创建节点控件)
- /// </summary>
- /// <returns></returns>
- public static bool CheckCreateNode()
- {
- if (ChartFlowIng != null)
- return true;
- else
- return false;
- }
- /// <summary>
- /// 创建节点
- /// </summary>
- /// <param name="node"></param>
- /// <param name="imageName"></param>
- public static void SetCreateNodeType(IVRControlBase node,string imageName)
- {
- ChartFlowIng = node;
- ChartFlowIng.Image =ControlImageList.Images[imageName];
- ChartFlowIng.SelectedImage = ControlImageList.Images[imageName];
- }
- /// <summary>
- /// 为绑定ComboBox
- /// </summary>
- /// <returns></returns>
- public static List<IVRControlBase> GetComBoBoxofIVR()
- {
- try
- {
- List<IVRControlBase> list = IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowNode;
- if (list.Where(a => a.Pos == "0").Count() == 0)
- {
- list.Add(new IVRControlBase() { Pos = "0", Name = "请选择" });
- }
- return list.Where(a => a != _SelectCanvas.SelectedNodes.Last()).OrderBy(a => a.Pos).ToList();
- }
- catch(Exception ex)
- {
- MessageBox.Show("获取下拉列表参数失败!详细信息" + ex.Message);
- return null;
- }
-
- }
- /// <summary>
- /// 为绑定ComboBox
- /// </summary>
- /// <returns></returns>
- public static List<IVRFlowInfo> GetComBoBoxofIVRFlow()
- {
- try
- {
- List<IVRFlowInfo> list = IVRCancas[_SelectTabControl.Name].IVRFlows.Where(a => a.Value.FlowID != _SelectCanvas.Name).Select(a=>a.Value).ToList();
- if (list.Where(a => a.FlowName == "请选择").Count() == 0)
- {
- list.Add(new IVRFlowInfo() { FlowID = "-1", FlowName = "请选择" });
- }
- return list.Where(a => a.FlowID != _SelectCanvas.Name).ToList();
- }
- catch (Exception ex)
- {
- MessageBox.Show("获取下拉列表参数失败!详细信息" + ex.Message);
- return null;
- }
- }
- /// <summary>
- /// 把变量节点中定义的变量缓存
- /// </summary>
- // public static List<IVRDefinevarDefVar> DefVar = new List<IVRDefinevarDefVar>();
- public static void SetFlowVar(List<IVRDefinevarDefVar> var)
- {
- IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowVar=(var);
- }
- public static List<IVRDefinevarDefVar> GetFlowVar()
- {
- try
- {
- return IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowVar;
- }
- catch (Exception ex)
- {
- MessageBox.Show("添加控件到全局变量中出现异常!详细信息:" + ex.Message);
- return null;
- }
- }
- public static void SetCurrentCancasIVRControlBase(IVRControlBase con)
- {
- try
- {
- IVRCancas[_SelectTabControl.Name].IVRFlows[_SelectCanvas.Name].IVRFlowNode.Add(con);
- }
- catch (Exception ex)
- {
- MessageBox.Show("添加控件到全局变量中出现异常!详细信息:" + ex.Message);
- }
- }
- /// <summary>
- ///
- /// </summary>
- public static Dictionary<string ,IVRCanvas> IVRCancas;
- /// <summary>
- /// 当前选中的画布,在FrmMain中赋值
- /// </summary>
- public static FlowEditorCanvas _SelectCanvas;
- /// <summary>
- /// 当前选中的TabControl
- /// </summary>
- public static TabControl _SelectTabControl;
- /// <summary>
- /// 创建一个节点
- /// </summary>
- /// <param name="id">节点编号</param>
- /// <returns></returns>
- public static IVRControlBase CreateNode(string id)
- {
- try
- {
- if (ChartFlowIng != null)
- {
- ChartFlowIng.Pos = id;
- ChartFlowIng.SelectedImage = new Bitmap(@"pic\Selected.png");
- ChartFlowIng.Image = new Bitmap(@"pic\NoSelect.png");
- }
- return ChartFlowIng;
-
- }
- finally
- {
- ChartFlowIng = null;
-
- }
- }
- #endregion
- #region 保存当前缓存对象
-
- #endregion
- #region 绑定ComBoBox
- /// <summary>
- /// 根据枚举DescriptionAttribute 特性绑定ComboBox要显示的数据
- /// </summary>
- /// <param name="com"></param>
- /// <param name="obj"></param>
- public static void BindComBoBoxOfEnumDesc(ComboBox com, object obj)
- {
- try
- {
- List<string> source = new List<string>();
- foreach (FieldInfo f in obj.GetType().GetFields())
- {
- var v = f.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (v != null && v.Count() > 0)
- source.Add((v[0] as DescriptionAttribute).Description);
- }
- com.DataSource = source;
- if (Enum.GetName(obj.GetType(), obj) != null && obj.GetType().GetField(Enum.GetName(obj.GetType(), obj)).GetCustomAttributes(typeof(DescriptionAttribute), false).Count() != 0)
- {
- var o = obj.GetType().GetField(Enum.GetName(obj.GetType(), obj)).GetCustomAttributes(typeof(DescriptionAttribute), false)[0] as DescriptionAttribute;
- com.Text = o.Description;
- }
- else
- {
- com.Text = source.First();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- /// <summary>
- /// 根据Type是具体值还是变量绑定Com
- /// </summary>
- /// <param name="com">要重新绑定的ComboBox</param>
- /// <param name="type">绑定类型</param>
- public static void BindComboBoxOFVar(ComboBox com, NumberType type)
- {
- switch (type)
- {
- case NumberType.变量:
- com.DataSource = GlobalController.GetFlowVar().ToList();
- com.DisplayMember = "VarName";
- com.ValueMember = "VarVal";
- break;
- case NumberType.具体值:
- com.DataSource = null;
- break;
- }
- }
- /// <summary>
- /// 返回ComboBox选中的enum信息
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="value"></param>
- /// <returns></returns>
- public static T GetEnumByComBoBoxValueOFDesc<T>(string value)
- {
- object obj= default(T);
- foreach (FieldInfo f in obj.GetType().GetFields())
- {
- var descs = f.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (descs != null)
- {
- foreach (DescriptionAttribute d in descs)
- {
- if (value == d.Description)
- {
- return(T)Enum.Parse(obj.GetType(),f.Name);
- }
- }
- }
- }
- return (T)obj;
- }
-
- #endregion
- #region 序列化处理
- /// <summary>
- /// 缓存序列化对象
- /// </summary>
- private static IVRFlowSerializer _IVRFlowSerializer;
- /// <summary>
- /// 获取序列化对象
- /// </summary>
- /// <returns></returns>
- public static IVRFlowSerializer GetSerializerHandle()
- {
- if (_IVRFlowSerializer == null)
- _IVRFlowSerializer = new IVRFlowSerializer();
- return _IVRFlowSerializer;
- }
- #endregion
- /// <summary>
- /// 缓存菜单图片
- /// </summary>
- public static System.Windows.Forms.ImageList ControlImageList;
- }
-
- }
|