package com.steering.comm;

import java.util.ArrayList;
import java.sql.SQLDataException;
import java.sql.SQLException;

import com.steering.comm.db.DBCommon;
import com.steering.comm.file.FtpStorage;
import com.steering.comm.tools.CodeTool;
import com.steering.comm.tools.StringTool;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreFileBean;
import CoreFS.SC01.CoreConstantData;

public class Test extends DBCommon{
    public static void main(String[] args) throws Exception{
        Test test = new Test();
        //test.test();
        //test.testFTP();
        System.out.println(StringTool.formatDecimal(0.00123, "###.###\u2030"));
    }
    
    public void testFTP(){
        FtpStorage ftp = new FtpStorage();
        CoreReturnObject cro = ftp.download("Image");
//        ArrayList<CoreFileBean> beans = (ArrayList<CoreFileBean>)cro.getResult();
//        for(CoreFileBean bean:beans){
//            bean.setPathName("Image/sale");
//        }
//        ftp.upload(beans);
        //ftp.delete("Image/sale");
    }
    
    public CoreReturnObject test1() throws Exception{
        this.startTransaction("tm");
        //this.getMapper(clazz).insert();
        this.commit();
        return null;
    }
    
    
    //事务处理
    public CoreReturnObject test() throws Exception{
        java.sql.Connection conn1 = this.getDao("GDHDao").getConnection();
        java.sql.Statement sta1= conn1.createStatement();
        java.sql.ResultSet rs1 = sta1.executeQuery("SELECT * FROM JTQZB_pdflow where testdate>'2015-03-01 00:00:00'");
        while(rs1.next()){
            System.out.println(rs1.getString(1));
        }
        rs1.close();
        sta1.close();
        conn1.close();
        
        // java.util.Map result =
        // this.getDao(CoreConstantData.sysbeanstr).CoreBeginTranscation();
        // try{
        // this.getDao(CoreConstantData.sysbeanstr).ExcuteQueryById(sqlid);
        // this.getDao(CoreConstantData.sysbeanstr).ExcuteNonQuery(sql, args);
        //
        // this.getDao(CoreConstantData.sysbeanstr).CoreCommit(result);
        // }
        // catch(Exception ex){
        // this.getDao(CoreConstantData.sysbeanstr).CoreRollBack(result);
        // }
        java.sql.Connection conn = null;
        try {
            conn = this.getDao("TgDao").getConnection();
            conn.setAutoCommit(false);
            String sql = "select name,age from test where name = ?,age = ?";// CoreXmlSqlParsersFactory.getSql("sqlid");
            java.sql.PreparedStatement psta = conn.prepareStatement(sql);
            psta.setString(1, "aaa");
            psta.setInt(2, 20);
            java.sql.ResultSet rs = psta.executeQuery();
            String flag = "";
            while (rs.next()) {
                flag = rs.getString(1);
                rs.getInt(2);
            }
            rs.close();
            psta.close();
            //是否
            if (check(conn)) {
                sql = "update";
                psta = conn.prepareStatement(sql);
                psta.setString(1, "aaa");
                psta.setInt(2, 20);
                int count = psta.executeUpdate();
                psta.close();

                java.sql.Statement sta = conn.createStatement();
                sta.executeQuery(sql);
                sta.close();
            }

            conn.commit();
        }
        catch (SQLException sqlex) {
            System.out.println(sqlex.getMessage());
            try {
                if (conn != null) {
                    conn.rollback();
                }
            }
            catch (Exception ex1) {

            }
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
        }
        finally {
            if (conn != null && !conn.isClosed()) {
                try {
                    conn.close();
                }
                catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        return new CoreReturnObject();
    }
    
    //取样
    public boolean check(java.sql.Connection conn){
        this.logAdapter.filelogger.logWarn("");
        //sql statement
        return true;
    }
}
