/// <summary> /// 获得数据列表 /// </summary> public List<DB_Talk.Model.m_CallingSource> DataTableToList(DataSet ds) { List<DB_Talk.Model.m_CallingSource> modelList = new List<DB_Talk.Model.m_CallingSource>(); if (ds == null) return modelList; DataTable dt = ds.Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DB_Talk.Model.m_CallingSource model; for (int n = 0; n < rowsCount; n++) { model = new DB_Talk.Model.m_CallingSource(); if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="") { model.ID=int.Parse(dt.Rows[n]["ID"].ToString()); } if(dt.Rows[n]["BoxID"]!=null && dt.Rows[n]["BoxID"].ToString()!="") { model.BoxID=int.Parse(dt.Rows[n]["BoxID"].ToString()); } if(dt.Rows[n]["vc_Code"]!=null && dt.Rows[n]["vc_Code"].ToString()!="") { model.vc_Code= dt.Rows[n]["vc_Code"].ToString(); } if(dt.Rows[n]["vc_Name"]!=null && dt.Rows[n]["vc_Name"].ToString()!="") { model.vc_Name= dt.Rows[n]["vc_Name"].ToString(); } if(dt.Rows[n]["i_MainType"]!=null && dt.Rows[n]["i_MainType"].ToString()!="") { model.i_MainType=int.Parse(dt.Rows[n]["i_MainType"].ToString()); } if(dt.Rows[n]["i_SubType"]!=null && dt.Rows[n]["i_SubType"].ToString()!="") { model.i_SubType=int.Parse(dt.Rows[n]["i_SubType"].ToString()); } if(dt.Rows[n]["vc_Memo"]!=null && dt.Rows[n]["vc_Memo"].ToString()!="") { model.vc_Memo= dt.Rows[n]["vc_Memo"].ToString(); } if(dt.Rows[n]["i_Flag"]!=null && dt.Rows[n]["i_Flag"].ToString()!="") { model.i_Flag=int.Parse(dt.Rows[n]["i_Flag"].ToString()); } modelList.Add(model); } } return modelList; }
//创建基础的 呼叫源,路由规则,呼叫源规则,*000的被叫规则 public static bool CreateCalinglSourceRule() { //创建呼叫源,1,任何类型,任何类型 DB_Talk.Model.m_CallingSource modelCs = new DB_Talk.Model.m_CallingSource(); modelCs.ID = 1; modelCs.i_MainType = 6; //任何类型 modelCs.i_SubType = 1; //任何类型 modelCs.BoxID=Global.Params.BoxID; List<DB_Talk.Model.m_CallingSource> list = new DB_Talk.BLL.m_CallingSource().GetModelList( string.Format(" i_Flag=0 and ID='{0}' and i_MainType='{1}' and i_SubType='{2}' and BoxID='{3}'", modelCs.ID, modelCs.i_MainType, modelCs.i_SubType, modelCs.BoxID)); if (list.Count == 0) //不存在才创建 { if (!CreateCallSource(modelCs)) return false; } //创建路由规则0,0,0 DB_Talk.Model.m_RouteRule modelRRule = new DB_Talk.Model.m_RouteRule(); modelRRule.ID = 0; modelRRule.OriRouteID = 0; modelRRule.DestRouteID = 0; modelRRule.BoxID = Global.Params.BoxID; List<DB_Talk.Model.m_RouteRule> listModelRRule = new DB_Talk.BLL.m_RouteRule().GetModelList( string.Format(" i_Flag=0 and ID='{0}' and OriRouteID='{1}' and DestRouteID='{2}' and BoxID='{3}'", modelRRule.ID, modelRRule.OriRouteID, modelRRule.DestRouteID, modelRRule.BoxID)); if (listModelRRule.Count == 0) { if (!CreateRoutingRule(modelRRule)) return false; } //创建呼叫源规则,1,不限,0,1,0 DB_Talk.Model.m_CalinglSourceRule CalinglSourceRule = new DB_Talk.Model.m_CalinglSourceRule(); CalinglSourceRule.CallingOrigID = 1; //呼叫源索引1 CalinglSourceRule.i_ServerType = 1; //服务类型不限 CalinglSourceRule.i_MinReLength = 0; //最小收号长度0 CalinglSourceRule.CalledRuleID = 1; //被叫分析规则索引1 CalinglSourceRule.OriRouteID = 0; //目的路由索引 CalinglSourceRule.BoxID = Global.Params.BoxID; List<DB_Talk.Model.m_CalinglSourceRule> listCallingSource = new DB_Talk.BLL.m_CalinglSourceRule().GetModelList( string.Format(" i_Flag=0 and CallingOrigID='{0}' and CalledRuleID='{1}' and i_ServerType='{2}' and OriRouteID='{3}' and BoxID='{4}'", CalinglSourceRule.CallingOrigID, CalinglSourceRule.CalledRuleID,CalinglSourceRule.i_ServerType, CalinglSourceRule.OriRouteID, CalinglSourceRule.BoxID)); if (listCallingSource.Count == 0) { if (!CreateCallSourceRule(CalinglSourceRule)) return false; } //设置默认的被叫规则 DB_Talk.Model.m_CalledRule CalledRule = new DB_Talk.Model.m_CalledRule(); CalledRule.BoxID = Global.Params.BoxID; CalledRule.CalledID = 1; CalledRule.CallingOriID = 1; CalledRule.DestRouteID = 0; CalledRule.vc_CalledNumber = "*000"; CalledRule.i_CalledType = MBoxSDK.ConfigSDK.CALLED_RULE_TYPE.SERVICE.GetHashCode(); CalledRule.i_CalledSubType = MBoxSDK.ConfigSDK.CALLED_SUB_RULE_TYPE.话务员.GetHashCode(); List<DB_Talk.Model.m_CalledRule> listCall = new DB_Talk.BLL.m_CalledRule().GetModelList( string.Format(" i_Flag=0 and vc_CalledNumber='{0}' and BoxID='{1}'", CalledRule.vc_CalledNumber, CalledRule.BoxID)); if (listCall.Count == 0) { if (CreateCalledRule(CalledRule)) new DB_Talk.BLL.m_CalledRule().Add(CalledRule); else return false; } //默认400的规则 DB_Talk.Model.m_CalledRule CalledRule400 = new DB_Talk.Model.m_CalledRule(); CalledRule400.BoxID = Global.Params.BoxID; CalledRule400.CalledID = 1; CalledRule400.CallingOriID = 1; CalledRule400.DestRouteID = 0; CalledRule400.vc_CalledNumber = "400"; CalledRule400.i_CalledType = MBoxSDK.ConfigSDK.CALLED_RULE_TYPE.SERVICE.GetHashCode(); CalledRule400.i_CalledSubType = MBoxSDK.ConfigSDK.CALLED_SUB_RULE_TYPE.FD.GetHashCode(); CalledRule400.i_CalledChangeType = 2; CalledRule400.i_CalledChangeLength = 3; List<DB_Talk.Model.m_CalledRule> listCall400 = new DB_Talk.BLL.m_CalledRule().GetModelList( string.Format(" i_Flag=0 and vc_CalledNumber='{0}' and BoxID='{1}'", CalledRule400.vc_CalledNumber, CalledRule400.BoxID)); if (listCall400.Count == 0) { if (CreateCalledRule(CalledRule400)) new DB_Talk.BLL.m_CalledRule().Add(CalledRule400); else return false; } return true; }
/// <summary> /// 根据条件得到一个对象实体 /// </summary> public DB_Talk.Model.m_CallingSource GetModel(string strWhere) { StringBuilder strSql=new StringBuilder(); strSql.Append(" select top 1 "); strSql.Append(" ID, BoxID, vc_Code, vc_Name, i_MainType, i_SubType, vc_Memo, i_Flag "); strSql.Append(" from m_CallingSource "); if(strWhere.Trim()!="") { strSql.Append(" where "+strWhere); } DB_Talk.Model.m_CallingSource model=new DB_Talk.Model.m_CallingSource(); DataSet ds=GetDataSet(strSql.ToString()); if(ds!=null && ds.Tables[0].Rows.Count>0) { model=DataTableToList(ds)[0]; return model; } else { return null; } }
//查询呼叫源 private static bool QueryCallSource(out List<DB_Talk.Model.m_CallingSource> lst) { bool b = false; lst = new List<DB_Talk.Model.m_CallingSource>(); byte[] byteArray = new byte[ArraySize]; int len = ArraySize; b = MBoxSDK.ConfigSDK.MBOX_GetCallSource(Global.Params.BoxHandle, byteArray, (uint)byteArray.Length, ref len); //if (b) { string str = System.Text.Encoding.Default.GetString(byteArray); str = str.Replace("\0", ""); string[] strArray = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < strArray.Length; i++) { DB_Talk.Model.m_CallingSource m = new DB_Talk.Model.m_CallingSource(); string[] strArray2 = strArray[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); m.ID = (int.Parse(strArray2[0])); m.i_MainType = (int.Parse(strArray2[1])); m.i_SubType = (int.Parse(strArray2[2])); m.BoxID = Global.Params.BoxID; lst.Add(m); } } return b; }