|
@@ -0,0 +1,167 @@
|
|
|
+package com.gyee;
|
|
|
+
|
|
|
+
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.geom.AffineTransform;
|
|
|
+import java.awt.image.AffineTransformOp;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.*;
|
|
|
+import java.sql.*;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+ * 图形开票 人员电子签名 数据库人员处理
|
|
|
+ */
|
|
|
+public class SqlSeverTicket {
|
|
|
+
|
|
|
+ public static void main(String []args) throws SQLException {
|
|
|
+
|
|
|
+ String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
|
|
+
|
|
|
+ String dbURL = "jdbc:sqlserver://10.155.32.2:1433;DatabaseName=fdeam";
|
|
|
+
|
|
|
+ String userName = "sa";
|
|
|
+ String userPwd = "gyee54321";
|
|
|
+ Connection conn = null;
|
|
|
+ try {
|
|
|
+ Class.forName(driverName);
|
|
|
+ conn = DriverManager.getConnection(dbURL, userName, userPwd);
|
|
|
+ System.out.println("Connection Successful!");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Map<String, List> getLabor(Connection conn){
|
|
|
+ Map<String, List> labors = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ PreparedStatement ps = conn.prepareStatement("select * from LABOR");
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
+ while(rs.next()){
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ String laborNum = rs.getString("LABORNUM");
|
|
|
+ String laborName = rs.getString("LABORNAME");
|
|
|
+ String deptNum = rs.getString("DEPTNUM");
|
|
|
+ list.add(0, laborName);
|
|
|
+ list.add(1, deptNum);
|
|
|
+ labors.put(laborNum, list);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return labors;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<String> getLabors(Connection conn){
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ PreparedStatement ps = conn.prepareStatement("select * from SIGNPICTURE");
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
+ while(rs.next()){
|
|
|
+ String laborNum = rs.getString("LABORNUM");
|
|
|
+ list.add(laborNum);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void setLabor(Connection conn, Map map) throws SQLException {
|
|
|
+ PreparedStatement ps = null;
|
|
|
+ try {
|
|
|
+ ps = conn.prepareStatement("Insert into SIGNPICTURE (LABORNUM,LABORNAME,DEPTNUM) values (?,?,?)");
|
|
|
+ Iterator<Map.Entry<String, List>> entries = map.entrySet().iterator();
|
|
|
+ while(entries.hasNext()){
|
|
|
+ Map.Entry<String, List> entry = entries.next();
|
|
|
+ String key = entry.getKey();
|
|
|
+ List list = entry.getValue();
|
|
|
+ ps.setString(1,key);
|
|
|
+ ps.setString(2, String.valueOf(list.get(0)));
|
|
|
+ ps.setString(3, String.valueOf(list.get(1)));
|
|
|
+
|
|
|
+ ps.executeUpdate();
|
|
|
+ }
|
|
|
+ ps.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ ps.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 写入图片
|
|
|
+ * @param conn
|
|
|
+ * @param filePath
|
|
|
+ */
|
|
|
+ public static void setImage(Connection conn, String filePath, String laborNum)
|
|
|
+ {
|
|
|
+ FileInputStream fis=null;
|
|
|
+ File file = new File(filePath);
|
|
|
+ try{
|
|
|
+ fis = new FileInputStream(file);
|
|
|
+ }catch(FileNotFoundException e){
|
|
|
+ System.out.println("Not find file!");
|
|
|
+ }
|
|
|
+ try{
|
|
|
+
|
|
|
+ PreparedStatement ps = conn.prepareStatement("update SIGNPICTURE set IMAGE = ? where LABORNUM = '"+laborNum+"'");
|
|
|
+ ps.setBinaryStream(1,fis,(int)file.length());
|
|
|
+ ps.executeUpdate();
|
|
|
+ ps.close();
|
|
|
+ fis.close();
|
|
|
+ System.out.println("写进去了!");
|
|
|
+ }catch(Exception e){
|
|
|
+ System.out.println("fis cann't cloase!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static void batchThumb(String filePath1, String filePath2) throws IOException {
|
|
|
+ File file = new File(filePath1);
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ if(files != null){
|
|
|
+ for(int i = 0; i < files.length; i++){
|
|
|
+ String fileName = files[i].getName();
|
|
|
+
|
|
|
+ Thumbnails.of(filePath1 + fileName)
|
|
|
+ .size(100, 40)
|
|
|
+ .toFile(filePath2 + fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void singleThumb(String filePath1, String filePath2, String fileName) throws IOException {
|
|
|
+ Thumbnails.of(filePath1 + fileName)
|
|
|
+ .size(100, 40)
|
|
|
+ .toFile(filePath2 + fileName);
|
|
|
+ }
|
|
|
+}
|