系统架构,用于计算不同价格表中的总价。 [英] System architecture for calculate total price from different price lists.
问题描述
大家好>
我对系统架构有疑问。
我想做什么是每小时的数据库价格表,例如:
价格|从小时|到小时
1 | 07:00 | 10:00
2 | 10:00 | 15:00
3 | 15:00 | 22:00
之后我会收到一些小时例如:
from hour |到小时
08:00 | 20:00
之后我需要的是按价格列表总计小时数的算法,例如:
总和支付:(02:00 *(价格表1))+(05:00 *(价目表2))+(07:00 *(价目表3))
问题是计算价格的最佳方法
*什么样的功能
*什么的功能需要接收
*在什么变量类型中我应该存储价格表以便在以后的总和过程中检查它。
有人有一个想知道VB.NET中有什么更好的方法吗?
谢谢。
Hello to everyone
I have a question about system architecture.
What i want to do is database price list per hour for example:
Price | from hour | to hour
1 | 07:00 | 10:00
2 | 10:00 | 15:00
3 | 15:00 | 22:00
after that i will receive some hour for example:
from hour | to hour
08:00 | 20:00
after that what i need is algorithm for sum the total hours by price lists for example:
sum to pay : (02:00 * (price list 1)) + (05:00 * (price list 2)) + (07:00 * (price list 3))
The question is what the best way to calculate the price
* what kind of function
* what the function needs to receive
* In what variable type should i store the price list to check it later in sum process.
Someone have an idea what the better way to do it in VB.NET ?
Thanks.
推荐答案
这是相当的简单:
1.声明变量以获得总额
2.循环收集价格
  ;  一个。在循环中计算差异 [ ^ ]小时,然后相乘价格结果
b。计算总额
这就是全部!
It's quite simple:
1. declare variable to get total
2. loop through the collection of prices
a. inside a loop calculate difference[^] in hours, then multiply the result by price
b. calculate total
That's all!
Public Function sumByPriceList(ByVal startTime As Date, ByVal endTime As Date) As Single
'Getting PricelistHours
Dim pricelistCollection As DataTable = getPriceListCollection()
Dim cost As Double
Dim tempEntryTime As DateTime = startTime
Dim dr As DataRow
While tempEntryTime < endTime
For i As Integer = 0 To pricelistCollection.Rows.Count - 1
dr = pricelistCollection.Rows(i)
Dim entryTime As DateTime = dr("FromHour")
Dim exitTime As DateTime = dr("ToHour")
If (tempEntryTime.Hour >= startTime.Hour And endTime.Hour >= exitTime.Hour) Then
cost += CalcPrice(tempEntryTime, exitTime)
tempEntryTime = exitTime
ElseIf (tempEntryTime.Hour >= entryTime.Hour And endTime.Hour < exitTime.Hour) Then
cost += CalcPrice(tempEntryTime, endTime)
tempEntryTime = endTime
End If
Next
End While
Return cost
End Function
这篇关于系统架构,用于计算不同价格表中的总价。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!