发票编号自动化 [英] Invoice Number Automation
问题描述
嗨
我正在开发一个用于发票管理的网站,我必须显示一个文本框发票编号,但必须是自动生成的,发票编号的格式是2011SCL001-DO.
< tag>
2011SCL001-DO -2011 (当年) + SCL (另一个文本框的值)+ 001-DO (基于数据库记录数)
2011SCL002-DO
2011SCL003-DO
------------
------------
您能否建议如何为此使用C#进行编码
降级
Lancy
Hi
I am doing a website for Invoice Management i have to display a TextBox Invoice No but must be auto generated,format for invoice no is 2011SCL001-DO.
<tag>
2011SCL001-DO -- 2011 (currentyear) + SCL(value of another text box) + 001-DO(in Database based on the number of record)
2011SCL002-DO
2011SCL003-DO
------------
------------
Could you please advice how to code in c# for this
Regrads
Lancy
推荐答案
假设recordnumber
是数据库ID,而txtbox1
是您的文本框:
Assumingrecordnumber
is the database ID andtxtbox1
is your textbox :
string invoicenumber = "" + DateTime.Now.Year + txtbox1.Text + recordnumber + "-DO";
注意:您的记录数为3位,这将在999张发票后溢出 [坏主意]
NOTE : your record number is 3 digits which will overflow after 999 invoices [bad idea]
尝试此,
该代码用于生成下面提到的ID系列
R20110001
R20110002
R20110003
.......
....
Try this one,
This code used to generates the series of Ids that have mentioned below
R20110001
R20110002
R20110003
.......
....
private String GenerateReqID()
{
String MaxReqID;
int No;
StringBuilder RequestID = new StringBuilder("R" + DateTime.Now.Year.ToString());
MaxReqID = objAdmin.GetMaxReqID();
if (MaxReqID == "-1")
{
return RequestID.Append("00001").ToString() ;
}
No = Convert.ToInt32(MaxReqID.Substring(5));
No++;
if (No.ToString().Length == 1)
{
RequestID.Append( "0000"+No.ToString());
}
else if (No.ToString().Length == 2)
{
RequestID.Append("000" + No.ToString());
}
else if (No.ToString().Length == 3)
{
RequestID.Append("00" + No.ToString());
}
else if (No.ToString().Length == 4)
{
RequestID.Append("0" + No.ToString());
}
return RequestID.ToString();
}
这篇关于发票编号自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!