package supermarket;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.sun.java_cup.internal.internal_error;
import supermarket.BuyManage.MyAction;
public class Backthings extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField jtdBackthing=new JTextField(15);
private JTextField jtdBacknumber=new JTextField(15);
public Backthings(String title){
super(title);
init();
}
void init(){
JButton jbtSearch=new JButton("查询当前货存");
JLabel jlbBackthing=new JLabel("请输入要退的商品:");
JLabel jlbBacknumber=new JLabel("请输入要退的商品的数量");
JButton jbtSure=new JButton("确定退货");
JButton jbtCancel=new JButton("取消");
//添加事件监听
MyAction myaction=new MyAction(this);
jbtSure.addActionListener(myaction);
jbtCancel.addActionListener(myaction);
jbtSearch.addActionListener(myaction);
JPanel jp1=new JPanel();
jp1.add(jbtSearch);
this.add(jp1,BorderLayout.NORTH);
JPanel jp2=new JPanel();
jp2.add(jlbBackthing);
jp2.add(jtdBackthing);
JPanel jp3=new JPanel();
jp3.add(jlbBacknumber);
jp3.add(jtdBacknumber);
JPanel jp4=new JPanel();
jp4.add(jbtSure);
jp4.add(jbtCancel);
setLayout(new GridLayout(4,1));
add(jp1);
add(jp2);
add(jp3);
add(jp4);
this.setLocation(400, 250);
pack();
}
class MyAction implements ActionListener{
private Backthings bk;
public MyAction(Backthings bk){
this.bk=bk;
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String click=e.getActionCommand();
if(click.equals("确定退货")){
int flag=0;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con=DriverManager.getConnection(
"jdbc:sqlserver://localhost;databasename=supermarket", "sa", "sasa");
String sql="update marketInfo set userNumber=userNumber-? where userName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1,Integer.parseInt(jtdBacknumber.getText()));
ps.setString(2, jtdBackthing.getText());
int i=ps.executeUpdate();
if(i>0){
flag=1;
}
ps.close();
con.close();
}catch(Exception er){
flag=2;
er.printStackTrace();
System.out.println("数据库有问题");
}
if(flag==1){
JOptionPane.showMessageDialog(null, "退货成功");
bk.dispose();
}
if(flag==2){
JOptionPane.showMessageDialog(null,"数据库发生错误,请联系管理员解决!");
}
// String userName=jtdBackthing.getText();
// String userNumber=jtdBacknumber.getText();
// // int userNumber=Integer.parseInt(number);
//
// //封装成用户对象
// User user=new User();
//
// user.setuserName(userName);
// user.setuserNumber(userNumber);
//
// //退货对象
//
// BackOpter bop=new BackOpter();
// int rst=bop.backthings(user);
// if(rst==1){
// JOptionPane.showMessageDialog(null, "退货成功");
// bk.dispose();
// }
// if(rst==2)
// {
// JOptionPane.showMessageDialog(null,"数据库发生错误,请联系管理员解决!");
// }
}
if(click.equals("取消")){
bk.setVisible(false);
}
if(click.equals("查询当前货存")){
//打开展示库存窗体
Search st=new Search("库存展示");
st.setVisible(true);
}
}
}
}
java 超市简单进销存系统
需积分: 10 188 浏览量
2011-04-08
23:06:20
上传
评论 1
收藏 193KB ZIP 举报
upair
- 粉丝: 0
- 资源: 2
最新资源
- IMG_20240423_191216.jpg
- 基于MATLAB实现分析黑体辐射光谱图时将通过迈克尔逊干涉仪得到干涉图经过傅里叶变换转换为光谱图的功能源码.zip
- DynamicArray02.java
- 数据可视化 matplotlib 实例.docx
- 数据可视化 matplotlib 实例.7z
- Python 使用 Matplotlib 绘制甘特图的实践.7z
- Python 使用 Matplotlib 绘制甘特图的实践.docx
- matplotlib 中的 cmap 参数介绍.docx
- matplotlib 中的 cmap 参数介绍.7z
- 基于matlab的毕业设计基于Matlab使用LQR实现车辆轨迹跟踪源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈