package com.vci.client.framework.systemConfig.log; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import com.vci.client.LogonApplication; import com.vci.client.common.VCIBasePanel; import com.vci.client.framework.delegate.LogManagementClientDelegate; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.framework.util.ClientHelper; import com.vci.client.oq.QTClient; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.image.bundle.BundleImage; import com.vci.client.ui.swing.KJButton; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.components.VCIJCalendarPanel; import com.vci.client.ui.swing.components.VCIJLabel; import com.vci.corba.common.VCIError; public class LogBasicConfPanel extends VCIBasePanel { private static final long serialVersionUID = 1L; private JLabel deleteLbl = new JLabel(getI18nString("logDelete")); private JRadioButton autoRadio = new JRadioButton(getI18nString("autoDelete")); private JRadioButton manualRadio = new JRadioButton(getI18nString("manualDelete")); private ButtonGroup btnGroup = new ButtonGroup(); //日志保存 private JLabel periodLabel = new JLabel(getI18nString("savePeriod")); private JComboBox periodComboBox = new JComboBox();//保存期限下拉框 private Map periodMap = new HashMap(); private Map periodValueMap = new HashMap(); private final String LOG_SAVE_PERIOD = "logSavePeriod";//日志保存期限 private KJButton savePeriodButton = new KJButton(getI18nString("saveBtn"),"save.png"); //日志删除 private JLabel deleteLabel = new JLabel(getI18nString("selectDate")); private VCIJCalendarPanel calDelDate = new VCIJCalendarPanel(true, true, true, false); private KJButton deleteLogButton = new KJButton(getI18nString("delete"),"delete.gif"); private LogManagementClientDelegate logDel = new LogManagementClientDelegate(LogonApplication.getUserEntityObject());; public LogBasicConfPanel(FunctionObject funcObj){ super(funcObj); init(); initAction(); } private void initAction() { /**自动删除**/ autoRadio.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { autoDeleteActionPerformed(); } }); /***手动删除**/ manualRadio.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { manualDeleteActionPerformed(); } }); /***保存日志**/ savePeriodButton.addActionListener(new ActionListener(){//保存日志保存期限 public void actionPerformed(ActionEvent e){ savePeriod_actionPerfermed(e); } }); /***删除日志**/ deleteLogButton.addActionListener(new ActionListener() {//删除日志 public void actionPerformed(ActionEvent e) { deleteLog_actionPerfermed(e); } }); } /** * 初始化界面 */ JPanel contentPanel = new JPanel(new BorderLayout()); JPanel logPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); private void init() { initSavePeroidCombox(); JLabel titleLabel = new JLabel(); titleLabel.setText(getI18nString("logBasicConf")); titleLabel.setIcon(new BundleImage().createImageIcon ("door.png")); JPanel bottomPanel = new JPanel(); contentPanel = initCenterContentPanel(); VCIJLabel lblNote = new VCIJLabel("" + "" + "

日志基础配置说明:

" + "

  " + "1:日志删除包含手动删除和自动删除

" + "

  " + "2:自动删除会根据日志的保存期限来进行日志删除

" + "

  " + "3:手动删除根据选定的时间来进行日志删除

" + "

" + "
" + ""); contentPanel.add(lblNote,BorderLayout.SOUTH); JPanel midPanel = new JPanel(); midPanel.setLayout(new BorderLayout()); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); jTextField1.setPreferredSize(new Dimension(63,2)); jTextField2.setPreferredSize(new Dimension(63,2)); midPanel.add(jTextField1, BorderLayout.NORTH); midPanel.add(jTextField2, BorderLayout.SOUTH); midPanel.add(contentPanel, BorderLayout.CENTER); this.setLayout(new BorderLayout()); this.add(titleLabel, BorderLayout.NORTH); this.add(midPanel, BorderLayout.CENTER); this.add(bottomPanel, BorderLayout.SOUTH); } /** * 初始化日期保存期限下拉列表框 *

Description:

* * @author Administrator * @time 2012-12-29 */ private void initSavePeroidCombox() { try { LogPeriodObject[] periods = logDel.getPeriods(); for(int i = 0;i2){ buff.append(s+""); }else{ buff.append("0"+s); } return buff.toString(); } private boolean checkCanDelete(String deleteDate, int monthSpan, String monthLabel){ boolean res = false; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.parse(deleteDate); } catch (ParseException e1) { VCIOptionPane.showError(LogonApplication.frame, "将" + deleteDate + "转换日期时发生错误!"); return false; } String sql = "SELECT FLOOR(MONTHS_BETWEEN(SYSDATE, to_date('" + deleteDate + "','yyyy-mm-dd'))) from dual"; String[][] vals; try { vals = QTClient.getService().queryBySqlWithoutKey(sql); if(vals != null && vals.length > 0 && vals[0].length > 0){ int spval = Integer.valueOf(vals[0][0]); if(spval <= monthSpan){ VCIOptionPane.showError(LogonApplication.frame, "只能删除 " + monthLabel + " 之前的数据!"); return false; } } } catch (VCIError e) { e.printStackTrace(); VCIOptionPane.showError(LogonApplication.frame, "计算是否可以删除指定日期之前的数据时发生错误!"); return false; } res = true; return res; } /** * 保存日志保存期限 * @param e */ private void savePeriod_actionPerfermed(ActionEvent e){ SystemCfgObject systemCfgObject = new SystemCfgObject(); boolean flag = false; try { String selectedPeriod = (String) this.periodComboBox.getSelectedItem(); if(selectedPeriod == null){ VCIOptionPane.showMessage(LogonApplication.frame, getI18nString("savePeriodAlert")); return; } systemCfgObject.setName(LOG_SAVE_PERIOD); systemCfgObject.setValue(this.periodValueMap.get(selectedPeriod));//通过名称取code值存入到数据库 flag = this.logDel.savePeriod(systemCfgObject); } catch (VCIException e1) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1); } if(flag){ VCIOptionPane.showMessage(LogonApplication.frame,getI18nString("saveSuccess")); } } private String getI18nString(String spCode){ return ClientHelper.getI18nStringForFramework("com.vci.rmip.framework.client.systemConfig.log.LogBasicConfPanel" + "." + spCode, this.getLocale()); } }