在C#和SQL中生成帐单的最佳实践 [英] Best practice to generate bills in C# and SQL
问题描述
大家好,我正在使用WinForms和数据库,这些表格是关于销售物品。我想用每个特殊号码(Bill_no)存储每个销售。我的账单号码是ddmmyyy00000000将每天重置。可以。请帮帮我,我该怎么做?我还想在文本框中显示交易时的账单号码?
如果你有关于账单的建议你很满意。
我尝试了什么:
到目前为止我从数据库中获取增量值并操纵它的Sale Form以获得下一个值。但这个方法非常好非常低效和混乱。
Hello guys,I m working with WinForms and Database,The forms is about selling items.I want to store each sale with unique number(Bill_no).My idea about bill number is "ddmmyyy0000" 0000 will reset everyday.Can you please help me how can i do this? i also want to show bill number at time of transaction in textbox?
if you have suggestion about bill you are wellcome.
What I have tried:
So far i m getting incremental values from database and and manipulating it Sale Form for next value.But this method is very is very inefficient and disorganized.
推荐答案
为什么?只需使用IDENTITY字段(将自动增量)和DATE或DATETIME2列来存储日期 - 它更灵活,更易于维护,更适合法律和会计程序,两者都不认为它是好的想要有破碎的序列,因为可以在以后添加或删除物品/发票。
如果你真的需要日期和每日序列号,然后:
1)不要这样做ddmmyy:把它变成yyMMdd(或更好的yyyyMMdd),因为它们排序更好。
2)使用计算列从中生成它另外两列(您可以使用WHERE子句轻松获取当天项目,并使用日期的ROW_NUMBER函数获取序列号。然后将其重新连接到原始表格。
Why? Just use an IDENTITY field (which will autoincrement) and a DATE or DATETIME2 column to store the date - it's a lot more flexible, a lot easier to maintain, and fits better with legal and accounting procedure, neither of which thinks it is a good idea to have "broken sequences" because it's possible to add or remove items / invoices at a later date.
If you really need the date and the daily sequence number, then:
1) Don't do it ddmmyy: make it yyMMdd (or better yyyyMMdd) as they sort better.
2) Use a computed column to generate it from the two other columns (You can get "that day" items easily with a WHERE clause, and the sequence number with the ROW_NUMBER function for the date. Then JOIN that back to your original table.
这篇关于在C#和SQL中生成帐单的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!