📄 form1.vb
字号:
Dim rowcount As Integer
Dim ReturnNum As Integer = 0, strExit As String
REM SQL语句初始化
Selectstr = str1
FromTB = strTB
Wherestr = str2
REM connection 和 command 的初始化
Dim objConn As OleDbConnection = GetConn()
If objConn.State = ConnectionState.Closed Then
objConn.Open()
End If
objCmd.Connection = objConn
objCmd.CommandText = "select " & Selectstr & " from " & FromTB & " where " & Wherestr 'select语句
REM table 绑定
objDA = New OleDbDataAdapter(objCmd)
Dim objDS As New DataSet
objDS.Clear()
objDA.Fill(objDS, "tmpTB") 'tmpTB只是一个中转,用来暂存表,不需定义
objTB = objDS.Tables("tmpTB")
REM 计算表的行数和列数
rowcount = objTB.Rows.Count
If rowcount <= 0 Then MsgBox("记录为空,不能导出!") : GoTo searchTB_exit
REM 返回值
strExit = ReturnNum
REM Grid部分
Grid.SetDataBinding(objDS, "tmpTB") '数据源
ts2.MappingName = "tmpTB"
ts2.AlternatingBackColor = Color.LightBlue
REM GridShed中的列变量
Dim cOrderDate1 As New DataGridTextBoxColumn, cOrderDate2 As New DataGridTextBoxColumn
Dim cOrderDate3 As New DataGridTextBoxColumn, cOrderDate4 As New DataGridTextBoxColumn
Dim cOrderDate5 As New DataGridTextBoxColumn, cOrderDate6 As New DataGridTextBoxColumn
ts2.GridColumnStyles.Clear() '清空以前的各列
'添加各列
cOrderDate1.MappingName = "记录日期" : cOrderDate1.HeaderText = "记录日期" : cOrderDate1.Width = 180 : ts2.GridColumnStyles.Add(cOrderDate1)
cOrderDate2.MappingName = "当前温度" : cOrderDate2.HeaderText = "当前温度" : cOrderDate2.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate2)
cOrderDate3.MappingName = "设定温度" : cOrderDate3.HeaderText = "设定温度" : cOrderDate3.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate3)
cOrderDate4.MappingName = "当前时间" : cOrderDate4.HeaderText = "当前时间" : cOrderDate4.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate4)
cOrderDate5.MappingName = "设定时间" : cOrderDate5.HeaderText = "设定时间" : cOrderDate5.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate5)
cOrderDate6.MappingName = "是否异常" : cOrderDate6.HeaderText = "是否异常" : cOrderDate6.Width = 100 : ts2.GridColumnStyles.Add(cOrderDate6)
searchTB_exit:
Grid.TableStyles.Add(ts2)
objConn.Close()
Return strExit
End Function
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
REM 选定校准MCU号
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub ComboBox5_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox5.SelectionChangeCommitted
Timer3.Enabled = True
'初始化选路控件
InitComBox2(ComboBox6, ComboBox5.SelectedValue)
Dim g As Graphics
Dim i As Integer, j As Integer
Dim x0 As Single, y0 As Single
Dim x1 As Point, y1 As Point, x2 As Point, y2 As Point
g = PictureBox5.CreateGraphics()
'清空画的图
g.Clear(Color.Coral)
'画XY轴
g.DrawLine(Pens.Blue, New Point(20, 20), New Point(20, 250))
g.DrawLine(Pens.Blue, New Point(20, 250), New Point(350, 250))
'画XY的刻度及单位
x0 = 20 : y0 = 250
'查找channel的信息
SearchAD(ComboBox5.SelectedValue)
DrawXY2(PictureBox5, x0, y0, ComboBox5.SelectedValue)
'画各个连接线
DrawnCurve2(PictureBox5, x0, y0)
g.Dispose()
End Sub
'*****************************************0907加**********************************************
REM "删除所选"下拉框
Private Sub ComboBox6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox6.SelectedIndexChanged
Dim no As Byte
Dim str, substr1, substr2 As String
Dim no1, no2 As Integer
Dim x, y As Integer
REM 获取2个下拉框中选中内容
no = ComboBox5.SelectedIndex
str = ComboBox6.Text
REM 提取删除所选中的x,y值
no1 = InStr(str, "x")
no2 = InStr(str, "y")
substr1 = Mid(str, no1 + 2, (no2 - 1) - (no1 + 2))
x = Val(substr1)
substr2 = Mid(str, no2 + 2, 3)
y = Val(substr2)
REM 确定+取消删除窗口
If MsgBox("确定要删除:" & Chr(13) & Chr(10) & Chr(10) & " AD值=" & x & Chr(13) & Chr(10) & " 物理量=" & y, MsgBoxStyle.OKCancel, "删除所选") = MsgBoxResult.Cancel Then
Exit Sub
End If
REM 从库中删除校准值
DelReviseVal(no, x)
REM 删除成功
MsgBox("删除成功!")
REM 重新加载此下拉框,并画图
ComboBox5_SelectionChangeCommitted(Nothing, Nothing)
End Sub
'===============================================0907加=======================================================================
Private Sub Timer3_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer3.Tick
StateTxt.Text = ""
Timer3.Enabled = False
Dim no As Byte = ComboBox5.SelectedValue
ReDim G_SendData(4)
G_SendData(0) = 130 + no
G_SendData(1) = CByte(Asc("R"))
G_SendData(2) = 0
G_SendData(3) = 0
G_SendData(4) = 69 '帧尾'E'=69
SCISendN(MSComm1, G_SendData)
Dim tmp As Byte = G_RecvNum - 1
ReDim G_RecvData(tmp)
SCIRecvN(MSComm1, G_RecvNum, 3)
If G_RecvData(0) <> 83 And G_RecvData(tmp) <> 69 Then
Form1.frmMain.StateTxt.Text = G_RecvData(0) & G_RecvData(tmp)
Exit Sub
End If
'当前选中通道的AD值
G_CurrentAD = G_RecvData(tmp - 2) * 256 + G_RecvData(tmp - 1) '当前温度的AD位于帧尾前的2字节
lbAD.Text = G_CurrentAD
lbPhy.Text = ADToPhy(G_CurrentAD, no)
btnRevise.Enabled = True
Timer3.Enabled = True
End Sub
REM 单击"校准"按钮
Private Sub btnRevise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRevise.Click
Dim myValue As String '定义临时串变量
Dim j As Integer
Dim x1 As Integer, x2 As Integer, y1 As Single, y2 As Single, y0 As Single
Dim message, title, defaultValue As String
Dim g As Graphics
''''''''''''''''Dim flag1 As Boolean = False
g = PictureBox5.CreateGraphics()
Dim no As Byte = ComboBox5.SelectedValue
Timer3.Enabled = False '0904加,校准时停止收数据
If G_RecordNum >= G_MaxRecordNum Then '*********************************************************************************0907加
MsgBox("校准点已经超过" & G_MaxRecordNum & "条!" & Chr(13) & Chr(10) & "请先删除再校准!")
Exit Sub
End If
''''''''''''''''''''''''''''''''''''''''''''''''
' G_CurrentAD = 718 '调试用
'''''''''''''''''''''''''''''''''''''''''''''
REM x0为本路当前的A/D值,已知,下面找出X1、X2两点,X1<X0<X2
For j = LBound(G_X) + 1 To UBound(G_X) '对数组x循环
If G_X(j) > G_CurrentAD Then
x1 = G_X(j - 1) : x2 = G_X(j) '找到了两点
y1 = G_Y(j - 1) : y2 = G_Y(j)
'''''''''''If (G_CurrentAD - x1) < 1 Or (x2 - G_CurrentAD) < 1 Then
''''''''''' MsgBox("选择点距离太近,放弃本次选择。", 16, "选择点错误")
''''''''''' Exit For
'''''''''''End If
'''''''''''flag1 = True
Exit For
End If
Next j
'''''''''''If flag1 = False Then Exit Sub '如果没有合适的两点,退出
REM input X0 得 y0
title = "模拟量校正—物理量标准值输入"
message = "当前值" & G_CurrentPhy & ",请输入标准值(" & G_MinPhy & "-" & G_MaxPhy & ")"
myValue = InputBox(message, title, )
y0 = Val(myValue)
If y0 < G_MinPhy Or y0 > G_MaxPhy Then '??????????myValue是string型,可以比较大小嘛?
MsgBox("输入的数值超出范围!")
Exit Sub
End If
REM 校准即写入数据库
WriteDB(no, G_CurrentAD, y0, x1, y1, x2, y2)
'************************************************************************************************0907加,校准后重画
ComboBox5_SelectionChangeCommitted(Nothing, Nothing)
REM 校准后要写Flash
'''''''''''''' WriteFlash()
Timer3.Enabled = True '0904加
End Sub
REM 单击"写入"按钮
Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
Timer3.Enabled = False '0904加,校准时停止收数据
If G_RecordNum > G_MaxRecordNum Then '*********************************************************************************0907加
MsgBox("写入点已经超过" & G_MaxRecordNum & "条!" & Chr(13) & Chr(10) & "请先删除再写入!")
Exit Sub
End If
WriteFlash()
'Timer3.Enabled = True '0904加
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ComboBox5_SelectionChangeCommitted(Nothing, Nothing)
End Sub
Private Sub ButState_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButState.Click
If ButState.Text = "隐藏信息" Then
StateTxt.Visible = False
ButState.Text = "显示信息"
Else
StateTxt.Visible = True
ButState.Text = "隐藏信息"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
txtWrite.Text = ""
TxtRead.Text = ""
End Sub
REM 选择显示Bake炉号
Private Sub cbShow_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbShow.SelectedIndexChanged
Dim no As Byte
''''''''''''''' no1 = Val(Microsoft.VisualBasic.Left(ComboBox2.Text, 1)) '可以不加取左函数
no = Val(cbShow.Text)
Select Case no
Case 1
ShowFlag1 = True : ShowFlag2 = False : ShowFlag3 = False : ShowFlag4 = False
Case 2
ShowFlag2 = True : ShowFlag1 = False : ShowFlag3 = False : ShowFlag4 = False
Case 3
ShowFlag3 = True : ShowFlag1 = False : ShowFlag2 = False : ShowFlag4 = False
Case 4
ShowFlag4 = True : ShowFlag1 = False : ShowFlag2 = False : ShowFlag3 = False
End Select
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
End Sub
REM 管理员登陆
Private Sub txtPasswordLogin_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPasswordLogin.KeyPress
Dim s0 As String, s1 As String, s2 As String, s3 As String
If Asc(e.KeyChar) = 13 Then
If txtPasswordLogin.Text = "" Then MsgBox("密码错误!") : GoTo txtPasswordLogin_exit
s1 = "Name" : s2 = "Manager" : s3 = "bar='" & Trim(txtManagerLogin.Text) & "' and userKey='" & Trim(txtPasswordLogin.Text) & "'"
s0 = JudgeUser(s1, s2, s3)
If s0 = "" Then MsgBox("密码错误!") : GoTo txtPasswordLogin_exit
G_ManagerFlag = True
txtPasswordLogin.Text = ""
MsgBox(s0 & "登陆成功!")
End If
txtPasswordLogin_exit:
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Han
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -