Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.ComponentModel
Imports System.Web.SessionState
Public Class Quotes
Private Shared names() As String = { "SUNW", "MSFT", "INTC", "CSCO", "SIRI", "AAPL", "HOKU", "ORCL", "AMAT", "YHOO", "LVLT", "DELL", "BEAS" }
Public Sub New()
End Sub
Private random As Random
Private Function GetRandom() As Random
If random Is Nothing Then
random = New Random()
End If
Return random
End Function
Private ReadOnly Property Session() As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property
Public Function LoadQuotes() As BindingList(Of Quote)
If Session("Quotes") Is Nothing Then
CreateQuotes()
End If
ModifyQuotes()
Return TryCast(Session("Quotes"), BindingList(Of Quote))
End Function
Private Sub ModifyQuotes()
Dim quotes As BindingList(Of Quote) = TryCast(Session("Quotes"), BindingList(Of Quote))
Dim count As Integer = GetRandom().Next(1, 5)
For n As Integer = 0 To count - 1
Dim num As Integer = GetRandom().Next(0, quotes.Count)
Dim q As Quote = quotes(num)
q.Value = CDec(GetRandom().Next((CInt(Fix(q.PrevValue)) * 10) - 30, (CInt(Fix(q.PrevValue)) * 10) + 30)) / CDec(10)
q.Time = DateTime.Now
Next n
End Sub
Private Sub CreateQuotes()
Dim res As New BindingList(Of Quote)()
For Each name As String In names
Dim q As New Quote(name)
q.Value = CDec(GetRandom().Next(800, 2000)) / CDec(10)
res.Add(q)
Next name
Session("Quotes") = res
End Sub
End Class
Public Class Quote
Private fSymbol As String
Private fTime As DateTime
Private fValue, fPrevValue As Decimal
Public Sub New(ByVal symbol As String)
Me.fSymbol = symbol
Me.fTime = DateTime.MinValue
Me.fValue = 0
Me.fPrevValue = 0
End Sub
Public ReadOnly Property Symbol() As String
Get
Return fSymbol
End Get
End Property
Public Property Time() As DateTime
Get
Return fTime
End Get
Set(ByVal value As DateTime)
fTime = value
End Set
End Property
Public Property Value() As Decimal
Get
Return Me.fValue
End Get
Set(ByVal value As Decimal)
If Me.fValue = value Then
Return
End If
If Me.fPrevValue = 0 Then
Me.fPrevValue = value
End If
Me.fValue = value
End Set
End Property
Public ReadOnly Property PrevValue() As Decimal
Get
Return fPrevValue
End Get
End Property
Public ReadOnly Property Change() As Decimal
Get
If PrevValue = 0 OrElse Value = 0 OrElse Value = PrevValue Then
Return 0
End If
If Value > PrevValue Then
Return (Value / PrevValue) - 1
Else
Return 1 - (PrevValue / Value)
End If
End Get
End Property
End Class