?? 主窗體.frm
字號:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Form1
Caption = "主窗體"
ClientHeight = 9105
ClientLeft = 165
ClientTop = 855
ClientWidth = 11550
LinkTopic = "Form1"
ScaleHeight = 9105
ScaleWidth = 11550
StartUpPosition = 3 '窗口缺省
WindowState = 2 'Maximized
Begin MSAdodcLib.Adodc Adodc1
Height = 735
Left = 2880
Top = 240
Visible = 0 'False
Width = 1455
_ExtentX = 2566
_ExtentY = 1296
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = $"主窗體.frx":0000
OLEDBString = $"主窗體.frx":0090
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "工資表"
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋體"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.TextBox Text6
Height = 495
Left = 9360
TabIndex = 12
Top = 8400
Width = 1935
End
Begin VB.CommandButton Command7
Caption = "更改"
Height = 495
Left = 4320
TabIndex = 11
Top = 6720
Width = 1215
End
Begin VB.TextBox Text5
Height = 495
Left = 7200
TabIndex = 10
Top = 8400
Width = 1935
End
Begin VB.TextBox Text4
Height = 495
Left = 4800
TabIndex = 9
Top = 8400
Width = 2055
End
Begin VB.TextBox Text3
Height = 495
Left = 2400
TabIndex = 8
Top = 8400
Width = 2055
End
Begin VB.TextBox Text2
Height = 495
Left = 240
TabIndex = 7
Top = 8400
Width = 1815
End
Begin VB.CommandButton Command6
Caption = "退出"
Height = 495
Left = 9840
TabIndex = 6
Top = 6720
Width = 1215
End
Begin VB.CommandButton Command5
Caption = "刪除"
Height = 495
Left = 8160
TabIndex = 5
Top = 6720
Width = 1215
End
Begin VB.CommandButton Command4
Caption = "更新工資"
Height = 495
Left = 6240
TabIndex = 4
Top = 6720
Width = 1215
End
Begin VB.CommandButton Command3
Caption = "顯示"
Height = 495
Left = 240
TabIndex = 3
Top = 6720
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "插入"
Height = 495
Left = 240
TabIndex = 2
Top = 7560
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "查詢"
Height = 495
Left = 2280
TabIndex = 1
Top = 6720
Width = 1215
End
Begin VB.ListBox List1
Height = 5280
Left = 240
TabIndex = 0
Top = 1080
Width = 11175
End
Begin VB.Menu about
Caption = "關于"
Begin VB.Menu edition
Caption = "版本"
End
Begin VB.Menu exit
Caption = "退出"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Firstupdate As Integer
Public Firstadd As Integer
Private Sub Command1_Click()
Form2.Show
End Sub
'添加模塊
Private Sub Command2_Click()
If Firstadd = 1 Then
Me.Text2.Text = "在此輸入序號"
Me.Text3.Text = "在此輸入姓名"
Me.Text4.Text = "在此輸入入校時間"
Me.Text5.Text = "在此輸入贍養人數"
Me.Text6.Text = "在此輸入工資"
MsgBox "在根據方框內的提示正確輸入"
Me.Text2.Text = ""
Me.Text3.Text = ""
Me.Text4.Text = ""
Me.Text5.Text = ""
Me.Text6.Text = ""
End If
Me.Text2.SetFocus
If Firstadd = 1 Then
Firstadd = Firstadd + 1
Exit Sub
End If
If Me.Text2.Text = "" Or Me.Text3.Text = "" Or Me.Text4 = "" Or Me.Text6.Text = "" Then
MsgBox "在方框內完整地輸入要插入的信息"
Else
If Not IsNumeric(Me.Text2.Text) Or Not IsNumeric(Me.Text5.Text) Or Not IsNumeric(Me.Text6.Text) Then
MsgBox "插入值類型不匹配.增添記錄失敗"
GoTo error
End If
If Int(Me.Text5.Text) > 128 Then
MsgBox "贍養人數不能超過128"
GoTo error
End If
If Len(Me.Text3.Text) > 20 Then
MsgBox "姓名字長不超過20"
GoTo error
End If
If Len(Me.Text2.Text) > 9 Or Len(Me.Text6.Text) > 9 Then
MsgBox "序號或工資大小越界"
GoTo error
End If
If Not IsDate(Me.Text4.Text) Then
MsgBox "日期格式不能識別"
GoTo error
End If
'若游標打開 ,則關閉他,重新用查詢語句打開游標
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 1
End If
'用查詢語句打開游標
RES.ActiveConnection = Comsalary
RES.Source = "select * from 工資表"
RES.Open
ResOpen = 1
ResClose = 0
'判斷是否有重復字段
For i = 0 To Me.List1.ListCount - 2
If Int(Me.Text2.Text) = RES.Fields("序號") Then
MsgBox "在關鍵字段插入了重復值,插入失敗"
GoTo error
End If
RES.MoveNext
Next
'插入記錄
If ResOpen = 1 Then
RES.Close
ResClose = 1
ResOpen = 0
RES.Source = "insert 工資表(序號,姓名,入校時間,贍養人數,原工資) values ( '" & Me.Text2.Text & "', '" & Me.Text3.Text & "','" & Me.Text4.Text & "','" & Me.Text5.Text & "', '" & Me.Text6.Text & "') "
RES.Open
ResOpen = 1
ResClose = 0
MsgBox "成功添加"
ResOpen = 0
ResClose = 1
Me.Adodc1.Refresh
Call showdata
End If
End If
error:
If ResOpen = 1 Then
RES.Close
ResClose = 1
ResOpen = 0
End If
End Sub
Private Sub Command3_Click()
Call showdata
End Sub
Private Sub Command4_Click()
CHANGE.ActiveConnection = Comsalary
CHANGE.Source = "select * from 工資表"
CHANGE.Open
CHANGE.MoveFirst
While Not CHANGE.EOF
Call refreshsalary(CHANGE.Fields("原工資"), CHANGE.Fields("入校時間"), CHANGE.Fields("贍養人數"))
CHANGE.MoveNext
Wend
Call showdata
CHANGE.Close
End Sub
Private Sub Command5_Click()
Dim Delno As String
Dim Nextres As Integer
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 0
End If
Delno = InputBox("輸入要刪除的教師的序號")
If IsNumeric(Delno) Then
RES.Source = "select *from 工資表"
RES.Open
ResOpen = 1
ResClose = 0
RES.MoveFirst
While Not RES.EOF
Nextres = Nextres + 1
If RES.Fields(0) = Int(Delno) Then
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 1
End If
RES.Source = "delete 工資表 where 序號= ' " & Delno & " '"
RES.Open
ResOpen = 1
ResClose = 0
MsgBox " 刪除成功"
Me.Adodc1.Refresh
ResOpen = 0
ResClose = 1
Call showdata '刷新顯示
ResOpen = 0
ResClose = 1
Exit Sub
Nextres = -1
End If
RES.MoveNext
Wend
If Nextres <> -1 Then
MsgBox "沒有此記錄 刪除失敗"
End If
End If
End Sub
Private Sub Command7_Click()
Dim UpdateIndex As String
Dim i As Integer
Dim Upname As String
Dim Upnewsalry As String
Dim Uppeople As String
Dim Uptime As String
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 1
End If
UpdateIndex = InputBox("輸入要更改教師的序號")
If IsNumeric(UpdateIndex) Then
RES.Source = "select * from 工資表"
RES.Open
ResClose = 0
ResOpen = 1
Else
GoTo error
End If
While Not RES.EOF
'查找你要更新的記錄
If RES.Fields(0) = Int(UpdateIndex) Then
i = 1
'查找到 輸入新記錄信息
'該姓名--------------------------------------------------------
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 1
End If
Upname = InputBox("輸入新姓名,如果保持原來姓名,單擊取消")
If Len(Upname) > 20 Then
MsgBox "姓名長度小于20"
Upname = ""
End If
If Upname <> "" Then
RES.ActiveConnection = Comsalary
RES.Source = "update 工資表 set 姓名 ='" & Upname & "' where 序號= '" & UpdateIndex & "'"
RES.Open
End If
'改日期 ------------------------------------------------------------
Uptime = (InputBox("輸入新的入校日期,如果保持原來的值,單擊取消"))
If Not IsDate(Uptime) And Uptime <> "" Then
MsgBox "輸入的日期格式不能識別"
Uptime = ""
End If
If Uptime <> "" Then
RES.Source = "update 工資表 set 入校時間 ='" & Uptime & "' where 序號= '" & UpdateIndex & "'"
RES.Open
End If
'改工資-------------------------------------------------------------
Upnewsalry = InputBox("輸入新的工資,如果保持原來的值,單擊取消")
If Not IsNumeric(Upnewsalry) And Upnewsalry <> "" Then
MsgBox "輸入錯誤"
Upnewsalry = ""
End If
If Upnewsalry <> "" Then
RES.Source = "update 工資表 set 原工資 ='" & Upnewsalry & "' where 序號= '" & UpdateIndex & "'"
RES.Open
End If
'改贍養人數-----------------------------------------------------
Uppeople = InputBox("輸入新的贍養人數,如果保持原來的值,單擊取消")
If Not IsNumeric(Uppeople) And Uppeople <> "" Then
MsgBox "輸入錯誤"
Uppeople = ""
End If
If Uppeople <> "" Then
RES.Source = "update 工資表 set 贍養人數 ='" & Uppeople & "' where 序號= '" & UpdateIndex & "'"
RES.Open
'更改后退出 自動關閉游標
End If
Call showdata
ResOpen = 0
ResClose = 1
Exit Sub
End If
RES.MoveNext
Wend
If i <> 1 Then
MsgBox "不存在序號為 " & UpdateIndex & " 的教師 更新無法完成"
GoTo error
End If
Firstupdate = 9
'未更改退出,關閉游標
RES.Close
ResClose = 1
ResOpen = 0
error:
End Sub
Private Sub Command6_Click()
End
End Sub
Private Sub edition_Click()
Form4.Show
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub Command8_Click()
End Sub
Private Sub Form_load()
ResClose = 1
If ResClose = 1 Then
RES.ActiveConnection = Comsalary
Firstadd = 1
Firstupdate = 1
End If
Call showdata
End Sub
'顯示列表
Public Sub showdata()
'游標的SQL語句
'RES.Close
If ResOpen = 1 Then '若游標打開,則關閉他重新打開
RES.Close
ResClose = 0
ResOpen = 1
End If
'重新用查詢語句將游標打開
RES.ActiveConnection = Comsalary
RES.Source = "select * from 工資表"
RES.Open
ResOpen = 1
ResClose = 0
Me.List1.Clear '清空列表
'當游標指向的記錄存在時操作
Me.List1.List(0) = RES.Fields(0).Name & " " & RES.Fields(1).Name & " " & RES.Fields(2).Name & " " & RES.Fields(3).Name & " " & RES.Fields(4).Name & " " & RES.Fields(5).Name
Index = 1
RES.MoveFirst
While Not RES.EOF
For num = 0 To RES.Fields.Count - 1
Me.List1.List(Index) = Me.List1.List(Index) & RES.Fields(num) & " "
Next
RES.MoveNext
Index = Index + 1
Wend
RES.Close
ResClose = 1
ResOpen = 0
End Sub
Public Sub refreshsalary(sa As Long, year As Date, people As Long)
Dim op As Long
Dim OY As Integer
If ResOpen = 1 Then
RES.Close
ResOpen = 0
ResClose = 1
End If
OY = Now - year
OY = OY / 365
If Int(year) < 0 Then
MsgBox "工齡為負數,計算終止"
End
End If
If Int(people) < 0 Then
MsgBox "贍養人數為負數,計算終止"
End
End If
If sa > 26000 Then
op = sa
Else
op = sa + 100 * people + Int(OY) * 50
If op > 26000 Then
op = 26000
End If
End If
RES.Source = "update 工資表 set 更改工資 = '" & op & "' where 原工資 = '" & sa & "'"
RES.Open
ResClose = 1
ResOpen = 0
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -