Exemple #1
0
 @Override
 public void run() {
   try {
     Scanner csvScan = new Scanner(csvFile);
     int count = 0;
     while (csvScan.hasNext()) {
       csvScan.nextLine();
       count++;
     }
     csvScan.close();
     csvScan = new Scanner(csvFile);
     for (int i = 0; i < count; i++) {
       progressBar.setValue(i * 100 / count);
       String data = csvScan.nextLine(), id = data.substring(1, data.indexOf('\'', 1));
       if (frame.database.exist(id)) {
         if (mode == 0) {
           String[] option = {"覆盖", "合并", "忽略"};
           mode =
               JOptionPane.showOptionDialog(
                       Port.this,
                       "请选择重复项处理方式",
                       "遇到重复项",
                       JOptionPane.YES_NO_CANCEL_OPTION,
                       JOptionPane.QUESTION_MESSAGE,
                       null,
                       option,
                       option[0])
                   + 1;
         }
         switch (mode) {
           case 1:
             frame.database.deletePic(frame.webServer, id);
             frame.database.delete(id);
             break;
           case 2:
             frame.database.merge(id, data);
             File picFile = new File(picDirectory.getPath() + "/" + id + ".jpg");
             if (picFile.exists()) {
               frame.database.deletePic(frame.webServer, id);
               frame.database.update(id, "pic", "'" + frame.webServer.setPic(picFile) + "'");
             }
           case 3:
             continue;
         }
       }
       frame.database.insert(data);
       File picFile = new File(picDirectory.getPath() + "/" + id + ".jpg");
       if (picFile.exists())
         frame.database.update(id, "pic", "'" + frame.webServer.setPic(picFile) + "'");
     }
     csvScan.close();
     frame.refresh();
     progressBar.setValue(100);
     finish();
   } catch (Exception e) {
     e.printStackTrace();
     JOptionPane.showMessageDialog(Port.this, "导入失败!", "错误", JOptionPane.ERROR_MESSAGE);
     try {
       if (frame.database.exist("temp")) frame.database.delete("temp");
     } catch (Exception e1) {
     }
     frame.refresh();
     dispose();
   }
 }
Exemple #2
0
 @Override
 public void run() {
   try {
     if (!picDirectory.exists()) picDirectory.mkdirs();
     File csvPath = csvFile.getParentFile();
     if ((csvPath != null) && !csvPath.exists()) csvPath.mkdirs();
     PrintWriter csvWrite = new PrintWriter(csvFile);
     for (int i = 0; i < id.length; i++) {
       progressBar.setValue(i * 100 / id.length);
       csvWrite.print("'" + id[i] + "'");
       Detail info = new Detail(frame.database, id[i]);
       for (int x = 0; x < 7; x++)
         for (int y = 0; y < 7; y++) {
           String data = info.get(List.COLUMN_NAME[x][y]);
           switch (List.COLUMN_TYPE[x][y]) {
             case 1:
               data = "'" + data + "'";
               break;
             case 2:
               if (data == null) data = "null";
               break;
             case 3:
               if (data == null) data = "0000-00-00";
               data = "'" + data + "'";
               break;
             case 4:
               data = "'" + data + "'";
           }
           csvWrite.print("," + data);
         }
       csvWrite.println();
       String picAddress = info.get("pic");
       info.close();
       if (picAddress.length() == 32) {
         ReadableByteChannel url =
             Channels.newChannel(
                 new URL(
                         "http://"
                             + Configure.webserverAddress
                             + "/"
                             + Configure.picDirectory
                             + picAddress.substring(0, picAddress.length() - 5)
                             + "/"
                             + picAddress.substring(picAddress.length() - 5)
                             + ".jpg")
                     .openStream());
         FileOutputStream outStream =
             new FileOutputStream(picDirectory.getPath() + "/" + id[i] + ".jpg");
         FileChannel out = outStream.getChannel();
         ByteBuffer buffer = ByteBuffer.allocate(10000);
         while (url.read(buffer) != -1) {
           buffer.flip();
           out.write(buffer);
           buffer.clear();
         }
         out.close();
         outStream.close();
         url.close();
       }
     }
     csvWrite.close();
     progressBar.setValue(100);
     finish();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(Port.this, "导出失败!", "错误", JOptionPane.ERROR_MESSAGE);
     dispose();
   }
 }
Exemple #3
0
 void finish() {
   JOptionPane.showMessageDialog(this, NAME[mode] + "完成!", "成功", JOptionPane.INFORMATION_MESSAGE);
   dispose();
 }