如何使用ASP.NET C#生成发票号 [英] How to generate invoice number using ASP.NET C#
本文介绍了如何使用ASP.NET C#生成发票号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨...朋友们,
在我的网络应用程序中,我需要为客户生成发票,发票号应该是这样的:
120214/001例如。 mmddyy /序列号以三位数字开头
此发票号码。它的序列号总是增加1并且它始终是唯一的...
我如何生成这个或任何其他想法来生成发票号。请帮忙我...
谢谢...
Sunil Sharma
解决方案
这并不困难。唯一需要注意的是:
- 你需要存储你最后分配的发票号码(你可以使用数据库,如果你的应用程序已经拥有它,或者序列化,或者你喜欢的任何东西)保持此值持久)。
- 您必须检查相对于上次分配的发票号是否更改日期。在这种情况下,您必须将序列号重置为
1
。
其他的东西只是格式化问题。
从下面的sql中执行
声明 @ PrevReferenceNo < span class =code-keyword> varchar ( 50 )
声明 @ PrevMonth int
声明 @ PrevNo int
声明 @ ReferenceNo varchar ( 10 )
set @ PrevReferenceNo =(选择 ReferenceNo 来自 tbl_FuelConsumption 其中 FuelConsumptionID =(选择 MAX(FuelConsumptionID)来自 tbl_FuelConsumption))
set @ PrevMonth = SUBSTRING( @ PrevReferenceNo , 5 , 2 )
set @PrevNo = SUBSTRING( @ PrevReferenceNo , 7 , 4 )
如果( @ PrevMonth =月(GETDATE()))
开始
set @ ReferenceNo 跨度> =(CAST(年(GETDATE()) as varchar ( 10 ))+ RIGHT (' 00' + CAST(MONTH(GETDATE()) as varchar ( 10 )), 2 )+ RIGHT (' 0000' + CAST(( @ PrevNo + < span class =code-digit> 1 ) as varchar ( 4 )), 4 ))
end
其他
开始
设置 @ R. eferenceNo =(CAST(年(GETDATE()) as varchar ( 10 ))+ RIGHT (' 00' + CAST(MONTH(GETDATE()) as varchar ( 10 )), 2 )+ RIGHT (' 0000' + CAST(( 1 ) as varchar ( 4 ) ), 4 ))
end
我们有像年和月一样的syntex。您可以将其更改为月份和日期。
在您的发票类中:
1.创建自动生成的Id属性。如果您使用的是ORM,则可以将此Id参数作为数据库自动生成的属性。
2.创建一个只读的自发发票编号(字符串),它返回日期和Id的连接
Hi...Friends,
In my web application i have need to generate invoice for clients, Invoice no should be look like this :
120214/001 eg. mmddyy/serial number starting with three digits
this invoice no. always increase by 1 in it's serial number and it remains always unique...
How can i generate this, or any other idea for generating invoice no., Please help me...
Thanks...
Sunil Sharma
解决方案
That's not difficult. The only caveats are:
- You need to store your last assigned invoice number (you could use a database, if your application already have it, or serialization, or whatever you like to keep this value persistent).
- You have to check if date changed with respect to last assigned invoice number. In such a case you have to reset the serial number to
1
.
The other stuff is just a matter of formatting.
do it from sql like below
declare @PrevReferenceNo varchar(50) declare @PrevMonth int declare @PrevNo int declare @ReferenceNo varchar(10) set @PrevReferenceNo = (select ReferenceNo from tbl_FuelConsumption where FuelConsumptionID = (select MAX(FuelConsumptionID) from tbl_FuelConsumption)) set @PrevMonth = SUBSTRING(@PrevReferenceNo,5,2) set @PrevNo = SUBSTRING(@PrevReferenceNo,7,4) if(@PrevMonth = MONTH(GETDATE())) begin set @ReferenceNo = (CAST(YEAR(GETDATE())as varchar(10))+ RIGHT('00' + CAST(MONTH(GETDATE()) as varchar(10)),2) + RIGHT('0000' + CAST((@PrevNo + 1)as varchar(4)) ,4)) end else begin set @ReferenceNo = (CAST(YEAR(GETDATE())as varchar(10))+ RIGHT('00' + CAST(MONTH(GETDATE()) as varchar(10)),2) + RIGHT('0000' + CAST((1)as varchar(4)) ,4)) end
we have syntex like year and month. you can change that to month and days.
In your invoice class:
1. create an Id property that is autogenerated. If you are using an ORM you can have this Id parameter as a database auto-generated property.
2. create a read only propery Invoice number(string) which returns the concatanation of date and Id
这篇关于如何使用ASP.NET C#生成发票号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文