📄 form2.vb
字号:
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button3 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form2))
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.LightSkyBlue
Me.Button1.ForeColor = System.Drawing.Color.Red
Me.Button1.Location = New System.Drawing.Point(80, 184)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "发试卷"
'
'TextBox1
'
Me.TextBox1.BackColor = System.Drawing.Color.SkyBlue
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.TextBox1.Size = New System.Drawing.Size(392, 160)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = ""
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.LightSkyBlue
Me.Button3.ForeColor = System.Drawing.Color.Red
Me.Button3.Location = New System.Drawing.Point(216, 184)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(80, 23)
Me.Button3.TabIndex = 4
Me.Button3.Text = "退出本系统"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(392, 266)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form2"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm1 As New Form1
Try
Dim sql As String = "select stu_name from student where stu_num='" & frm1.text2 & "'"
Dim da As New OleDbDataAdapter(sql, gLinkString)
Dim ds As New DataSet
Dim tb As DataTable
da.Fill(ds, "Allstudents")
tb = ds.Tables.Item(0)
If tb.Rows.Count <> 0 Then
MsgBox("您已经选过题目了!!")
Else
CreateNewFolder("e:\", frm1.text1 & frm1.text2)
copyfile()
openfile()
Try
Dim sql1 As String
sql1 = "insert into student values ('" & frm1.text1 & "','" & frm1.text2 & "','" & TextBox1.Text & "')"
Dim com As New OleDbCommand(sql1)
With com
.Connection = New OleDbConnection(gLinkString)
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
End With
Catch
MsgBox(Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "错误")
End Try
End If
Catch
'显示系统的异常信息
MsgBox(Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "您出错了")
Exit Sub
End Try
End Sub
Function CreateNewFolder(ByVal Path, ByVal NewFolderName)
Dim objFSO
objFSO = CreateObject("Scripting.FileSystemObject")
Dim FullPath
FullPath = Path & NewFolderName
If Not objFSO.FolderExists(FullPath) Then
objFSO.CreateFolder(FullPath)
CreateNewFolder = True
Else
CreateNewFolder = False
openfile()
MsgBox("您已经选过题目了!!")
Me.Close()
End If
objFSO = Nothing
End Function
Function copyfile()
Dim frm1 As New Form1
Dim text1 As String
Dim i As Integer
Randomize()
i = CInt(Int((10 * Rnd()) + 1))
If i = 1 Then
text1 = "data\1.txt"
End If
If i = 2 Then
text1 = "data\2.txt"
End If
If i = 3 Then
text1 = "data\3.txt"
End If
If i = 4 Then
text1 = "data\4.txt"
End If
If i = 5 Then
text1 = "data\5.txt"
End If
If i = 6 Then
text1 = "data\6.txt"
End If
If i = 7 Then
text1 = "data\7.txt"
End If
If i = 8 Then
text1 = "data\8.txt"
End If
If i = 9 Then
text1 = "data\9.txt"
End If
If i = 10 Then
text1 = "data\10.txt"
End If
Dim srcfile As New FileInfo(text1)
If srcfile.Exists Then
srcfile.CopyTo("e:\" & frm1.text1 & frm1.text2 & "\" & frm1.text1 & frm1.text2 & ".txt", True)
Else
MsgBox("您操作的文件不存在!!")
End If
End Function
Function openfile()
Dim frm1 As New Form1
Dim fs As New FileStream("e:\" & frm1.text1 & frm1.text2 & "\" & frm1.text1 & frm1.text2 & ".txt", FileMode.Open)
Dim sr As New StreamReader(fs, Encoding.Default)
While sr.Peek <> -1
TextBox1.Text &= sr.ReadLine() & vbCrLf
End While
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -