📄 form1.vb
字号:
Imports System.Data.SQLite
Imports System.IO
Imports System.Reflection
Imports System.Data
Public Class Form1
Const PI = 3.1415926
Dim intGMRule(64) As Integer
Dim strGmCaption(64) As String
Dim snJd As Integer
Dim XtFw(7) As Byte
Dim conn As New SQLiteConnection()
Dim Cmd As SQLiteCommand
Dim iLocalBG As Integer
Dim iSelectGC As Integer
Dim blSelect As Boolean
Dim iShowSum As Integer
Dim iSD As Integer
Dim blStop As Boolean
Dim blinitFlags As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim AppPath As String
AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim str As String
'MinimizeBox = False
str = AppPath + "\xj.db"
If (File.Exists(str) = False) Then
MsgBox("初试化错误,系统退出!")
Me.Close()
Application.Exit()
Else
conn.ConnectionString = "Data Source=" + str + ";Synchronous=Off;Compress=False;UTF8Encoding=False;Version=3;"
conn.Open()
Cmd = conn.CreateCommand()
Cmd.CommandText = "SELECT * FROM GT"
Dim da As IDbDataAdapter
da = New SQLiteDataAdapter
da.SelectCommand = Cmd
Dim ds As DataSet
ds = New DataSet()
da.Fill(ds)
Dim tb As New DataTable
Dim i As Integer
tb = ds.Tables(0)
For i = 0 To tb.Rows.Count - 1
If i < 64 Then
intGMRule(i) = tb.Rows(i).Item(0)
strGmCaption(i) = tb.Rows(i).Item("MasterCaption")
End If
ComboBox1.Items.Add(tb.Rows(i).Item(1))
Next i
conn.Close()
snJd = 0
XtFw(0) = 7
XtFw(1) = 3
XtFw(2) = 2
XtFw(3) = 1
XtFw(4) = 0
XtFw(5) = 4
XtFw(6) = 5
XtFw(7) = 6
NumericUpDown1.Minimum = 1
NumericUpDown1.Maximum = 8
ComboBox1.SelectedIndex = 0
blSelect = False
blStop = False
iSD = 0
blinitFlags = True
snJd = 0
PictureBox1.Image = CreateBmp()
End If
End Sub
Function CreateBmp() As System.Drawing.Bitmap
Dim g As Graphics
Dim tempbrush As SolidBrush
Dim ShowTextBrush As SolidBrush
Dim mFont As Font
Dim bm As New Bitmap(120, 120)
Dim myBrush As SolidBrush
g = Graphics.FromImage(bm)
Dim PenWhite As Pen
PenWhite = New Pen(Color.White)
tempbrush = New SolidBrush(Color.FromArgb(192, 192, 255))
myBrush = New SolidBrush(Color.Red)
ShowTextBrush = New SolidBrush(Color.Blue)
mFont = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular)
g.FillRectangle(tempbrush, 0, 0, 120, 120)
g.DrawImage(bm, 0, 0)
' g.FillEllipse(myBrush, 0, 0, 120, 120)
'fillPie(g, myBrush, 60, 60, 120, 120, 0, 360)
ShowTj(snJd, g, 60, 60, 30)
Return bm
End Function
Sub ShowTj(ByVal jd As Single, ByVal GraphDC As Graphics, ByVal iCenterX As Integer, ByVal iCenterY As Integer, ByVal Raddim As Integer)
Dim PenWhite As Pen
Dim PenBlack As Pen
Dim Pen3 As Pen
Dim PenBK As Pen
Dim PenRed As Pen
Dim WhiteBrush As SolidBrush
Dim CurX As Integer
Dim CurY As Integer
Dim PenTemp As Pen
WhiteBrush = New SolidBrush(Color.White)
Dim BlackBrush As SolidBrush
BlackBrush = New SolidBrush(Color.Black)
PenWhite = New Pen(Color.White)
PenBlack = New Pen(Color.Black)
Pen3 = New Pen(Color.Blue)
PenRed = New Pen(Color.Red)
PenRed.Width = 2
Pen3.Width = 2
PenBK = New Pen(Color.FromArgb(128, 128, 128))
GraphDC.FillEllipse(BlackBrush, iCenterX - Raddim, iCenterY - Raddim, Raddim * 2, Raddim * 2)
fillPie(GraphDC, WhiteBrush, iCenterX, iCenterY, Raddim * 2, Raddim * 2, jd, -180 + jd)
CurX = (iCenterX - Raddim / 2 * Math.Cos(jd * (Math.PI / 180)))
CurY = iCenterY - Raddim / 2 * Math.Sin(jd * (Math.PI / 180))
GraphDC.FillEllipse(BlackBrush, CurX - Raddim / 2, CurY - Raddim / 2, Raddim, Raddim)
GraphDC.FillEllipse(WhiteBrush, CurX - Raddim / 4, CurY - Raddim / 4, Raddim / 2, Raddim / 2)
CurX = iCenterX + Raddim / 2 * Math.Cos(jd * (Math.PI / 180))
CurY = iCenterY + Raddim / 2 * Math.Sin(jd * (Math.PI / 180))
GraphDC.FillEllipse(WhiteBrush, CurX - Raddim / 2, CurY - Raddim / 2, Raddim, Raddim)
GraphDC.FillEllipse(BlackBrush, CurX - Raddim / 4, CurY - Raddim / 4, Raddim / 2, Raddim / 2)
GraphDC.DrawEllipse(PenBK, iCenterX - Raddim, iCenterY - Raddim, Raddim * 2, Raddim * 2)
Dim i As Integer
Dim j As Integer
Dim iStartY As Integer
Dim iStartX As Integer
Dim iStep As Integer
Dim iWidth As Integer
For i = 0 To 7
If i = iLocalBG Then
If blinitFlags = False Then
PenTemp = PenRed
Else
PenTemp = Pen3
End If
Else
PenTemp = Pen3
End If
For j = 0 To 2
iStartY = iCenterY - Math.Cos(Math.PI / 4 * i) * (Raddim + 8) - Math.Cos(Math.PI / 4 * i) * 8 * j
iStartX = iCenterX + Math.Sin(Math.PI / 4 * i) * (Raddim + 8) + Math.Sin(Math.PI / 4 * i) * 8 * j
If (XtFw(i) And 2 ^ j) > 0 Then
iStep = 0
Else
iStep = 3
End If
iWidth = 10 + j * 3
If iStep = 0 Then
GraphDC.DrawLine(PenTemp, iStartX - iWidth * Math.Cos(Math.PI / 4 * i), iStartY - iWidth * Math.Sin(Math.PI / 4 * i), iStartX + iWidth * Math.Cos(Math.PI / 4 * i), iStartY + iWidth * Math.Sin(Math.PI / 4 * i))
Else
GraphDC.DrawLine(PenTemp, iStartX + iStep * Math.Cos(Math.PI / 4 * i), iStartY + iStep * Math.Sin(Math.PI / 4 * i), iStartX + iWidth * Math.Cos(Math.PI / 4 * i), iStartY + iWidth * Math.Sin(Math.PI / 4 * i))
GraphDC.DrawLine(PenTemp, iStartX - iStep * Math.Cos(Math.PI / 4 * i), iStartY - iStep * Math.Sin(Math.PI / 4 * i), iStartX - iWidth * Math.Cos(Math.PI / 4 * i), iStartY - iWidth * Math.Sin(Math.PI / 4 * i))
End If
Next j
Next i
End Sub
'=====================================================
'Draw Pie segment
'
' graphicsObject - Drawing surface for pie segment
' pen - Pen to use to draw pie segment
' x,y - Center Coordinates of pie chart
' width - width of pie chart
' height - height of pie chart
' startAngle - Angle of start of pie segment
' sweepAngle - Angle of end of pie segment
'
Private Sub drawPie(ByVal graphicsObject As Graphics, ByVal pen As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal startAngle As Single, ByVal sweepAngle As Single)
Dim xAngle(12) As Single
Dim yAngle(12) As Single
Dim angleIncrement As Single
angleIncrement = (sweepAngle - startAngle) / 10
Dim angle As Single
angle = startAngle
Dim i As Integer
For i = 0 To 10
xAngle(i) = x + (Math.Cos(angle * (Math.PI / 180)) * (width / 2))
yAngle(i) = y + (Math.Sin(angle * (Math.PI / 180)) * (height / 2))
angle += angleIncrement
Next i
xAngle(11) = x + (Math.Cos(sweepAngle * (Math.PI / 180)) * (width / 2))
yAngle(11) = y + (Math.Sin(sweepAngle * (Math.PI / 180)) * (height / 2))
Dim anglePoints(12) As Point
anglePoints(0) = New Point(x, y)
For i = 0 To 11
anglePoints(i + 1) = New Point(CInt(xAngle(i)), CInt(yAngle(i)))
Next
graphicsObject.DrawPolygon(pen, anglePoints)
End Sub
'=====================================================
'Draw Filled Pie segment
'
' graphicsObject - Drawing surface for pie segment
' solidBrush - Brush to use to draw pie segment
' x,y - Center Coordinates of pie chart
' width - width of pie chart
' height - height of pie chart
' startAngle - Angle of start of pie segment
' sweepAngle - Angle of end of pie segment
'
Sub fillPie(ByVal graphicsObject As Graphics, ByVal solidBrush As SolidBrush, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal startAngle As Single, ByVal sweepAngle As Single)
Dim xAngle(12) As Single
Dim yAngle(12) As Single
Dim angleIncrement As Single
angleIncrement = (sweepAngle - startAngle) / 10
Dim angle As Single
angle = startAngle
Dim i As Integer
For i = 0 To 10
xAngle(i) = x + (Math.Cos(angle * (Math.PI / 180)) * (width / 2))
yAngle(i) = y + (Math.Sin(angle * (Math.PI / 180)) * (height / 2))
angle += angleIncrement
Next i
xAngle(11) = x + (Math.Cos(sweepAngle * (Math.PI / 180)) * (width / 2))
yAngle(11) = y + (Math.Sin(sweepAngle * (Math.PI / 180)) * (height / 2))
Dim anglePoints(12) As Point
anglePoints(0) = New Point(x, y)
For i = 0 To 11
anglePoints(i + 1) = New Point(CInt(xAngle(i)), CInt(yAngle(i)))
Next
graphicsObject.FillPolygon(solidBrush, anglePoints)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If blSelect = False Then
TextBox1.Text = ""
blinitFlags = False
blStop = False
blSelect = True
Timer1.Interval = 100
Button1.Text = "停止卦盘"
Timer1.Enabled = True
Else
blStop = True
blSelect = False
Timer1.Interval = 100
iSD = 0
iSelectGC = iLocalBG
Button1.Text = "启动卦盘"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
snJd += 15
snJd = snJd Mod 360
PictureBox1.Image = CreateBmp()
If blStop = True Then
If Timer1.Interval >= 200 Then
If iLocalBG = iSelectGC Then
Timer1.Enabled = False
showTitle(intGMRule(ComboBox1.SelectedIndex) * 100 + iSelectGC + 1)
End If
Else
Timer1.Interval = Timer1.Interval + 20
End If
End If
iLocalBG = (iLocalBG + 1) Mod 8
End Sub
Sub showTitle(ByVal ID As Integer)
'If ID > 800 Then
' MsgBox("试用版本,请与作者联系netsrc@yeah.net")
'Else
Cmd.CommandText = "SELECT * FROM TJ where MasterID=" + CStr(ID)
Dim da As IDbDataAdapter
da = New SQLiteDataAdapter
da.SelectCommand = Cmd
Dim ds As DataSet
ds = New DataSet()
da.Fill(ds)
Dim tb As New DataTable
tb = ds.Tables(0)
If tb.Rows.Count > 0 Then
TextBox1.Text = tb.Rows(0).Item("caption") + Chr(13) + Chr(10)
TextBox1.Text = TextBox1.Text + tb.Rows(0).Item("MasterName")
End If
'End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iValue As Integer
TextBox1.Text = ""
iValue = CInt(NumericUpDown1.Value)
showTitle(intGMRule(ComboBox1.SelectedIndex) * 100 + iValue)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ""
TextBox2.Text = strGmCaption(ComboBox1.SelectedIndex)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -