报纸发行员投递管理系统
报纸发行员投递管理系统
报纸的客户主要集中在社区,每个社区有若干客户。每个发行员管理若干客户。 为该报社开发一个报纸发行员投递管理系统。 系统主要功能如下:
(1) 系统用户管理:实现系统管理员添加、删除和更改密码等功能。 (2) 发行员管理:实现发行员个人信息的查询和维护。 (3) 客户信息管理:实现客户信息的查询和维护。 (4) 报纸管理:报纸订购和退订信息的维护和查询
(5) 管理统计:发行员负责区域的安排,客户数量和订购信息的统计。
一、报纸发行员投递管理系统的分析和概要设计 (1)系统模块菜单:
1 系统用户管理 实现系统管理员添加 删除以及密码更改功能 2 发行员管理
实现发行员个人信息的维护 对发行员进行查询 3 客户信息管理 实现客户信息的维护 对客户进行查询 4 报纸管理
报纸订购和退订信息的维护 报纸订购和退订信息的查询 5 管理统计
发行员负责区域的安排
客户数量和订购信息的统计
(2)报纸发行员投递管理系统功能描述
1 系统用户管理:
对系统管理员添加,删除,更新及查询; 2 发行员管理:
实现对每个发行员添加,删除,更新及查询 3 客户信息管理:
实现对每个客户信息添加,删除,更新及查询 4 报纸管理:
报纸订购与退订,及报纸信息的添加,删除,更新及查询 5 管理统计:
发行员负责的区域的更新,客户数量的统计,订购信息的统计
二、系统数据结构设计
用户需求具体有报刊发行员管理系统提供保存、更新、查询、维护,这就需求数据库结构能充分满足各种信息的输入与输出,实现有组织地、动态地存储大量关联数据,方便用户访问系统中的数据。
1. 数据流图描述:
本系统从总体上分为系统系统用户管理、发行员管理、客户管理、报纸管理和统计功能。
信息流入图
2. 数据库中的表
有关创建数据库和关系表的SQL 语句如下所示:
/*==============================================================*/
/* DataBase: 报纸发行员投递管理系统, 创建数据库,数据库名称为报纸发行员投递管理系统*/ /*==============================================================*/ create database报纸发行员投递管理系统 go
/*==============================================================*/ /* Table: paper, 报纸信息表 */
/*==============================================================*/ create table paper (
paper nchar(10), /*报纸名*/ ) go
/*==============================================================*/ /* Table: CustomerInfo, 客户个人信息表 */
/*==============================================================*/ create table CustomerInfo (
name1 nchar(10), /*客户姓名*/ sex nchar(10) , /*客户性别*/ telephone nchar(20), /*客户电话*/ site nchar(10), /*客户住址*/
distributor nchar(10), /*客户发行员*/ ) go
/*==============================================================*/ /* Table: CustomerOrder,客户订购信息表 */
/*==============================================================*/ create table CustomerOrder(
name1 nchar(10), /*客户姓名*/ sex nchar(10) , /*客户性别*/ telephone nchar(20), /*客户电话*/ site nchar(10), /*客户住址*/
distributor nchar(10), /*客户发行员*/ date datetime /*订购时间*/ ) go
/*==============================================================*/ /* Table: CustomerCancle,客户退订信息表*/
/*==============================================================*/ create table CustomerCancle( name1 nchar(10), /*客户姓名*/ sex nchar(10) , /*客户性别*/ telephone nchar(20), /*客户电话*/ site nchar(10), /*客户住址*/
distributor nchar(10), /*客户发行员*/ date datetime /*退订时间*/ ) Go
3.ER 图
1. 系统管理员查询
2. 添加系统用户
3. 删除系统用户
4. 更新系统用户
5. 发行员查询
6. 发行员添加信息
7. 发行员信息删除
8. 发行员信息更新
9. 客户信息查询
10. 客户信息添加
11. 客户信息删除
12. 客户信息更新
13. 报纸订购与退订的查询
14. 报纸订购添加
15. 报纸退订删除
16. 报纸订购与退订更新
17. 统计管理
三、应用系统设计
登录界面:
登录按钮点击事件代码:
private void btnLogin_Click(object sender, EventArgs e) { try {
if (txtUserName.Text == "" ) //判断用户是否输入登录名
{
MessageBox .Show(" 用户名不能为空" ); } else
if (txtPwd.Text == "" ) //判断用户是否输入密码
{
MessageBox .Show(" 密码不能为空" ); } else
if (cmbLogin.Text == "" ) //判断用户是否选择用户界面
{
MessageBox .Show(" 请选择登录界面" ); cmbLogin.Focus(); return ; } else {
if (cmbLogin.Text == " 客户" ) {
SqlConnection con = PaperCon .createCon(); //创建数据库连接
con.Open(); //打开连接
SqlCommand cmd = new SqlCommand ("select count(*)from Users where name1='" + txtUserName.Text + "' and pwd1='" + txtPwd.Text + "'and permission='"+cmbLogin.Text+"'" , con);
Int32 count = (Int32)cmd.ExecuteScalar(); //获取返回值 if (count==1) {
frmMain1 main = new frmMain1();
main.Show(); //弹出客户登陆界面 Login_name = txtUserName.Text; this .Hide(); //隐藏登陆界面
} else {
MessageBox .Show(" 用户名或者密码错误" ); //弹出提示 }
con.Close(); }
if (cmbLogin.Text == " 发行员" ) {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open(); //打开连接 SqlCommand cmd = new SqlCommand ("select count(*)from Users where name1='" + txtUserName.Text + "' and pwd1='" + txtPwd.Text + "'and permission='" + cmbLogin.Text + "'" , con);
Int32 count = (Int32)cmd.ExecuteScalar(); //获取返回值 if (count==1) {
frmMain2 main = new frmMain2(); main.Show();
Login_name = txtUserName.Text; //记录登陆用户名
this .Hide(); } else {
MessageBox .Show(" 用户名或者密码错误" ); //弹出提示 }
con.Close(); }
if (cmbLogin.Text == " 系统用户" ) {
SqlConnection con = PaperCon .createCon(); //创建数据库连接
con.Open(); //打开连接
SqlCommand cmd = new SqlCommand ("select count(*)from Users where name1='" + txtUserName.Text + "' and pwd1='" + txtPwd.Text + "'and permission='" + cmbLogin.Text + "'" , con);
Int32 count = (Int32)cmd.ExecuteScalar(); //获取返回值 if (count==1) {
frmMain3 main = new frmMain3(); main.Show();
Login_name = txtUserName.Text; this .Hide(); } else {
MessageBox .Show(" 用户名或者密码错误" ); //弹出提示 }
con.Close(); //关闭连接
} } }
catch (Exception ex) {
MessageBox .Show(ex.ToString()); //获取异常
} }
客户界面:
报纸订购事件程序:
private void button1_Click(object sender, EventArgs e) { try {
if (textBox1.Text == "" ) {
MessageBox .Show(" 请输入要订购的报纸名" ); } else {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd1 = new SqlCommand ("select count(*)from Allpaper where paper='"
+ textBox1.Text + "'" , con);
Int32 count1 = (Int32)cmd1.ExecuteScalar();
SqlCommand cmd4 = new SqlCommand ("select count(*)from CustomerOrder where name1='" + label8.Text + "' and paper='" + textBox1.Text + "'" , con); Int32 count4 = (Int32)cmd4.ExecuteScalar(); if (count4 > 0) //判断用户是否订购了该报纸 {
MessageBox .Show(" 您¨已经订购了该报纸!!!" ); }
if (count1 == 0) //判断是否有该报纸名 {
MessageBox .Show(" 没有该报纸名,订购失败!!!" ); }
else if ( count1 > 0 && count4==0) {
string strSql = "insert into CustomerOrder
(name1,sex,paper,telephone,site,date) values('" + label8.Text.ToString() + "','" +
label9.Text.ToString() + "','" + textBox1.Text.ToString() + "','" + label11.Text.ToString() + "','" + label12.Text.ToString() + "','" + DateTime .Now.ToString() + "')" ; SqlCommand cmd = new SqlCommand (strSql, con); cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 MessageBox .Show(" 订购成功!!!" );
string strSql1 = " update CustomerOrder set distributorname=(select distributorname from CustomerInfo where name1='" + label8.Text.ToString() + "')where name1='" + label8.Text.ToString() + "'" ;
SqlCommand cmd3 = new SqlCommand (strSql1, con); cmd3.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 con.Close(); } } }
catch (Exception ex) {
MessageBox .Show(ex.ToString()); } }
private void Paperorder_Load(object sender, EventArgs e) {
label8.Text=frmLogin .Login_name;
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
string str1="select sex from CustomerInfo where name1='"+frmLogin .Login_name+"'" ;
SqlCommand cmd1 = new SqlCommand (str1, con); string sex = (string )cmd1.ExecuteScalar(); label9.Text = sex.ToString();
string str2 = "select telephone from CustomerInfo where name1='" + frmLogin .Login_name + "'" ;
SqlCommand cmd2 = new SqlCommand (str2, con); string telephone = (string )cmd2.ExecuteScalar(); label11.Text = telephone.ToString();
string str3 = "select site from CustomerInfo where name1='" + frmLogin .Login_name + "'" ; SqlCommand cmd3 = new SqlCommand (str3, con); string site = (string )cmd3.ExecuteScalar(); label12.Text = site.ToString();
label13.Text = DateTime .Now.ToString(); con.Close();
}
报纸退订事件程序:
private void button1_Click(object sender, EventArgs e)
{ try {
if (textBox3.Text == "" ) {
MessageBox .Show(" 报纸名不能为空" ); } else {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd1 = new SqlCommand ("select count(*)from CustomerOrder where name1='" + label8.Text + "'and paper='" + textBox3.Text + "'" , con); Int32 count = (Int32)cmd1.ExecuteScalar(); if ( count > 0) {
string strSql = "DELETE FROM CustomerOrder where name1='" + label8.Text.ToString() + "'and paper='" + textBox3.Text.ToString() + "'" ;
SqlCommand cmd = new SqlCommand (strSql, con); cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 MessageBox .Show(" 退订成功!!!" );
string strSql1 = "insert into CustomerCancle
(name1,sex,paper,telephone,site,date) values('" + label8.Text.ToString() + "','" +
label9.Text.ToString() + "','" + textBox3.Text.ToString() + "','" + label10.Text.ToString() + "','" + label11.Text.ToString() + "','" + DateTime .Now.ToString() + "')" ; SqlCommand cmd3 = new SqlCommand (strSql1, con); cmd3.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 con.Close(); }
else if (count == 0) //判断是否有该订购记录 {
MessageBox .Show(" 您没有订购该报纸,操作失败!!!" ); } } }
catch (Exception ex) {
MessageBox .Show(ex.ToString()); } }
private void PaperCancle_Load(object sender, EventArgs e) {
label8.Text = frmLogin .Login_name;
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
string str1 = "select sex from CustomerInfo where name1='" + frmLogin .Login_name + "'" ; SqlCommand cmd1 = new SqlCommand (str1, con); string sex = (string )cmd1.ExecuteScalar(); label9.Text = sex.ToString();
string str2 = "select telephone from CustomerInfo where name1='" + frmLogin .Login_name + "'" ;
SqlCommand cmd2 = new SqlCommand (str2, con); string telephone = (string )cmd2.ExecuteScalar(); label10.Text = telephone.ToString();
string str3 = "select site from CustomerInfo where name1='" + frmLogin .Login_name + "'" ; SqlCommand cmd3 = new SqlCommand (str3, con); string site = (string )cmd3.ExecuteScalar(); label11.Text = site.ToString();
label12.Text = DateTime .Now.ToString(); con.Close(); }
发行员界面:
我的客户点击事件程序:
private void 我的客户¡ìToolStripMenuItem_Click(object sender, EventArgs e) {
SqlConnection con = PaperCon .createCon(); //创建数据库连接¨ con.Open();
string commandString = "Select * from CustomerInfo where distributorname='" + frmLogin .Login_name + "'" ; //获取该发行员的客户信息
SqlDataAdapter DataAdapter = new SqlDataAdapter (commandString, con); DataSet DataSet = new DataSet ();
DataAdapter.Fill(DataSet, "CustomerInfo" ); DataTable dataTable = DataSet.Tables[0]; dataGridView1.DataSource = dataTable; con.Close(); }
删除退订点击事件程序:
private void 删¦除ToolStripMenuItem_Click(object sender, EventArgs e) {
if (MessageBox .Show(" 确定删¦除所选记录吗" , " 提示" , MessageBoxButtons .OKCancel, MessageBoxIcon .Asterisk) == DialogResult .OK) {
SqlConnection con = PaperCon .createCon(); //创建数据库连接
con.Open();
string sql = "delete from CustomerCancle where paper='" +
dataGridView1.CurrentRow.Cells["paper" ].FormattedValue.ToString() + "' "; //删除该条退订记录 SqlCommand cmd = new SqlCommand (sql, con); cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命 dataGridView1.Rows.Remove(dataGridView1.CurrentRow); con.Close(); } }
订购数量点击事件程序:
private void 订购数量ToolStripMenuItem_Click(object sender, EventArgs e) {
show2(); //调用show2() }
private void show2() {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
string strSql = "Select * from CustomerOrder where distributorname='" + frmLogin .Login_name + "'" ;
SqlCommand cmd = new SqlCommand (strSql, con); cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 int count = 0;
SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) {
count++;
Console .WriteLine(String .Format("{0}", reader[0])); }
MessageBox .Show(" 我的客户订购数量为:" +count.ToString()); con.Close();
}
系统用户界面:
增加报纸点击事件程序:
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == "" ) {
MessageBox .Show(" 报纸名不能为空" ); } else { try
{
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd = new SqlCommand ("insert into Allpaper (paper) values('" + textBox1.Text.ToString() + "')" , con); //向表中插入该报纸名
cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 con.Close();
MessageBox .Show(" 添加成功" ); }
catch (Exception ex) {
MessageBox .Show(" 该报纸名已存在 ! ! !"); } } }
添加客户点击事件代码:
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == "" )
{
MessageBox .Show(" 用户名不能为空" ); }
else if (textBox2.Text == "" ) {
MessageBox .Show(" 密码不能为空" ); } else {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd2 = new SqlCommand ("select count(*)from Users where name1='" + textBox1.Text.ToString() + "'" , con);
Int32 count = (Int32)cmd2.ExecuteScalar(); if (count == 1) //判断是否有该用户
{
MessageBox .Show(" 该用户已经存在" ); } else {
string strSql = "insert into Users(name1,pwd1,permission) values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "',' 客户')" ; //向用户表中插入该客户 SqlCommand cmd = new SqlCommand (strSql, con); cmd.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令
string strSql1 = "insert into CustomerInfo(name1) values('" + textBox1.Text.ToString() + "')" ; //向客户信息表中插入该客户
SqlCommand cmd1 = new SqlCommand (strSql1, con); cmd1.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 MessageBox .Show(" 添加成功!!!" ); con.Close(); } } }
private void button1_Click(object sender, EventArgs e) { try {
if (textBox1.Text == "" ) {
MessageBox .Show(" 客户姓名不能为空" ); }
else if (textBox2.Text == "" ) {
MessageBox .Show(" 发行员不能为空" ); } else {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd1 = new SqlCommand ("select count(*)from Users where name1='" + textBox1.Text + "'and permission='客¨ª户¡ì'", con);
Int32 count1 = (Int32)cmd1.ExecuteScalar(); //判断是否有该客户
SqlCommand cmd2 = new SqlCommand ("select count(*)from Users where name1='" + textBox2.Text + "' and permission='发¤¡é行D 员¡À'", con);
Int32 count2 = (Int32)cmd2.ExecuteScalar(); //判断是否有该发行员 if (count1==0)
{
MessageBox .Show(" 没有该客户!!!" ); }
else if (count2 == 0) {
MessageBox .Show(" 没有该发行员!!!" ); } else {
string strSql3 = " update CustomerInfo set distributorname='" + textBox2.Text.ToString() + "'where name1='" + textBox1.Text.ToString() + "'" ; SqlCommand cmd3 = new SqlCommand (strSql3, con); cmd3.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令
string strSql4 = " update CustomerOrder set distributorname='" + textBox2.Text.ToString() + "'where name1='" + textBox1.Text.ToString() + "'" ; SqlCommand cmd4 = new SqlCommand (strSql4, con); cmd4.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 con.Close();
MessageBox .Show(" 分配成功!!!" ); } } }
catch (Exception ex) {
MessageBox .Show(ex.ToString()); } }
更改密码点击事件程序:
private void button1_Click(object sender, EventArgs e) {
if (textBox3.Text == "" ) //判断用户是否输入了用户名 {
MessageBox .Show(" 用户名不能为空" ); } else {
if (textBox1.Text == "" ) {
MessageBox .Show(" 原密码不能为空" ); //判断用户是否输入了密码
}
else if (textBox2.Text == "" ) {
MessageBox .Show(" 新密码不能为空" ); } else {
SqlConnection con = PaperCon .createCon(); //创建数据库连接 con.Open();
SqlCommand cmd2 = new SqlCommand ("select count(*) from Users where name1='" + textBox3.Text.ToString() + "' and pwd1='" + textBox1.Text.ToString() + "'" , con); Int32 count2 = (Int32)cmd2.ExecuteScalar();
if (count2 > 0) {
string strSql1 = "update users set pwd1='" + textBox2.Text.ToString() + "' where pwd1='" + textBox1.Text.ToString() + "' ";
SqlCommand cmd1 = new SqlCommand (strSql1, con); cmd1.ExecuteNonQuery();// 执行SQL 语句完成SQL 命令 con.Close();
MessageBox .Show(" 修改成功!!!" ); }
{
}
con.Close(); } } }
if (count2 == 0) MessageBox .Show(" 用户名或密码错误!!!" );