为了账号安全,请及时绑定邮箱和手机立即绑定

一个批量处理数组的方法

标签:
测试

一个批量处理数组的方法

#region Send MobileMessage By userList 
        /// <summary>
        /// Send MobileMessage By userList 
        /// Tony 2007-05-31
        /// <param name="site">Site</param>
        /// <param name="lng">lng</param>
        /// <param name="UserList">userList</param>
        /// <param name="SendContent">SendContent</param>
        /// <param name="MobileSource">1为PassPort,1为Message</param>
        public static  void SendToMobileByUserList(string site,string lng,string [] UserList,string SendContent,short MobileSource)
        {
            if(UserList ==null || UserList.Length==0 )
            {return;}
            else
            {
                if(IsLoginWithSite(site.Trim()))
                {
                    try
                    {
                        #region 定义变量
                        SendHistory s;
                        StringBuilder sb = new StringBuilder();
                        //组内计数
                        int LevelCount=0;
                        //数组长度
                        int userLen=UserList.Length;
                        string temp1 = string.Empty;
                        //当前组序号
                        int CurrentLevel=0;
                        //总的组数(取整) such as 8/3=2
                        //MaxBatchMobileNumber为外部public Vars,每批处理的数量
                        int MaxLevel=userLen/MaxBatchMobileNumber;
                        PassPort.User2007.Framework.Components.User2007 ur;
                        PassPortWebService pws=new PassPortWebService();
                        MobileMessageSet m;
                        string m1;
                        #endregion
                        foreach(string u in UserList)
                        {
                            if(u==null || u.Trim().Length==0)
                            {
                                //组内计数加一
                                LevelCount++;
                                continue;
                            }
                            #region 获取一串手机号码
                            switch (MobileSource)
                            {
                                case 1:
                                    #region 从Passport获取号码
                                    ur=pws.GetUser2007(u,lng);
                                    if(ur!=null  &&  ur.Mobile!=null)  
                                    {
                                        m1=string.Empty;
                                        m1=GetMobileStartWith13(ur.Mobile.Trim());
                                        if(m1.Length>10)
                                        {sb.Append(m1+",");}
                                    }
                                    ur=null;
                                    #endregion
                                    break;
                                case 2:
                                    #region 从短信提醒设置获取号码
                                    m=SMS.MobileMessageSet.Framework.Data.DataDTOProvider.MobileMessageSetSelectByLoginID(0,u,lng);
                                    if(m!=null && m.ToMobile!=null )
                                    {
                                        m1=string.Empty;
                                        m1=GetMobileStartWith13(m.ToMobile);
                                        if(m1.Length>10)
                                        {sb.Append(m1+",");    }
                                    }
                                    m=null;
                                    #endregion
                                    break;
                                default:
                                    #region 从Passport获取号码
                                    ur=pws.GetUser2007(u,lng);
                                    if(ur!=null  &&  ur.Mobile!=null)  
                                    {
                                        m1=string.Empty;
                                        m1=GetMobileStartWith13(ur.Mobile.Trim());
                                        if(m1.Length>10)
                                        {sb.Append(m1+",");}
                                    }
                                    ur=null;
                                    #endregion
                                    break;
                            }
                            //组内计数加一
                            LevelCount++;
                            #endregion
                            #region 发送一批号码
                            
                            if(LevelCount==userLen && LevelCount<MaxBatchMobileNumber)
                            {
                                #region 用户数量小于批数量
                                temp1=sb.ToString();                                
                                if(temp1.EndsWith(","))
                                {
                                    temp1=temp1.Remove(temp1.Length-1,1);
                                }
                                int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                #region 发送成功后写入数据库
                                if(bRtn==0)
                                {
                                    s=new SendHistory();
                                    s.MessageID=-100;
                                    s.Status=0;
                                    lng=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime=DateTime.Now;
                                    s.F1=0;
                                    s.F2=0;
                                    s.F3=site+"-"+lng;
                                    s.F4="";
                                    s.UpdateTime=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s=null;
                                }
                                #endregion
                                #region 完成后清零
                                sb=new StringBuilder();
                                temp1=string.Empty;
                                LevelCount=0;
                                #endregion
                                #endregion
                            }
                            else if (LevelCount == MaxBatchMobileNumber)
                            {
                                #region 刚好一批
                                temp1=sb.ToString();                                
                                if(temp1.EndsWith(","))
                                {
                                    temp1=temp1.Remove(temp1.Length-1,1);
                                }
                                int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                #region 发送成功后写入数据库
                                if(bRtn==0)
                                {
                                    s=new SendHistory();
                                    s.MessageID=-100;
                                    s.Status=0;
                                    lng=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime=DateTime.Now;
                                    s.F1=0;
                                    s.F2=0;
                                    s.F3=site+"-"+lng;
                                    s.F4="";
                                    s.UpdateTime=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s=null;
                                }
                                #endregion
                                #region 完成后清零
                                sb=new StringBuilder();
                                temp1=string.Empty;
                                LevelCount=0;
                                //当前组数加一
                                CurrentLevel++;
                                #endregion
                                #endregion
                            }
                            else if(LevelCount<MaxBatchMobileNumber   && (userLen%MaxBatchMobileNumber)==LevelCount && MaxLevel==CurrentLevel)
                            {
                                #region 最后一批
                                temp1=sb.ToString();                                
                                if(temp1.EndsWith(","))
                                {
                                    temp1=temp1.Remove(temp1.Length-1,1);
                                }
                                int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                #region 发送成功后写入数据库
                                if(bRtn==0)
                                {
                                    s=new SendHistory();
                                    s.MessageID=-100;
                                    s.Status=0;
                                    lng=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime=DateTime.Now;
                                    s.F1=0;
                                    s.F2=0;
                                    s.F3=site+"-"+lng;
                                    s.F4="";
                                    s.UpdateTime=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s=null;
                                }
                                #endregion
                                #region 完成后清零
                                sb=new StringBuilder();
                                temp1=string.Empty;
                                LevelCount=0;
                                #endregion
                                #endregion

                            }
                            #endregion
                        }
                    }
                    catch //(Exception ex)
                    {
                        return;
                    }
                }
            }
        }
                
        #endregion

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消