学生信息管理系统3.docx

上传人:大张伟 文档编号:7220255 上传时间:2020-11-07 格式:DOCX 页数:37 大小:147.12KB
返回 下载 相关 举报
学生信息管理系统3.docx_第1页
第1页 / 共37页
学生信息管理系统3.docx_第2页
第2页 / 共37页
学生信息管理系统3.docx_第3页
第3页 / 共37页
学生信息管理系统3.docx_第4页
第4页 / 共37页
学生信息管理系统3.docx_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《学生信息管理系统3.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统3.docx(37页珍藏版)》请在三一文库上搜索。

1、在此处添加一个“用户管理”文件夹,包含添加用户、修改用户、浏览用户“添加用户”界面代码为:using System;using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;/此处为添加之行namespace 学生信息管理系统.用户管理public partial cl

2、ass 添加用户 : Formstring strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integrated Security=True;public 添加用户()InitializeComponent();private void btnok_Click(object sender, EventArgs e)if (txtid.Text=|txtname.Text = | txtpassword.Text = | txtremark.Text = )MessageBox.Show(请将用户信息填写完整!);elseusing (SqlCon

3、nection con = new SqlConnection(strcon)if (con.State = ConnectionState.Closed)con.Open();trySqlCommand cmd = newSqlCommand(select * from 用户管理 where 用户编号= +txtid.Text.Trim() + , con);if (cmd.ExecuteScalar() != null)MessageBox.Show(此用户已添加,不能重复!);elsestring sql = insert into 用户管理(用户编号,用户名称,用户密码,用户描述) v

4、alues(+txtid.Text.ToString()+, + txtname.Text.ToString() + , + txtpassword.Text.ToString() + , + txtremark.Text.ToString() + );cmd.CommandText = sql;cmd.ExecuteNonQuery();MessageBox.Show(添加用户成功!);txtname.Clear();txtpassword.Clear();txtremark.Clear();this.Hide();catch (Exception er)MessageBox.Show(er

5、.Message);finallyif (con.State = ConnectionState.Open)con.Close();con.Dispose();private void btncancle_Click(object sender, EventArgse)this.Close();“修改用户”界面全部代码:using System;using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;using System.Linq;using

6、 System.Text;using System.Windows.Forms;using System.Data.SqlClient;/此处为添加之行namespace 学生信息管理系统.用户管理public partial class 修改用户 : Formstring strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integrated Security=True;public 修改用户()InitializeComponent();private void btnok_Click(object sender, EventArgs e)if

7、 (this.txtpassword.Text.Trim() = | this.txtremark.Text.Trim() = )MessageBox.Show(请输入完整信息!);elseusing (SqlConnection con = new SqlConnection(strcon)if (con.State = ConnectionState.Closed)con.Open();trySqlCommand cmd = newSqlCommand(select * from 用户管理 where 用户名称=+txtname.Text+ and 用户编号+this.Tag.ToStri

8、ng().Trim(),con);if (cmd.ExecuteScalar() !=null)MessageBox.Show(输入记录重复,请重新输入!);elsestring sql = update 用户管理 set用户密码= + txtpassword.Text.ToString() + ,用户描述 =+this.txtremark.Text.ToString()+ where 用户编号 =+this.Tag.ToString().Trim();cmd.CommandText = sql;cmd.ExecuteNonQuery();MessageBox.Show(用户信息修改成功!);

9、this.Hide();catch (Exception er)MessageBox.Show(er.Message);finallyif (con.State = ConnectionState.Open)con.Close();con.Dispose();private void btncancle_Click(object sender, EventArgse)this.Close();“浏览用户”界面:全部代码:using System;using System.Collections.Generic; using System.ComponentModel; using System

10、.Data; using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;/此处为添加之行namespace 学生信息管理系统.用户管理public partial class 浏览用户 : Formstring strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integrated Security=True;public 浏览用户()InitializeComponent();pri

11、vate void 浏览用户_Load(object sender, EventArgs e)SqlConnection con = new SqlConnection(strcon);trycon.Open();SqlCommand cmd = new SqlCommand(exec users,con);BindingSource bs = new BindingSource(); bs.DataSource = cmd.ExecuteReader(); dataGridView1.DataSource = bs;catch (Exception er)MessageBox.Show(er

12、.Message);finallycon.Close();private void show用户()using (SqlConnection con = new SqlConnection(strcon)if (con.State = ConnectionState.Closed)con.Open();trystring sql = select * from 用户管理 ; SqlDataAdapter adp = newSqlDataAdapter(sql, con);DataSet ds = new DataSet();ds.Clear();adp.Fill(ds, 用户表);this.d

13、ataGridView1.DataSource = ds.Tables0.DefaultView;catch (Exception er)MessageBox.Show(er.Message);finallyif (con.State = ConnectionState.Open)con.Close();con.Dispose();修改用户 frm修改用户;private void btnupdate_Click(object sender, EventArgse)if (this.dataGridView1.CurrentCell != null)frm修改用户 = new 修改用户();f

14、rm修改用户.Tag = this.dataGridView10, dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim();frm修改用户.txtid.Text= this.dataGridView10, dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim();frm修改用户.txtname.Text = this.dataGridView11, dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim();frm修

15、改用户.txtpassword.Text =this.dataGridView12,dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim();frm修改用户.txtremark.Text= this.dataGridView13, dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim();frm修改用户.StartPosition =FormStartPosition.CenterParent; frm修改用户.ShowDialog();show用户();if (frm修改用

16、户.DialogResult = DialogResult.OK)show用户();private void btndel_Click(object sender, EventArgs e)using (SqlConnection con = new SqlConnection(strcon)if (con.State = ConnectionState.Closed)con.Open();tryif (this.dataGridView1.CurrentCell !=null)string sql = select 用户名称 from 用户管理 where 用户编号=+this.dataGr

17、idView10,dataGridView1.CurrentCell.RowIndex.V ;SqlCommand cmd = new SqlCommand(sql,con);SqlDataReader dr;dr = cmd.ExecuteReader();if (!dr.Read()MessageBox.Show(删除失败!请删除与该表有关的记录!);dr.Close();elsedr.Close();cmd.CommandText = delete from 用户管理 where 用户编号=+this.dataGridView10,dataGridView1.CurrentCell.Ro

18、wIndex.V ;cmd.ExecuteReader();MessageBox.Show(删除用户成功!); show用户();catch (Exception er)MessageBox.Show(er.Message);finallyif (con.State = ConnectionState.Open)con.Close();con.Dispose();show用户();private void btncancle_Click(object sender, EventArgse)this.Close();用户登录界面全部代码:using System;using System.Col

19、lections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;/此处为添加之行namespace 学生信息管理系统public partial class 用户登录界面 : Formstring strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integra

20、ted Security=True;public 用户登录界面()InitializeComponent();private void btnok_Click(object sender, EventArgs e)/”登录”代码using (SqlConnection con = new SqlConnection(strcon)if (txtname.Text = | txtpassword.Text=)MessageBox.Show(请输入用户名或密码!);elsetrythis.Hide();con.Open();SqlCommand cmd=new SqlCommand();cmd.C

21、onnection=con;cmd.CommandText=select *from 用户管理where 用户名称=+txtname.Text+and 用户密码=+txtpassword.Text+;if (cmd.ExecuteScalar() != null)学生管理系统 主界面=new 学生管理系统();主界面.ShowDialog();this.Close();catch(Exception er)MessageBox.Show(er.Message);finallycon.Close();private void btncancle_Click(object sender, Even

22、tArgs e)/”取消”代码this.Close();学生管理系统在此处添加一个menuStrip控件“基本管理”菜单下还有“用户管理”菜单下还有所有代码为:using System;using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using 学生信息管理系统.用户管理;/此处为添加之行private void

23、学生信息管理ToolStripMenuItem_Click(object sender, EventArgs e)学生信息管理 student = new 学生信息管理(); student.ShowDialog();private void 课程信息管理ToolStripMenuItem_Click(object sender, EventArgs e)课程信息管理 course = new 课程信息管理(); course.ShowDialog();private void 成绩信息管理ToolStripMenuItem_Click(object sender, EventArgs e)成

24、绩信息管理 score = new 成绩信息管理(); score.ShowDialog();private void 添加用户ToolStripMenuItem_Click(object sender, EventArgs e)添加用户 add = new 添加用户();add.ShowDialog();private void 浏览用户ToolStripMenuItem_Click(object sender, EventArgs e)修改用户 update = new 修改用户(); update.ShowDialog();private void 浏览用户ToolStripMenuIt

25、em1_Click(object sender, EventArgs e)浏览用户 browse = new 浏览用户(); browse.ShowDialog();private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)this.Close();学生信息管理:学生信息管理的全部代码:using System;using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;u

26、sing System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;/此处为添加之行namespace 学生信息管理系统public partial class 学生信息管理 : Formpublic 学生信息管理()InitializeComponent();private DataSet myDataSet = new DataSet();/初始化一下新的DataSetprivate CurrencyManager myBind;/用于数据导航控制 private void 学生

27、信息管理_Load(object sender,EventArgs e)string strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integrated Security=True;SqlConnection con = new SqlConnection(strcon) ; con.Open();SqlDataAdapter adp = new SqlDataAdapter(select * from 学生信息管理 , con);adp.Fill(myDataSet, 学生表);this.dataGrid1.DataSource =myDat

28、aSet.Tables0;con.Close();myBind =(CurrencyManager)this.BindingContextmyDataSet,学生表;/设置dataGridView1数据导航控制this.dataGrid1.Select(myBind.Count-1);myBind.Position = myBind.Count - 1;this.dataGrid1.CurrentRowIndex = myBind.Position;SetBindings();private void SetBindings()textBox1.DataBindings.Add(Text,my

29、DataSet,学生表.学号);textBox2.DataBindings.Add(Text, myDataSet, 学生表.姓名);textBox3.DataBindings.Add(Text, myDataSet, 学生表.性别);textBox4.DataBindings.Add(Text, myDataSet, 学生表.入学成绩);textBox5.DataBindings.Add(Text, myDataSet, 学生表.出生日期);textBox6.DataBindings.Add(Text, myDataSet, 学生表.联系电话);textBox7.DataBindings.A

30、dd(Text, myDataSet, 学生表.家庭住址);private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)if(e.Button.ToolTipText=首记录)this.dataGrid1.UnSelect(myBind.Position );/取消原选中的行myBind.Position=0;this.dataGrid1.Select(myBind.Position );/选中当前行this.dataGrid1.CurrentRowIndex=myBind.Position;/移

31、动表头指针图标return;if(e.Button.ToolTipText=上记录)if(myBind.Position=0)MessageBox.Show(已经到了第一条记录!);elsethis.dataGrid1.UnSelect(myBind.Position);myBind.Position-;this.dataGrid1.Select(myBind.Position);this.dataGrid1.CurrentRowIndex=myBind.Position; return;if(e.Button.ToolTipText=下记录)if(myBind.Position=myBind

32、.Count-1)MessageBox.Show(已经到了最后一条记录!);elsethis.dataGrid1.UnSelect(myBind.Position);myBind.Position+;this.dataGrid1.Select(myBind.Position);this.dataGrid1.CurrentRowIndex=myBind.Position;return;if(e.Button.ToolTipText=尾记录)this.dataGrid1.UnSelect(myBind.Position);myBind.Position=myBind.Count-1;this.da

33、taGrid1.Select(myBind.Position);this.dataGrid1.CurrentRowIndex=myBind.Position; return;if(e.Button.ToolTipText=插入)tryif (textBox1.Text != & textBox2.Text != & textBox3.Text != & textBox4.Text != & textBox5.Text != & textBox6.Text != & textBox7.Text != )string connectionString = DataSource=.;Initial

34、Catalog=学生信息管理系统;Integrated Security=True;SqlConnection myConnection;myConnection = newSqlConnection(connectionString); myConnection.Open();string strInsert = insert into 学生信息管理 (学号,姓名,性别,入学成绩,出生日期,联系电话,家庭住址) values ( + textBox1.Text + , + textBox2.Text + , + textBox3.Text + , + textBox4.Text + , +

35、textBox5.Text + , + textBox6.Text + , + textBox7.Text + );SqlCommand mycmd = newSqlCommand(strInsert, myConnection );mycmd.ExecuteNonQuery();myConnection.Close();myDataSet.Tables学生表.RowsmyBind.Position.BeginEdit(); myDataSet.Tables学生表.RowsmyBind.Position.EndEdit(); myDataSet.Tables学生表.AcceptChanges(

36、);MessageBox.Show(插入成功!);elseMessageBox.Show(必须填满所有字段值!);catch (Exception er)MessageBox.Show(保存数据记录发生 +er.ToString();if(e.Button.ToolTipText=删除)DialogResult r=MessageBox.Show(是否删除当前记录!,删除当前记录!,MessageBoxButtons.YesNo,MessageBoxIcon.Question); int ss=(int)r;if(ss=6)trystring strcon = Data Source=.;In

37、itialCatalog=学生信息管理系统;Integrated Security=True; SqlConnection con=newSqlConnection(strcon);con.Open();string cmd=delete from 学生信息管理 where 学号=+textBox1.Text;SqlCommand mycmd=new SqlCommand(cmd,con); mycmd.ExecuteNonQuery(); myDataSet.Tables学生表.RowsmyBind.Position.Delete(); myDataSet.Tables学生表.AcceptC

38、hanges(); con.Close();MessageBox.Show(删除成功!);catch(Exception er)MessageBox.Show(删除记录错误信息:+er.ToString();if (e.Button.ToolTipText = 退出)this.Close();private void button1_Click(object sender, EventArgs e)trymyDataSet.Clear();string str = textBox8.Text;string sqlcmd = select * from 学生信息管理 where 学号= + st

39、r;string strcon = Data Source=.;Initial Catalog=学生信息管理系统;Integrated Security=True;SqlConnection con = new SqlConnection(strcon); con.Open();SqlDataAdapter mycmd = newSqlDataAdapter(sqlcmd, con);mycmd.Fill(myDataSet, 学生表);dataGrid1.DataSource = myDataSet.Tables0;con.Close();myBind =(CurrencyManager)this.BindingContextmyDa

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1