设计题目: 工资管理系统 班 级: 学 号: 姓 名:
任务分配表
第 一 组 学号 姓名 负责部分 成绩 组长 数据库的建表与连接 组员 实验报告完善与界面设计 目录
一 绪论 ··········································3 二 需求分析 ·······································3 三 概要设计 ·······································4 四 物理设计 ·······································5 五 详细设计 ·······································6 六 调试分析 ·······································9 七 小结 ··········································16 八 附件············································16
一、绪论
随着计算机技术的飞速发展和经济改革的不断深入,传统企业管理方法、手段以及工作效率已不能适应新的发展需要,无法很好地完成员工工资管理工作。提高公司企业管理水平的主要途径是更新管理者的思想,增强对管理活动的科学认识。基于 C#与SQL server数据库技术建立一个通用工资管理系统,该系统为提供了查询、增加记录、删除等功能,功能比较的齐全,并对工资进行了统计如津贴管理、报表统计等。基本上能满足管理员和公司的要求。
此次数据库课程设计的主要设计如下:
原理分析、程序设计过程、程序实现和程序调试以及数据库的设计。 需求分析、概要结构设计、逻辑结构设计、物理结构设计和数据库的实施和
维护.
主要包括两大大功能模块: 1.管理员管理界面设计. 2.员工管理界面设计。
二、 需求分析
功能需求分析:
该通用工资管理系统具备下列功能:管理员通过输入用户名和密码进下该系统后,可以进行一些基本查询(员工信息查询、工资奖金信息查询)、工资管理(计算总工资、奖金管理);通过输入密码,可以进行查询员工的数据(工资,奖金,税收等)。
具体功能的详细描述如下
1、在首页进行选择,员工与管理员通道 2、点击[管理员登陆]
3、用户名和密码即可进入 [工资管理]功能窗体,在此可以选择功能,添加,查询,人员列表
4、点击[添加]功能窗体,添加员工工资信息。
5、点击[查询]功能窗体,输入员工号即可查询员工信息。
6、点击[人员列表]功能窗体,可查看所有员工的列表,这界面内可以进行删除操作。
7、点击[员工登陆]
8、用户名和密码即可进入 [员工工资查询]功能窗体,在此可以选择查询基本信息,查询工资信息。
9、在[查询基本信息],员工可自己查看自己的信息。 10、在[查询工作信息],员工可自己查看自己的工作信息。 数据流需求分析:
登陆信息 返回信息 用 户 登 录 操 作 数据库
错误信息 寻找信息 数据库需求分析-—数据流图
三、概要设计
根据需求分析阶段得到的功能需求,管理员、员工通过输入用户名号和密码进下该系统后,可以进行一些基本查询(员工工资信息查询、信息查询)、还可以进行员工删除和添加员工的操作,员工通过登录并输入密码,可以进行查询自己的数据(工资,基本信息)。
模块功能大概可以分为如图下几个个方面: 图如下图所示
四、物理设计
1. 选择[登陆] 则会进入相应登陆界面。 2. 选择[员工登陆] [管理员登陆] 按钮命令
3. 选择[管理员登陆]按钮命令即可进入 [管理]功能窗体. 4。 选择[员工登陆] 按钮命令即可进入 [员工查询]功能窗体。 5. 在[添加],管理员对员工的信息进行添加. 6。 在[查询],可以对员工查询并进行修改。 7。 在[列表],可以查看所有员工的列表.
五、详细设计
(1) 数据库的E-R图及合并部分视图生成E-R 图 员工信息E-R图:
工龄 姓名 工种名称 银行卡 Empinfotale 用户名 年龄 工作天数 病假天数 性别
员工工资信息E-R图:
国家税收 基本工资 总工资 工作天数 Salaryinfo 员号 实际工作 奖金 退休工资 银行卡号
管理员用户E-R图:
用户 admin 用户号 密码
(2) 数据库结构设计
根据上面概念结构设计阶段得到的E-R图,下一步应该将它转化为关系模型.可以得到对应的关系模式为:
Empinfotale([cin],[name],[year],[sex],[workyear],[position],[creditcard],[workday],
[illday])
Salaryinfo([cin],[bonus],[salary],[individual],[individual2],[workout],[workday],[Reality],
[creditcar])
admin([id],[cin],[password])
数据库表的建立:(sql语句及截图) 语句如下:
CREATE TABLE [dbo]。[Admin](
[id] [int] IDENTITY(1,1) NOT NULL, [cin] [int] NULL, );
CREATE TABLE [dbo]。[Empinfotale](
[cin] [int] NOT NULL, [name] [char](8) NULL, [year] [int] NULL, [sex] [char](4) NULL, [workyear] [int] NULL, [position] [char](18) NULL, [creditcard] [char](19) NULL, [workday] [int] NULL,
[illday] [int] NULL, );
CREATE TABLE [dbo]。[Admin](
[id] [int] IDENTITY(1,1) NOT NULL, [cin] [int] NULL, );
[password] [char](20) NULL, [password] [char](20) NULL,
六、调试分析
(1)数据库的表的建立与实现
admin表的建立: Salaryinfo表的建立: Empinfotale表的建立: 1. 数据库的运行和截图:
选择登录界面截图: 管理员登录后: 查询界面: 添加界面: 显示所有信息:
(2)调试与运行程序分析及存在的主要问题
在此次课程设计中的主要数据库部分为数据库的连接部分,该部分直接影响到数据库与应用程序的接口实现,而且必须注意数据库的名称与连接数据库是取的名称一致。
七、小结
该工资管理系统总体说来功能不是很齐全齐全,只具备管理员和员工的一些基本的功能;数据库的设计方面,建有员工信息表、个人信息表、工资表.数据库中存在一些问题,如数据冗余,不够完善.
但在做课程设计的过程中也遇到很多问题,一开始时其中最大的问题是不知道用哪种编译工具,后来选择了Microsoft Visual Studio,在编写程序时,编写程序起来也有点困难,但是也越来越顺利了。经过调试后终于把自已想到实现的功能一步步实现了,通过这次课程设计使我收获了好多,熟悉了C#的运用,还复习了数据库相关语句的编写。
此次课程设计让我感受颇多:做一个数据库其实是一件很有趣的事情。想到自己可以创建一个小型的数据库系统,有点学习后的满足感。数据库的建立并非难事,难点在于数据库的连接和编程语言的选择。C#的功能很强大,这也是我以后需要学习的课程,于是我毅然选择了它.再就是建立数据库系统的步骤,我的经验就是要先总体规划,再局部整理.先做好总的界面,再通过该界面的布置一步一步实现其功能!
同时我体会到:熟练的编程能力,对知识运用的强烈渴望及其创新和团队的合作精神设做好一个大型数据库的基础。因此通过此次课程设计我明显感觉到自身的不足,并希望以后能更加用心地运用所学知识和学习新的知识。
在这个系统中我主要负责了数据库的建立和管理员管理的页面设计,虽然做的不是很好的,但是让我们学到了很多关于数据库连接方面的知识.我会继续完善下去的.
八、附件
一、程序代码
选择登陆页面
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.Configuration; namespace GZMS {
public partial class index : Form {
public index() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
Form1 indexform = new Form1(); indexform。Owner = this;
indexform。Show(); this。Hide(); }
private void button2_Click(object sender, EventArgs e) {
Form11 indexform = new Form11(); indexform.Owner = this; indexform。Show(); this.Hide(); } } }
验证用户名登陆页面
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; using System.Configuration; namespace GZMS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
protected override void OnClosed(EventArgs e) {
Application.Exit(); }
private void index_Click(object sender, EventArgs e) {
string username = txusername.Text; string usrepaw = txuserpaw.Text; if (username == ”\" || usrepaw == ””) {
MessageBox.Show(\"请输入用户名或密码\", \"提示”); return; }
SqlConnection sqlCon = new
SqlConnection(ConfigurationManager.ConnectionStrings[\"GZB。Properties。Settings.ConnectionString”]。ConnectionString);
//string ConnectionString = @\"Data Source=(local);Initial Catalog=GZB;User=sa;Password=admin;Integrated Security=True\";
//SqlConnection sqlCon = new SqlConnection(ConnectionString); //创建Connection对象
//Data Source=.;Initial Catalog=数据库名;Integrated Security=True id = 用户名 password = 密码 try {
sqlCon。Open();
string sql = String.Format(\"select cin,password from Admin where cin='{0}’and password = ’{1}’ \", username, usrepaw);
SqlCommand comm = new SqlCommand(sql,sqlCon); SqlDataReader c = comm。ExecuteReader(); if (c.Read()) {
this.DialogResult = DialogResult.OK; //触发确定¨
//MessageBox.Show(\"成功|\", \"登陆成功|\", MessageBoxButtons.OK); search add = new search(); add。Owner = this; add.Show(); this。Hide(); } else {
MessageBox.Show(”成功\", \"登陆成功|”, MessageBoxButtons。OK); } }
catch (SqlException ex) {
MessageBox.Show(”数据库错误”,”错误\"); } finally {
sqlCon。Close(); } }
private void quet_Click(object sender, EventArgs e) {
Application.Exit(); } } }
功能选择页面
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; using System。Configuration; namespace GZMS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
protected override void OnClosed(EventArgs e) {
Application.Exit(); }
private void index_Click(object sender, EventArgs e) {
string username = txusername。Text; string usrepaw = txuserpaw.Text; if (username == ”” || usrepaw == \"\") {
MessageBox.Show(\"请输入用户名或密码”, \"提示”); return; }
SqlConnection sqlCon = new SqlConnection(ConfigurationManager。
ConnectionStrings[”GZB。Properties。Settings.ConnectionString\"].ConnectionString); //string ConnectionString = @\"Data Source=(local);Initial
Catalog=GZB;User=sa;Password=admin;Integrated Security=True\";
//SqlConnection sqlCon = new SqlConnection(ConnectionString); //创建Connection对象
//Data Source=.;Initial Catalog=数据库名;Integrated Security=True id = 用户名 password = 密码 try {
sqlCon。Open();
string sql = String。Format(\"select cin,password from Admin where cin=’{0}’and password = '{1}’ \", username, usrepaw);
SqlCommand comm = new SqlCommand(sql,sqlCon); SqlDataReader c = comm.ExecuteReader(); if (c。Read()) {
this.DialogResult = DialogResult。OK; //触发确定
//MessageBox。Show(”成功”, \"登陆成功”, MessageBoxButtons.OK); search add = new search(); add.Owner = this; add。Show(); this.Hide(); } else {
MessageBox。Show(\"no成功|\", \"登陆no成功|\", MessageBoxButtons。OK);
} }
catch (SqlException ex) {
MessageBox.Show(\"数据库错误”,\"错误\"); }
finally {
sqlCon.Close(); } }
private void quet_Click(object sender, EventArgs e) {
Application。Exit(); } } }
添加员工信息页面
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; using System。Configuration; namespace GZMS {
public partial class add : Form {
public add() {
InitializeComponent(); }
protected override void OnClosed(EventArgs e)
{
Application。Exit(); }
private void button2_Click(object sender, EventArgs e) {
this.Close(); }
private void button1_Click(object sender, EventArgs e) { try {
string name = tbname.Text; string num = tbnum.Text; string sex = ”\"; if (rbboy。Checked) {
sex = rbboy.Text; } else
sex = rdgirl。Text;
int year = Convert.ToInt32(tbyear.Text);
int workyear = Convert。ToInt32(tbworkyear。Text); string position = cbposition。SelectedItem.ToString(); int workday = Convert.ToInt32(tbworkday.Text); int illday = Convert。ToInt32(tbillday1.Text); string credit = tbcredit。Text;
// string constring = @”server = (local); database = GZB;UID=sa;Password=admin; integrated security=True\";
// SqlConnection conn = new SqlConnection(constring); SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings[”GZB.Properties。
Settings.ConnectionString”].ConnectionString); conn。Open();
string sql = string。Format(\"insert into Empinfotale(cin,
name,year,sex,workyear,position,creditcard,workday,illday)VALUES(’{0}’,’{1}','{2}',’{3}’,’{4}',’{5}',’{6}’,’{7}',{8})”, num, name, year, sex, workyear, position, credit, workday, illday);
SqlCommand com = new SqlCommand(sql, conn); int i = com。ExecuteNonQuery(); if (i != 0) {
MessageBox.Show(\"成功\", ”插入成功|\", MessageBoxButtons.OK, MessageBoxIcon。None); } }
catch (FormatException ex) {
MessageBox。Show(”请重新输入空白地方”, \"输入错误”, MessageBoxButtons.OK); }
catch (SqlException ex) {
MessageBox。Show(”错误”, ”数据库连接异常\", MessageBoxButtons.OK); } }
private void tbworkday_TextChanged(object sender, EventArgs e) { try {
int workday = Convert。ToInt32(tbworkday.Text); if (workday 〉= 30 && workday 〈= 1) {
MessageBox.Show(\"输入有误”, \"请重新输入”, MessageBoxButtons.OK); return; }
int illday = 30 — workday;
tbillday1.Text = illday.ToString(); }
catch (Exception ex) {
return; } } } }
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; using System.Configuration; namespace GZMS {
public partial class add1 : Form {
public add1() {
InitializeComponent();
/* int bonus = Convert。ToInt32(tbbonus.Text);
int salary = Convert。ToInt32(tbsalary。Text); int individual = Convert.ToInt32(tbindividual。Text); int individual1 = Convert。ToInt32(tbindividual1.Text); int workout = Convert。ToInt32(tbworkout.Text); int toworkout = individual1 + individual; tbtotal。Text = Convert。ToString(toworkout); int total = Convert。ToInt32(tbtotal。Text);
int toreality = salary + bonus — toworkout + workout; tbreality。Text = Convert.ToString(toreality); int reality = Convert.ToInt32(tbreality.Text); string credit = tbcredit.Text;*/ }
private void button1_Click(object sender, EventArgs e) {
int num = Convert。ToInt32(tbnum。Text); int bonus = Convert.ToInt32(tbbonus.Text); int salary = Convert。ToInt32(tbsalary.Text);
int individual = Convert。ToInt32(tbindividual。Text); int individual1 = Convert。ToInt32(tbindividual1。Text); int workout = Convert.ToInt32(tbworkout。Text); int total = Convert.ToInt32(tbtotal。Text); string credit = tbcredit。Text;
int reality = Convert.ToInt32(tbreality。Text);
SqlConnection conn = new SqlConnection(ConfigurationManager。
ConnectionStrings[\"GZB。Properties.Settings.ConnectionString”].ConnectionString); try {
conn.Open();
string sql = string.Format(\"insert into Salaryinfo([cin],[bonus],[salary],[individual],[individual2],[workout],[workday],[Reality],[creditcard])VALUES('{0}’,'{1}',’{2}’,’{3}’,’{4}',’{5}’,’{6}',’{7}',{8})”, num, bonus, salary,
individual, individual1, workout, total, reality, credit); SqlCommand com = new SqlCommand(sql, conn); int i = com.ExecuteNonQuery(); if (i != 0) {
MessageBox。Show(\"成功\", \"插入成功\", MessageBoxButtons。OK, MessageBoxIcon.None); } }
catch (Exception ex) {
MessageBox.Show(”出错了”, \"错误”, MessageBoxButtons.RetryCancel); } }
private void tbworkout_TextChanged(object sender, EventArgs e) { try {
int bonus = Convert。ToInt32(tbbonus。Text); int salary = Convert.ToInt32(tbsalary。Text); int individual = Convert.ToInt32(tbindividual.Text); int individual1 = Convert.ToInt32(tbindividual1。Text); int workout = Convert.ToInt32(tbworkout。Text); int toworkout = individual1 + individual; tbtotal.Text = Convert。ToString(toworkout); int total = Convert.ToInt32(tbtotal。Text);
int toreality = salary + bonus - toworkout + workout; tbreality。Text = Convert.ToString(toreality); int reality = Convert。ToInt32(tbreality.Text); string credit = tbcredit。Text; }
catch (Exception ex) {
return; } }
private void button2_Click(object sender, EventArgs e) {
this.Close(); } } } 查询页面 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; using System。Configuration; namespace GZMS {
public partial class updata : Form {
public updata() {
InitializeComponent(); }
private void button1_Click(object sender,EventArgs e)
{ // try //{
string id = txid.Text; string name = txname。Text; if (id == null) {
id = \" ”; }
if (name == null) {
name = ” \"; }
SqlConnection con = new SqlConnection(ConfigurationManager。ConnectionStrings[”GZB。Properties。Settings。ConnectionString\"]。ConnectionString); //SqlConnection con = new SqlConnection(Connection); con.Open();
String comm = string。Format(\"select name from Empinfotale where cin ={0}”,id);
if (comm == string.Format(”select name from Empinfotale where cin =\")) {
comm = string。Format(”select name from Empinfotale where name ={0}\", name); }
SqlCommand cmmm = new SqlCommand(comm,con); SqlDataReader c = cmmm。ExecuteReader(); if (c.Read()) {
updataemploy ad = new updataemploy(); ad.Flag = txid.Text; ad。Owner = this; ad.Show();
this。Hide(); } else {
MessageBox.Show(”查无此人\",”错误”); return; } }
private void updata_Load(object sender, { } } } 修改页面 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; using System。Configuration; namespace GZMS {
public partial class updataemploy : Form {
private string flag; /// get { return flag; } set { flag = value; } } public updataemploy() { InitializeComponent(); } public void Showcurrentstudrnt1() { } private void button1_Click(object sender, EventArgs e) { string name = tbname。Text; string num = tbnum.Text; string sex = ”\"; if (rbboy。Checked) { sex = rbboy.Text; } else sex = rdgirl.Text; int year = Convert.ToInt32(tbyear.Text); int workyear = Convert。ToInt32(tbworkyear.Text); string position = cbposition。SelectedItem。ToString(); int workday = Convert。ToInt32(tbworkday.Text); int illday = Convert.ToInt32(tbillday1.Text); string credit = tbcredit.Text; int bonus = Convert。ToInt32(tbbonus。Text); int salary = Convert。ToInt32(tbsalary。Text); int individual = Convert.ToInt32(tbindividual.Text); int individual1 = Convert。ToInt32(tbindividual1。Text); int workout = Convert。ToInt32(tbworkout.Text); int total = Convert.ToInt32(tbtotal.Text); int reality = Convert。ToInt32(tbreality。Text); try { // string constring = @\"server = (local); database = GZB;UID=sa;Password=admin; integrated security=True\"; // SqlConnection conn = new SqlConnection(constring); SqlConnection conn = new SqlConnection(ConfigurationManager。ConnectionStrings[\"GZB。Properties.Settings.ConnectionString”].ConnectionString); conn。Open(); string sql = string。Format(\"update Empinfotale set cin='{0}’,name='{1}’,year=’{2}’,sex=’{3}',workyear='{4}’,position='{5}',creditcard=’ {6}’,workday='{7}’,illday=’{8}' where cin = '{9}')”, num, name, year, sex, workyear, position, credit, workday, illday,num); SqlCommand com = new SqlCommand(sql, conn); int i = com。ExecuteNonQuery(); if (i != 0) { MessageBox。Show(\"成功”, ”插入成功|”, MessageBoxButtons.OK, MessageBoxIcon。None); } } catch (FormatException ex) { MessageBox。Show(\"请重新输入空白地方?”, ”输入错误”, MessageBoxButtons.OK); } catch (SqlException ex) { MessageBox.Show(”错误\", ”数据库连接异常\", MessageBoxButtons。OK); } SqlConnection conn1 = new SqlConnection(ConfigurationManager。 ConnectionStrings[\"GZB。Properties。Settings.ConnectionString”].ConnectionString); try { conn1。Open(); string sql1 = string.Format(”update Salaryinfo set [bonus]='{1}',[salary]='{2}',[individual]='{3}’,[individual2]='{4}',[workout]='{5}’,[workday]='{6}’,[Reality]='{7}',[creditcard]=’{8} where cin ={0}’”, num, bonus, salary, individual, individual1, workout, total, reality, credit); SqlCommand com = new SqlCommand(sql1, conn1); int f = com.ExecuteNonQuery(); if (f != 0) { MessageBox。Show(\"成功\", ”插入成功\", MessageBoxButtons.OK, MessageBoxIcon。None); } } catch (Exception ex) { MessageBox.Show(\"出错了”, ”错误”, MessageBoxButtons.RetryCancel); } } private void updataemploy_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager。 ConnectionStrings[\"GZB.Properties。Settings。ConnectionString\"]。ConnectionString); conn。Open(); string sql = string。Format(”select cin,name,year,sex,position,creditcard,workyear from [Empinfotale] WHERE cin = ’{0}’\", flag); SqlCommand comm1 = new SqlCommand(sql, conn); SqlDataReader reader = comm1。ExecuteReader(); if (reader.Read()) { tbnum。Text = reader。GetSqlInt32(0)。ToString(); tbname。Text = reader。GetString(1).ToString(); tbyear。Text = reader.GetSqlInt32(2)。ToString(); string sex1 = reader.GetString(3); if (sex1 == \"女\") { rdgirl.Checked = true; } cbposition。Text = reader。GetString(4)。ToString(); tbcredit.Text = reader.GetString(5)。ToString(); tbworkyear.Text = reader。GetSqlInt32(6)。ToString(); } SqlConnection conn1 = new SqlConnection (ConfigurationManager.ConnectionStrings[”GZB.Properties.Settings。ConnectionString”]。ConnectionString); conn1.Open(); string sql1 = string。Format(”select bonus,salary,individual, individual2,workout,workday,Reality from [Salaryinfo] WHERE cin = ’{0}'”, flag); SqlCommand comm2 = new SqlCommand(sql1, conn1); SqlDataReader reader1 = comm2.ExecuteReader(); if (reader1。Read()) { tbbonus。Text = reader1.GetSqlInt32(0).ToString(); tbsalary。Text = reader1。GetSqlDouble(1).ToString(); tbindividual.Text = reader1。GetSqlDouble(2)。ToString(); tbindividual1.Text = reader1。GetSqlDouble(3)。ToString(); tbworkout.Text = reader1.GetSqlDouble(4).ToString(); tbworkday。Text = reader1.GetSqlDouble(5)。ToString(); tbreality。Text = reader1。GetSqlDouble(6)。ToString(); tbtotal。Text = (reader1。GetSqlDouble(2) + reader1。GetSqlDouble(3))。ToString(); tbillday1。Text = (30 - reader1.GetSqlDouble(5))。ToString(); } } private void button2_Click(object sender, EventArgs e) { this.Close(); } } } 所有成员列表页面 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; using System。Configuration; namespace GZMS { public partial class list : Form { public list() { InitializeComponent(); } SqlDataAdapter objSqlAdapter; DataSet sufeidataset1; private void list_Load(object sender, EventArgs e) { /*DataTable dt = new DataTable(); String ConnectionString = @\"server = (local); database = GZB;UID=sa;Password=admin; integrated security=True”; SqlConnection sqlCon = new SqlConnection(ConnectionString); sqlCon。Open(); SqlCommand comm = new SqlCommand(); comm。CommandText = str;/////str为asql语句 comm.Connection = conn; using (SqlDataReader dr = comm。ExecuteReader()) { dt.Clear(); dt。Load(dr); conn.Close(); conn。Dispose(); }*/ try { SqlConnection conn = new SqlConnection(ConfigurationManager。 ConnectionStrings[”GZB。Properties.Settings。ConnectionString\"]。ConnectionString); conn.Open();//打开连接 string mysql = ”select * from Empinfotale”; objSqlAdapter = new SqlDataAdapter(mysql, conn); sufeidataset1 = new DataSet(); objSqlAdapter.Fill(sufeidataset1, ”Empinfotale”); dgMyGrid。DataSource = sufeidataset1。Tables[”Empinfotale\"];//把得到的值给DataGrid } catch (Exception ee) { MessageBox。Show(ee。Message.ToString() + \"没有可有的数据库或连接不成功,请自行检测!!!\"); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void add_Click(object sender, EventArgs e) { add indexform = new add(); indexform。Owner = this; indexform.Show(); this。Hide(); } private void dele_Click(object sender, EventArgs e) { //int j = dgMyGrid.SelectedRows。Count; /*int[] l = new int[j]; for (int i = 0; i 〈 j; i++) { l[i] = dgMyGrid.SelectedRows[i].Index; } int k = 0; while (k < j) { dgMyGrid.Rows。RemoveAt(l[k]); k++; } objSqlAdapter.Update(sufeidataset1。Tables[\"Empinfotale\"]);//更新到数据库 sufeidataset1。Tables[”Empinfotale”].AcceptChanges();*/ try { SqlConnection conn = new SqlConnection(ConfigurationManager。ConnectionStrings[\"GZB。Properties.Settings。ConnectionString”].ConnectionString); string sql = string.Format(\"delete from Empinfotale where cin = ’{0}'\", dgMyGrid。SelectedRows[0]。Cells[0].Value); SqlCommand com = new SqlCommand(sql, conn); //定义SqlCommand命ü令? conn。Open(); //打开数据库 com.ExecuteNonQuery(); //更新数据库 conn。Close(); //关闭数据 MessageBox。Show(”记录已从数据库删除,请按刷新按钮刷新显示列表,友情提示\", MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (DataGridViewRow r in dgMyGrid。SelectedRows) { if (!r。IsNewRow) { dgMyGrid。Rows。Remove(r); } } } catch (Exception ex) { MessageBox。Show(”请先选中一列”, ”友情提示”, MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void xiangxi_Click(object sender, EventArgs e) { updataemploy indexform2 = new updataemploy(); indexform2.Flag = dgMyGrid。SelectedRows[0].Cells[0].Value。ToString(); indexform2.Owner = this; indexform2.Show(); this。Hide(); } private void button3_Click(object sender, EventArgs e) { updataemploy indexform1 = new updataemploy(); indexform1。Flag = dgMyGrid。SelectedRows[0].Cells[0].Value。ToString(); indexform1.Owner = this; indexform1。Show(); this.Hide(); } } } 二、程序清单 用的是 sqlserver 2008 R2和Microsoft Visual Studio 2010 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- stra.cn 版权所有 赣ICP备2024042791号-4
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务