Form1.frm
Upload User: sss810909
Upload Date: 2008-01-20
Package Size: 244k
Code Size: 16k
Category:

Other systems

Development Platform:

Visual Basic

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "数据库操作实例-----简易通讯录-----By AlicE-----西工大17191班"
  4.    ClientHeight    =   5985
  5.    ClientLeft      =   -645
  6.    ClientTop       =   150
  7.    ClientWidth     =   7110
  8.    Icon            =   "Form1.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   5985
  11.    ScaleWidth      =   7110
  12.    Begin VB.Frame Frame3 
  13.       Caption         =   "修改、删除"
  14.       Height          =   1935
  15.       Left            =   240
  16.       TabIndex        =   13
  17.       Top             =   3840
  18.       Width           =   6375
  19.       Begin VB.TextBox Text13 
  20.          BackColor       =   &H80000004&
  21.          Height          =   375
  22.          Left            =   1680
  23.          TabIndex        =   32
  24.          Top             =   1440
  25.          Width           =   1695
  26.       End
  27.       Begin VB.TextBox Text12 
  28.          BackColor       =   &H80000004&
  29.          Height          =   375
  30.          Left            =   4440
  31.          TabIndex        =   30
  32.          Top             =   840
  33.          Width           =   1815
  34.       End
  35.       Begin VB.CommandButton Command5 
  36.          Caption         =   "删除"
  37.          Height          =   495
  38.          Left            =   3480
  39.          TabIndex        =   23
  40.          Top             =   240
  41.          Width           =   1215
  42.       End
  43.       Begin VB.CommandButton Command4 
  44.          Caption         =   "修改"
  45.          Height          =   495
  46.          Left            =   4920
  47.          TabIndex        =   22
  48.          Top             =   240
  49.          Width           =   1335
  50.       End
  51.       Begin VB.TextBox Text9 
  52.          BackColor       =   &H80000004&
  53.          Height          =   375
  54.          Left            =   3840
  55.          TabIndex        =   21
  56.          Top             =   1440
  57.          Width           =   2415
  58.       End
  59.       Begin VB.TextBox Text8 
  60.          BackColor       =   &H80000004&
  61.          Height          =   375
  62.          Left            =   1680
  63.          TabIndex        =   18
  64.          Top             =   840
  65.          Width           =   1860
  66.       End
  67.       Begin VB.CommandButton Command3 
  68.          Caption         =   "显示结果"
  69.          Height          =   495
  70.          Left            =   2040
  71.          TabIndex        =   16
  72.          Top             =   240
  73.          Width           =   1215
  74.       End
  75.       Begin VB.TextBox Text7 
  76.          Height          =   375
  77.          Left            =   960
  78.          TabIndex        =   15
  79.          Top             =   240
  80.          Width           =   735
  81.       End
  82.       Begin VB.Label Label14 
  83.          Caption         =   "访问次数"
  84.          Height          =   255
  85.          Left            =   840
  86.          TabIndex        =   31
  87.          Top             =   1560
  88.          Width           =   735
  89.       End
  90.       Begin VB.Label Label13 
  91.          Caption         =   "验证码"
  92.          Height          =   375
  93.          Left            =   3720
  94.          TabIndex        =   29
  95.          Top             =   960
  96.          Width           =   855
  97.       End
  98.       Begin VB.Label Label10 
  99.          Caption         =   "备注"
  100.          Height          =   255
  101.          Left            =   3480
  102.          TabIndex        =   20
  103.          Top             =   1560
  104.          Width           =   495
  105.       End
  106.       Begin VB.Label Label9 
  107.          Caption         =   "文件名"
  108.          Height          =   375
  109.          Left            =   1080
  110.          TabIndex        =   19
  111.          Top             =   960
  112.          Width           =   615
  113.       End
  114.       Begin VB.Label Label8 
  115.          Caption         =   "当前数据:"
  116.          Height          =   375
  117.          Left            =   120
  118.          TabIndex        =   17
  119.          Top             =   960
  120.          Width           =   975
  121.       End
  122.       Begin VB.Label Label7 
  123.          Caption         =   "ID值"
  124.          Height          =   255
  125.          Left            =   480
  126.          TabIndex        =   14
  127.          Top             =   360
  128.          Width           =   495
  129.       End
  130.    End
  131.    Begin VB.Frame Frame2 
  132.       Caption         =   "添加"
  133.       Height          =   1695
  134.       Left            =   240
  135.       TabIndex        =   7
  136.       Top             =   2040
  137.       Width           =   6375
  138.       Begin VB.TextBox Text11 
  139.          Height          =   375
  140.          Left            =   960
  141.          TabIndex        =   28
  142.          Top             =   960
  143.          Width           =   1575
  144.       End
  145.       Begin VB.TextBox Text10 
  146.          Height          =   375
  147.          Left            =   3240
  148.          TabIndex        =   26
  149.          Top             =   240
  150.          Width           =   1335
  151.       End
  152.       Begin VB.CommandButton Command6 
  153.          Caption         =   "显示所有"
  154.          Height          =   495
  155.          Left            =   4920
  156.          TabIndex        =   24
  157.          Top             =   240
  158.          Width           =   1335
  159.       End
  160.       Begin VB.CommandButton Command2 
  161.          Caption         =   "添加"
  162.          Height          =   495
  163.          Left            =   4920
  164.          TabIndex        =   12
  165.          Top             =   840
  166.          Width           =   1335
  167.       End
  168.       Begin VB.TextBox Text6 
  169.          Height          =   375
  170.          Left            =   3120
  171.          TabIndex        =   11
  172.          Top             =   960
  173.          Width           =   1575
  174.       End
  175.       Begin VB.TextBox Text5 
  176.          Height          =   375
  177.          Left            =   960
  178.          TabIndex        =   10
  179.          Top             =   240
  180.          Width           =   1455
  181.       End
  182.       Begin VB.Label Label12 
  183.          Caption         =   "访问次数"
  184.          Height          =   375
  185.          Left            =   120
  186.          TabIndex        =   27
  187.          Top             =   1080
  188.          Width           =   855
  189.       End
  190.       Begin VB.Label Label11 
  191.          Caption         =   "验证码"
  192.          Height          =   375
  193.          Left            =   2520
  194.          TabIndex        =   25
  195.          Top             =   360
  196.          Width           =   735
  197.       End
  198.       Begin VB.Label Label6 
  199.          Caption         =   "备注"
  200.          Height          =   375
  201.          Left            =   2640
  202.          TabIndex        =   9
  203.          Top             =   1080
  204.          Width           =   495
  205.       End
  206.       Begin VB.Label Label5 
  207.          Caption         =   "文件名"
  208.          Height          =   255
  209.          Left            =   120
  210.          TabIndex        =   8
  211.          Top             =   360
  212.          Width           =   735
  213.       End
  214.    End
  215.    Begin VB.CommandButton Command1 
  216.       Caption         =   "查询"
  217.       Height          =   375
  218.       Left            =   1920
  219.       TabIndex        =   0
  220.       Top             =   960
  221.       Width           =   975
  222.    End
  223.    Begin VB.Frame Frame1 
  224.       Caption         =   "查询"
  225.       Height          =   1575
  226.       Left            =   240
  227.       TabIndex        =   1
  228.       Top             =   120
  229.       Width           =   6375
  230.       Begin VB.TextBox Text1 
  231.          Height          =   375
  232.          Left            =   3480
  233.          TabIndex        =   35
  234.          Top             =   360
  235.          Width           =   2535
  236.       End
  237.       Begin VB.ComboBox Combo2 
  238.          Height          =   300
  239.          ItemData        =   "Form1.frx":038A
  240.          Left            =   1920
  241.          List            =   "Form1.frx":03A0
  242.          TabIndex        =   34
  243.          Text            =   "请选择表"
  244.          Top             =   360
  245.          Width           =   1215
  246.       End
  247.       Begin VB.ComboBox Combo1 
  248.          Height          =   300
  249.          ItemData        =   "Form1.frx":03D2
  250.          Left            =   360
  251.          List            =   "Form1.frx":03D4
  252.          TabIndex        =   33
  253.          Text            =   "请选择库"
  254.          Top             =   360
  255.          Width           =   1335
  256.       End
  257.       Begin VB.TextBox Text4 
  258.          BackColor       =   &H80000004&
  259.          Enabled         =   0   'False
  260.          Height          =   375
  261.          Left            =   5160
  262.          TabIndex        =   5
  263.          Top             =   840
  264.          Width           =   735
  265.       End
  266.       Begin VB.TextBox Text3 
  267.          BackColor       =   &H80000004&
  268.          Enabled         =   0   'False
  269.          Height          =   375
  270.          Left            =   3960
  271.          TabIndex        =   2
  272.          Top             =   840
  273.          Width           =   735
  274.       End
  275.       Begin VB.Label Label3 
  276.          Height          =   495
  277.          Left            =   1800
  278.          TabIndex        =   6
  279.          Top             =   240
  280.          Width           =   1335
  281.       End
  282.       Begin VB.Label Label2 
  283.          Caption         =   "到"
  284.          Height          =   255
  285.          Left            =   4800
  286.          TabIndex        =   4
  287.          Top             =   960
  288.          Width           =   255
  289.       End
  290.       Begin VB.Label Label1 
  291.          Caption         =   "ID的范围从"
  292.          Height          =   255
  293.          Left            =   2880
  294.          TabIndex        =   3
  295.          Top             =   960
  296.          Width           =   975
  297.       End
  298.    End
  299.    Begin VB.Menu File1 
  300.       Caption         =   "文件(&F)"
  301.       Begin VB.Menu source1 
  302.          Caption         =   "源码(&S)"
  303.       End
  304.       Begin VB.Menu exit1 
  305.          Caption         =   "退出(&X)"
  306.       End
  307.    End
  308.    Begin VB.Menu beifen 
  309.       Caption         =   "备份(&E)"
  310.    End
  311.    Begin VB.Menu about1 
  312.       Caption         =   "关于(&A)"
  313.    End
  314. End
  315. Attribute VB_Name = "Form1"
  316. Attribute VB_GlobalNameSpace = False
  317. Attribute VB_Creatable = False
  318. Attribute VB_PredeclaredId = True
  319. Attribute VB_Exposed = False
  320. Dim DBS As Database
  321. Dim counter As Integer
  322. Private Sub about1_Click()
  323. frmAbout.Show
  324. End Sub
  325. Private Sub beifen_Click()
  326. Dim fso As New FileSystemObject, fil As File
  327. Set fil = fso.GetFile(AppP & "data.mdb")
  328. fil.Copy (AppP & "backupdata_" & Date & ".mdb")
  329. MsgBox "数据备份已经成功完成!" & vbCrLf & "数据备份到文件夹:" & AppP & "backup" & vbCrLf & _
  330. "数据还原方法:拷贝备份文件到" & AppP & "替换原数据文件", vbInformation, "备份提示"
  331. End Sub
  332. Private Sub Combo2_Click()
  333. If Combo2.ListIndex = 5 Then
  334. Text1.BackColor = &H80000004
  335. Text3.BackColor = &H80000005
  336. Text4.BackColor = &H80000005
  337. Text3.Enabled = True
  338. Text4.Enabled = True
  339. Text1.Enabled = False
  340. Else
  341. Text3.BackColor = &H80000004
  342. Text4.BackColor = &H80000004
  343. Text1.BackColor = &H80000005
  344. Text3.Enabled = False
  345. Text4.Enabled = False
  346. Text1.Enabled = True
  347. End If
  348. End Sub
  349. Private Sub Command1_Click()
  350. 'ID查询
  351. If Combo2.ListIndex = 0 Then
  352. LSQL = Trim(Text1.Text)
  353. SQLNow = "select * from info where ID like '%" & LSQL & "%'  order by ID"
  354. Form3.Show
  355. End If
  356. '文件名查询
  357. If Combo2.ListIndex = 1 Then
  358. LSQL = Trim(Text1.Text)
  359. SQLNow = "select * from info where 文件名 like '%" & LSQL & "%'  order by ID"
  360. Form3.Show
  361. End If
  362. '验证码查询
  363. If Combo2.ListIndex = 2 Then
  364. LSQL = Trim(Text1.Text)
  365. SQLNow = "select * from info where 验证码 like '%" & LSQL & "%'  order by ID"
  366. Form3.Show
  367. End If
  368. '访问次数查询
  369. If Combo2.ListIndex = 3 Then
  370. LSQL = Trim(Text1.Text)
  371. SQLNow = "select * from info where 访问次数 like '%" & LSQL & "%'  order by ID"
  372. Form3.Show
  373. End If
  374. '状态查询
  375. If Combo2.ListIndex = 4 Then
  376. LSQL = Trim(Text1.Text)
  377. SQLNow = "select * from info where 状态 like '%" & LSQL & "%'  order by ID"
  378. Form3.Show
  379. End If
  380. 'ID查询
  381. If Combo2.ListIndex = 5 Then
  382. If Trim(Text3.Text) = "" Or Trim(Text4.Text) = "" Then
  383. MsgBox "请输入数值!", vbExclamation, "错误提示"
  384. Exit Sub
  385. ElseIf CInt(Trim(Text4.Text)) < CInt(Trim(Text3.Text)) Then
  386. MsgBox "请输入正确的数值!", vbExclamation, "错误提示"
  387. Else
  388. LSQL = "where 文件名 like '此列为%' or ID>=" & CInt(Trim(Text3.Text)) & " and ID<=" & CInt(Trim(Text4.Text)) & "  order by ID"
  389. SQLNow = "select * from info " & LSQL
  390. Form3.Show
  391. End If
  392. End If
  393. End Sub
  394. Private Sub Command2_Click()
  395. Dim RSEMail As Recordset
  396. Dim counter As String
  397. If Trim(Text5.Text) = "" Then
  398. MsgBox "名称不能为空!", vbExclamation, "错误提示"
  399. Exit Sub
  400. Else
  401. value1 = Trim(Text5.Text)
  402. value2 = Trim(Text6.Text)
  403. value3 = Trim(Text10.Text)
  404. value4 = Trim(Text11.Text)
  405. Call InsertFunction
  406. End If
  407. End Sub
  408. Private Sub Command3_Click()
  409. Dim DataID As Integer
  410. If Trim(Text7.Text) = "" Then
  411. MsgBox "请输入正确的ID值!", vbExclamation, "错误提示"
  412. Exit Sub
  413. End If
  414. Set DBEmail = OpenDatabase(AppP & "data.mdb", ture, ture, ";Pwd=lyttlyqjhqjw ")
  415. Set RSEMail = DBEmail.OpenRecordset("select 文件名,验证码,访问次数,状态 from info where ID=" & CInt(Trim(Text7.Text)), dbOpenDynaset, dbSeeChanges, dbOptimistic)
  416. If RSEMail.EOF Then
  417. MsgBox "没有这个ID的纪录!", vbInformation, "错误提示"
  418. RSEMail.Close
  419. Set RSEMail = Nothing
  420. Exit Sub
  421. End If
  422. Text8.Text = RSEMail.Fields("文件名").Value & ""
  423. Text12.Text = RSEMail.Fields("验证码").Value & ""
  424. Text13.Text = RSEMail.Fields("访问次数").Value & ""
  425. Text9.Text = RSEMail.Fields("状态").Value & ""
  426. RSEMail.Close
  427. Set RSEMail = Nothing
  428. Text7.BackColor = &H80000004
  429. Text8.BackColor = &H80000005
  430. Text9.BackColor = &H80000005
  431. Text12.BackColor = &H80000005
  432. Text13.BackColor = &H80000005
  433. End Sub
  434. Private Sub Command4_Click()
  435. If Trim(Text8.Text) = "" Then
  436. MsgBox "先按下显示结果按钮才能更新修改数据。", vbInformation, "提示"
  437. Exit Sub
  438. End If
  439. If MsgBox("你真的要修改这个纪录吗?", vbYesNo + vbQuestion, "确认修改") = vbYes Then
  440. Set DBEmail = OpenDatabase(AppP & "data.mdb", ture, ture, ";Pwd=lyttlyqjhqjw ")
  441. Set RSEMail = DBEmail.OpenRecordset("select * from info where ID=" & CInt(Trim(Text7.Text)), dbOpenDynaset, dbSeeChanges, dbOptimistic)
  442. RSEMail.Edit
  443. RSEMail.Fields("文件名") = Trim(Text8.Text)
  444. RSEMail.Fields("验证码") = Trim(Text12.Text)
  445. RSEMail.Fields("访问次数") = Trim(Text13.Text)
  446. RSEMail.Fields("状态") = Trim(Text9.Text)
  447. RSEMail.Update
  448. RSEMail.Close
  449. Set RSEMail = Nothing
  450. MsgBox "修改成功!" & vbCrLf & "相关信息:" & vbCrLf & "文件名:" & Trim(Text8.Text) _
  451. & vbCrLf & "验证码:" & Trim(Text12.Text) & vbCrLf & "访问次数:" & Trim(Text13.Text) & vbCrLf _
  452. & "备注:" & Trim(Text9.Text), vbInformation, "提示"
  453. End If
  454. End Sub
  455. Private Sub Command5_Click()
  456. If Trim(Text7.Text) = "" Then
  457. MsgBox "请输入正确的ID值!", vbExclamation, "错误提示"
  458. Exit Sub
  459. End If
  460. Set DBEmail = OpenDatabase(AppP & "data.mdb", ture, ture, ";Pwd=lyttlyqjhqjw ")
  461. Set RSEMail = DBEmail.OpenRecordset("select 文件名 from info where ID=" & CInt(Trim(Text7.Text)), dbOpenDynaset, dbSeeChanges, dbOptimistic)
  462. If RSEMail.EOF Then
  463. MsgBox "没有这个ID的纪录!", vbInformation, "提示"
  464. RSEMail.Close
  465. Set RSEMail = Nothing
  466. Exit Sub
  467. End If
  468. datavalue = RSEMail.Fields("文件名").Value
  469. If MsgBox("你真的要删除这个纪录吗?", vbYesNo + vbQuestion, "确认删除") = vbYes Then
  470. RSEMail.Edit
  471. RSEMail.Delete
  472. RSEMail.Close
  473. Set RSEMail = Nothing
  474. MsgBox "纪录" & datavalue & "已经被删除。", vbInformation, "提示"
  475. Text7.Text = ""
  476. Text8.Text = ""
  477. Text9.Text = ""
  478. End If
  479. End Sub
  480. Private Sub Command6_Click()
  481. Dim RS As Recordset
  482. Dim AppPath
  483. Form2.Show
  484. End Sub
  485. Private Sub exit1_Click()
  486. End
  487. End Sub
  488. Private Sub Form_Load()
  489. Dim X0 As Long
  490. Dim Y0 As Long
  491. Call GetAppPath
  492.     '让窗体居中
  493.     X0 = Screen.Width
  494.     Y0 = Screen.Height
  495.     X0 = (X0 - Me.Width) / 2
  496.     Y0 = (Y0 - Me.Height) / 2
  497.     Me.Move X0, Y0
  498. End Sub
  499. Private Sub Form_Unload(Cancel As Integer)
  500. Cancel = True
  501.  Select Case MsgBox("您真的想退出吗?", vbOKCancel + vbQuestion, "确认退出本程序")
  502. Case vbOK
  503. End
  504. Cancel = False
  505. Case Else
  506. Cancel = True
  507. End Select
  508. End Sub
  509. Private Sub Option1_Click()
  510. Text1.BackColor = &H80000004
  511. Text2.BackColor = &H80000005
  512. Text3.BackColor = &H80000004
  513. Text4.BackColor = &H80000004
  514. End Sub
  515. Private Sub Option2_Click()
  516. Text1.BackColor = &H80000005
  517. Text2.BackColor = &H80000004
  518. Text3.BackColor = &H80000004
  519. Text4.BackColor = &H80000004
  520. End Sub
  521. Private Sub Option3_Click()
  522. Text1.BackColor = &H80000004
  523. Text2.BackColor = &H80000004
  524. Text3.BackColor = &H80000005
  525. Text4.BackColor = &H80000005
  526. End Sub
  527. Private Sub source1_Click()
  528. form4.Show
  529. End Sub
  530. Private Sub Text7_GotFocus()
  531. Text7.BackColor = &H80000005
  532. End Sub