string gcdh = Request["gcdh"];
string rqdh = Request["rqdh"];
string sbh = Request["sbh"];
string wlbm = Request["wlbm"];
string lsh = Request["lsh"];
string jyh = Request["jyh"];
string qz = Request["qz"];
string sl = Request["sl"];
string totalcontent;
string generateCodeContet;
if (HelperComm.IsNumberic(sl) == true && HelperComm.IsNumberic(lsh) == true)//判断是否是数字 如果是数字返回ture
{
string mYear = Convert.ToDateTime(rqdh).Year.ToString();
string mMonth = Convert.ToDateTime(rqdh).Month.ToString();
string mDay = Convert.ToDateTime(rqdh).Day.ToString();
string year = "";
if (mYear == "2015")
{
year = "A";
}
else if (mYear == "2016")
{
year = "B";
}
else if (mYear == "2017")
{
year = "C";
}
else if (mYear == "2018")
{
year = "D";
}
DateATranscoding datCode = (from d in db.DateATranscodings
where d.monthM == mMonth && d.monthDay == mDay
select d).FirstOrDefault();
int exceptNumber = Convert.ToInt32(datCode.exceptNumber);
int plusNumber = Convert.ToInt32(datCode.plusNumber);
int sl_i = Convert.ToInt32(sl);
for (int i = 0; i < sl_i; i++)
{
int lsh_i = Convert.ToInt32(lsh);
lsh_i = lsh_i + i;
//根据加密因子 计算校验码
//加密校验码
//如果流水号是 1232111 ,除因子是9,加因子是4, 则加密校验码为 05 计算方法见下
//如 1232111/9=136901.22222 保留小数点前两位 01 ,加上4 ,即为05
//如果前俩为是大于91 91+9 = 100 取值为 00
string jmyz = "";
if (lsh_i / exceptNumber + plusNumber >= 100)
{
if (lsh_i / exceptNumber >= 100)
{
string lins = (lsh_i / exceptNumber).ToString();
lins = lins.Substring(lins.Length - 2, 2);
jmyz = (Convert.ToInt32(lins) + plusNumber).ToString("00");
}
else//包括90-100
{
string lins = (lsh_i / exceptNumber + plusNumber).ToString();
lins = lins.Substring(lins.Length - 2, 2);
jmyz = Convert.ToInt32(lins).ToString("00");
}
}
else
{
jmyz = (lsh_i / exceptNumber + plusNumber).ToString("00");
}
totalcontent = "";
totalcontent = qz + gcdh + year + datCode.monthDayCode + sbh + wlbm + lsh_i.ToString("0000000") + jmyz;
generateCodeContet = gcdh + year + datCode.monthDayCode + sbh + wlbm + lsh_i.ToString("0000000") + jmyz;
}
------解决思路----------------------
--判断是否存在存储过程CTwodimensionalcode,若存在就删除
if OBJECT_ID('CTwodimensionalcode','p') is not null
begin
drop proc CTwodimensionalcode
end
GO
--创建存储过程CTwodimensionalcode
create procedure CTwodimensionalcode
(
@gcdh INT,--取值1或者2
@rqdh VARCHAR(20),--取值3位数的字母
@sbh VARCHAR(20),--取值字母A-Z
@wlbh VARCHAR(20),--取值00001-99999 特别要求5位,没有5位前面补0补到5位
@lsh INT,--取值0000000-9999999 特别要求7位,没有7位前面补0补到7位 流水号
@jyh INT,--00-99 特别要求2位,没有俩位前面补0补到7位
@qz VARCHAR(200),--前缀网址http:www.baidu.com
@sl INT--数量 取值小于9999999
)
AS
BEGIN
declare @i INT,
@add int
SET @i=0
while @i<=@sl AND @lsh < 9999999
BEGIN
IF(len(@lsh)<7)
BEGIN
SET @add=7-len(@lsh)
SET @lsh=Replicate('0',@add)+ltrim(@lsh)
SET @lsh = @lsh + 1
END
ELSE if(len(@lsh)=7)
BEGIN
SET @lsh = @lsh + 1
end
--向Twodimensionalcode_A表中插入数据
insert into Twodimensionalcode_A(generateCode)
SELECT @gcdh+@rqdh+@sbh+@wlbh+@lsh+@jyh
set @i+=1
end
END
go