一个批量处理数组的方法
#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
共同学习,写下你的评论
评论加载中...
作者其他优质文章