📄 goodsintopane.java
字号:
package file2;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.io.*;
public class GoodsInToPane extends JPanel{
//声明数据库连接组件
private DBConnection con=null;
private File file=null;//声明所选择的文件
private String fileName;//声明所选择文件的文件名
private JFileChooser fileChooser;//声明目的文件
public GoodsInToPane(JFrame frame){
fileChooser=new JFileChooser();
int returnValue=fileChooser.showOpenDialog(frame);
if(returnValue==JFileChooser.APPROVE_OPTION){
con=new DBConnection();
file=fileChooser.getSelectedFile();
if(file==null){
JOptionPane.showMessageDialog(null, "导入文件不能为空,请您选择导入文件!", "提示", JOptionPane.ERROR_MESSAGE);
return;
}
fileName=file.getName();
JOptionPane.showMessageDialog(null, "正往文件"+fileName+"导出数据", "提示", JOptionPane.INFORMATION_MESSAGE);
int returnPara=saveTo(file);
if(returnPara==0){
JOptionPane.showMessageDialog(null, "往文件导出数据成功", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null, "往文件导出数据失败", "提示", JOptionPane.ERROR_MESSAGE);
}
return;
}
}
public int saveTo(File file){
try{
BufferedWriter bw=new BufferedWriter(new FileWriter(file));
String strQuery="select To_Third_name,quantity,operateTime from operationRecord where operationState=0";
ResultSet rs=con.executeSelect(strQuery);
bw.write("------------以下是所有的进货记录-------------");
bw.newLine();
bw.newLine();
bw.write("具体商品名称-----进货数量-----进货时间");
bw.newLine();
bw.newLine();
while(rs.next()){
bw.write(rs.getString("To_Third_name").trim());
bw.write("-----");
String quantity=(new Integer(rs.getInt("quantity"))).toString();
bw.write(quantity.trim());
bw.write("-----");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String mydate=sdf.format(rs.getDate("operateTime"));
bw.write(mydate.trim());
bw.newLine();
bw.newLine();
}
bw.close();
return 0;
}catch(IOException e){
//e.printStackTrace();
JOptionPane.showMessageDialog(null, "导出文件失败!", "提示", JOptionPane.ERROR_MESSAGE);
return 1;
}catch(SQLException e){
//e.printStackTrace();
JOptionPane.showMessageDialog(null, "导出文件失败!", "提示", JOptionPane.ERROR_MESSAGE);
return 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -