package com.skic.service;

import java.sql.*;

import com.skic.DAO.UserDAO;
import com.skic.DAO.impl.UserDAOimpl;
import com.skic.DTO.UserDTO;
import com.skic.util.ConnectionFactory;

public class CheckRegisterService {
	private UserDAO userdao = new UserDAOimpl();

	public boolean AddUser(UserDTO USERDTO) {
		Connection conn = null;

		try {
			conn = ConnectionFactory.getInstance().makeConnection();
			conn.setAutoCommit(false);
			System.out.println(USERDTO.getUserName());
			System.out.println(USERDTO.getPassword());
			int status = userdao.insert(conn, USERDTO);
			conn.commit();
			if (status!=0) {
				return true;
			}
			/*ResultSet resultSet1 = userdao.select(conn, USERDTO);
			int id_log = userdao.insertLogName(conn, USERDTO);
			System.out.println("id_log="+id_log);
			if (resultSet1.next()) {
				userdao.updateLogStatus(conn, USERDTO, "成功",id_log);
				return true;
			}else {
				userdao.updateLogStatus(conn, USERDTO, "失败",id_log);
			}*/
		} catch (SQLException e) {
			System.out.println("插入数据失败");
			e.printStackTrace();
			try {
				System.out.println("更新数据失败，数据库回滚");
				conn.rollback();
			} catch (SQLException e1) {
				System.out.println("数据库回滚失败");
				e1.printStackTrace();
			}
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					System.out.println("数据库关闭失败");
					e.printStackTrace();
				}
			}
		}

		return false;
	}
}
