<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.db.Logger" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="com.censoft.db.DBUtil" %>
<%@ page import="java.sql.DatabaseMetaData" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="java.util.regex.Matcher" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list;
    String action = pub.trimNull(request.getParameter("action"));
    String col_name = pub.trimNull(request.getParameter("col_name"));
    String col_order = pub.trimNull(request.getParameter("col_order"));
    String beizhu = pub.trimNull(request.getParameter("beizhu"));
    String update_id = pub.trimNull(request.getParameter("update_id"));
    String zd_id = pub.trimNull(request.getParameter("zd_id"));
    String delete_id = pub.trimNull(request.getParameter("delete_id"));
    String id = DBUtil.getUUID();
    String add_user = (String) session.getAttribute("session_login_id");
    String add_time = pub.getCurrentServerTime();
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        conn.setAutoCommit(false);
        if ("add".equals(action)) {
            boolean is_up = cf.executeUpdate(conn, "insert into zc_zd_col (id,zd_id,col_name,col_order,beizhu,add_user,add_time) values (?,?,?,?,?,?,?)"
                    , new Object[]{id,zd_id,col_name,col_order,beizhu,add_user,add_time});
            if (!is_up) {
                out.println("新增字典元素报错" + cf.getMsg());
                conn.rollback();
                return;
            }
            Logger.log(conn,"字典元素管理", "添加", id, "", request);
            out.println("success");
            conn.commit();
            conn.setAutoCommit(true);
            return;
        }if ("update".equals(action)) {
            boolean is_up = cf.executeUpdate(conn, "update zc_zd_col set col_name=?,col_order=?,beizhu=?,add_time=?,add_user=? where id=? "
                    , new Object[]{col_name,col_order,beizhu,add_time,add_user,update_id});
            if (!is_up) {
                out.println("修改字典元素报错" + cf.getMsg());
                conn.rollback();
                return;
            }
            Logger.log(conn,"字典元素管理", "修改", id, "", request);
            out.println("success");
            conn.commit();
            conn.setAutoCommit(true);
            return;
        }else if("delete".equals(action)){
            boolean is_up = cf.executeUpdate(conn, "delete from zc_zd_col where id=?"
                    , new Object[]{delete_id});
            if (!is_up) {
                out.println("字典元素删除报错" + cf.getMsg());
                conn.rollback();
                return;
            }

            Logger.log(conn,"字典元素管理", "删除", delete_id, "", request);
            out.println("success");
            conn.commit();
            conn.setAutoCommit(true);
            return;
        }
    } catch (Exception e) {
        try {
            if(conn != null){
                conn.rollback();
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
