如何设计用过一次就废弃的号码 就像是手机充值 如何设计用过一次就废弃的号码 就像是手机充值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果有网卡就用guid,不用担心重复的问题 我们的应用还是自定义规则生成序列号的,guid生成的太“难看” 如果自定义格式,要求生成随机号码,系统确需要保证100%正确不出错时,只能生成一个号码,加上标志列,用过的做上标志。但效率上是很郁闷的,每次生成时都要确保此号码没有生成过,当号码多到一定程序,扫描表要花N长时间。》》呵呵,开始我也郁闷过一段时间,你有没有试过作为PK?PK重复异常的捕捉出奇的快public class UBISerials { public static void MakeSerials(int num,MyRandom rnd,string batchid) { //递归调用 int ierr=InsertSerials(num,rnd,batchid); if(ierr>0) MakeSerials(ierr,rnd,batchid); else { SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"])); SqlCommand cmd=new SqlCommand("sp_SerialBatchState",conn); //CREATE PROCEDURE sp_batchstate //@batchid nvarchar(50) //as //update batch set batch_state=0 where batch_id=@batchid //GO cmd.CommandType=CommandType.StoredProcedure; SqlParameter parm1=new SqlParameter("@batchid",SqlDbType.VarChar,50); parm1.Value=batchid; cmd.Parameters.Add(parm1); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } public static int ResetNumber(string batchid) { SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"])); SqlCommand cmd=new SqlCommand("sp_SerialsNumberReset",conn); cmd.CommandType=CommandType.StoredProcedure; SqlParameter parm1=new SqlParameter("@batchid",SqlDbType.VarChar,50); parm1.Value=batchid; cmd.Parameters.Add(parm1); SqlParameter parm2=new SqlParameter("@notdonum",SqlDbType.Int); parm2.Direction=ParameterDirection.Output; cmd.Parameters.Add(parm2); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return (int)cmd.Parameters[1].Value; } public static int InsertSerials(int num,MyRandom rnd,string batchid) { int ierr=0; SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"])); SqlCommand cmd=new SqlCommand("sp_SerialAdd",conn); //CREATE PROCEDURE sp_addkey //@key nvarchar(50),@batchid nvarchar(50) //as //insert into keys (keys_key,keys_batch_id)values(@key,@batchid) //GO cmd.CommandType=CommandType.StoredProcedure; SqlParameter parm1=new SqlParameter("@key",SqlDbType.VarChar,50); SqlParameter parm2=new SqlParameter("@batchid",SqlDbType.VarChar,50); parm2.Value=batchid; cmd.Parameters.Add(parm1); cmd.Parameters.Add(parm2); conn.Open(); for(int i=0;i<num;i++) { try { parm1.Value=rnd.GetRandomNum(); cmd.ExecuteNonQuery(); } catch { ierr++; } } conn.Close(); return ierr; } } 晕 杂这么复杂列?用GUID 用过就丢了那有这么多麻烦事情? 用随机数经过一些简单的算法生成序列号存到sql里,用过一个就标记一下,比如给这条数据的used标记true 天啊 当然是用guid了 @_@ 最简单就是加一个字段就ok了啊,used,没使用就0,使用就1啊,这不就ok了 请教高手,静态页面如何实现登陆!! 筛选 在内容页给母板页的viewstate赋值的问题。 有什么办法可以获得远程用户网卡的的MAC地址,这些代码不能用啊? 如何生成pdf文件??? 急急急!!!请进!! MVC这个框架不错! 请问在怎样在XP与SQL个人版相连接! 在线等待,为什么Requiredfieldvalidator1控件不能显示(我把它的TEXT属情设置为*),启动之后,*显示不出来。请大家帮助,谢谢! 不知道那里出错,数据库写入不了,请高手帮忙下! 一个关于怎么调用用户自定义控件的问题 asp.net能不能控制显示字数,谢谢啦,在线等。就剩十分了
》》
呵呵,开始我也郁闷过一段时间,你有没有试过作为PK?PK重复异常的捕捉出奇的快
public class UBISerials
{
public static void MakeSerials(int num,MyRandom rnd,string batchid)
{
//递归调用
int ierr=InsertSerials(num,rnd,batchid);
if(ierr>0)
MakeSerials(ierr,rnd,batchid);
else
{
SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"]));
SqlCommand cmd=new SqlCommand("sp_SerialBatchState",conn);
//CREATE PROCEDURE sp_batchstate
//@batchid nvarchar(50)
//as
//update batch set batch_state=0 where batch_id=@batchid
//GO
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter parm1=new SqlParameter("@batchid",SqlDbType.VarChar,50);
parm1.Value=batchid;
cmd.Parameters.Add(parm1);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
} } public static int ResetNumber(string batchid)
{
SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"]));
SqlCommand cmd=new SqlCommand("sp_SerialsNumberReset",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter parm1=new SqlParameter("@batchid",SqlDbType.VarChar,50);
parm1.Value=batchid;
cmd.Parameters.Add(parm1);
SqlParameter parm2=new SqlParameter("@notdonum",SqlDbType.Int);
parm2.Direction=ParameterDirection.Output;
cmd.Parameters.Add(parm2);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
return (int)cmd.Parameters[1].Value;
} public static int InsertSerials(int num,MyRandom rnd,string batchid)
{
int ierr=0;
SqlConnection conn=new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["conn"]));
SqlCommand cmd=new SqlCommand("sp_SerialAdd",conn);
//CREATE PROCEDURE sp_addkey
//@key nvarchar(50),@batchid nvarchar(50)
//as
//insert into keys (keys_key,keys_batch_id)values(@key,@batchid)
//GO
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter parm1=new SqlParameter("@key",SqlDbType.VarChar,50);
SqlParameter parm2=new SqlParameter("@batchid",SqlDbType.VarChar,50);
parm2.Value=batchid;
cmd.Parameters.Add(parm1);
cmd.Parameters.Add(parm2);
conn.Open();
for(int i=0;i<num;i++)
{
try
{
parm1.Value=rnd.GetRandomNum();
cmd.ExecuteNonQuery();
}
catch
{
ierr++;
}
}
conn.Close();
return ierr;
}
}
用GUID 用过就丢了那有这么多麻烦事情?