Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/GridMainDemo/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/VB/GridMainDemo/Modules/Data.vb

Imports DevExpress.Xpo
Imports DevExpress.LookAndFeel
Imports DevExpress.Skins
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors
Imports System.ComponentModel
Imports DevExpress.Utils
Imports DevExpress.Utils.Text

Namespace DevExpress.XtraGrid.Demos
	Public Class OutlookData
		Public Shared rnd As New Random()
		Friend Shared users() As String = {"Peter Dolan", "Ryan Fischer", "Richard Fisher", "Tom Hamlett", "Mark Hamilton", "Steve Lee", "Jimmy Lewis", "Jeffrey W McClain", "Andrew Miller", "Dave Murrel", "Bert Parkins", "Mike Roller", "Ray Shipman", "Paul Bailey", "Brad Barnes", "Carl Lucas", "Jerry Campbell"}
		Private Shared subject() As String = { "Integrating Developer Express MasterView control into an Accounting System.", "Web Edition: Data Entry Page. There is an issue with date validation.", "Payables Due Calculator is ready for testing.", "Web Edition: Search Page is ready for testing.", "Main Menu: Duplicate Items. Somebody has to review all menu items in the system.", "Receivables Calculator. Where can I find the complete specs?", "Ledger: Inconsistency. Please fix it.", "Receivables Printing module is ready for testing.", "Screen Redraw. Somebody has to look at it.", "Email System. What library are we going to use?", "Cannot add new vendor. This module doesn't work!", "History. Will we track sales history in our system?", "Main Menu: Add a File menu. File menu item is missing.", "Currency Mask. The current currency mask in completely unusable.", "Drag & Drop operations are not available in the scheduler module.", "Data Import. What database types will we support?", "Reports. The list of incomplete reports.", "Data Archiving. We still don't have this features in our application.", "Email Attachments. Is it possible to add multiple attachments? I haven't found a way to do this.", "Check Register. We are using different paths for different modules.", "Data Export. Our customers asked us for export to Microsoft Excel"}

		Private Shared Function GetImportance(ByVal num As Integer) As Integer
			Dim ret As Integer = rnd.Next(num)
			If ret > 2 Then
				ret = 1
			End If
			Return ret
		End Function

		Private Shared Function GetIcon() As Integer
			Dim ret As Integer = rnd.Next(10)
			ret = If(ret > 2, 1, 0)
			Return ret
		End Function

		Private Shared Function GetAttach() As Integer
			Dim ret As Integer = rnd.Next(10)
			ret = If(ret > 5, 1, 0)
			Return ret
		End Function

		Private Shared Function GetSent() As Date
			Dim ret As Date = Date.Now
			Dim r As Integer = rnd.Next(12)
			If r > 1 Then
				ret = ret.AddDays(-rnd.Next(50))
			End If
			ret = ret.AddMinutes(-rnd.Next(ret.Minute + ret.Hour * 60 + 360))
			Return ret
		End Function

		Private Shared Function GetReceived(ByVal sent As Date) As Date
			Dim dt As Date = sent.AddMinutes(10 + rnd.Next(120))
			If dt > Date.Now Then
				dt = Date.Now.AddMinutes(-1)
			End If
			Return dt
		End Function

		Private Shared Function GetSubject() As String
			Return subject(rnd.Next(subject.Length - 1))
		End Function

		Public Shared Function GetFrom() As String
			Return users(rnd.Next(users.Length - 2))
		End Function

		Private Shared Function GetTo() As String
			Return users(users.Length - 1)
		End Function

		Private Shared Function GetSentDate() As Date
			Dim ret As Date = Date.Today
			Dim r As Integer = rnd.Next(12)
			If r > 1 Then
				ret = ret.AddDays(-rnd.Next(50))
			End If
			Return ret
		End Function

		Private Shared Function GetSentDateWithTime() As Date
			Dim ret As Date = Date.Now.AddMinutes(-rnd.Next(60, 250000))
			Return ret
		End Function

		Public Shared Function GetDueDate() As Date
			Dim ret As Date = Date.Today
			ret = ret.AddDays(60 + rnd.Next(50))
			Return ret
		End Function

		Private Shared Function GetSize(ByVal largeData As Boolean) As Integer
			Return 1000 + (If(largeData, 20 * rnd.Next(10000), 30 * rnd.Next(100)))
		End Function
		Private Shared Function GetHasAttachment() As Boolean
			Return rnd.Next(10) > 5
		End Function

		Public Shared Function CreateDataTable() As DataTable
			Return CreateDataTable(7)
		End Function
		Public Shared Function CreateMailRow(ByVal num As Integer, ByVal realTime As Boolean) As Object()
			Dim sent As Date = GetSent()
			Return New Object() { GetImportance(num), GetAttach(),If(realTime, 0, GetIcon()), GetIcon(), GetSubject(), GetFrom(), GetTo(), sent,If(realTime, Date.Now, GetReceived(sent))}
		End Function
		Public Shared Function CreateDataTable(ByVal num As Integer) As DataTable
			Dim tbl As New DataTable("Outlook")
			tbl.Columns.Add("Priority", GetType(Integer))
			tbl.Columns.Add("Attachment", GetType(Integer))
			tbl.Columns.Add("Read", GetType(Integer))
			tbl.Columns.Add("Flag", GetType(Integer))
			tbl.Columns.Add("Subject", GetType(String))
			tbl.Columns.Add("From", GetType(String))
			tbl.Columns.Add("To", GetType(String))
			tbl.Columns.Add("Sent", GetType(Date))
			tbl.Columns.Add("Received", GetType(Date))
			For i As Integer = 0 To 79
				tbl.Rows.Add(CreateMailRow(num, False))
			Next i
			Return tbl
		End Function
		Public Shared Function CreateIssueList() As DataTable
			Dim tbl As New DataTable()
			tbl = New DataTable("IssueList")
			tbl.Columns.Add("ID", GetType(Integer))
			tbl.Columns.Add("Subject", GetType(String))
			tbl.Columns.Add("Implemented", GetType(Integer))
			tbl.Columns.Add("Suspended", GetType(Boolean))
			For i As Integer = 1 To subject.Length
				tbl.Rows.Add(New Object() { i, subject.GetValue(i - 1), rnd.Next(100), rnd.Next(10) > 8 })
			Next i
			Return tbl
		End Function

		Public Shared Function CreateNewObject(ByVal uow As UnitOfWork) As ServerSideGridTest
			Dim obj As New ServerSideGridTest(uow)
			obj.Subject = GetSubject()
			obj.From = GetFrom()
			obj.Sent = GetSentDateWithTime()
			obj.HasAttachment = GetHasAttachment()
			obj.Size = GetSize(obj.HasAttachment)
			obj.Priority = GetImportance(4)
			Return obj
		End Function
	End Class
	Public Class GroupIntervalData
		Public Shared rnd As New Random()
		Private Shared Function GetCount() As Decimal
			Return rnd.Next(50) + 10
		End Function
		Private Shared Function GetDate(ByVal range As Boolean) As Date
			Dim ret As Date = Date.Now
			Dim r As Integer = rnd.Next(20)
			If range Then
				If r > 1 Then
					ret = ret.AddDays(rnd.Next(80) - 40)
				End If
				If r > 18 Then
					ret = ret.AddMonths(rnd.Next(18))
				End If
			Else
				ret = ret.AddDays(rnd.Next(r * 30) - r * 15)
			End If
			Return ret
		End Function
		Public Shared Function CreateDataTable(ByVal maxRows As Integer) As DataTable
			Return CreateDataTable(maxRows, True)
		End Function
		Public Shared Function CreateDataTable(ByVal maxRows As Integer, ByVal range As Boolean) As DataTable
			Dim tbl As DataTable = Nothing
			Dim DBFileName As String = String.Empty
			DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, "Data\nwind.mdb")
			If DBFileName <> String.Empty Then
				Dim ds As New DataSet()
				Dim tblName As String = "Products"

				Dim con As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBFileName
				Dim oleDbDataAdapter As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM " & tblName, con)
				oleDbDataAdapter.Fill(ds, tblName)

				Dim product As DataTable = ds.Tables(tblName)
				tbl = New DataTable("GroupInterval")
				tbl.Columns.Add("Product Name", GetType(String))
				tbl.Columns.Add("Category", GetType(Integer))
				tbl.Columns.Add("Unit Price", GetType(Decimal))
				tbl.Columns.Add("Count", GetType(Integer))
				tbl.Columns.Add("Order Date", GetType(Date))
				tbl.Columns.Add("Order Sum", GetType(Decimal), "[Unit Price] * [Count]")
				For i As Integer = 0 To maxRows - 1
					Dim row_Renamed As DataRow = product.Rows(rnd.Next(product.Rows.Count - 1))
					tbl.Rows.Add(New Object() { row_Renamed("ProductName"), row_Renamed("CategoryID"), row_Renamed("UnitPrice"), GetCount(), GetDate(range) })
				Next i
			End If
			Return tbl
		End Function
	End Class
	Public Class MailData
		Private row_Renamed As DataRow
		Public Sub New(ByVal row_Renamed As DataRow)
			Me.row_Renamed = row_Renamed
		End Sub
		Public ReadOnly Property Row() As DataRow
			Get
				Return row_Renamed
			End Get
		End Property
		Public Property Priority() As Integer
			Get
				Return CInt(Fix(row_Renamed("Priority")))
			End Get
			Set(ByVal value As Integer)
				row_Renamed("Priority") = value
			End Set
		End Property
		Public ReadOnly Property Attachment() As Integer
			Get
				Return CInt(Fix(row_Renamed("Attachment")))
			End Get
		End Property
		Public Property Read() As Integer
			Get
				Return CInt(Fix(row_Renamed("Read")))
			End Get
			Set(ByVal value As Integer)
				row_Renamed("Read") = value
			End Set
		End Property
		Public Property Flag() As Integer
			Get
				Return CInt(Fix(row_Renamed("Flag")))
			End Get
			Set(ByVal value As Integer)
				row_Renamed("Flag") = value
			End Set
		End Property
		Public ReadOnly Property Subject() As String
			Get
				Return String.Format("{0}", row_Renamed("Subject"))
			End Get
		End Property
		Public ReadOnly Property [From]() As String
			Get
				Return String.Format("{0}", row_Renamed("From"))
			End Get
		End Property
	End Class
	Public Class ColorsObject
		Private fforeColor, fbackColor As Color
		Public Sub New(ByVal fforeColor As Color, ByVal fbackColor As Color)
			Me.fforeColor = fforeColor
			Me.fbackColor = fbackColor
		End Sub
		Public Property ForeColor() As Color
			Get
				Return fforeColor
			End Get
			Set(ByVal value As Color)
				fforeColor = value
			End Set
		End Property
		Public Property BackColor() As Color
			Get
				Return fbackColor
			End Get
			Set(ByVal value As Color)
				fbackColor = value
			End Set
		End Property
	End Class
	Public Class ColorHelper
		Public Shared Sub UpdateColor(ByVal list As ImageList, ByVal lf As UserLookAndFeel)
			For i As Integer = 0 To list.Images.Count - 1
				list.Images(i) = SetColor(TryCast(list.Images(i), Bitmap), GetHeaderForeColor(lf))
			Next i
		End Sub
		Public Shared Function GetHeaderForeColor(ByVal lf As UserLookAndFeel) As Color
			Dim ret As Color = SystemColors.ControlText
			If lf.ActiveStyle <> ActiveLookAndFeelStyle.Skin Then
				Return ret
			End If
			Return GridSkins.GetSkin(lf)(GridSkins.SkinHeader).Color.GetForeColor()
		End Function
		Private Shared Function SetColor(ByVal bmp As Bitmap, ByVal color As Color) As Bitmap
			For i As Integer = 0 To bmp.Width - 1
				For j As Integer = 0 To bmp.Height - 1
					If bmp.GetPixel(i, j).Name <> "0" Then
						bmp.SetPixel(i, j, color)
					End If
				Next j
			Next i
			Return bmp
		End Function
	End Class
	Public Class LoanPayment
		Private monthNumber_Renamed As Integer
		Private balance_Renamed, interest_Renamed, principal_Renamed As Double
		Private month_Renamed As Date
		Public Sub New(ByVal balance As Double, ByVal monthlyPayment As Double, ByVal month As Integer, ByVal interestRate As Double, ByVal startMonth As Date)
			Me.monthNumber_Renamed = month
			Me.month_Renamed = startMonth.AddMonths(month - 1)
			Me.interest_Renamed = Trunc2(balance * interestRate)
			Me.principal_Renamed = Trunc2(monthlyPayment - Me.interest_Renamed)
			Me.balance_Renamed = Trunc2(balance - Me.principal_Renamed)
		End Sub
		Public Sub UpdateBalance()
			If Me.balance_Renamed < 0 Then
				Me.principal_Renamed += Me.balance_Renamed
			End If
			Me.balance_Renamed = 0
		End Sub

		Public ReadOnly Property Month() As Date
			Get
				Return month_Renamed
			End Get
		End Property
		Public ReadOnly Property MonthNumber() As Integer
			Get
				Return monthNumber_Renamed
			End Get
		End Property
		Public ReadOnly Property MonthlyPayment() As Double
			Get
				Return Interest + Principal
			End Get
		End Property
		Public ReadOnly Property Balance() As Double
			Get
				Return balance_Renamed
			End Get
		End Property
		Public ReadOnly Property Interest() As Double
			Get
				Return interest_Renamed
			End Get
		End Property
		Public ReadOnly Property Principal() As Double
			Get
				Return principal_Renamed
			End Get
		End Property
		Public ReadOnly Property MonthString() As String
			Get
				Return String.Format("{0}<size=-2> ({1:MMMM, yyyy})", MonthNumber, Month)
			End Get
		End Property
		Public Shared Function Trunc2(ByVal val As Double) As Double
			Return Convert.ToDouble(Convert.ToInt64(val * 100)) / 100
		End Function
        Public Shared Function Calculate(ByVal loanAmount As Double, ByVal interestRate As Double, ByVal months As Double, ByVal startMonth As Date, <System.Runtime.InteropServices.Out()> ByRef payment As Double) As List(Of LoanPayment)
            payment = (loanAmount * interestRate) / (1 - Math.Exp((-months) * Math.Log(1 + interestRate)))
            payment = LoanPayment.Trunc2(payment)
            Dim payments As New List(Of LoanPayment)()
            Dim balance_Renamed As Double = loanAmount
            For i As Integer = 1 To Convert.ToInt32(months)
                Dim lp As New LoanPayment(balance_Renamed, payment, i, interestRate, startMonth)
                balance_Renamed = lp.Balance
                payments.Add(lp)
                If lp.Balance <= 0 Then
                    Exit For
                End If
            Next i
            payments(payments.Count - 1).UpdateBalance()
            Return payments
        End Function
		Public Shared Sub InitStartMonth(ByVal edit As ImageComboBoxEdit)
			Dim start As New Date(Date.Today.Year, Date.Today.Month, 1)
			For i As Integer = 1 To 6
				edit.Properties.Items.Add(New ImageComboBoxItem(String.Format("{0:MMMM, yyyy}", start.AddMonths(i)), start.AddMonths(i), -1))
			Next i
			edit.SelectedIndex = 0
		End Sub
		Public Shared Sub InitTermOfLoan(ByVal edit As ImageComboBoxEdit)
			Dim terms() As Integer = { 5, 10, 15, 20, 25, 30 }
			For Each term As Integer In terms
				edit.Properties.Items.Add(New ImageComboBoxItem(String.Format("{0} {1}", term, My.Resources.Years), term, -1))
			Next term
			edit.SelectedIndex = 5
		End Sub
		Public Shared Sub InitInterestRateData(ByVal edit As ImageComboBoxEdit)
			For i As Double = 2.5 To 14 Step 0.125
				edit.Properties.Items.Add(New ImageComboBoxItem(String.Format("{0:n3} %", i), i, -1))
			Next i
			edit.SelectedIndex = 25
		End Sub
		Public Shared Function GetMonthString(ByVal month As Integer, ByVal data As List(Of LoanPayment)) As String
			For Each payment As LoanPayment In data
				If payment.MonthNumber.Equals(month) Then
					Return StringPainter.Default.RemoveFormat(payment.MonthString)
				End If
			Next payment
			Return String.Empty
		End Function
	End Class
	Public Class PaymentTypeSum
		Private interestSum_Renamed As Double = 0
		Private principalSum_Renamed As Double = 0
		Public Sub New()
			interestSum_Renamed = 0
			principalSum_Renamed = 0
		End Sub
		Public ReadOnly Property InterestSum() As Double
			Get
				Return interestSum_Renamed
			End Get
		End Property
		Public ReadOnly Property PrincipalSum() As Double
			Get
				Return principalSum_Renamed
			End Get
		End Property
		Public Sub AddToSum(ByVal value1 As Double, ByVal value2 As Double)
			interestSum_Renamed += value1
			principalSum_Renamed += value2
		End Sub
	End Class
	Public Enum PropertyType
		<Description("Single Family Home")> _
		SingleFamilyHome
		<Description("Condo/Townhouse")> _
		Townhome
		<Description("Multi-Family Home")> _
		MultiFamilyHome
	End Enum
	Public Enum PropertyStatus
		<Description("New Construction")> _
		NewConstruction
		<Description("Foreclosures")> _
		Foreclosures
		<Description("Recently Sold")> _
		RecentlySold
	End Enum
	Public Class Home
		Private Shared homes_Renamed As List(Of Home)
		Private row As DataRow
		Private photo_Renamed As Image
		Public Sub New(ByVal row_Renamed As DataRow)
			Me.row = row_Renamed
			If Not(TypeOf row_Renamed("Photo") Is DBNull) Then
				photo_Renamed = ByteImageConverter.FromByteArray(CType(row_Renamed("Photo"), Byte()))
			End If
		End Sub
		Public ReadOnly Property ID() As Integer
			Get
				Return CInt(Fix(row("ID")))
			End Get
		End Property
		Public ReadOnly Property Address() As String
			Get
				Return String.Format("{0}", row("Address"))
			End Get
		End Property
		Public ReadOnly Property Baths() As Short
			Get
				Return CShort(Fix(row("Baths")))
			End Get
		End Property
		Public ReadOnly Property Beds() As Short
			Get
				Return CShort(Fix(row("Beds")))
			End Get
		End Property
		Public ReadOnly Property HouseSize() As Double
			Get
				Return CDbl(row("HouseSize"))
			End Get
		End Property
		Public ReadOnly Property LotSize() As Double
			Get
				Return CDbl(row("LotSize"))
			End Get
		End Property
		Public ReadOnly Property Price() As Decimal
			Get
				Return Convert.ToDecimal(row("Price"))
			End Get
		End Property
		Public ReadOnly Property YearBuilt() As String
			Get
				Return String.Format("{0}", row("YearBuilt"))
			End Get
		End Property
		Public ReadOnly Property Photo() As Image
			Get
				Return photo_Renamed
			End Get
		End Property
		Public ReadOnly Property Features() As String
			Get
				Return String.Format("{0}", row("Features"))
			End Get
		End Property
		Public ReadOnly Property Type() As String
			Get
				Return DevExpress.Data.Mask.EnumHelper.GetEnumItemDisplayText(CType(row("Type"), PropertyType))
			End Get
		End Property
		Public ReadOnly Property Status() As String
			Get
				Return DevExpress.Data.Mask.EnumHelper.GetEnumItemDisplayText(CType(row("Status"), PropertyStatus))
			End Get
		End Property
		Private Shared Function GetHomes() As List(Of Home)
			Dim temp As New DataSet()
			Dim db As String = FilesHelper.FindingFileName(Application.StartupPath, "Data\Homes.xml")
			If String.IsNullOrEmpty(db) Then
				Return Nothing
			End If
			temp.ReadXml(db)
			Dim ret As New List(Of Home)()
			For Each row_Renamed As DataRow In temp.Tables("Homes").Rows
				ret.Add(New Home(row_Renamed))
			Next row_Renamed
			Return ret
		End Function
		Public Shared ReadOnly Property Homes() As List(Of Home)
			Get
				If homes_Renamed Is Nothing Then
					homes_Renamed = GetHomes()
				End If
				Return homes_Renamed
			End Get
		End Property
	End Class
End Namespace