//创建基础的 呼叫源,路由规则,呼叫源规则,*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;
        }
        //创建呼叫源规则
        private static bool CreateCallSourceRule(DB_Talk.Model.m_CalinglSourceRule model)
        {
            bool b = false;
            List<DB_Talk.Model.m_CalinglSourceRule> lst = new List<DB_Talk.Model.m_CalinglSourceRule>();
            QueryCallSourceRule(out lst);
            if (lst != null && lst.Count > 0)
            {
                if (lst.Contains(model))
                {
                    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}'",
                         model.CallingOrigID, model.CalledRuleID, model.i_ServerType, model.OriRouteID, model.BoxID));
                    if (listCallingSource.Count==0) new DB_Talk.BLL.m_CalinglSourceRule().Add(model);
                    return true;  //存在的不再添加
                }
            }
            MBoxSDK.ConfigSDK.tagCallSourceRule CallSourceRule = new MBoxSDK.ConfigSDK.tagCallSourceRule();
            CallSourceRule.callSourceIndex = model.CallingOrigID;
            CallSourceRule.seviceType = model.i_ServerType;  //默认1不限
            CallSourceRule.minReceiveNumLength = model.i_MinReLength;  //0;
            b = MBoxSDK.ConfigSDK.MBOX_CreateCallSourceRule(Global.Params.BoxHandle, CallSourceRule);
            if (b) new DB_Talk.BLL.m_CalinglSourceRule().Add(model);
            return b;

        }