package com.steering.mes.signature;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

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

import com.steering.comm.db.DBCommon;
import com.steering.common.EntityTool;
import com.steering.mes.zgmil.entity.ComBaseQualityObjectivesEntity;
import com.steering.mes.zgmil.entity.MatZcMEntity;
/**
 * 质量目标维护
 * @author Administrator
 *
 */
public class FrmQualityObjectives extends DBCommon{

	/**
	 * 查询
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryData(String jugeNo)
	{
		return this.getDataBySqlID("FrmQualityObjectives.doQueryData",new Object[]{});
	}
	/**
	 * 查询
	 * @param departid
	 * @return
	 */
	public CoreReturnObject getComBaseInfo(String departid)
	{
		return this.getDataBySqlID("FrmQualityObjectives.getComBaseInfo",new Object[]{departid});
	}
	
	
	/**
	 * 新增
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doAdd(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs = null;
		String sql1 = "";
		
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmQualityObjectives.doAdd");
			for (String str : parm) {
				ComBaseQualityObjectivesEntity qualityEntity = EntityTool.getEntityByJSONStr(str,
						ComBaseQualityObjectivesEntity.class);
				sql1 = EntityTool.fillSqlByEntity(sql, qualityEntity);
				PreparedStatement updateMilProcess = connection
				.prepareStatement(sql1);
				updateMilProcess.addBatch();
				updateMilProcess.executeBatch();
			}
			cro.setV_errMsg("新增成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/**
	 * 修改
	 * @param parm
	 * @return
	 */
	public CoreReturnObject doUpdate(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs = null;
		String sql1 = "";
		
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sql = CoreXmlSqlParsersFactory
					.getSql("FrmQualityObjectives.doUpdate");
			for (String str : parm) {
				ComBaseQualityObjectivesEntity qualityEntity = EntityTool.getEntityByJSONStr(str,
						ComBaseQualityObjectivesEntity.class);
				sql1 = EntityTool.fillSqlByEntity(sql, qualityEntity);
				PreparedStatement updateMilProcess = connection
				.prepareStatement(sql1);
				updateMilProcess.addBatch();
				updateMilProcess.executeBatch();
			}
			cro.setV_errMsg("修改成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/**
	 * 作废
	 * @param pram
	 * @return
	 */
	public CoreReturnObject doDelete(ArrayList<ArrayList<String>> pram) {
		ArrayList<String> sqllist = new ArrayList<String>();
		ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
		for (int i = 0; i < pram.size(); i++) {
			sqllist.add(CoreXmlSqlParsersFactory
					.getSql("FrmQualityObjectives.doDelete"));
			parmlist.add(pram.get(i).toArray());
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist, parmlist); // 执行事务处理（多个非查询， 自动提交、回滚）
	}
}
