//用于产生新的一个UserCode private string getTicketCode(int length) { CommonFunction comFun = new CommonFunction(); string newCode = comFun.GetRandNumString(length); bool bExist = ExistTicketCode(newCode); if (bExist == false)//表示不存在该Code,则可以加入 { return newCode; } else { //循环100次,如果还不存在,则提示不能再生成了。 int flag = 0; //用于标记,循环100次后,是否有形成可用的ticketcode for (int i = 0; i < 100; i++) { newCode = comFun.GetRandNumString(length); if (ExistTicketCode(newCode) == false) { flag = 1; break; } } if (flag == 1) { return newCode; } else { return ""; } } }