已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
附录:源程序 32 Program.csusing System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace studentMIS static class Program / / 应用程序的主入口点。 / STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Formlogin(); Formlogin.csusing 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 DAL;namespace studentMIS public partial class Formlogin : Form public Formlogin() InitializeComponent(); private void buttonok_Click(object sender, EventArgs e) int total = new SQLHelper().login(textBoxusername.Text.Trim(), textBoxpassword.Text.Trim(); if (total 0) formmain main =new formmain (); main .Show (); this.Hide (); main.bind(); else MessageBox.Show (用户名或密码错误,提示); textBoxusername.Text =; textBoxpassword.Text =; textBoxusername.Focus(); private void buttoncancel_Click(object sender, EventArgs e) textBoxusername.Text = ; textBoxpassword.Text = ; textBoxusername.Focus(); Formmain.csusing 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 DAL;namespace studentMIS public partial class formmain : Form public formmain() InitializeComponent(); private void 信息录入ToolStripMenuItem_Click(object sender, EventArgs e) FormAddStudent add = new FormAddStudent(); add.ShowDialog();if (add.DialogResult = DialogResult.OK) bind(); BindingSource bs = new BindingSource(); public void bind()/刷新网络 bs.DataSource = new SQLHelper().CreateTable(); dataGridView.DataSource = bs; public void Formmain_Load(object sender, EventArgs e) bind(); private void 信息删除ToolStripMenuItem_Click(object sender, EventArgs e) FormDeleteStudent delete = new FormDeleteStudent(); delete.ShowDialog(); if (delete.DialogResult = DialogResult.OK) bind(); private void 信息查找ToolStripMenuItem_Click(object sender, EventArgs e) FormSearchStudent select = new FormSearchStudent(); select.ShowDialog(); private void 信息修改ToolStripMenuItem_Click(object sender, EventArgs e) FormModifystudent modify = new FormModifystudent(); modify.ShowDialog(); if (modify.DialogResult = DialogResult.OK) bind(); private void 注销ToolStripMenuItem_Click(object sender, EventArgs e) Formlogin login = new Formlogin(); DialogResult dr = MessageBox.Show(确定注销吗?, 提示, MessageBoxButtons.OKCancel) if (dr = DialogResult.OK) login.Show(); this.Hide(); else return; private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) DialogResult dr = MessageBox.Show(确定退出系统吗?, 提示, MessageBoxButtons.OKCancel); if (dr = DialogResult.OK) this.Dispose(); else return; FormAddStudent.csusing 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 DAL;namespace studentMIS public partial class FormAddStudent : Form public FormAddStudent() InitializeComponent(); private void textBox3_TextChanged(object sender, EventArgs e) private voidbuttonok_Click(object sender, EventArgs e) string sno = textBoxsno.Text.Trim(); string sname = textBoxsname.Text.Trim(); string sex = comboBoxsex.Text.Trim(); string birthday = textBoxbirthday.Text.Trim(); new StudentDAO().insert(sno, sname, sex, birthday); this.DialogResult = DialogResult.OK; MessageBox.Show(输入成功,提示); FormDeleteStudent.csusing 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 DAL;namespace studentMIS public partial class FormDeleteStudent : Form public FormDeleteStudent() InitializeComponent(); private void buttonok_Click(object sender, EventArgs e) if (textBoxsno.Text != ) int total = new SQLHelper().delectstudentbysno(textBoxsno.Text.Trim(); if (total 0) new StudentDAO().deletebysno(textBoxsno.Text.Trim(); MessageBox.Show(删除成功!, 提示); this.DialogResult = DialogResult.OK; else MessageBox.Show(输入不正确,请重新输入!, 提示);textBoxsno.Focus();textBoxsno.Text = ; return; else int total = new SQLHelper().delectstudentbysname(textBoxsname.Text.Trim(); if (total 0) new StudentDAO().deletebysname(textBoxsname.Text.Trim(); MessageBox.Show(删除成功!, 提示); this.DialogResult = DialogResult.OK; else MessageBox.Show(输入不正确,请重新输入!, 提示); textBoxsname.Focus(); textBoxsname.Text = ; return; private void buttoncancel_Click(object sender, EventArgs e) textBoxsno.Text = ; textBoxsname.Text = ; textBoxsno.Focus(); private void radioButton2_CheckedChanged(object sender, EventArgs e) textBoxsno.Focus(); FormSearchStudent.csusing 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 DAL;namespace studentMIS public partial class FormSearchStudent : Form public FormSearchStudent() InitializeComponent(); private void textBox1_TextChanged(object sender, EventArgs e) BindingSource bs = new BindingSource(); private void buttonsearchbysno_Click(object sender, EventArgs e) bs.DataSource = new StudentDAO().searchbysno(textBoxsno.Text.Trim(); /表格 if (bs != null) textBoxsno.Text = null; textBoxsno.Focus(); dataGridViewSearch.DataSource = bs; else MessageBox.Show(查询失败,数据库中没有该学生!, 提示); return; private void buttonsearchbysname_Click(object sender, EventArgs e) bs.DataSource = new StudentDAO().searchbysname(textBoxsname.Text.Trim(); if (bs != null) textBoxsname.Text = null; textBoxsname.Focus(); dataGridViewSearch.DataSource = bs; else MessageBox.Show(查询失败,数据库中没有该学生!, 提示); return; private void radioButtonsno_CheckedChanged(object sender, EventArgs e) textBoxsno.Focus(); private void radioButtonsname_CheckedChanged(object sender, EventArgs e) textBoxsname.Focus(); FormModifystudent.csusing 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 DAL;namespace studentMIS public partial class FormModifystudent : Form public FormModifystudent() InitializeComponent(); private void buttonok_Click(object sender, EventArgs e) string msno = textBoxmsno.Text.Trim(); string sname = textBoxsname.Text.Trim(); string sex = comboBoxsex.Text.Trim(); string birthday = textBoxbirthday.Text.Trim(); new StudentDAO().modify(msno, sname, sex, birthday); this.DialogResult = DialogResult.OK; MessageBox.Show(修改成功!,提示); private void buttoncancel_Click(object sender, EventArgs e) textBoxmsno.Text=; textBoxsname.Text=; comboBoxsex.Text=男; textBoxbirthday.Text =; textBoxmsno.Focus(); BindingSource bs = new BindingSource(); private void button1_Click(object sender, EventArgs e) bs.DataSource = new StudentDAO().searchbysno(textBoxmsno.Text.Trim(); /表格 if (bs != null) dataGridViewSearch.DataSource = bs; else MessageBox.Show(查询失败,数据库中没有该学生!, 提示); return; private void buttoncancel1_Click(object sender, EventArgs e) textBoxmsno.Text = ; textBoxmsno.Focus(); StudentDAO.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient;using System.Data;namespace DAL public class StudentDAO private SQLHelper sqlhelper = null; public StudentDAO() sqlhelper = new SQLHelper(); /增 public void insert(string sno, string sname, string sex, string birthday) string sql = insert into student values(sno,sname,sex,birthday); SqlParameter para = new SqlParameter new SqlParameter(sno,SqlDbType.NChar), new SqlParameter(sname,SqlDbType.NVarChar), new SqlParameter(sex,SqlDbType.NChar), new SqlParameter(birthday,SqlDbType.NChar) ; int i = 0; parai+.Value = sno; parai+.Value = sname; parai+.Value = sex; parai+.Value = birthday; sqlhelper.ExecuteNonQuery(sql, para); /删除 public void deletebysno(string sno) string sql = delete from student where sno=sno; SqlParameter para = new SqlParameter new SqlParameter(sno,SqlDbType.NChar) ; int i = 0; parai+.Value = sno; sqlhelper.ExecuteNonQuery(sql, para); public void deletebysname(string sname) string sql = delete from student where sname=sname; SqlParameter para = new SqlParameter new SqlParameter(sname,SqlDbType.NVarChar) ; int i = 0; parai+.Value = sname; sqlhelper.ExecuteNonQuery(sql, para); /查找 public DataTable searchbysno(string sno) DataTable table = new DataTable(); string sql = select * from student where sno=sno; SqlParameter para = new SqlParameter new SqlParameter(sno,SqlDbType.NChar) ; int i = 0; parai+.Value = sno; table = sqlhelper.CreateTablesearch(sql, para); return table; public DataTable searchbysname(string sname) DataTable table = new DataTable(); string sql = select * from student where sname=sname; SqlParameter para = new SqlParameter new SqlParameter(sname ,SqlDbType.NChar) ; int i = 0; parai+.Value = sname; table = sqlhelper.CreateTablesearch(sql, para); return table; /修改 public DataTable modify(string msno, string sname, string sex, string birthday) DataTable table = new DataTable(); string sql = update student set sname=sname,ssex=sex,birthday=birthday where sno=msno; SqlParameter para = new SqlParameter new SqlParameter (msno,SqlDbType.NChar), new SqlParameter(sname,SqlDbType.NVarChar), new SqlParameter(sex,SqlDbType.NChar), new SqlParameter(birthday,SqlDbType.NChar) ; int i = 0; parai+.Value = msno; parai+.Value = sname; parai+.Value = sex; parai+.Value = birthday; table = sqlhelper.CreateTablemodify(sql, para); return table; SQLHelper.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient;using System.Data;namespace DAL public class SQLHelper public void ExecuteNonQuery(string sql, params SqlParameter para) string connstr = server=97SD-UG;database=student;integrated security=sspi; using (SqlConnection conn = new SqlConnection(connstr) conn.Open(); using (SqlCommand cmd = new SqlCommand(sql, conn) cmd.Parameters.AddRange(para); cmd.ExecuteNonQuery(); /判断学号是否与后台数据库取出来的是否一致 public int delectstudentbysno(string tsno) string connstr = server=97SD-UG;database=student;integrated security=sspi; using (SqlConnection conn = new SqlConnection(connstr) conn.Open(); using (SqlCommand cmd = conn.CreateCommand() cmd.CommandText = select count(*) from student where sno=sno; cmd.Parameters.Add(new SqlParameter(sno, tsno); int total = Convert.ToInt32(cmd.ExecuteScalar();/返回查询值的首行首列,返回值类型 /不确定,是object 类型, return total; /判断姓名是否与后台数据库取出来的是否一致 public int delectstudentbysname(string tsname) string connstr = server=97SD-UG;database=student;integrated security=sspi; using (SqlConnection conn = new SqlConnection(connstr) conn.Open(); using (SqlCommand cmd = conn.CreateCommand() cmd.CommandText = select count(*) from student where sname=sname ; cmd.Parameters.Add(new SqlParameter(sname, tsname); int total = Convert.ToInt32(cmd.ExecuteScalar();/返回查询值的首行首列,返回值类型 /不确定,是object 类型, return total; public DataTable CreateTable() DataTable table = new DataTable(); string connstr = server=97SD-UG;database=student;integrated security=sspi; using (SqlConnection conn = new SqlConnection(connstr) conn.Open(); string sql = select * from student; using (SqlDataAdapter adapter = new SqlDataAdapter(sql, conn) adapter.Fill(table); return table; public DataTable CreateTablesearch(string sql, params SqlParameter para) DataTable table = new DataTable(); string c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年基础护理单元试卷及答案
- 2025年住宅委托销售合同协议
- 2025年肠内营养考试试题及答案
- 2025年霍尔开关知识题库及答案
- 边缘计算优化策略-第13篇-洞察与解读
- 2025办公室装修合同签订注意事项
- 2025年职教高考机械真题及答案
- 《2025磨砂玻璃供货合同》
- 2025财务主管劳动合同范本
- 2025年危急值报告制度培训考核试题(附答案)
- 2024年全国初中数学联赛试题及答案(修正版)
- 单位消防安全基本情况档案模板
- 医用耗材管理培训课件
- 蜜雪冰城供应链优势分析
- 学校预防传染病和食物中毒健康教育讲座
- 抗凝药物的使用和注意事项课件
- 有机朗肯循环中低温余热发电技术与工业余热利用课件
- 储能技术 习题答案汇总 (梅生伟)第1-9章
- 《儿童安全用药》课件
- 完整版新概念第一册笔记(张云生)word版
- 美术课堂教学的有效性研究 论文
评论
0/150
提交评论