string date = DateTime.Now.ToString("yyyyMMdd"); Random r = new Random(); date = date + r.Next(0, 9); string OrderNo = "RK" + date.PadRight(10, '0'); Response.Write(OrderNo);
using System; using System.Collections.Generic; using System.Text; using System.IO; namespace tttttttt { class Program { public static string transfer(int i) {
string order = ""; if (i >= 1000) { order = i.ToString(); return order; } else if (i >= 100) { order = "0" + i.ToString(); return order; } else if (i >= 10) { order = "00" + i.ToString(); return order; } else { order = "000" + i.ToString(); return order; } } static void Main(string[] args) { FileStream fl = new FileStream(@"d:\shuju.txt", FileMode.Create, FileAccess.Write); StreamWriter wl = new StreamWriter(fl); string date = string.Empty ; for (int i = 0; i < 10000; i++) { string order = transfer(i); date =DateTime.Now.ToString("yyyyMMdd"); date += order; wl.WriteLine(date);//需要的数据写到了D盘下的shuju.txt } wl.Close(); fl.Close(); Console.Read(); }
后面由系统产生随机数补上。。 注意check Dup。
Random r = new Random();
date = date + r.Next(0, 9);
string OrderNo = "RK" + date.PadRight(10, '0');
Response.Write(OrderNo);
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace tttttttt
{
class Program
{
public static string transfer(int i)
{
string order = "";
if (i >= 1000)
{
order = i.ToString();
return order;
}
else if (i >= 100)
{
order = "0" + i.ToString();
return order;
}
else if (i >= 10)
{
order = "00" + i.ToString();
return order;
}
else
{
order = "000" + i.ToString();
return order;
}
} static void Main(string[] args)
{
FileStream fl = new FileStream(@"d:\shuju.txt", FileMode.Create, FileAccess.Write);
StreamWriter wl = new StreamWriter(fl);
string date = string.Empty ;
for (int i = 0; i < 10000; i++)
{
string order = transfer(i);
date =DateTime.Now.ToString("yyyyMMdd");
date += order;
wl.WriteLine(date);//需要的数据写到了D盘下的shuju.txt
}
wl.Close();
fl.Close();
Console.Read(); }
}
}
select @id='RK'+@convert(varchar,getdate(),112)+right(1001+isnull(right(max(id),3),0),3)
from tb
新增一条时,查询当天最大编号,+1作为新的编号