Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports DevExpress.Utils
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.IO
Imports System.Xml.Serialization
Namespace DevExpress.Demos.DataSources
Public Class Fish
Private privateID As Integer
<DisplayName("ID")> _
Public Property ID() As Integer
Get
Return privateID
End Get
Set(ByVal value As Integer)
privateID = value
End Set
End Property
Private privateCategory As String
<DisplayName("Category")> _
Public Property Category() As String
Get
Return privateCategory
End Get
Set(ByVal value As String)
privateCategory = value
End Set
End Property
Private privateCommonName As String
<DisplayName("Common Name")> _
Public Property CommonName() As String
Get
Return privateCommonName
End Get
Set(ByVal value As String)
privateCommonName = value
End Set
End Property
Private privateNotes As String
<DisplayName("Notes")> _
Public Property Notes() As String
Get
Return privateNotes
End Get
Set(ByVal value As String)
privateNotes = value
End Set
End Property
Private privateScientificClassification As ScientificClassification
<DisplayName("Scientific Classification")> _
Public Property ScientificClassification() As ScientificClassification
Get
Return privateScientificClassification
End Get
Set(ByVal value As ScientificClassification)
privateScientificClassification = value
End Set
End Property
End Class
Public Class ScientificClassification
Private privateHyperlink As String
<XmlElement("Reference")> _
Public Property Hyperlink() As String
Get
Return privateHyperlink
End Get
Set(ByVal value As String)
privateHyperlink = value
End Set
End Property
Private privateKingdom As String
Public Property Kingdom() As String
Get
Return privateKingdom
End Get
Set(ByVal value As String)
privateKingdom = value
End Set
End Property
Private privatePhylum As String
Public Property Phylum() As String
Get
Return privatePhylum
End Get
Set(ByVal value As String)
privatePhylum = value
End Set
End Property
Private private_Class As String
<XmlElement("Class"), DisplayName("Class")> _
Public Property _Class() As String
Get
Return private_Class
End Get
Set(ByVal value As String)
private_Class = value
End Set
End Property
Private privateOrder As String
Public Property Order() As String
Get
Return privateOrder
End Get
Set(ByVal value As String)
privateOrder = value
End Set
End Property
Private privateFamily As String
Public Property Family() As String
Get
Return privateFamily
End Get
Set(ByVal value As String)
privateFamily = value
End Set
End Property
Private privateGenus As String
Public Property Genus() As String
Get
Return privateGenus
End Get
Set(ByVal value As String)
privateGenus = value
End Set
End Property
Private privateSpecies As String
Public Property Species() As String
Get
Return privateSpecies
End Get
Set(ByVal value As String)
privateSpecies = value
End Set
End Property
End Class
Public NotInheritable Class FishesSource
Private Shared data_Renamed As List(Of Fish)
Private Sub New()
End Sub
Public Shared ReadOnly Property Data() As List(Of Fish)
Get
If data_Renamed Is Nothing Then
data_Renamed = GetDataSource()
End If
Return data_Renamed
End Get
End Property
Private Shared Function GetDataSource() As List(Of Fish)
Dim path As String = FilesHelper.FindingFileName(AppDomain.CurrentDomain.BaseDirectory, "Data\fishes.xml", False)
If (Not File.Exists(path)) Then
Return Nothing
End If
Using stream As Stream = File.OpenRead(path)
Dim s As New XmlSerializer(GetType(List(Of Fish)), New XmlRootAttribute("Fishes"))
Return CType(s.Deserialize(stream), List(Of Fish))
End Using
End Function
End Class
'[DisplayName("Fishes")]
'public class Fishes : List<Fish> {
' public Fishes(string filePath) {
' if (File.Exists(filePath)) {
' using (Stream stream = File.OpenRead(filePath)) {
' this.LoadFrom(stream);
' }
' }
' }
' public Fishes(Stream stream) {
' this.LoadFrom(stream);
' }
' void LoadFrom(Stream stream) {
' TextReader input = new StreamReader(stream);
' string line;
' int id = 0;
' while ((line = input.ReadLine()) != null) {
' string[] items = line.Split('|');
' if (items.Length == 4) {
' Fish fishItem = new Fish(items[0], items[1], items[2], items[3], ++id);
' this.Add(fishItem);
' }
' }
' input.Close();
' }
'}
'public class Fish {
' private int id;
' private string category = "Undefined";
' private string commonName = "Undefined";
' private string speciesName = "Undefined";
' private string notes = "Undefined";
' [DisplayName("Fish Category")]
' public string Category {
' get { return category; }
' set { category = value; }
' }
' [DisplayName("Fish Common Name")]
' public string CommonName {
' get { return commonName; }
' set { commonName = value; }
' }
' [DisplayName("Fish Species Name")]
' public string SpeciesName {
' get { return speciesName; }
' set { speciesName = value; }
' }
' [DisplayName("Fish Notes")]
' public string Notes {
' get { return notes; }
' set { notes = value; }
' }
' [DisplayName("Fish ID")]
' public int ID {
' get { return id; }
' set { id = value; }
' }
' public Fish(string category, string commonName, string speciesName, string notes, int id) {
' this.category = category;
' this.commonName = commonName;
' this.speciesName = speciesName;
' this.notes = notes;
' this.id = id;
' }
'}
End Namespace