import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class OutOrInterWare extends JFrame {
public OutOrInterWare() {
this.setTitle("商品出入库界面");//设置窗口标题
this.setBounds(100, 100, 500, 700);//设置窗口大小
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);//设置关闭子窗口但是不关闭父类窗口
this.setLayout(null);//设置布局方式为null,自己控制组件位置
//创建标签和按钮
JLabel jLabel = new JLabel("商品出入库界面");
JLabel jLabel1 = new JLabel("记录编号:");
JLabel jLabel2 = new JLabel("商品编号:");
JLabel jLabel3 = new JLabel("操作类型:");
JLabel jLabel4 = new JLabel("操作数量:");
JLabel jLabel5 = new JLabel("操作时间:");
JButton jb1 = new JButton("操作");
//创建文本框和面板
JTextField field1 = new JTextField(18);
JTextField field2 = new JTextField(18);
JTextField field3 = new JTextField(18);
JTextField field4 = new JTextField(18);
JTextField field5 = new JTextField(18);
//创建面板
JPanel jPanel = new JPanel();
JPanel jPanel0 = new JPanel();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
JPanel jPanel5 = new JPanel();
//将标签和文本框添加到面板中
jPanel.add(jLabel);
jPanel1.add(jLabel1);
jPanel1.add(field1);
jPanel2.add(jLabel2);
jPanel2.add(field2);
jPanel3.add(jLabel3);
jPanel3.add(field3);
jPanel4.add(jLabel4);
jPanel4.add(field4);
jPanel5.add(jLabel5);
jPanel5.add(field5);
jPanel0.add(jb1);
//设置面板位置和大小
jPanel.setBounds(0, 40, 450, 50);
jPanel1.setBounds(0, 110, 450, 50);
jPanel2.setBounds(0, 180, 450, 50);
jPanel3.setBounds(0, 250, 450, 50);
jPanel4.setBounds(0, 320, 450, 50);
jPanel5.setBounds(0, 390, 450, 50);
jPanel0.setBounds(0, 460, 450, 50);
//设置字体大小
jLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jLabel1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jLabel3.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jLabel4.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jLabel5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
jb1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
//将面板添加到窗口中
this.add(jPanel);
this.add(jPanel1);
this.add(jPanel2);
this.add(jPanel3);
this.add(jPanel4);
this.add(jPanel5);
this.add(jPanel0);
//设置界面可见
this.setVisible(true);
UIManager.put("OptionPane.messageFont", new Font("微软雅黑", Font.PLAIN, 15));
jb1.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e) {
//注册驱动 使用驱动连接数据库
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = JDBCUtils.getConnection();
//判断药品是否存在
String sql = "select * from product where id = ?";
stmt = con.prepareStatement(sql);
stmt.setString(1, field2.getText());
// 执行查询
rs = stmt.executeQuery();
if (!rs.next()) {
//ResultSet 为空
JOptionPane.showMessageDialog(null, "对应商品不存在!");
return;
}else{
if (field3.getText().equals("入库")){
int num = rs.getInt("num");
String sql2 = "update product set num=? where id=?";
stmt = con.prepareStatement(sql2);
stmt.setInt(1, num+ Integer.parseInt(field4.getText()));
stmt.setString(2, field2.getText());
stmt.execute();
String sql3 = "insert into record values(?,?,?,?,?)";
stmt = con.prepareStatement(sql3);
stmt.setString(1, field1.getText());
stmt.setString(2, field2.getText());
stmt.setString(3, field3.getText());
stmt.setString(4, field4.getText());
stmt.setString(5, field5.getText());
stmt.execute();
JOptionPane.showMessageDialog(null, "操作成功!");
}else if (field3.getText().equals("出库")){
int num = rs.getInt("num");
if (num<Integer.parseInt(field4.getText())){
JOptionPane.showMessageDialog(null, "库存不足!");
return;
}
String sql2 = "update product set num=? where id=?";
stmt = con.prepareStatement(sql2);
stmt.setInt(1, num- Integer.parseInt(field4.getText()));
stmt.setString(2, field2.getText());
stmt.execute();
String sql3 = "insert into record values(?,?,?,?,?)";
stmt = con.prepareStatement(sql3);
stmt.setString(1, field1.getText());
stmt.setString(2, field2.getText());
stmt.setString(3, field3.getText());
stmt.setString(4, field4.getText());
stmt.setString(5, field5.getText());
stmt.execute();
JOptionPane.showMessageDialog(null, "操作成功!");
}else{
JOptionPane.showMessageDialog(null, "操作类型请填写入库或者出库!");
return;
}
}
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}finally {
try {
JDBCUtils.close(rs, stmt, con);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
});
}
}
茶叶蛋xq
- 粉丝: 1w+
- 资源: 188
最新资源
- java毕设项目之ssm安徽新华学院实验中心管理系统的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm毕业lw管理系统+vue(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm毕业生就业信息统计系统+vue(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm大学生兼职平台的设计与开发+jsp(完整前后端+说明文档+mysql).zip
- java毕设项目之ssm博客系统的设计与实现+vue(完整前后端+说明文档+mysql).zip
- java毕设项目之ssm单位人事管理系统+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm电子竞技管理平台的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm房屋租售网站的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm高校专业信息管理系统设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm会员管理系统+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm基于 Java Web 的校园驿站管理系统+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm基于JavaEE的龙腾公司员工信息管理系统的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm基于Java的菜匣子优选系统设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- 大题解题方法等4个文件.zip
- java毕设项目之ssm基于JavaWeb的家居商城系统的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
- java毕设项目之ssm基于Java的汽车客运站管理系统的设计与实现+jsp(完整前后端+说明文档+mysql+lw).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈