每天重启账号..... [英] Restart Bill Number every day.....
问题描述
那里,
i我正在创建餐馆软件..他们需要按日期帐单编号。
每天帐单编号应该从Bill No:1
和今天一样是2015年9月18日。今天总账单产生了1,2,3,4,5,6。
现在如果时间是9月19日上午12点,我想在文本框中输入1个号码/2015.
将最后一个账单号码与其自己的日期一起存储。然后,如果您需要新的帐单编号,请将当前日期与最后一个帐单编号进行比较。如果它们相同,那么新账单号=最后账单号+ 1
,否则新账单numbwer = 1
。
如果您希望在白天更改时立即更新
TextBox
,请执行以下操作。使用 System.Windows.Threading; // 参考WindowsBase
// 类声明
private readonly DispatcherTimer timer = new DispatcherTimer();
private int lastDay;
private void timer_Tick( object sender,EventArgs e)
{
if (DateTime.Now.Date.Day!= 这 .lastDay)
{
this .lastDay = DateTime.Now.Date.Day;
setBillTextBoxToOne(); // 您的更新TextBox方法
}
}
// 在类构造函数中
this .timer.Interval = TimeSpan.FromSeconds( 15 );
this .timer.Tick + = this .timer_Tick;
this .lastDay = DateTime.Now.Date.Day;
此 .timer.Start();
如果账单号仅为报告或收据打印和账单信息所需的信息不会被删除然后我就不会打扰它了。
如果你得到它那么你就不会冒风险意外地将相同的数字写入数据库两次(或更多次)也不必重置预先指定的数字,如果没有创建账单,例如,当客户抱怨并且经理通过以下方式注销成本时赔偿方式。
名义表...
创建 表 bill
(
issueDate datetime 不 null
约束 df_bill_issued 默认 getdate(),
- 按发布日期对所有帐单进行分组的计算列。
issueDay as floor(cast(issueDate as float )),
totalNoTax < span class =code-keyword> decimal ( 5 , 2 )不 null ,
taxRate decimal (< span class =code-digit> 3 , 2 )不 null
约束 df_bill_tax 默认( 0 )
)
套装一些点头数据......
插入 进入< /跨度> bill(issueDate,totalNoTax) values (getdate(), 0 。 75 )
insert into bill(issueDate,totalNoTax) values (dateadd(hh, 1 ,getdate()), 1 。 50 )
insert 进入 bill(issueDate,totalNoTax)值(dateadd(hh, 2 ,getdate() ), 2 。 50 )
insert into bill(issueDate,totalNoTax) values (dateadd(hh, 3 ,getdate()), 3 。 50 )
insert into bill(issueDate,totalNoTax)值(dateadd(hh, 4 ,getdate()), 4 。< span class =code-digit> 50 )
编写查询以获取包含派生账单的账单信息号码..
set ANSI_WARNINGS OFF - Squelch null抑制警告。
选择
count(counter.issueDay)+1 as billNumber,
bill.issueDate,
bill.totalNoTax,
bill.taxRate
from bill
left join (选择 issueDay,issueDate 从 bill) as counter
on counter.issueDay = bill.Issueday
和 counter.issueDate< bill.IssueDate
group by
bill.issueDate,
bill .totalNoTax,
bill.taxRate
- billNumber issueDate totalNoTax
- ----------- ----------------------- ------------ ---------------------------
- 1 2015-09-18 20:56:38.563 0.75
- 2 2015-09-18 21:56:38.580 1.50
- 3 2015-09-18 22:56:38.583 2.50
- 4 2015-09-18 23:56:38.583 3.50
- 1 2015-09-19 00:56:38.587 4.50
如果你是在你需要重复访问账单号码的地方做很多工作然后考虑将查询转换为视图...
创建 视图 indexedBill
as
选择
count(counter.issueDay)+1 as billNumber,
bill.issueDate,
bill.totalNoTax,
bill.taxRate
from bill
left join ( select issueDay,issueDate < span class =code-keyword> from bill) as counter
on counter.issueDay = bill.Issueday
和 counter.issueDate< bill.IssueDate
group by
bill.issueDate,
bill .totalNoTax,
bill.taxRate
...然后假装你有一张新桌子。例如......
选择 * 来自 indexedBill 其中 billNumber = 1
- billNumber issueDate totalNoTax
- 1 2015-09-18 21:02:07.037 0.75
- 1 2015-09-19 00:02:07.040 3.50
< pre lang =SQL> 选择 * 来自 indexedBill 其中 issueDate< ' 2015年9月18日23:59:00'
- billNumber issueDate totalNoTax
- < span class =code-comment> 1 2015-09-18 21:02:07.037 0.75
- 2 2015-09-18 22:02:07.040 1.50
- 3 2015-09-18 23:02:07.040 2.50
如果你真的必须在账单时显示账单号码创建一个新的账单(为什么?)然后如果没有多少并发账单创建,则沿着以下行的查询应该是足够的。
选择 max(billNumber)+ 1 from indexedBill
其中 issueDate = floor(cast(getdate() as as float ))
hi there,
i am creating restaurant software.. they need datewise bill number.
every day bill number should be start from Bill No : 1
Like today is 9/18/2015. today total bill generated 1,2,3,4,5,6.
now i want 1 number in textbox if time is 12:00 AM on 9/19/2015.
Store the last bill number together with its own date. Then, if you need a new bill number compare the current date with last bill number's one. If they are the same thennew bill number = last bill number + 1
, otherwisenew bill numbwer = 1
.
If you wish to update the
TextBox
as soon as the day changes, do something like this.using System.Windows.Threading;//reference WindowsBase //Inside the class declaration private readonly DispatcherTimer timer = new DispatcherTimer(); private int lastDay; private void timer_Tick(object sender, EventArgs e) { if (DateTime.Now.Date.Day!=this.lastDay) { this.lastDay = DateTime.Now.Date.Day; setBillTextBoxToOne() ;//Your update TextBox method } } //in the class constructor this.timer.Interval = TimeSpan.FromSeconds(15); this.timer.Tick += this.timer_Tick; this.lastDay = DateTime.Now.Date.Day; this.timer.Start();
If the bill number is only needed for reporting or receipt printing and bill information isn't deleted then I wouldn't bother storing it.
If you derive then it you don't run the risk of accidentally writing the same number twice (or more times) to the DB nor do you have to reset a pre-assigned number if a bill doesn't get created when, for example, a customer complains and the manager writes off the cost by way of compensation.
A notional table...
create table bill ( issueDate datetime not null constraint df_bill_issued default getdate(), -- A computed column that groups all bills by issue date. issueDay as floor(cast(issueDate as float)), totalNoTax decimal(5,2) not null, taxRate decimal(3,2) not null constraint df_bill_tax default(0) )
Set up some noddy data...
insert into bill(issueDate, totalNoTax) values (getdate(), 0.75) insert into bill(issueDate, totalNoTax) values (dateadd(hh, 1, getdate()), 1.50) insert into bill(issueDate, totalNoTax) values (dateadd(hh, 2, getdate()), 2.50) insert into bill(issueDate, totalNoTax) values (dateadd(hh, 3, getdate()), 3.50) insert into bill(issueDate, totalNoTax) values (dateadd(hh, 4, getdate()), 4.50)
Write a query to get the bill information with a derived bill number..
set ANSI_WARNINGS OFF -- Squelch null suppression warning. select count(counter.issueDay)+1 as billNumber, bill.issueDate, bill.totalNoTax, bill.taxRate from bill left join (select issueDay, issueDate from bill) as counter on counter.issueDay= bill.Issueday and counter.issueDate < bill.IssueDate group by bill.issueDate, bill.totalNoTax, bill.taxRate
-- billNumber issueDate totalNoTax -- ----------- ----------------------- --------------------------------------- -- 1 2015-09-18 20:56:38.563 0.75 -- 2 2015-09-18 21:56:38.580 1.50 -- 3 2015-09-18 22:56:38.583 2.50 -- 4 2015-09-18 23:56:38.583 3.50 -- 1 2015-09-19 00:56:38.587 4.50
If you are going to be doing a lot of work where you need repeated access to bill number then consider converting the query to a view...
create view indexedBill as select count(counter.issueDay)+1 as billNumber, bill.issueDate, bill.totalNoTax, bill.taxRate from bill left join (select issueDay, issueDate from bill) as counter on counter.issueDay= bill.Issueday and counter.issueDate < bill.IssueDate group by bill.issueDate, bill.totalNoTax, bill.taxRate
...then pretend you've got a new table. For example...
select * from indexedBill where billNumber = 1 -- billNumber issueDate totalNoTax -- 1 2015-09-18 21:02:07.037 0.75 -- 1 2015-09-19 00:02:07.040 3.50
select * from indexedBill where issueDate < '18 september 2015 23:59:00' -- billNumber issueDate totalNoTax -- 1 2015-09-18 21:02:07.037 0.75 -- 2 2015-09-18 22:02:07.040 1.50 -- 3 2015-09-18 23:02:07.040 2.50
And if you really must display a bill number when creating a new bill (why?) then a query along the following lines ought to be adequate if there isn't much concurrent bill creation.
select max(billNumber) + 1 from indexedBill where issueDate = floor(cast(getdate() as float))
这篇关于每天重启账号.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!