Fichier #imcctz28-3492 - VBNET - Code source
Téléchargé par un utilisateur anonyme - 29/07/2010 22:25 - 65 affichages
Code source
Public Class MuDB
Const LineBreak = Microsoft.VisualBasic.vbCrLf
Dim conn As New SqlCeConnection("Data Source=mudb.sdf")
Dim cmd As New SqlCeCommand
Dim Arr As New System.Collections.ArrayList
Dim F1 As New Font("Microsoft Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Point)
Dim F2 As New Font("Microsoft Sans Serif", 8, FontStyle.Bold, GraphicsUnit.Point)
Dim Tab As Byte = 1
Dim TT0, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9 As New ToolTip
Private Function ByteToImage(ByVal myByteArray As Byte()) As Image
Dim myImage As ImageUsing ms As System.IO.MemoryStream = New System.IO.MemoryStream(myByteArray, 0, myByteArray.Length)
ms.Write(myByteArray, 0, myByteArray.Length)
myImage = Image.FromStream(ms, True)
End UsingReturn myImageEnd Function
Private Sub ListBox1_ItemsClick() Handles ListBox1.Click
If ListBox1.SelectedItem > "" Then
cmd = New SqlCeCommand("SELECT * FROM " & TabControl1.SelectedTab.Name & " WHERE Name=@name", conn)
cmd.Parameters.AddWithValue("@name", ListBox1.SelectedItem.ToString)
Using da As New SqlCeDataAdapter()
Using ds As New DataSet()
conn.Open()
da.SelectCommand = cmd
da.Fill(ds, "table")
conn.Close()
PictureBox1.Image = ByteToImage(ds.Tables("table").Rows(0).Item(1))
'Filling ClassesDim L As Label()Dim T As ByteSelect Case TabCase 3T = 8Case ElseT = 10End SelectL = New Label() {DK, BK, BM, DW, SM, GM, FE, ME1, HE, S, BS, DiM1, MG, DuM, DL, LE}For i As Byte = 0 To 15If ds.Tables("table").Rows(0).Item(T + i) = True ThenL(i).Font = F2L(i).ForeColor = SystemColors.ControlTextElseL(i).Font = F1L(i).ForeColor = SystemColors.ControlDarkEnd IfNext i'Filling Resistance, Socket and BOK
Select Case TabCase 2
If ds.Tables("table").Rows(0).Item(9) Then
Socket.Font = F2
Socket.ForeColor = SystemColors.ControlText
ElseSocket.Font = F1
Socket.ForeColor = SystemColors.ControlDark
End If
If ds.Tables("table").Rows(0).Item(26) Then
Drop.Font = F2
Drop.ForeColor = SystemColors.ControlText
Drop.Text = "Drops from BOK +" & ds.Tables("table").Rows(0).Item(26)
ElseDrop.Font = F1
Drop.ForeColor = SystemColors.ControlDark
Drop.Text = "Drops from BOK"
End If
Case Else
If ds.Tables("table").Rows(0).Item(8 - Tab) Then
Drop.Font = F2
Drop.ForeColor = SystemColors.ControlText
Drop.Text = "Drops from BOK +" & ds.Tables("table").Rows(0).Item(8 - Tab)
ElseDrop.Font = F1
Drop.ForeColor = SystemColors.ControlDark
Drop.Text = "Drops from BOK"
End If
If ds.Tables("table").Rows(0).Item(9 - Tab) Then
Socket.Font = F2
Socket.ForeColor = SystemColors.ControlText
ElseSocket.Font = F1
Socket.ForeColor = SystemColors.ControlDark
End If
If ds.Tables("table").Rows(0).Item(10 - Tab) Then
Resist.Font = F2
Resist.ForeColor = SystemColors.ControlText
ElseResist.Font = F1
Resist.ForeColor = SystemColors.ControlDark
End If
End Select'Filling StatisticsSelect Case TabCase 1cmd = New SqlCeCommand("SELECT * FROM set_items WHERE ID IN " & _"(SELECT ArmorID FROM sets WHERE Name=@name UNION " & _"SELECT GlovesID FROM sets WHERE Name=@name UNION " & _"SELECT PantsID FROM sets WHERE Name=@name UNION " & _"SELECT BootsID FROM sets WHERE Name=@name UNION " & _"SELECT HelmID FROM sets WHERE Name=@name)", conn)cmd.Parameters.AddWithValue("@name", ListBox1.SelectedItem.ToString)conn.Open()da.SelectCommand = cmdda.Fill(ds, "sets")conn.Close()Sets_Fill(ds.Tables("sets"), ds.Tables("sets").Rows.Count)Case 2Weapons_Fill(ds.Tables("table").Rows(0))Case ElseShields_Fill(ds.Tables("table").Rows(0))End SelectEnd UsingEnd UsingEnd IfEnd SubPrivate Sub Sets_Fill(ByVal Table As DataTable, ByVal N As Byte)Dim Cache1, Cache2 As String'This MUST be included in For ... Next
ADef.Text = Table.Rows(N - 4).Item(1)
AEDef.Text = Table.Rows(N - 4).Item(2)
Cache1 = Sets_Calc(ADef.Text)
Cache2 = Sets_Calc(AEDef.Text)
TT0.SetToolTip(ADef, Cache1)
TT1.SetToolTip(AEDef, Cache2)
GDef.Text = Table.Rows(N - 3).Item(1)
If GDef.Text = ADef.Text Then
TT2.SetToolTip(GDef, Cache1)
ElseTT2.SetToolTip(GDef, Sets_Calc(GDef.Text))
End If
GEDef.Text = Table.Rows(N - 3).Item(2)
If GEDef.Text = AEDef.Text Then
TT3.SetToolTip(GEDef, Cache2)
ElseTT3.SetToolTip(GEDef, Sets_Calc(GEDef.Text))
End If
PDef.Text = Table.Rows(N - 2).Item(1)
If PDef.Text = ADef.Text Then
TT4.SetToolTip(PDef, Cache1)
ElseTT4.SetToolTip(PDef, Sets_Calc(PDef.Text))
End If
PEDef.Text = Table.Rows(N - 2).Item(2)
If PEDef.Text = AEDef.Text Then
TT5.SetToolTip(PEDef, Cache2)
ElseTT5.SetToolTip(PEDef, Sets_Calc(PEDef.Text))
End If
BDef.Text = Table.Rows(N - 1).Item(1)
If BDef.Text = ADef.Text Then
TT6.SetToolTip(BDef, Cache1)
ElseTT6.SetToolTip(BDef, Sets_Calc(BDef.Text))
End If
BEDef.Text = Table.Rows(N - 1).Item(2)
If BEDef.Text = AEDef.Text Then
TT7.SetToolTip(BEDef, Cache2)
ElseTT7.SetToolTip(BEDef, Sets_Calc(BEDef.Text))
End If
If N = 5 Then
HDef.Text = Table.Rows(0).Item(1)
If HDef.Text = ADef.Text Then
TT8.SetToolTip(HDef, Cache1)
ElseTT8.SetToolTip(HDef, Sets_Calc(HDef.Text))
End If
HEDef.Text = Table.Rows(0).Item(2)
If HEDef.Text = AEDef.Text Then
TT9.SetToolTip(HEDef, Cache2)
ElseTT9.SetToolTip(HEDef, Sets_Calc(HEDef.Text))
End If
ElseHDef.Text = ""
TT8.SetToolTip(HDef, "")
HEDef.Text = ""
TT9.SetToolTip(HEDef, "")
End If
End SubPrivate Sub Weapons_Fill(ByVal Row As DataRow)
'Bad style, better to make variables for Row.Item'Anyway, I must optimize it
SDmg.Text = Row.Item(2) & "-" & Row.Item(3)
TT0.SetToolTip(SDmg, Weapons_Calc(Row.Item(2), Row.Item(3)))
EDmg.Text = Row.Item(4) & "-" & Row.Item(5)
TT1.SetToolTip(EDmg, Weapons_Calc(Row.Item(4), Row.Item(5)))
Spd.Text = Row.Item(8)
SWiz.Text = Row.Item(6) & "%"
TT2.SetToolTip(SWiz, Wiz_Calc(Row.Item(6)))
EWiz.Text = Row.Item(27) & "%"
TT3.SetToolTip(EWiz, Wiz_Calc(Row.Item(27)))
SPet.Text = Row.Item(7) & "%"
TT4.SetToolTip(SPet, Pet_Calc(Row.Item(7), Row.Item(29)))
EPet.Text = Row.Item(28) & "%"
TT5.SetToolTip(EPet, Pet_Calc(Row.Item(28), Row.Item(29)))
End SubPrivate Sub Shields_Fill(ByVal Row As DataRow)
Def.Text = Row.Item(2)
TT0.SetToolTip(Def, Shield_Def(Row.Item(2)))
SDefrate.Text = Row.Item(3)
TT1.SetToolTip(SDefrate, Sets_Calc(Row.Item(3)))
EDefrate.Text = Row.Item(4)
TT2.SetToolTip(EDefrate, Sets_Calc(Row.Item(4)))
End SubPrivate Sub TextBox1_TextChanged() Handles TextBox1.TextChanged
ListBox_Fill()
End SubPrivate Sub ListBox_Fill()
If TextBox1.Text <> "" Then
cmd = New SqlCeCommand("SELECT Name, BM, GM, HE, DiM, DuM, LE FROM " & TabControl1.SelectedTab.Name & " WHERE Name LIKE '%" & TextBox1.Text & "%'", conn)
Elsecmd = New SqlCeCommand("SELECT Name, BM, GM, HE, DiM, DuM, LE FROM " & TabControl1.SelectedTab.Name, conn)
End If
If conn.State = ConnectionState.Closed Then conn.Open()
Using DataReader As SqlCeDataReader = cmd.ExecuteReader()
Dim name As Byte = DataReader.GetOrdinal("Name")
While DataReader.Read()
If RadioDK.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("BM")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseIf RadioDW.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("GM")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseIf RadioFE.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("HE")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseIf RadioS.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("DiM")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseIf RadioMG.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("DuM")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseIf RadioDL.Checked Then
If DataReader.GetBoolean(DataReader.GetOrdinal("LE")) Then
Arr.Add(DataReader.GetString(name))
End If
ElseArr.Add(DataReader.GetString(name))
End If
End While
conn.Close()
End UsingArr.Sort()
ListBox1.Items.Clear()
'Datatype must be changed if there's overflowFor i As Short = 0 To Arr.Count - 1
ListBox1.Items.Add(Arr(i))
Next iArr.Clear()
End SubPrivate Sub TabControl_Selected() Handles TabControl1.Selected
Select Case TabControl1.SelectedTab.Name
Case "Sets"
Tab = 1
Resist.Visible = True
Clear_Weapons()
Clear_Shields()
Case "Weapons"
Tab = 2
Resist.Visible = False
Clear_Sets()
Clear_Shields()
Case Else
Tab = 3
Resist.Visible = True
Clear_Sets()
Clear_Weapons()
End SelectRadio()
ListBox_Fill()
End SubPrivate Sub Clear_Sets()
ADef.Text = Nothing
AEDef.Text = Nothing
GDef.Text = Nothing
GEDef.Text = Nothing
PDef.Text = Nothing
PEDef.Text = Nothing
BDef.Text = Nothing
BEDef.Text = Nothing
HDef.Text = Nothing
HEDef.Text = Nothing
End SubPrivate Sub Clear_Weapons()
SDmg.Text = Nothing
EDmg.Text = Nothing
Spd.Text = Nothing
SWiz.Text = Nothing
EWiz.Text = Nothing
SPet.Text = Nothing
EPet.Text = Nothing
End SubPrivate Sub Clear_Shields()
Def.Text = Nothing
SDefrate.Text = Nothing
EDefrate.Text = Nothing
End SubPrivate Function Sets_Calc(ByVal i As Short) As String
If i <> 0 Then
Dim Str As StringStr = "+0 | " & i - 49 & LineBreak & "+1 | " & i - 46 & LineBreak & "+2 | " & i - 43 & LineBreak & _
"+3 | " & i - 40 & LineBreak & "+4 | " & i - 37 & LineBreak & "+5 | " & i - 34 & LineBreak & _
"+6 | " & i - 31 & LineBreak & "+7 | " & i - 28 & LineBreak & "+8 | " & i - 25 & LineBreak & _
"+9 | " & i - 22 & LineBreak & "+10 | " & i - 18 & LineBreak & "+11 | " & i - 13 & LineBreak & _
"+12 | " & i - 7 & LineBreak & "+13 | " & i
Return StrElseReturn ""
End If
End Function
Private Function Weapons_Calc(ByVal i As Short, ByVal j As Short) As String
If i <> 0 Then
Dim Str As StringStr = "+0 | " & i - 49 & "-" & j - 49 & LineBreak & "+1 | " & i - 46 & "-" & j - 46 & LineBreak & "+2 | " & i - 43 & "-" & j - 43 & LineBreak & _
"+3 | " & i - 40 & "-" & j - 40 & LineBreak & "+4 | " & i - 37 & "-" & j - 37 & LineBreak & "+5 | " & i - 34 & "-" & j - 34 & LineBreak & _
"+6 | " & i - 31 & "-" & j - 31 & LineBreak & "+7 | " & i - 28 & "-" & j - 28 & LineBreak & "+8 | " & i - 25 & "-" & j - 25 & LineBreak & _
"+9 | " & i - 22 & "-" & j - 22 & LineBreak & "+10 | " & i - 18 & "-" & j - 18 & LineBreak & "+11 | " & i - 13 & "-" & j - 13 & LineBreak & _
"+12 | " & i - 7 & "-" & j - 7 & LineBreak & "+13 | " & i & "-" & j
Return StrElseReturn ""
End If
End Function
Private Function Wiz_Calc(ByVal i As Short) As String
If i <> 0 Then
Dim Str As StringStr = "+0 | " & i - 50 & "%" & LineBreak & "+1 | " & i - 47 & "%" & LineBreak & "+2 | " & i - 43 & "%" & LineBreak & _
"+3 | " & i - 40 & "%" & LineBreak & "+4 | " & i - 36 & "%" & LineBreak & "+5 | " & i - 33 & "%" & LineBreak & _
"+6 | " & i - 29 & "%" & LineBreak & "+7 | " & i - 26 & "%" & LineBreak & "+8 | " & i - 22 & "%" & LineBreak & _
"+9 | " & i - 19 & "%" & LineBreak & "+10 | " & i - 15 & "%" & LineBreak & "+11 | " & i - 10 & "%" & LineBreak & _
"+12 | " & i - 5 & "%" & LineBreak & "+13 | " & i & "%"
Return StrElseReturn ""
End If
End Function
Private Function Pet_Calc(ByVal i As Short, ByVal j As Short) As String
If i <> 0 Then
Dim Str As StringIf j = 1 Then
Str = "+0 | " & i - 24 & "%" & LineBreak & "+1 | " & i - 23 & "%" & LineBreak & "+2 | " & i - 21 & "%" & LineBreak & _
"+3 | " & i - 20 & "%" & LineBreak & "+4 | " & i - 18 & "%" & LineBreak & "+5 | " & i - 17 & "%" & LineBreak & _
"+6 | " & i - 15 & "%" & LineBreak & "+7 | " & i - 14 & "%" & LineBreak & "+8 | " & i - 12 & "%" & LineBreak & _
"+9 | " & i - 11 & "%" & LineBreak & "+10 | " & i - 9 & "%" & LineBreak & "+11 | " & i - 6 & "%" & LineBreak & _
"+12 | " & i - 3 & "%" & LineBreak & "+13 | " & i & "%"
ElseIf j = 2 Then
Str = "+0 | " & i - 25 & "%" & LineBreak & "+1 | " & i - 23 & "%" & LineBreak & "+2 | " & i - 22 & "%" & LineBreak & _
"+3 | " & i - 20 & "%" & LineBreak & "+4 | " & i - 19 & "%" & LineBreak & "+5 | " & i - 17 & "%" & LineBreak & _
"+6 | " & i - 16 & "%" & LineBreak & "+7 | " & i - 14 & "%" & LineBreak & "+8 | " & i - 13 & "%" & LineBreak & _
"+9 | " & i - 11 & "%" & LineBreak & "+10 | " & i - 9 & "%" & LineBreak & "+11 | " & i - 7 & "%" & LineBreak & _
"+12 | " & i - 4 & "%" & LineBreak & "+13 | " & i & "%"
ElseStr = "+0 | " & i - 50 & "%" & LineBreak & "+1 | " & i - 47 & "%" & LineBreak & "+2 | " & i - 43 & "%" & LineBreak & _
"+3 | " & i - 40 & "%" & LineBreak & "+4 | " & i - 36 & "%" & LineBreak & "+5 | " & i - 33 & "%" & LineBreak & _
"+6 | " & i - 29 & "%" & LineBreak & "+7 | " & i - 26 & "%" & LineBreak & "+8 | " & i - 22 & "%" & LineBreak & _
"+9 | " & i - 19 & "%" & LineBreak & "+10 | " & i - 15 & "%" & LineBreak & "+11 | " & i - 10 & "%" & LineBreak & _
"+12 | " & i - 5 & "%" & LineBreak & "+13 | " & i & "%"
End If
Return StrElseReturn ""
End If
End Function
Private Function Shield_Def(ByVal i As Short) As String
If i <> 0 Then
Dim Str As StringStr = "+0 | " & i - 13 & "%" & LineBreak & "+1 | " & i - 12 & "%" & LineBreak & "+2 | " & i - 11 & "%" & LineBreak & _
"+3 | " & i - 10 & "%" & LineBreak & "+4 | " & i - 9 & "%" & LineBreak & "+5 | " & i - 8 & "%" & LineBreak & _
"+6 | " & i - 7 & "%" & LineBreak & "+7 | " & i - 6 & "%" & LineBreak & "+8 | " & i - 5 & "%" & LineBreak & _
"+9 | " & i - 4 & "%" & LineBreak & "+10 | " & i - 3 & "%" & LineBreak & "+11 | " & i - 2 & "%" & LineBreak & _
"+12 | " & i - 1 & "%" & LineBreak & "+13 | " & i & "%"
Return StrElseReturn ""
End If
End Function
Private Sub AllChange() Handles RadioAll.CheckedChanged, RadioDK.CheckedChanged, RadioDL.CheckedChanged, RadioDW.CheckedChanged, RadioFE.CheckedChanged, RadioMG.CheckedChanged, RadioS.CheckedChanged
Radio()
End SubPrivate Sub Radio()
PictureBox1.Image = Nothing
ListBox1.Items.Clear()
TextBox1.Text = Nothing
TextBox1.Focus()
End SubPrivate Sub About() Handles Button1.Click
Help.Show()
End SubEnd Class
