using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Student
{
public partial class Most : Form
{
List<student> list = new List<student>();
public Most()
{
InitializeComponent();
}
private void butAdd_Click(object sender, EventArgs e)
{
student st = new student();
st.ID1 = Convert.ToInt32(this.txtID.Text);
st.Name = this.txtName.Text;
st.Sex = this.cboSex.Text;
st.Age = Convert.ToInt32(this.txtAge.Text);
st.Score = Convert.ToInt32(this.txtScore.Text);
st.Address = this.txtAddress.Text;
list.Add(st);
this.listBox1.Items.Add("学号:" + this.txtID.Text);
this.listBox1.Items.Add("姓名:" + this.txtName.Text);
this.listBox1.Items.Add("性别:" + this.cboSex.Text);
this.listBox1.Items.Add("年龄:" + this.txtAge.Text);
this.listBox1.Items.Add("成绩:" + this.txtScore.Text);
this.listBox1.Items.Add("地址:" + this.txtAddress.Text);
this.txtID.Clear();
this.txtName.Clear();
this.cboSex.Enabled = false;
this.txtAge.Clear();
this.txtScore.Clear();
this.txtAddress.Clear();
//this.cboSex.Enabled = true;
}
private void butShanchu_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
this.butAdd.Enabled = true;
}
private void txtID_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsDigit(e.KeyChar)))
{
MessageBox.Show("输入只能为数字","提示");
e.Handled = true;
}
}
private void txtAge_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsDigit(e.KeyChar)))
{
MessageBox.Show("输入只能为数字", "提示");
e.Handled = true;
}
}
private void txtScore_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsDigit(e.KeyChar)))
{
MessageBox.Show("输入只能为数字", "提示");
e.Handled = true;
}
}
private void butXiugai_Click(object sender, EventArgs e)
{
string str = this.listBox1.SelectedItem.ToString();
this.listBox1.Items.Remove(str);
this.listBox1.Items.Add(this.txtUp.Text);
if (MessageBox.Show("是否修改?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.txtUp.Text = "";
}
}
private void butQueren_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
FileStream fs = new FileStream("Student.bin", FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, list);
MessageBox.Show("保存成功!");
fs.Close();
this.cboSex.Enabled = true;
}
private void Most_Load(object sender, EventArgs e)
{
}
private void butClose_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
FileStream fs = new FileStream("Student.bin",FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
List<student> l = (List<student>)bf.Deserialize(fs);
foreach (student stu in l)
{
string s = "";
s += "学号:" + stu.ID1 + "姓名:" + stu.Name + "性别:" + stu.Sex + "年龄:" + stu.Age + "成绩:" + stu.Score + "地址:" + stu.Address;
this.listBox1.Items.Add(s);
}
fs.Close();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int count = 0; count < this.listBox1.SelectedItems.Count;count++ )
{
this.txtUp.Text = Convert.ToString(this.listBox1.SelectedItems[count]);
}
}
//查询
private void butChanxun_Click(object sender, EventArgs e)
{
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
该系统没连数据库,用的是序列化和反序列化,请问该查询语句怎样写啊(根据学号和姓名来进行查询)