联系方式: 微信:biyebang QQ: 629001810
系统设计
市场竞争的激烈意味着管理工作的重要性,药品种类和数量的增加也就意味着销售管理的重要性。本医药公司销售管理系统的目标大体有:
1.为该公司提供一体化解决方案涵盖物流的整个过程,满足业内各种经营模式和特性。
2.适合特色管理和经营,针对该行业经营品种繁多,对药品的有效期,批准文号,合格证等要有比较严格的管理。
5.3 系统功能模块设计
系统开发的总体任务是实现各种信息的系统化,规范化和自动化。该公司的销售管理系统完成功能的设计如下:
1系统管理用于管理本系统用户的增加、删除和修改用户密码等操作。
2基本信息设置包括对药品类别的设置、药品的设置、供应商的设置和业务员的设置等
系统实现
面向对象分析首要的高能工作,是建立问题域的对象模型,这个模型描述了现实世界的“类---&----对象”以及它们之间的关系,表示了目标系统的静态数据结构,静态数据结构对应细节以来较少,比较容易确定;当用户的需求变化时,静态数据结构相对来说比较稳定。因此,用面向对象开发的决大多数软件时,都首先建立对象模型,然后再建立子模型。
类和对象是对应用领域中的概念的标识,是系统分析及软件的复用的基础,这一过程需要考虑多种情况,正确的表示类—对象,以形成下一步软件的复用性,提高软件质量及生产效率。例如,在办公自动化系统中,文档是整个软件的基础,如果没有标识此类对象,一旦文档稍有改变,则整个系统就会面临重建的风险。
OOA系统的属性层包括对象的属性及对象间的实例连接(关系),属性为对象的一些静态信息,它是对象的内部资料描述,即内部封装的资料。
对象所能执行的操作称为服务或方法。在属性层讨论是应用领域的静态方面。而对象间的动态关系及对象实例间的消息连接构成了服务层。
结合面向对象的语言,就非常符合实际的情况。应用户在各种处理方面的需求,以及针对系统功能的具体设计将得到如下所示的本系统所要处理的数据流程图。
用户登陆模块的创建
运行本系统后将出现一个对话框如图6所示,提供用户输入用户名和密码,验证用户的合法性。如果用户3次输入登陆信息错误,将退出系统。这个模块包括三个类:LoginSystem.java、CheckUser.java和Main.java。其中Main.java是系统启动后运行的第一个类,在该类中初始化登陆窗口(Longinsystem.java)并将它显示出来,CheckUser.java封装了登陆和验证中一些公用的方法。
在CheckUser类中用JDBC连接数据库,提供了验证用户,也实现了为以后添加用户和修改密码的功能。
packagecom.csbook.restaurant.utility;
import java.sql.*;
import javax.swing.*;
public class CheckUser{
//构造数据库连接参数
//private Stringurl="jdbc:odbc:yumen","","";
public CheckUser() {
try {
//装载数据库驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
//检查指定用户是否为合法用户
public boolean isValidUser(Stringoperator,String password)
{
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
boolean isValid=false;
try{
con =DriverManager.getConnection("jdbc:odbc:yumen","","");
String queryStr = "select * fromoperator WHERE id=? and password=?";
ps = con.prepareStatement(queryStr);
ps.setString(1, operator);
ps.setString(2, password);
rs = ps.executeQuery();
if (rs.next())
isValid = true;
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (rs != null) try { rs.close();}catch (SQLException ignore) {}
if (ps != null) try{ ps.close();}catch (SQLException ignore) {}
if (con != null)try{con.close();}catch (SQLException ignore) {}
}
return isValid;
}
//更改用户密码
public void updatePassword(String operator,Stringpassword)
{
Connection con=null;
PreparedStatementps=null;
try{
//con =DriverManager.getConnection(url);
con =DriverManager.getConnection("jdbc:odbc:yumen","","");
String updateStr = "updateoperator set password=? WHERE id=?";
ps = con.prepareStatement(updateStr);
ps.setString(1, password);
ps.setString(2, operator);
ps.executeUpdate();
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (ps != null)try{ ps.close();}catch (SQLExceptionignore) {}
if (con != null) try{con.close();}catch (SQLException ignore) {}
}
}
//检查指定用户是否存在
public boolean userExist(String userID)
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs=null;
boolean exist=false;
try{
// con =DriverManager.getConnection(url);
con =DriverManager.getConnection("jdbc:odbc:yumen","","");
StringselectStr = "select id from operator where id=?";
ps = con.prepareStatement(selectStr);
ps.setString(1, userID);
rs=ps.executeQuery();
if(rs.next())
exist=true;
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (rs != null)try{ rs.close();}catch (SQLExceptionignore) {}
if (ps != null)try{ ps.close();}catch (SQLExceptionignore) {}
if (con != null) try{con.close();}catch(SQLException ignore) {}
}
return exist;
}
//添加新用户
public void addOperator(StringuserID,String username,String userType,String password,String PICNo,Stringtel,String addr,String remark)
{
Connection con=null;
PreparedStatement ps=null;
try{
//con = DriverManager.getConnection(url);
con =DriverManager.getConnection("jdbc:odbc:yumen","","");
String updateStr = "insert intooperator(id,password,name,type,tel,addr,PICNo,remark)values(?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(updateStr);
ps.setString(1, userID);
ps.setString(2, password);
ps.setString(3,username);
ps.setString(4,userType);
ps.setString(5,tel);
ps.setString(6,addr);
ps.setString(7,PICNo);
ps.setString(8,remark);
ps.executeUpdate();
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (ps != null) try{ ps.close();}catch (SQLException ignore) {}
if (con != null)try{con.close();}catch (SQLException ignore) {}
}
}
//删除用户
public boolean deleteOperator(StringuserID)
{
Connection con=null;
PreparedStatement ps=null;
boolean succeed=true;
try{
//con =DriverManager.getConnection(url);
con = DriverManager.getConnection("jdbc:odbc:yumen","","");
String deleteStr="delete fromoperator where id=?";
ps=con.prepareStatement(deleteStr);
ps.setString(1,userID);
ps.executeUpdate();
}
catch(SQLException exc){
succeed=false;
}
finally{
if (ps != null) try{ ps.close();}catch (SQLException ignore) {}
if (con != null)try{con.close();}catch (SQLException ignore) {}
}
return succeed;
}
//获得用户类型
public String getUserType(String user)
{
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
String userType="";
try{
//con = DriverManager.getConnection(url);
con = DriverManager.getConnection("jdbc:odbc:yumen","","");
String queryStr = "select * from operator WHERE id=?";
ps = con.prepareStatement(queryStr);
ps.setString(1, user);
rs = ps.executeQuery();
if (rs.next())
userType =rs.getString("type");
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (rs != null) try { rs.close();}catch (SQLException ignore) {}
if (ps != null) try{ ps.close();}catch(SQLException ignore) {}
if (con != null) try{con.close();}catch (SQLException ignore) {}
}
return userType;
}
}
5.4.2用户管理功能的实现
以添加用户为例说明用户管理功能的实现,在Jbuilder自动生成的jbInint()方法的末尾加上如下的代码:
userType.addItem("operator");
userType.addItem("manager");
userType.addItem("sa");
然后在设计(design)界面选定“确定”按钮,在Events选项的actionPerformed后的空格中双击,加入如下代码:voidok_actionPerformed(ActionEvent e) {
String id = userID.getText();
//检查用户名是否为空,如为空,提示用户输入用户名
if(id.trim().equals("")){
JOptionPane.showMessageDialog(this,"用户名不能为空!", "警告",
JOptionPane.ERROR_MESSAGE);
return;
}
String name = username.getText();
String userT = (String)userType.getSelectedItem();
String telephone = tel.getText();
String addr = address.getText();
char temp[]=password.getPassword();
String pass=new String(temp);
String PIC = PICNo.getText();
String note = remark.getText();
CheckUser cUser = new CheckUser();
boolean userExist=cUser.userExist(id);
if(userExist)
{
JOptionPane.showMessageDialog(this,"系统中已存在该用户!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
//调用CheckUser类中的方法添加用户
cUser.addOperator(id,name,userT,pass,PIC,telephone,addr,note);
//刷新列表显示
JButtonrefreshButton=DBNavToolBar.getRefreshButton();
refreshButton.doClick();
//提示用户添加成功
JOptionPane.showMessageDialog(this,"该用户已成功添加","提示",JOptionPane.PLAIN_MESSAGE);
}
药品信息设置功能的实现
在药品信息设置界面中,药品类型和生产厂商的输入信息是以下拉框的形式给出的,它不能由用户自由输入,它们的选项列表分别从yType和supplier中读取的。在本系统中它们是在prepareShow()方法中实现的。
private voidprepareShow(){
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:yumen","","");
ps=conn.prepareStatement("select namefrom supplier");
rs=ps.executeQuery();
while(rs.next())
producer.addItem(rs.getString("name"));
ps=conn.prepareStatement("select namefrom foodType");
rs=ps.executeQuery();
while(rs.next())
foodType.addItem(rs.getString("name"));
}
catch(SQLException e){
e.printStackTrace();
}
finally{
if(rs!=null)try{rs.close();}catch(SQLException ignore){}
if(ps!=null)try{ps.close();}catch(SQLExceptionignore){}
if(conn!=null)try{conn.close();}catch(SQLException ignore){}
}
}
在添加之前,先要检测系统中是否已经存在相同名称的药品,通过加入下面的方法来实现。
private booleanfoodExist(String food)
{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
boolean exist=false;
try{
conn=DriverManager.getConnection("jdbc:odbc:yumen","","");
ps=conn.prepareStatement("selectname from food where name='"+food+"'");
rs=ps.executeQuery();
if(rs.next())
exist=true;
}
catch(SQLException e){
e.printStackTrace();
}
finally{
if(rs!=null)try{rs.close();}catch(SQLException ignore){}
if(ps!=null)try{ps.close();}catch(SQLExceptionignore){}
if(conn!=null)try{conn.close();}catch(SQLException ignore){}
}
return exist;
}
创建销售功能模块
销售模块是本系统中比较复杂的功能模块,主要是同时更新销售信息表和库存信息表里的对应信息和一些异常处理。把Jbuilder自动生成的构造函数修改为:
public BookService(Stringtitle,boolean resizable,boolean closable,boolean maximizable,booleaniconifiable,String operator) {
super(title,resizable,closable,maximizable,iconifiable);
this.currentOper=operator;
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
此外,还要在BookServer中声明一个String类型的变量currentOper来保存传入的数据。在系统的构造函数中还应有下面的方法,提供下拉框的选项。
public void prepareShow(){
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:yumen","","");
ps=conn.prepareStatement("select idfrom room");
rs=ps.executeQuery();
while(rs.next())
roomNo.addItem(rs.getString("id"));
}
catch(SQLException ex){
ex.printStackTrace();
}
try{
conn=DriverManager.getConnection("jdbc:odbc:yumen","","");
ps=conn.prepareStatement("selectcommodity from stockInfo");
rs=ps.executeQuery();
while(rs.next())
customer.addItem(rs.getString("commodity"));
}
catch(SQLException ex){
ex.printStackTrace();
}
finally{
if(rs!=null)try{rs.close();}catch(SQLException ignore){}
if(ps!=null)try{ps.close();}catch(SQLException ignore){}
if(conn!=null)try{conn.close();}catch(SQLException ignore){}
}
}
源文件
版权所有© 帮我毕业网 并保留所有权利