Public Class Form1
#Region "Classes"
Private Class ¦a°Ï
Implements IComparable
'shared
Public Shared ReadOnly ¦a°Ïªí As New SortedDictionary(Of String, ¦a°Ï)
'properties
Public ReadOnly ID As Integer
Public ReadOnly ¦WºÙ As String
Public ¥Xª©ªÀ As New List(Of ¥Xª©ªÀ)
'generation
''' <summary>
''' It's for preventing the key(name) of the regions is repeated.
''' </summary>
''' <param name="¨ú²{¦³È">Actually, it's crap and can be removed.</param>
Public Shared Function «Ø¥ß(ByVal ¦WºÙ As String, ByVal ID As Integer, _
Optional ByVal ¨ú²{¦³È As Boolean = False) As ¦a°Ï
Dim nw¦a°Ï As ¦a°Ï = Nothing
If ¦a°Ïªí.TryGetValue(¦WºÙ, nw¦a°Ï) Then
If ¨ú²{¦³È Then Return nw¦a°Ï Else Return Nothing
Else
Return New ¦a°Ï(¦WºÙ, ID)
End If
End Function
Private Sub New(ByVal ¦WºÙ As String, ByVal ID As Integer)
Me.¦WºÙ = ¦WºÙ
Me.ID = ID
¦a°Ïªí.Add(¦WºÙ, Me)
End Sub
Public Sub ²¾°£() 'crap also.
Me.¥Xª©ªÀ.Clear()
¦a°Ïªí.Remove(Me.¦WºÙ)
GC.Collect(GC.GetGeneration(Me), GCCollectionMode.Forced)
End Sub
'Impements
Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
Select Case obj.GetType
Case GetType(¦a°Ï)
Return Me.¦WºÙ.CompareTo(CType(obj, ¦a°Ï).¦WºÙ)
Case GetType(String)
Return Me.¦WºÙ.CompareTo(CStr(obj))
Case GetType(Byte), GetType(Short), GetType(Integer), GetType(Long)
Return Me.ID.CompareTo(CLng(obj))
Case Else
Throw New Exception(String.Format("¦a°Ï cannot compare to {0}.", obj.GetType()))
End Select
End Function
End Class
Private Class ¥Xª©ªÀ
Implements IComparable
'shared
Public Shared ReadOnly ¥Xª©ªÀªí As New SortedDictionary(Of String, ¥Xª©ªÀ)
'properties
Public ReadOnly ID As Integer
Public ReadOnly ¦WºÙ As String
Public ReadOnly ¦a°Ï() As ¦a°Ï
'generation
''' <summary>
''' It's for preventing the key(name) of the publishers is repeated.
''' </summary>
''' <param name="¦a°Ï">The ParamArray for this program only.</param>
Public Shared Function «Ø¥ß(ByVal ¦WºÙ As String, ByVal ID As Integer, _
ByVal ParamArray ¦a°Ï() As ¦a°Ï) As ¥Xª©ªÀ
Dim nw¥Xª©ªÀ As ¥Xª©ªÀ = Nothing
If ¥Xª©ªÀªí.TryGetValue(¦WºÙ, nw¥Xª©ªÀ) Then
Return Nothing
Else
Return New ¥Xª©ªÀ(¦WºÙ, ID, ¦a°Ï)
End If
End Function
Private Sub New(ByVal ¦WºÙ As String, ByVal ID As Integer, ByVal ¦a°Ï() As ¦a°Ï)
Me.¦WºÙ = ¦WºÙ
Me.ID = ID
Me.¦a°Ï = ¦a°Ï
For Each e¦a°Ï As ¦a°Ï In ¦a°Ï
e¦a°Ï.¥Xª©ªÀ.Add(Me)
Next
¥Xª©ªÀªí.Add(¦WºÙ, Me)
End Sub
Public Sub ²¾°£() 'crap+1
For Each e¦a°Ï As ¦a°Ï In ¦a°Ï
e¦a°Ï.¥Xª©ªÀ.Remove(Me)
Next
¥Xª©ªÀªí.Remove(Me.¦WºÙ)
GC.Collect(GC.GetGeneration(Me), GCCollectionMode.Forced)
End Sub
'implements
Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
Select Case obj.GetType
Case GetType(¥Xª©ªÀ)
Return Me.¦WºÙ.CompareTo(CType(obj, ¥Xª©ªÀ).¦WºÙ)
Case GetType(String)
Return Me.¦WºÙ.CompareTo(CStr(obj))
Case GetType(Byte), GetType(Short), GetType(Integer), GetType(Long)
Return Me.ID.CompareTo(CLng(obj))
Case Else
Throw New Exception(String.Format("¥Xª©ªÀ cannot compare to {0}.", obj.GetType()))
End Select
End Function
End Class
#End Region
#Region "Initialization"
Private Sub ME_LOAD(sender As Object, e As EventArgs) Handles Me.Load
'Creating the regions
Dim TWA As ¦a°Ï = ¦a°Ï.«Ø¥ß("¥xÆW957", 957)
Dim TWB As ¦a°Ï = ¦a°Ï.«Ø¥ß("¥xÆW986", 986)
Dim CNA As ¦a°Ï = ¦a°Ï.«Ø¥ß("¤¤°ê81", 81)
Dim CNB As ¦a°Ï = ¦a°Ï.«Ø¥ß("¤¤°ê93", 93)
'Dim KOR As ¦a°Ï = ¦a°Ï.«Ø¥ß("¥_Áú", 9946) 'No publishers
'Create Press,, of Tai Wan
¥Xª©ªÀ.«Ø¥ß("ùÖ®p", 181, TWA, TWB)
¥Xª©ªÀ.«Ø¥ß("¥þµØ", 21, TWA, TWB)
¥Xª©ªÀ.«Ø¥ß("ªQ±^", 22, TWA, TWB)
',, of Mainland CN
¥Xª©ªÀ.«Ø¥ß("¤¤°ê¥_¨Ê¤j¾Ç", 301, CNA, CNB)
¥Xª©ªÀ.«Ø¥ß("¥_¨Ê¥«ªF¤è", 5060, CNA, CNB)
'GUIs
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
For Each ¦a°Ï As ¦a°Ï In ¦a°Ï.¦a°Ïªí.Values
ComboBox1.Items.Add(¦a°Ï.¦WºÙ)
Next
End Sub
#End Region
#Region "Controls Handles"
''' <summary>
''' Handling Button1.Click, generate a New ISBN number then display in Label4.
''' </summary>
''' <param name="sender">Button1</param>
''' <param name="e">Nothing</param>
''' <remarks>The ISBN number will start with 978 or 979 randomly with the same probability</remarks>
Private Sub Button1_Click(sender As Button, e As System.EventArgs) Handles Button1.Click
Randomize()
If ComboBox1.SelectedIndex < 0 Or ComboBox2.SelectedIndex < 0 Then Exit Sub 'debug
Dim s$ = CStr(IIf(Rnd() > 0.5, "978", "979")) & _
¦a°Ï.¦a°Ïªí(ComboBox1.SelectedItem).ID & _
¥Xª©ªÀ.¥Xª©ªÀªí(ComboBox2.SelectedItem).ID
s &= New String("0", 12 - s.Length - TextBox1.Text.Length) & TextBox1.Text
Dim b As Boolean, sm As Integer
For Each c As Char In s.ToCharArray()
If b Then
sm += (Asc(c) - 48) * 3
Else
sm += Asc(c) - 48
End If
b = Not b
Next c
s &= 10 - (sm Mod 10)
#If DEBUG Then
Debug.Print(s)
#End If
Label4.Text = s
End Sub
''' <summary>
''' Handling Combox1.SelectedIndexChanged. Change the publishers while the region is changed.
''' </summary>
''' <param name="sender">Combobox1</param>
''' <remarks>If the region is changed to nothing, Combobox2 will be cleared. </remarks>
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As ComboBox, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Clear()
If sender.SelectedIndex >= 0 Then
For Each ¥Xª©ªÀ As ¥Xª©ªÀ In ¦a°Ï.¦a°Ïªí(sender.SelectedItem).¥Xª©ªÀ
ComboBox2.Items.Add(¥Xª©ªÀ.¦WºÙ)
Next
End If
End Sub
#End Region
End Class
¡¹Kit¡û..