6.4、删除信息
次界面有两个功能,左边是删除运动员项目,此要先输入要删除运动员的编号和所参 加的的项目名称,点击确定,即可删除成功。右边是删除运动员,直接输入运动员编号, 点击确定,即可删除成功。
6.5、录入成绩
此界面功能是为运动员录入成绩,要先输入运动员的编号和所参加的项目名称,输入 成绩,点击确定,即可录入成功。所有查询成绩,都要先在此录入,才可查询得到成绩, 否则查询到的成绩都为空。
6.6、运动员查询
以运动员身份进入该管理系统,只能进行查询,此界面跟管理员查询界面相同,故在 此不再赘述。
主要代码如下: 登录界面:
private void button1_Click(object sender, EventArgs e) {
string username = textBox1.Text; string password = textBox2.Text;
string connString = \Source = . ; Initial Catalog=db ; User ID=crl ; Pwd=123\
SqlConnection connection = new SqlConnection(connString); connection.Open();////打开数据库 if (radioButton1.Checked == true) {
string sql = String.Format(\count(*) from [athlete] where username='{0}'and password='{1}'\ try {
SqlCommand command = new SqlCommand(sql, connection);////////创建command对象
int num = (int)command.ExecuteScalar();////执行查询语句 if (num > 0) {
MessageBox.Show(\欢迎进入安徽工程大学运动会管理系统!\\登陆成功!\
athlete_information athlete = new athlete_information(); athlete.Show(); this.Visible = false; } else {
MessageBox.Show(\您输入的用户名和密码有误!\登录失败!\
textBox1.Text = \如果登录失败,设置两个textBox为空,且光标处在textBox1的位置
textBox2.Text = \ textBox1.Focus();
radioButton1.Checked =false; // 设置radioButton为空 radioButton3.Checked = false; } }
catch (Exception ex) {
MessageBox.Show(ex.Message, \操作数据库错误!\MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
finally {
connection.Close(); } }
if (radioButton3.Checked == true) //以管理员身份进入管理系统 {
string sql = String.Format(\count(*) from [dba] where username='{0}'and password='{1}'\ try {
SqlCommand command = new SqlCommand(sql, connection);////////创建command对象
int num = (int)command.ExecuteScalar();////执行查询语句 if (num > 0) {
MessageBox.Show(\欢迎进入安徽工程大学运动会管理系统!\\登陆成功!\
dba_operations operation = new dba_operations(); operation.Show(); this.Visible = false; } else {
MessageBox.Show(\您输入的用户名和密码有误!\登录失败!\
textBox1.Text = \如果登录失败,设置两个textBox为空,且光标处在textBox1的位置
textBox2.Text = \ textBox1.Focus();
radioButton1.Checked = false; // 设置radioButton为空 radioButton3.Checked = false; } }
catch (Exception ex) {
MessageBox.Show(ex.Message, \操作数据库错误!\MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
finally {
connection.Close(); } }
if (radioButton1.Checked = false || radioButton3.Checked == false) {
MessageBox.Show(\请选择身份后登录\\登录失败\MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Text = \如果登录失败,设置两个textBox为空,且光标处在textBox1的位置
textBox2.Text = \ textBox1.Focus();
radioButton1.Checked = false; radioButton3.Checked = false; } }
private void button2_Click(object sender, EventArgs e) {
textBox1.Text = \ textBox2.Text = \ textBox1.Focus(); }
添加运动运信息代码:
private void button1_Click(object sender, EventArgs e) {
string connString = @\Source = . ; Initial Catalog=db ; User ID=crl ; Pwd=123\
SqlConnection connection = new SqlConnection(connString); connection.Open();////打开数据库
//创建添加运动员信息的Sql语句,一个运动员可以添加多个项目,同时对应的有多个时间
string sql = String.Format(\into player(snum,sno,sname,sex,grade,col,items,times)\ + \textBox1.Text, textBox3.Text, textBox2.Text, comboBox2.Text, comboBox4.Text, comboBox1.Text, comboBox3.Text, comboBox7.Text); try {
SqlCommand command = new SqlCommand(sql, connection);
int count = command.ExecuteNonQuery(); if (count > 0) {
MessageBox.Show(\添加运动员信息成功\\添加成功!!!\MessageBoxButtons.OK, MessageBoxIcon.Information); } else