Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
syed shanu 24-Dec-14 2:43am    
You can do this in your Database and return the result.
best way is you can create a Storeprocedure and pass the parameter of your input and you can perform yout Sum to pay logic in your SP and return the final result.
[no name] 24-Dec-14 2:55am    
can you give me simple example ?
syed shanu 24-Dec-14 3:04am    
Can you give me your create table and sample insert query so that i can create a simple sample for you.
Praveen Kumar Upadhyay 24-Dec-14 3:09am    
I have only understood that database has the values which you have mentioned. Now what is your input and what output you want.
[no name] 24-Dec-14 3:26am    
in the database i have table with the number of price list and its hours (fromHour and toHour)

what i need is to take that information store it in my function in some collection and check if the hour is in the range of the price list

For example:

i need to to find out that from 08:00 to 10:00 is price list 1
priceList = 1
startTime = 08:00
endTime = 10:00
send it to calculation tot = calcprice(priceList,startTime,endTime) + ...

pricelists can be 1 and many (its dynamic)

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!
 
Share this answer
 
VB
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

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900