如何在.net中生成发票号 [英] How to generate invoice number in .net
本文介绍了如何在.net中生成发票号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好b $ b
我需要生成和存储发票号码,格式为''E000001''
如何在VB.Net中执行此操作。请帮我一个代码逻辑或建议一个更好的方法。
感谢您的期待
Sri
Hi
I need to generate and store Invoice Numbers like in the format ''E000001''
How to do it in VB.Net. Please help me with a code logic or suggest a better approach.
Thanks in anticipation
Sri
推荐答案
这里有一些C#,但VB并没有太大的不同。
Here''s some C#, but the VB isn''t much different.
string s = System.String.Format ( "E{0:000000}" , 42 ) ;
or
System.Console.WriteLine ( "E{0:000000}" , 42 ) ;
我在记事本中写了这个所以我不知道它是否会编译,但它至少应该指向正确的方向。
I wrote this in notepad so i have no idea if it will even compile but it should at least point you in right direction.
//No Database Approach
int seedNum = 1;
char pad = '0';
private void Main()
{
for(int i=0; i < 10; i ++)
{
Console.WriteLine("E" + seedNum.ToString().padLeft(6,pad);
seedNum += 1;
}
}
private string GenerateInvNo()
{
return seedNum.ToString().PadLeft(6, pad);
}
// --------------------------------------------- ----------
//-------------------------------------------------------
//Database Approach
string ConnectionString = String.Format(@"Data Source = {0};User Id={1}; password={2}; Initial Catalog = {3};",
"DB_Server",
"DB_User",
"DB_Pass",
"DB_Name");
string query = "SELECT SeedNumber FROM YourTableName; UPDATE YourTableName SET SeedNumber = SeedNumber + 1";
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
SqlCommand queryCMD = new SqlCommand(query, connection);
int seedNum = (int)queryCMD.ExecuteScalar();
char pad = '0';
Console.WriteLine("E" + seedNum.ToString().padLeft(6,pad);
Sub generate_inv()
Dim id_tmp As String
Query = "select top 1 InoviceNo from Invoice order by InoviceNo desc"
cmd = New OleDbCommand(query, cn)
dr = cmd.ExecuteReader
If dr.HasRows = False Then
dr.Close()
id_tmp = "E000001"
Else
dr.Read()
id_tmp = Format(Mid(dr("InoviceNo"), 2, 6) + 1,"E00000#")
End If
dr.Close()
txtInvoice.Text = id_tmp
End Sub
这篇关于如何在.net中生成发票号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文