数据库实训+邮局订报管理系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

江苏理工学院课程设计报告
课程名称数据库原理及应用设计题目邮局订报管理系统姓名施坡专业班级12东计B 学号12961119 日期2013—2-26 ~2012—3-9 成绩
江苏理工学院
目录
一、需求分析 (5)
1.1用户需求 (5)
1.2系统功能需求 (5)
1.3系统软硬件环境确定 (6)
二、系统功能设计 (6)
2。

1系统功能结构 (6)
2。

2系统功能处理流程 (7)
三、系统数据库设计 (7)
3。

1数据库概念设计 (7)
3。

2数据库逻辑设计 (8)
3.3数据库物理设计 (8)
四、系统实现 (9)
4.1数据库连接的实现 (9)
4.2用户登录功能的实现 (10)
4.3 用户订购报纸功能的实现 (15)
4.4用户查看自己已订阅报纸的功能的实现 (19)
4。

5 用户退订报纸功能的实现 (20)
4。

6 管理员查看报纸信息的实现 (20)
4。

7管理员查看用户信息的实现 (23)
4。

8 管理员查看用户订阅信息的实现 (24)
4.9 管理员进行搜索功能的实现 (27)
4.10 管理员插入报纸功能的实现 (32)
4。

11 管理员删除报纸功能的实现 (37)
4。

12关于............................................................ 错误!未定义书签。

五、小结 (43)
六、参考文献. (44)
一、需求分析
1。

1用户需求
1、可随时查询处可订购报纸的详细情况,如报纸编号(PNO)、报纸名称(PNA)、报纸单价(5、版面规格(PSI)、出版单位(PDW)等,这样便于客户选定.
2、客户查询报纸情况后即可订购所需报纸,可订购多种报纸,每种报纸可订若干份,交清所需金额后,就算订购处理完成。

3、为便于邮局投递报纸,客户需写明如下信息:客户姓名(CAN)、电话(CAD)、地址(CAW)及邮政编码(CAY),邮局将即时为每一客户编制唯一代码(CNA)。

4、邮局对每种报纸订购人数不限,每个客户可多次订购报纸,所定报纸亦可重复。

5、能对报纸、客户等信息进行添加、修改、删除、查询、打印等基本操作。

6、能根据订报要求订购各报纸,并完成一次订购任务后汇总总金额,模拟付钱、开票操作。

7、能明细查询某客户的订报情况及某报纸的订出情况。

8、能统计出某报纸的总订购量与总金额及某客户订购报纸种数、报纸份数与总订购金额等。

1.2系统功能需求
1、在SQL Server中建立各相应的关系模式对应的库表,并确定索引等.
2、能对各库表进行输入,添加,修改,删除,查询,打印等基本操作。

3、查询功能:能根据邮局订报管理系统,管理员实现报纸的管理功能,用户实现报纸订阅和退订功能。

4、统计功能:能名细查询每报纸的总订数量与总金额及客户订购报纸种类,
份数和总金额.
5、要求子系统设计界面友好,功能操作方便合理,并考虑子系统在安全性,完整性方面的功能要求。

6用户管理功能,如:用户登陆等。

1.3系统软硬件环境确定
系统开发工具为局域网或校园网网络环境,网络中有一台安装了windows xp的服务器,服务器上安装了SQL Server 2000,本子系统使用C#开发。

二、系统功能设计
2。

1系统功能结构
1、查询报纸
2、订报纸
3、开票
4、付钱结算
5、订购后的查询
6、统计
2.2系统功能处理流程
图2—1 系统流图
三、系统数据库设计
3。

1数据库概念设计
数据库在一个信息管理系统中占有非常重要的地位,数据库结构设计的好坏将直接决定对应用系统的效率以及实现的效果的影响。

合理的数据库结构设计可以提高数据存储的效率,保证数据的完整和一致。

同时,合理的数据库也有利与应用系统程序的实现.
在充分的寻求分析基础上,经过逐步抽象,分析,充分研讨,可画出如下反映邮局订报子系统数据的整体
图3-1 E-R图
3。

2数据库逻辑设计
1、数据库关系模式 News_info(PNO ,PN ,PPR ,P SI,PDW )
报纸(报纸编号,报纸名称,报纸价格,版面规格,出版单位)
customer_info (CAN ,CAD ,CAW,CAY )
客户(客户名称,电话,地址,邮政编码)
sub_news (PNO ,CAN ,NUM )
订购(报纸编号,客户名称,数量)
2、数据库的视图
3.3数据库物理设计
本系统使用的数据库是SQL 2000,根据已设计出的关系模式及各关系模式的完整性约束要求,在SQL 2000数据库系统中实现这些逻辑结构。

数据库表的创建
本系统使用的数据库名为newspaper 下面是创建数据库及其表结构的SQL命令:
CA N O CAY O
CAW CAD PNO PN PPR
PSI PDW
NUM sub_news customer_info News_info
n
m
CREATE TABLE LOGININ(
CNO varCHAR(20)PRIMARY KEY,
PSW varCHAR(20))
CREATE TABLE Customer(
CNO varCHAR(20) PRIMARY KEY,
CNA varCHAR(50),
CTE varCHAR(15),
CAD varCHAR(50),
CPO varCHAR(10),
FOREIGN KEY(CNO) REFERENCES LOGININ(CNO)) CREATE TABLE news_info (
PNO varCHAR(20) PRIMARY KEY,
PNA varCHAR(50),
PPR FLOAT,
PSI varCHAR(50),
PDW varCHAR(50))
CREATE TABLE Subcribe(
CNO varCHAR(20),
PNO varCHAR(20),
NUM SMALLINT,
FOREIGN KEY(CNO) REFERENCES LOGININ(CNO),FOREIGN KEY(PNO)REFERENCES news_info(PNO),PRIMARY KEY(CAN,PNO))
四、系统实现4。

1数据库连接的实现
class connection

SqlConnection conn;
public SqlConnection connect

get

return this。

conn;
}

public void CreateConnection()

conn = new SqlConnection(”data source=.;initial catalog=SubcribPost;user ID=sa”);
this。

conn。

Open();
SqlCommand command = this。

conn。

CreateCommand();


static void Main()
{
conn = new connection();
conn.CreateConnection();
Application.EnableVisualStyles();
Application。

SetCompatibleTextRenderingDefault(false);
Application。

Run(new logFrm()

4.2用户登录功能的实现
using System;
using System.Collections。

Generic;
using System。

ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System。

Drawing;
using System.Text;
using System.Windows.Forms;
namespace邮局订报
{
public partial class admin:Form

public admin()

InitializeComponent();

private void button1_Click(object sender,EventArgs e)

string username = textBox1.Text;
string password = textBox2.Text;
SqlConnection sqlCon = new SqlConnection();
SqlCommand LogInCommand = new SqlCommand();
SqlDataAdapter userAdapter = new SqlDataAdapter();
DataSet dt = new DataSet();
sqlCon.ConnectionString = ”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True;";
LogInCommand。

Connection = sqlCon;
LogInCommand。

CommandText = "SELECT username,password From [user] where username=’" + username + "' and password=’" + password + "’";
userAdapter。

SelectCommand = LogInCommand;
userAdapter。

SelectCommand.Connection = sqlCon;
sqlCon.Open();
userAdapter。

Fill(dt, "UserInfo");//填充数据集
if (dt。

Tables[0]。

Rows.Count 〉 0)

MessageBox。

Show(”登陆成功");
this。

Visible = false;
Form1 fr = new Form1(1);
fr。

ShowDialog();
}
else
MessageBox.Show(" 失败”);
}
private void admin_Load(object sender, EventArgs e)
{
textBox1.Focus();
}
private void button2_Click(object sender,EventArgs e)
{
this.Close();
}
private void button3_Click(object sender,EventArgs e)
{
this。

Visible = false;
Form1 fr = new Form1(0);
fr.ShowDialog();

private void label2_Click(object sender,EventArgs e)



1、}管理员登录
图4—1 登录
图4-2 管理员界面
2、已注册用户登录
图4—3 普通用户登录点击确定后即可进入用户订报界面.
3、新用户登录
图4-4 新用户登录
图4—5 信息提示
注册个人信息的代码:
using System;
using System.Collections.Generic;
using ponentModel;
using System。

Data;
using System.Data。

SqlClient;
using System。

Drawing;
using System。

Text;
using System.Windows。

Forms;
namespace邮局订报
{
public partial class yonghu : Form

public yonghu()

InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)

SqlConnection sqconn = new SqlConnection(”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True”);
string sql = String。

Format("insert into customer_info(CAN,CAD,CAW,CAY) VALUES(’{0}',’{1}',’{2}',{3})”, textBox1.Text, textBox2.Text, textBox3。

Text, Convert。

ToUInt64(textBox4.Text));
try

sqconn.Open();
SqlCommand command = new SqlCommand(sql, sqconn);
int count = command.ExecuteNonQuery();
if(count > 0)
{
MessageBox。

Show(”注册成功", ”注册信息”,MessageBoxButtons.OK,MessageBoxIcon。

Information);

else

MessageBox.Show(”注册失败”);

}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "操作数据库错误!”, MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);
}
finally
{
sqconn。

Close();


}
}
确定后即进入订报界面.
4。

3 用户订购报纸功能的实现
选好报纸后,输入要订购的份数,点击订购,即完成报纸的订购。

图4—7 用户界面
using System;
using System.Collections.Generic;
using System。

ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows。

Forms;
namespace邮局订报

public partial class dinggou:Form

public dinggou()

InitializeComponent();

private void dinggou_Load(object sender, EventArgs e)
{
SqlConnection sqconn = new SqlConnection(”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True;”);
string stri = ”select distinct PNA from news_info ”;
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset);
this。

comboBox1.DataSource = Dset.Tables[0];

catch (Exception ex)

MessageBox。

Show(ex.Message, "操作数据库错误!”,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally

sqconn。

Close();

}
private void button6_Click(object sender,EventArgs e)
{
int mon = 0, num = 0;
SqlConnection sqconn = new SqlConnection("Data Source=.;Initial
Catalog=newspaper;Integrated Security=True;”);
string stri = String.Format(”select PPR,PNUM from news_info where
PNA='{0}'", comboBox1。

Text);
// string stri_i = String.Format(”select CAD,CAW from customer_info where CAN=’{0}’”, comboBox2.Text);
SqlCommand com;
try

sqconn.Open();
com = new SqlCommand(stri, sqconn);
SqlDataReader re = com.ExecuteReader();
re.Read();
mon=Convert。

ToInt32(re[0]);
num = Convert。

ToInt32(re[1]);
}
catch(Exception ex)
{
MessageBox.Show(ex。

Message, ”操作数据库错误!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);

finally
{
sqconn.Close();
}
if(num >= Convert。

ToInt32(textBox2。

Text))

int money = mon *Convert.ToInt32(textBox2。

Text);
stri = String.Format(”insert into sub_news() VALUES(’{0}',’{1}’,’{2}’)", comboBox1.Text, textBox2.Text,Convert。

ToInt32(textBox1。

Text));
string stru = ”update news_info set NUM=” + (num - Convert。

ToInt32(textBox2.Text));
try

sqconn.Open();
com = new SqlCommand(stri, sqconn);
int count = com.ExecuteNonQuery();
com = new SqlCommand(stru, sqconn);
int co = com.ExecuteNonQuery();
if(count 〉 0 && co 〉 0)

MessageBox.Show(”订报成功", "订阅报纸”, MessageBoxButtons。

OK, rmation);

else

MessageBox.Show(”订报失败");


catch (Exception ex)

MessageBox.Show(ex。

Message, "操作数据库错误!", MessageBoxButtons.OK,MessageBoxIcon。

Exclamation);
}
finally

sqconn.Close();
}

else
MessageBox。

Show("报纸剩余数量不足!");

}
}
4。

4用户查看自己已订阅报纸的功能的实现
图4-10 用户查看
4.5 用户退订报纸功能的实现
用户在已订阅栏里可选择想要退订的报纸,然后点击退订按钮即可实现报纸的退订。

图4—11 已定报纸
using System;
using System.Collections.Generic;
using System。

ComponentModel;
using System。

Data;
using System.Data。

SqlClient;
using System。

Drawing;
using System.Text;
using System.Windows.Forms;
namespace邮局订报

public partial class state:Form

public state()

InitializeComponent();

// private void state_Load(object sender, EventArgs e)
// {
// this.button2.Visible = false;
// }
private void button1_Click(object sender,EventArgs e)
{
SqlConnection sqconn = new SqlConnection("Data Source=.;Initial Catalog=newspaper;Integrated Security=True");
string stri = String.Format(”select PNO 报纸编号,CAN 客户姓名,NUM 报纸数量 from sub_news where CAN=’{0}'",textBox1。

Text);
try

sqconn。

Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat.Fill(Dset, ”sub_news");
this.dataGridView1。

DataSource = Dset。

Tables[”sub_news”];
//if (this。

dataGridView1.Rows。

Count != 0)

catch(Exception ex)
{
MessageBox。

Show(ex。

Message,”操作数据库错误!", MessageBoxButtons。

OK,MessageBoxIcon。

Exclamation);

finally
{
sqconn.Close();


private void textBox1_TextChanged(object sender, EventArgs e)
{
}

}4。

6 管理员查看报纸信息的实现
图4-12 管理员查看
4。

7管理员查看用户信息的实现
图4—13 管理员查看
4.8 管理员查看用户订阅信息的实现
图4—14 管理员查看using System;
using System.Collections.Generic;
using ponentModel;
using System。

Data;
using System。

Data.SqlClient;
using System。

Drawing;
using System.Text;
using System.Windows.Forms;
namespace邮局订报
{
public partial class tongji : Form

public tongji()
{
InitializeComponent();
}
private void tongji_Load(object sender,EventArgs e)
{
SqlConnection sqconn = new SqlConnection(”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True");
string stri = ”select distinct PNA from news_info ";
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat.Fill(Dset);
this。

comboBox1.DataSource = Dset.Tables[0];

catch (Exception ex)
{
MessageBox.Show(ex.Message,"操作数据库错误!", MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);
}
finally

sqconn。

Close();
}

private void button1_Click(object sender, EventArgs e)

string name = comboBox1。

Text;
SqlConnection sqconn = new SqlConnection("Data Source=.;Initial Catalog=newspaper;Integrated Security=True”);
string stri = String。

Format(”select news_info.PNA 报纸名称,sum(。

sub_news.NUM) 总定数量 from sub_news,news_info where news_info。

PNA = sub_news.PNO and news_info。

PNA='{0}'group by PNA", name);
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset,”newspaper");
this。

dataGridView1。

DataSource = Dset.Tables["newspaper”];

catch(Exception ex)

MessageBox.Show(ex.Message,"操作数据库错误!”, MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);

finally

sqconn.Close();
}
}
private void button2_Click(object sender,EventArgs e)

SqlConnection sqconn = new SqlConnection("Data Source=.;Initial Catalog=newspaper;Integrated Security=True”);
string stri = String.Format("select customer_info。

CAN 客户姓名,
sum(sub_news.NUM) 总定数量 from customer_info,sub_news where sub_news。

CAN = customer_info。

CAN and customer_info。

CAN='{0}’group by customer_info。

CAN ", textBox1。

Text);
try
{
sqconn。

Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset,"newspaper”);
this.dataGridView1。

DataSource = Dset.Tables["newspaper”];
}
catch(Exception ex)

MessageBox。

Show(ex.Message,”操作数据库错误!”, MessageBoxButtons。

OK, MessageBoxIcon。

Exclamation);
}
finally

sqconn。

Close();

int sum = 0;
int money = 0;
for (int i = 0; i < dataGridView1.RowCount; i++)
{
sum += Convert。

ToInt32( dataGridView1。

Rows[i]。

Cells[1]。

Value); }
}

}
4。

9 用户查询报纸功能的实现
(1)客户订报情况
图4—16 客户订报
using System;
using System。

Collections。

Generic;
using System。

ComponentModel;
using System。

Data;
using System.Data.SqlClient;
using System.Drawing;
using System。

Text;
using System.Windows。

Forms;
namespace邮局订报
{
public partial class state : Form

public state()

InitializeComponent();
}
// private void state_Load(object sender, EventArgs e)
// {
// this.button2.Visible = false;
// }
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqconn = new SqlConnection(”Data Source=.;Initial Catalog=newspaper;Integrated Security=True");
string stri = String.Format(”select PNO 报纸编号,CAN 客户姓名,LEI 报纸类型,NUM 报纸数量 from sub_news where CAN='{0}’”,textBox1。

Text);
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat.Fill(Dset, ”sub_news");
this.dataGridView1.DataSource = Dset.Tables["sub_news”];
//if (this。

dataGridView1。

Rows.Count != 0)
}
catch (Exception ex)

MessageBox.Show(ex。

Message,"操作数据库错误!”,MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);

finally
{
sqconn。

Close();
}

private void textBox1_TextChanged(object sender,EventArgs e)


}

(2)报纸的订出情况
图4—17 报纸的订出情况
using System;
using System.Collections。

Generic;
using System。

ComponentModel;
using System。

Data;
using System.Data。

SqlClient;
using System。

Drawing;
using System.Text;
using System.Windows.Forms;
namespace邮局订报
{
public partial class tongji : Form
{
public tongji()

InitializeComponent();

private void tongji_Load(object sender,EventArgs e)
{
SqlConnection sqconn = new SqlConnection("Data Source=.;Initial Catalog=newspaper;Integrated Security=True”);
string stri = ”select distinct PNA from news_info ”;
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset);
boBox1.DataSource = Dset.Tables[0];
}
catch(Exception ex)

MessageBox。

Show(ex.Message, ”操作数据库错误!", MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);
}
finally

sqconn。

Close();


private void button1_Click(object sender,EventArgs e)

string name = comboBox1.Text;
SqlConnection sqconn = new SqlConnection("Data Source=.;Initial
Catalog=newspaper;Integrated Security=True”);
string stri = String.Format(”select news_info。

PNA 报纸名称,sum(.sub_news。

NUM)总定数量 from sub_news,news_info where news_info。

PNA = sub_news.PNO and news_info。

PNA=’{0}'group by PNA”, name);
try
{
sqconn。

Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset, "newspaper”);
this.dataGridView1.DataSource = Dset.Tables["newspaper"];
}
catch(Exception ex)

MessageBox.Show(ex。

Message, "操作数据库错误!”,MessageBoxButtons。

OK,MessageBoxIcon.Exclamation);

finally
{
sqconn。

Close();


private void button2_Click(object sender, EventArgs e)

SqlConnection sqconn = new SqlConnection("Data Source=。

;Initial Catalog=newspaper;Integrated Security=True");
string stri = String。

Format("select customer_info.CAN 客户姓名,sum (sub_news.NUM) 总定数量 from customer_info,sub_news where sub_news.CAN =
customer_info。

CAN and customer_info。

CAN=’{0}' group by customer_info。

CAN ", textBox1。

Text);
try
{
sqconn。

Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat.Fill(Dset, "newspaper");
this.dataGridView1.DataSource = Dset.Tables["newspaper”];

catch (Exception ex)
{
MessageBox。

Show(ex。

Message,”操作数据库错误!”,MessageBoxButtons。

OK,MessageBoxIcon.Exclamation);
}
finally

sqconn.Close();
}
int sum = 0;
int money = 0;
for (int i = 0; i < dataGridView1。

RowCount; i++)

sum += Convert.ToInt32( dataGridView1.Rows[i].Cells[1].Value);
// money += Convert.ToInt32(dataGridView1。

Rows[i].Cells[2]。

Value); }
//label3。

Text =textBox1。

Text+ "总订报纸份数为:”+sum.ToString();
// label4。

Text = ”总订报纸金额为:" + money。

ToString();
}
}
}
4。

10 管理员插入报纸功能的实现
using System;
using System.Collections.Generic;
using System。

ComponentModel;
using System.Data;
using System.Drawing;
using System。

Data。

SqlClient;
using System。

Text;
using System。

Windows.Forms;
namespace邮局订报
{
public partial class start:Form

public start()
{
InitializeComponent();

private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)

if(this.dataGridView1。

Rows[e。

RowIndex].Cells[0].Value != null) {
this。

textBox1。

Text = this.dataGridView1。

Rows[e.RowIndex]。

Cells [0].Value.ToString();
this.textBox2.Text = this。

dataGridView1。

Rows[e。

RowIndex]。

Cells [1]。

Value。

ToString();
this。

textBox3。

Text = this.dataGridView1。

Rows[e.RowIndex].Cells [2].Value。

ToString();
this。

textBox4.Text = this。

dataGridView1。

Rows[e。

RowIndex].Cells[3]。

Value。

ToString();
this。

textBox5。

Text = this.dataGridView1.Rows[e.RowIndex].Cells[4]。

Value。

ToString();


public void connnectn()
{
SqlConnection sqconn = new SqlConnection(”Data Source=.;Initial
Catalog=newspaper;Integrated Security=True”);
string stri = "select PNA 报纸名称,PPR 报纸周单价,PPY 报纸月价格,PSI 报纸版面规格,PDW 报纸出版单位 from news_info ”;
try

sqconn.Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat.Fill(Dset,"newspaper");
this。

dataGridView1.DataSource = Dset。

Tables[”newspaper"];

catch(Exception ex)
{
MessageBox.Show(ex.Message,"操作数据库错误!",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally

sqconn.Close();
}

private void start_Load(object sender, EventArgs e)

connnectn();
}
private void button7_Click(object sender,EventArgs e)

string connectionstr = "Data Source=.;Initial Catalog=newspaper;Integrated Security=True";
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String.Format(”insert into [newspaper].[dbo]。

[news_info](PNO,PNA,PPR,PPY,PSI,PDW) VALUES('{0}’,'{1}','{2}','{3}','
{4}','{5}')”,textBox6.Text,textBox1。

Text, textBox2。

Text, textBox3。

Text, textBox4。

Text, textBox5.Text);
try
{
sconn。

Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command。

ExecuteNonQuery();
}
catch(Exception ex)

MessageBox。

Show(ex.Message, ”操作数据库错误!",MessageBoxButtons。

OK,MessageBoxIcon。

Exclamation);
}
finally
{
sconn。

Close();
}
connnectn();

private void button8_Click(object sender,EventArgs e)

string connectionstr = ”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True";
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String。

Format(”update [newspaper]。

[dbo].[news_info] set PPR=’{0}’,PSI=’{1}’,PDW='{2}’,PPY={3} WHERE PNA='{4}'”, textBox2.Text。

Trim(), textBox5。

Text, textBox3.Text, textBox4。

Text。

Trim(), textBox1。

Text。

Trim());
try
{
sconn。

Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command.ExecuteNonQuery();
if (count 〉 0)
{
MessageBox。

Show(”修改成功”, ”修改报纸信息", MessageBoxButtons.OK, rmation);
}
else
{
MessageBox。

Show("修改失败");
}

catch (Exception ex)

MessageBox.Show(ex。

Message, "操作数据库错误!",MessageBoxButtons。

OK,MessageBoxIcon。

Exclamation);
}
finally
{
sconn。

Close();
}
connnectn();

private void button1_Click(object sender, EventArgs e)

string connectionstr = "Data Source=.;Initial Catalog=newspaper;Integrated Security=True”;
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String.Format("delete from [newspaper]。

[dbo]。

[news_info]WHERE PNA=’{0}’", textBox1.Text);
try

sconn。

Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command。

ExecuteNonQuery();

catch (Exception ex)

MessageBox。

Show(ex.Message, "操作数据库错误!”, MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);

finally
{
sconn.Close();

connnectn();

private void label5_Click(object sender,EventArgs e)


private void textBox5_TextChanged(object sender, EventArgs e)
{
}

}
点击插入报纸按钮,即弹出如下对话框:
图4—19 添加报纸完善信息后,点击确认添加,即完成了报纸的添加.
4.11 管理员删除与增加报纸功能的实现
using System;
using System.Collections.Generic; using System。

ComponentModel;
using System.Data;
using System。

Drawing;
using System。

Data。

SqlClient;
using System。

Text;
using System.Windows.Forms;
namespace邮局订报

public partial class start:Form

public start()

InitializeComponent();

private void dataGridView1_RowEnter(object sender,DataGridViewCellEventArgs e)

if (this.dataGridView1.Rows[e.RowIndex].Cells[0]。

Value != null)
{
this.textBox1.Text = this.dataGridView1。

Rows[e.RowIndex]。

Cells [0].Value。

ToString();
this。

textBox2。

Text = this。

dataGridView1.Rows[e。

RowIndex]。

Cells [1]。

Value。

ToString();
this。

textBox3.Text = this.dataGridView1.Rows[e。

RowIndex].Cells[2].Value。

ToString();
this。

textBox4。

Text = this.dataGridView1.Rows[e。

RowIndex].Cells [3].Value.ToString();
this.textBox5。

Text = this。

dataGridView1。

Rows[e。

RowIndex]。

Cells[4].Value.ToString();
}
}
public void connnectn()
{
SqlConnection sqconn = new SqlConnection(”Data Source=.;Initial Catalog=newspaper;Integrated Security=True”);
string stri = ”select PNA 报纸名称,PPR 报纸单价,PSI 报纸版面规格,PDW 报纸出版单位,PNUM 报纸数量 from news_info ”;
try

sqconn。

Open();
SqlDataAdapter sdat = new SqlDataAdapter(stri, sqconn);
DataSet Dset = new DataSet();
sdat。

Fill(Dset,”newspaper”);
this。

dataGridView1.DataSource = Dset.Tables["newspaper"];
}
catch(Exception ex)

MessageBox。

Show(ex。

Message, "操作数据库错误!", MessageBoxButtons。

OK, MessageBoxIcon。

Exclamation);

finally
{
sqconn。

Close();
}
}
private void start_Load(object sender,EventArgs e)
{
connnectn();
}
private void button7_Click(object sender, EventArgs e)
{
string connectionstr = "Data Source=.;Initial
Catalog=newspaper;Integrated Security=True”;
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String。

Format("insert into news_info(PNA,PPR,PSI,PDW,PNUM) VALUES(’{0}',’{1}’,’{2}’,’{3}’,’{4}')”, textBox1.Text,Convert.ToInt16(textBox2.Text), textBox3.Text, textBox4.Text, Convert。

ToInt16(textBox5.Text));
try
{
sconn.Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command。

ExecuteNonQuery();

catch(Exception ex)

MessageBox.Show(ex.Message, "操作数据库错误!",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
sconn。

Close();
}
connnectn();

private void button8_Click(object sender, EventArgs e)

string connectionstr = ”Data Source=.;Initial
Catalog=newspaper;Integrated Security=True";
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String。

Format(”update news_info set PPR={0},PSI=’{1}’,PDW='{2}',PNUM={3} WHERE PNA=’{4}’",Convert。

ToInt16(textBox2。

Text), textBox3。

Text, textBox4.Text, Convert.ToInt16(textBox5。

Text), textBox1.Text);
try
{
sconn.Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command.ExecuteNonQuery();
if(count 〉 0)
{
MessageBox.Show(”修改成功", ”修改报纸信息",MessageBoxButtons。

OK,rmation);

else
{
MessageBox.Show(”修改失败");
}

catch(Exception ex)
{
MessageBox.Show(ex.Message,”操作数据库错误!”,MessageBoxButtons。

OK, MessageBoxIcon.Exclamation);
}
finally
{
sconn。

Close();

connnectn();
}
private void button1_Click(object sender, EventArgs e)

string connectionstr = ”Data Source=。

;Initial Catalog=newspaper;Integrated Security=True”;
SqlConnection sconn = new SqlConnection(connectionstr);
string sql = String。

Format("delete from newspaper WHERE PNA=’{0}'”,
textBox1。

Text);
try
{
sconn.Open();
SqlCommand command = new SqlCommand(sql, sconn);
int count = command.ExecuteNonQuery();

catch(Exception ex)
{
MessageBox。

Show(ex。

Message, ”操作数据库错误!”,MessageBoxButtons。

OK, MessageBoxIcon。

Exclamation);

finally
{
sconn。

Close();

connnectn();
}
}

五、小结
刚接到做数据库课程设计的任务的时候,因为之前从未接触过,有一点迷茫,自己一个人面对一整个邮局订报系统的设计实验,感觉到这将对自己是一个挑战。

幸好自己从不畏惧挑战,也愿意学习和接触新的知识.于是从课本基础知识开始,到网络上搜索相关文献知识,从需求分析,到数据库的逻辑设计、物理设计,从基本表的建立到E—R图转化为关系模型,从算法流程设计,到最后转换成代码实现,自己一点一点的努力,觉得收获很大。

期间也遇到过很多问题,也有过瓶颈,每次遇到困难就通过网络或者向其他人寻求帮助,一点一点坚持了下来。

到最后整个程序调试成功,运行正确的时候,那种喜悦的心情真的难以言表。

虽然由于时间的关系,最后实现的系统还只是一个比较简易的系统,不那么完善,也不够健壮,数据库基本表设计还不够复杂,只能管理简单信息。

但是麻雀虽小五脏俱全,通过这次课程设计,在查询各类资料以及自己一点一点摸索系统实现的过程中,对数据库的基本知识有了更深刻的理解,掌握了数据库软件设计的核心内容,也对这类软件的设计流程有了很直观也更具体的认识,达到了这次课程设计的主要目的.如果有机会我想利用假期的时间把系统完善,做到尽善尽美。

通过这次的邮局订报系统课程设计,在对系统数据结构的分析和设计以及连接数据库的实现中,我对数据库的理论知识有了更加深入的理解,很多以前觉得抽象的内容都有更直观的认识;同时巩固练习了C#语言的基本知识和编程技巧,并掌握了C#与SQL语言的嵌套使用,使我的实践能力有了很大提高;更重要的,在课程设计的过程中,我深深体会到了一种自主学习的努力和坚持带来的力量和努力过后的喜悦感,使我受益匪浅.
六、参考文献。

参考文献
[1]数据库原理及技术课程设计. 钱雪忠。

清华大学出版社. 2012 [2]数据库系统概论. 王珊。

高等教育出版社. 2012。

相关文档
最新文档