请教各位,现在我想打印产品流水号,流水号前面字符固定为ZKS-,后面为000000至999999,
即ZKS-000000至ZKS-999999,该如何写,麻烦大家了!
即ZKS-000000至ZKS-999999,该如何写,麻烦大家了!
解决方案 »
- 程序怎么实现这个功能
- 大家谁有p2p 文件下载的 源代码 例子啊 谢谢
- C#如何判断一个点是否在可拖动的对象范围内
- box到底执行哪些操作(汇编级解释)?
- C#成员名称不能与它们的封闭类型相同
- 急!急!急!请教一些小问题?关于相对路径获取的问题!
- C#写配置文件(XML),如法正常输出
- 如何制作黄历
- windows FORM 里datagrid双击问题
- 再问一个简单的,我想实现一下功能,怎么做?(内详)
- 在局域网中,如果一个客户端更新了服务器上数据库表m中的记录后,其它客户端如何及时知道表m被更改了?服务器能自动及时发出通知信息让客户端知道吗?
- 请问如何实现窗体透明控件不透明,比如桌面宠物那种窗体?
create TABLE test
(
codeID Int IDENTITY(1,1)
primary key(codeID)
)
select 'ZKS-' + right('000000'+ Convert(varchar(1000), codeID ),6) youCode from test
drop table test
create TABLE test
(
codeID Int IDENTITY(1,1),
value int
primary key(codeID)
)
insert into test (value) values(1)
insert into test (value) values(2)
insert into test (value) values(3)
insert into test (value) values(4)
select 'ZKS-' + right('000000'+ Convert(varchar(1000), codeID ),6) youCode from test
drop table test
create TABLE aaa
(
codeID Int IDENTITY(1,1),
value int
primary key(codeID)
)
go
insert into aaa (value) values(1)
insert into aaa (value) values(2)
insert into aaa (value) values(3)
insert into aaa (value) values(4)
goselect 'ZKS-' + right('000000'+ Convert(varchar(1000), codeID ),6) youCode from aaa
go
drop table aaa
go
/*创建表BillNo*/
if exists (select * from sysobjects where name='BillNo')
drop table BillNo
go
CREATE TABLE [dbo].[BillNo](
[BillName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,/*前缀字符串,如'ZKS-',*/
[CurrentNo] [int] NOT NULL,/*当前序号*/
[Length] [int] NOT NULL,/*后缀序号长度*/
CONSTRAINT [PK_BillNo] PRIMARY KEY CLUSTERED
(
[BillName] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
go
/*插入*/
insert into BillNo(BillName,CurrentNo,Length) values ('ZKS-',0,6)
go/*创建存储过程*/
if exists (select * from sysobjects where name='GetBillNo' and type='p')
drop procedure GetBillNo
gocreate procedure GetBillNo
@BillName nvarchar(50)/*前缀字符串,如'ZKS-',这要和BillNo表中的BillName相对应*/
as declare @currentno int
declare @currentstring nvarchar(10)
declare @NoLength int
/*获得当前号码*/
select @currentno=CurrentNo,@NoLength=Length from BillNo where BillName=@BillName
/*如果BillNo表存在前缀为@BillName*/
if(@currentno is not null)
begin
set @currentno=@currentno+1
update BillNo set CurrentNo=@currentno where BillName=@BillName
end
/*BillNo表不存在前缀为@BillName,永远返回0*/
else set @currentno=0set @currentstring=convert(nvarchar(10[code=C#]),@currentno)
while(len(@currentstring)<@NoLength)
set @currentstring='0'+@currentstring;
select @BillName+@currentstringgoexec GetBillNo 'ZKS-'[/code]
这种方法,复用性好一点,只要在BillNo表中添加不同的编码规则就可以了.你还可以对BillNo表进行扩展,如单据编号需要时间,你可以添加时间字段,然后修改上面的存储过程,反正思路是这样的.
set @currentstring=convert(nvarchar(10),@currentno)
while(len(@currentstring) <@NoLength)
set @currentstring='0'+@currentstring;
select @BillName+@currentstring as CurrentBillNogo exec GetBillNo 'ZKS-'
{
string returnStr = "";
returnStr = "000000" + codeID.ToString();
returnStr = returnStr.Substring((returnStr.Length - 7), (returnStr.Length - 1));
return returnStr; }sql的方法一样
理想中应该是这样:如codeID为6时,returnStr为000006;codeID为123时,returnStr为000123
///length是长度
public string GetID(int id,int length)
{
string strID =id.ToString();
strID=strID.PadLeft(length, '0');
return strID;
}
/// 获取固定长度数字字符串
/// </summary>
/// <param name="number">要格式化的数字</param>
/// <param name="length">格式化后字符串长度</param>
/// <returns></returns>
public static string GetString(int number, int length)
{
string result = number.ToString();
int len = result.Length;
for (int i = 0; i < length - len; i++)
{
result = "0" + result;
}
return result;
}
2.将转换后的数字加1。
3.设置新流水号"ZKS-"+ newInt.toString("#####0")。
4.将新流水号插入数据库。