蓝宇快递打印系统.docx
《蓝宇快递打印系统.docx》由会员分享,可在线阅读,更多相关《蓝宇快递打印系统.docx(102页珍藏版)》请在冰豆网上搜索。
![蓝宇快递打印系统.docx](https://file1.bdocx.com/fileroot1/2023-1/10/60acdc6c-0754-450f-908c-7c5642d290f9/60acdc6c-0754-450f-908c-7c5642d290f91.gif)
蓝宇快递打印系统
实验十三综合案例
1.实验目的:
通过综合系统的练习,我们可以对我们所学的知识进行系统的复习
2.实验题目:
做一个蓝宇快递系统
3.实验代码
packagecom.zzk.bean;
publicclassExpressMessage{
privateintid=0;
privateStringsendName=null;
privateStringsendTelephone=null;
privateStringsendCompary=null;
privateStringsendAddress=null;
privateStringsendPostcode=null;
privateStringreceiveName=null;
privateStringreceiveTelephone=null;
privateStringreceiveCompary=null;
privateStringreceiveAddress=null;
privateStringreceivePostcode=null;
privateStringControlPosition=null;//快递单上添加信息的组件位置(坐标)
privateStringexpressSize=null;//快递单的尺寸(大小)
publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
}
publicStringgetSendName(){
returnsendName;
}
publicvoidsetSendName(StringsendName){
this.sendName=sendName;
}
publicStringgetSendTelephone(){
returnsendTelephone;
}
publicvoidsetSendTelephone(StringsendTelephone){
this.sendTelephone=sendTelephone;
}
publicStringgetSendCompary(){
returnsendCompary;
}
publicvoidsetSendCompary(StringsendCompary){
this.sendCompary=sendCompary;
}
publicStringgetSendAddress(){
returnsendAddress;
}
publicvoidsetSendAddress(StringsendAddress){
this.sendAddress=sendAddress;
}
publicStringgetSendPostcode(){
returnsendPostcode;
}
publicvoidsetSendPostcode(StringsendPostcode){
this.sendPostcode=sendPostcode;
}
publicStringgetReceiveName(){
returnreceiveName;
}
publicvoidsetReceiveName(StringreceiveName){
this.receiveName=receiveName;
}
publicStringgetReceiveTelephone(){
returnreceiveTelephone;
}
publicvoidsetReceiveTelephone(StringrecieveTelephone){
this.receiveTelephone=recieveTelephone;
}
publicStringgetReceiveCompary(){
returnreceiveCompary;
}
publicvoidsetReceiveCompary(StringrecieveCompary){
this.receiveCompary=recieveCompary;
}
publicStringgetReceiveAddress(){
returnreceiveAddress;
}
publicvoidsetReceiveAddress(StringreceiveAddress){
this.receiveAddress=receiveAddress;
}
publicStringgetReceivePostcode(){
returnreceivePostcode;
}
publicvoidsetReceivePostcode(StringreceivePostcode){
this.receivePostcode=receivePostcode;
}
publicStringgetControlPosition(){
returnControlPosition;
}
publicvoidsetControlPosition(StringcontrolPosition){
ControlPosition=controlPosition;
}
publicStringgetExpressSize(){
returnexpressSize;
}
publicvoidsetExpressSize(StringexpressSize){
this.expressSize=expressSize;
}
}
packagecom.zzk.bean;
publicclassUser{
privateStringname=null;
privateStringpwd=null;
privateStringokPwd=null;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetPwd(){
returnpwd;
}
publicvoidsetPwd(Stringpwd){
this.pwd=pwd;
}
publicvoidsetOkPwd(StringokPwd){
this.okPwd=okPwd;
}
publicStringgetOkPwd(){
returnokPwd;
}
}
packagecom.zzk.dao;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjavax.swing.JOptionPane;
publicclassDAO{
privatestaticDAOdao=newDAO();//声明DAO类的静态实例
/**
*构造方法,加载数据库驱动
*/
publicDAO(){
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");//加载数据库驱动
}catch(ClassNotFoundExceptione){
JOptionPane.showMessageDialog(null,"数据库驱动加载失败,请将JTDS驱动配置到构建路径中。
\n"+e.getMessage());
}
}
/**
*获得数据库连接的方法
*
*@returnConnection
*/
publicstaticConnectiongetConn(){
try{
Connectionconn=null;//定义数据库连接
Stringurl="jdbc:
jtds:
sqlserver:
//localhost:
1433/db_ExpressPrint";//数据库db_Express的URL
Stringusername="sa";//数据库的用户名
Stringpassword="";//数据库密码
conn=DriverManager.getConnection(url,username,password);//建立连接
returnconn;//返回连接
}catch(Exceptione){
JOptionPane.showMessageDialog(null,"数据库连接失败。
\n请检查数据库用户名和密码是否正确。
"+e.getMessage());
returnnull;
}
}
}
packagecom.zzk.dao;
importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.Vector;
importjavax.swing.JOptionPane;
importcom.zzk.bean.ExpressMessage;
publicclassExpressMessageDao{
publicstaticvoidinsertExpress(ExpressMessagem){
if(m.getSendName()==null||m.getSendName().trim().equals("")){
JOptionPane.showMessageDialog(null,"寄件人信息必须填写。
");
return;
}
if(m.getSendTelephone()==null||m.getSendTelephone().trim().equals("")){
JOptionPane.showMessageDialog(null,"寄件人信息必须填写。
");
return;
}
if(m.getSendCompary()==null||m.getSendCompary().trim().equals("")){
JOptionPane.showMessageDialog(null,"寄件人信息必须填写。
");
return;
}
if(m.getSendAddress()==null||m.getSendAddress().trim().equals("||")){
JOptionPane.showMessageDialog(null,"寄件人信息必须填写。
");
return;
}
if(m.getSendPostcode()==null||m.getSendPostcode().trim().equals("")){
JOptionPane.showMessageDialog(null,"寄件人信息必须填写。
");
return;
}
if(m.getReceiveName()==null||m.getReceiveName().trim().equals("")){
JOptionPane.showMessageDialog(null,"收件人信息必须填写。
");
return;
}
if(m.getReceiveTelephone()==null||m.getReceiveTelephone().trim().equals("")){
JOptionPane.showMessageDialog(null,"收件人信息必须填写。
");
return;
}
if(m.getReceiveCompary()==null||m.getReceiveCompary().trim().equals("")){
JOptionPane.showMessageDialog(null,"收件人信息必须填写。
");
return;
}
if(m.getReceiveAddress()==null||m.getReceiveAddress().trim().equals("||")){
JOptionPane.showMessageDialog(null,"收件人信息必须填写。
");
return;
}
if(m.getReceivePostcode()==null||m.getReceivePostcode().trim().equals("")){
JOptionPane.showMessageDialog(null,"收件人信息必须填写。
");
return;
}
Connectionconn=null;//声明数据库连接
//声明PreparedStatement对象
PreparedStatementps=null;
try{
conn=DAO.getConn();//获得数据库连接
//创建PreparedStatement对象,并传递SQL语句
ps=conn
.prepareStatement("insertintotb_receiveSendMessage(sendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,recieveTelephone,recieveCompary,receiveAddress,receivePostcode,ControlPosition,expressSize)values(?
?
?
?
?
?
?
?
?
?
?
?
)");
ps.setString(1,m.getSendName());//为参数赋值
ps.setString(2,m.getSendTelephone());
ps.setString(3,m.getSendCompary());
ps.setString(4,m.getSendAddress());
ps.setString(5,m.getSendPostcode());
ps.setString(6,m.getReceiveName());//为参数赋值
ps.setString(7,m.getReceiveTelephone());
ps.setString(8,m.getReceiveCompary());
ps.setString(9,m.getReceiveAddress());
ps.setString(10,m.getReceivePostcode());
ps.setString(11,m.getControlPosition());//为参数赋值
ps.setString(12,m.getExpressSize());
intflag=ps.executeUpdate();
if(flag>0){
JOptionPane.showMessageDialog(null,"添加成功。
");
}else{
JOptionPane.showMessageDialog(null,"添加失败。
");
}
}catch(Exceptionex){
JOptionPane.showMessageDialog(null,"添加失败!
");
ex.printStackTrace();
}finally{
try{
if(ps!
=null){
ps.close();
}
if(conn!
=null){
conn.close();
}
}catch(SQLExceptione){
e.printStackTrace();
}
}
}
publicstaticvoidupdateExpress(ExpressMessagem){
Connectionconn=null;//声明数据库连接
//声明PreparedStatement对象
PreparedStatementps=null;
try{
conn=DAO.getConn();//获得数据库连接
//创建PreparedStatement对象,并传递SQL语句
ps=conn
.prepareStatement("updatetb_receiveSendMessagesetsendName=?
sendTelephone=?
sendCompary=?
sendAddress=?
sendPostcode=?
receiveName=?
recieveTelephone=?
recieveCompary=?
receiveAddress=?
receivePostcode=?
ControlPosition=?
expressSize=?
whereid=?
");
ps.setString(1,m.getSendName());//为参数赋值
ps.setString(2,m.getSendTelephone());
ps.setString(3,m.getSendCompary());
ps.setString(4,m.getSendAddress());
ps.setString(5,m.getSendPostcode());
ps.setString(6,m.getReceiveName());//为参数赋值
ps.setString(7,m.getReceiveTelephone());
ps.setString(8,m.getReceiveCompary());
ps.setString(9,m.getReceiveAddress());
ps.setString(10,m.getReceivePostcode());
ps.setString(11,m.getControlPosition());//为参数赋值
ps.setString(12,m.getExpressSize());
ps.setInt(13,m.getId());
intflag=ps.executeUpdate();
if(flag>0){
JOptionPane.showMessageDialog(null,"修改成功。
");
}else{
JOptionPane.showMessageDialog(null,"修改失败。
");
}
}catch(Exceptionex){
JOptionPane.showMessageDialog(null,"修改失败!
"+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(ps!
=null){
ps.close();
}
if(conn!
=null){
conn.close();
}
}catch(SQLExceptione){
e.printStackTrace();
}
}
}
publicstaticVectorqueryExpress(){
Connectionconn=null;//声明数据库连接
//声明PreparedStatement对象
PreparedStatementps=null;
try{
conn=DAO.getConn();//获得数据库连接
//创建PreparedStatement对象,并传递SQL语句
ps=conn
.prepareStatement("selectsendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,recieveTelephone,recieveCompary,receiveAddress,receivePostcode,ControlPosition,expressSizefromtb_receiveSendMessage");
ResultSetrs=ps.executeQuery();
Vectorv=newVector();
while(rs.next()){
ExpressMessagem=newExpressMessage();
m.setSendName(rs.getString
(1));
m.setSendTelephone(rs.getString
(2));
m.setSendCompary(rs.getString(3));
m.setSendAddress(rs.getString(4));
m.setSendPostcode(rs.getString(5));
m.setReceiveName(rs.getString(6));
m.setReceiveTelephone(rs.getString(7));
m.setReceiveCompary(rs.getString(8));
m.setReceiveAddress(rs.getString(9));
m.setReceivePostcode(rs.getString(10));
m.setControlPosition(rs.getString(11));
m.setExpressSize(rs.getString(12));
v.add(m);
}
returnv;