我想一个订单号可以买N张点卡,但是N张点卡的卡密当然是N个,那么应该建个数组来存储卡密,因为我嫌麻烦,没有专门用个表来存卡密,所以就用用个随机函数的方法来给予卡密,大家帮我改改下面的代码。实现的结果:一个订单号可以包含 N 张点卡的卡密,当我在购物车中点击查看卡密时,可以弹出 N 张点卡的卡密,而不是只有一个卡密。CardClose cc=new CardClose();
cc=CardCloseManager.GetCardCloseByOrderNo(Session["OrderNo"].ToString()); // 卡密的对象实例化 cc.OrderNo = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + cs.ProId.ToString(); // 订单号
cc.CardNo =this.RandomNum(10); //点卡卡号
cc.CardPsw = this.RandomNum(8); // 点卡密码
cc.Validity = DateTime.Now.AddYears(2).ToString("yyyy年MM月dd日"); // 点卡有效期 CardCloseManager.AddCardClose(cc); public string RandomNum(int len) // 获得卡密的方法
{
string strSep = ",";
string strChar = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,-";
string intChar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6";
char[] chrSep = strSep.ToCharArray();
char[] intSep = strSep.ToCharArray();
string[] aryChar = strChar.Split(chrSep, strChar.Length);
string[] aryInt = intChar.Split(intSep, intChar.Length);
string guid = System.Guid.NewGuid().ToString();
for (int i = 0; i < aryChar.Length; i++)
{
guid = guid.Replace(aryChar[i], aryInt[i]);
}
return guid.Substring(0, len);
}
cc=CardCloseManager.GetCardCloseByOrderNo(Session["OrderNo"].ToString()); // 卡密的对象实例化 cc.OrderNo = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + cs.ProId.ToString(); // 订单号
cc.CardNo =this.RandomNum(10); //点卡卡号
cc.CardPsw = this.RandomNum(8); // 点卡密码
cc.Validity = DateTime.Now.AddYears(2).ToString("yyyy年MM月dd日"); // 点卡有效期 CardCloseManager.AddCardClose(cc); public string RandomNum(int len) // 获得卡密的方法
{
string strSep = ",";
string strChar = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,-";
string intChar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6";
char[] chrSep = strSep.ToCharArray();
char[] intSep = strSep.ToCharArray();
string[] aryChar = strChar.Split(chrSep, strChar.Length);
string[] aryInt = intChar.Split(intSep, intChar.Length);
string guid = System.Guid.NewGuid().ToString();
for (int i = 0; i < aryChar.Length; i++)
{
guid = guid.Replace(aryChar[i], aryInt[i]);
}
return guid.Substring(0, len);
}
{
string Vchar = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p" + ",q,r,s,t,u,v,w,x,y,z";
string[] VcArray = Vchar.Split(new Char[] { ',' });
string VNum = "";
int temp = -1; Random rand = new Random(); for (int i = 1; i < VcodeNum + 1; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
} int t = rand.Next(35); //生成随即说的范围 如果Next(9) 只生成随即数字,Next(35)生成数字和字符
if (temp != -1 && temp == t)
{
return RandomNum(VcodeNum);
}
temp = t;
VNum += VcArray[t];
}
return VNum;
}
所以在for循环里取随机数是不行的
点卡张数的变量是:number 根据点卡的张数来判断生成卡密的组数