Windows程序设计实践之实验十(学生筛选过滤窗口)

  • 格式:doc
  • 大小:150.50 KB
  • 文档页数:8

实 验 报 告 实验项目编号:_____实验十________ 所属课程名称:Windows程序设计实践 实验日期:-------------------------- 指导教师:-------------------------- 班 级:---------------------------- 学 号:--------------------------- 姓 名:--------------------------- 成 绩:_____________________ 实验概述: 【实验名称】 创建如下图所示的“筛选”界面(frmSelect),实现用户可以自由组合查询条件,从Tbl_Student表中筛选满足特定条件的记录集。

【实验要求】 (1)通过点击“学生基本信息维护”窗体中“记录”菜单下的“筛选”菜单打开“筛选”界面。 (2)在该界面中只有在“选择查询项目”中选中某项(如:“姓名”复选框被选中),才可以在“设置筛选条件”中设置该项的查询条件(如:“姓名”文本框可输入),否则筛选条件不可输入或选择。 (3)点击“查询”按钮后,将查询结果显示在右边的表格中(DataGridView),查询结果显示符合查询条件的学生的全部信息。 实验内容: 【核心代码(程序流程图)】 '在窗体frmStInfo中,筛选ToolStripMenuItem_Click事件中编辑代码 frmSelect.Show() '在窗体frmSelect中,引入类包,定义全局变量 Imports System.Data.SqlClient Dim Conn As SqlConnection Dim dt As DataTable Dim select_string As String ' frmSelect_Load事件中 Dim x For x = 1879 To 2019 ComboBox5.Items.Add(x + 1) ComboBox5.Items.Add(x + 1) Next Try Conn = New SqlConnection() Conn.ConnectionString = "Data Source=YIQI;Initial Catalog=student;Integrated Security=True" Conn.Open() Dim nat_s, dep_s, spe_s As String nat_s = "select S_Nation from Tbl_Nation" dep_s = "select S_Department from Tbl_Dep" spe_s = "select S_Specialty from Tbl_Spe" Dim nat_Comm As New SqlCommand(nat_s, Conn) Dim dep_Comm As New SqlCommand(dep_s, Conn) Dim spe_Comm As New SqlCommand(spe_s, Conn) Dim dr As SqlDataReader '----------------------------------------------- dr = nat_Comm.ExecuteReader() While dr.Read Dim nat_dr_s As String = "" nat_dr_s = dr.Item(0) ComboBox2.Items.Add(nat_dr_s) End While dr.Close() '---------------------------------------------- dr = dep_Comm.ExecuteReader() While dr.Read Dim dep_dr_s As String = "" dep_dr_s = dr.Item(0) ComboBox3.Items.Add(dep_dr_s) End While dr.Close() '--------------------------------------------- dr = spe_Comm.ExecuteReader() While dr.Read Dim spe_dr_s As String = "" spe_dr_s = dr.Item(0) ComboBox4.Items.Add(spe_dr_s) End While dr.Close() Conn.Close() Catch MessageBox.Show("数据库连接有错误!") End Try ' CheckBox1_CheckedChanged事件中 If CheckBox1.Checked = True Then Label9.Enabled = True TextBox2.Enabled = True Else TextBox2.Text = "" Label9.Enabled = False TextBox2.Enabled = False End If ' CheckBox2_CheckedChanged事件中 If CheckBox2.Checked = True Then Label8.Enabled = True TextBox1.Enabled = True Else TextBox1.Text = "" Label8.Enabled = False TextBox1.Enabled = False End If ' CheckBox3_CheckedChanged事件中 If CheckBox3.Checked = True Then Label1.Enabled = True ComboBox1.Enabled = True Else ComboBox1.Text = "" Label1.Enabled = False ComboBox1.Enabled = False End If 'CheckBox4_CheckedChanged事件中 If CheckBox4.Checked = True Then Label2.Enabled = True ComboBox2.Enabled = True Else ComboBox2.Text = "" Label2.Enabled = False ComboBox2.Enabled = False End If ' CheckBox5_CheckedChanged事件中 If CheckBox5.Checked = True Then Label3.Enabled = True ComboBox3.Enabled = True Else ComboBox3.Text = "" Label3.Enabled = False ComboBox3.Enabled = False End If ' CheckBox6_CheckedChanged事件中 If CheckBox6.Checked = True Then Label4.Enabled = True ComboBox4.Enabled = True Else ComboBox4.Text = "" Label4.Enabled = False ComboBox4.Enabled = False End If ' CheckBox7_CheckedChanged事件中 If CheckBox7.Checked = True Then Label10.Enabled = True TextBox3.Enabled = True Else TextBox3.Text = "" Label10.Enabled = False TextBox3.Enabled = False End If ' CheckBox8_CheckedChanged事件中 If CheckBox8.Checked = True Then Label5.Enabled = True ComboBox5.Enabled = True Else ComboBox5.Text = "" Label5.Enabled = False ComboBox5.Enabled = False End If ' CheckBox9_CheckedChanged事件中 If CheckBox9.Checked = True Then Label6.Enabled = True ComboBox6.Enabled = True Else ComboBox6.Text = "" Label6.Enabled = False ComboBox6.Enabled = False End If 'Button1_Click事件中 '----------------------------------------- If CheckBox1.Checked = True And TextBox2.Text <> "" Then select_string = select_string + " and " + "S_Name" + " like '%" + TextBox2.Text + "%'" End If If CheckBox2.Checked = True And TextBox1.Text <> "" Then select_string = select_string + " and " + "S_StNo" + " like '%" + TextBox1.Text + "%'" End If If CheckBox3.Checked = True And ComboBox1.Text <> "" Then select_string = select_string + " and " + "S_Gender" + "='" + ComboBox1.Text + "'" End If If CheckBox4.Checked = True And ComboBox2.Text <> "" Then select_string = select_string + " and " + "S_Nation" + "='" + ComboBox2.Text + "'" End If If CheckBox5.Checked = True And ComboBox3.Text <> "" Then select_string = select_string + " and " + "S_Department" + "='" + ComboBox3.Text + "'" End If If CheckBox6.Checked = True And ComboBox4.Text <> "" Then select_string = select_string + " and " + "S_Specialty" + "='" + ComboBox4.Text + "'" End If If CheckBox7.Checked = True And TextBox3.Text <> "" Then select_string = select_string + " and " + "S_Native_Place" + " like '%" + TextBox3.Text + "%'" End If If CheckBox8.Checked = True And ComboBox5.Text <> "" Then select_string = select_string + " and " + "datepart(year,S_Entertime)=" + "='" + ComboBox5.Text + "'"