package com.vci.client.framework.systemConfig.secretGrade; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.TitledBorder; import com.vci.client.LogonApplication; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.common.VCIBasePanel; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.framework.appConfig.object.AppConfigCategoryObject; import com.vci.client.framework.appConfig.object.AppConfigDetailObject; import com.vci.client.framework.delegate.AppConfigCategoryClientDelegate; import com.vci.client.framework.delegate.AppConfigDetailClientDelegate; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow; import com.vci.client.ui.exception.VCIException; import com.vci.corba.common.VCIError; import com.vci.corba.omd.etm.EnumChild; import com.vci.corba.omd.etm.EnumItem; public class OpenOrCloseConfigForUserAndPcPanel extends VCIBasePanel implements IModuleShow { /** * */ private static final long serialVersionUID = 1L; private String logonUserId = "",logonRoleId; private String moduleName = ""; private String iconName,moduleShowInfo; JCheckBox userSecuritySwith = new JCheckBox(); JCheckBox ipSecuritySwitch = new JCheckBox(); public OpenOrCloseConfigForUserAndPcPanel(FunctionObject funcObj) { super(funcObj); // TODO Auto-generated constructor stub init(); } private void init() { this.setLayout(new BorderLayout()); this.setBorder(new TitledBorder("用户\\机器密级停启用配置")); JPanel mainPanel = new JPanel(); JPanel contentPanel = initContentPanel(); JPanel buttonPanel = initButtonPanel(); mainPanel.setLayout(new BorderLayout()); mainPanel.add(contentPanel, BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); this.add(mainPanel, BorderLayout.CENTER); } private JPanel initContentPanel() { JPanel contentPanel = new JPanel(); AppConfigDetailClientDelegate delegate = new AppConfigDetailClientDelegate(LogonApplication.getUserEntityObject()); try { AppConfigDetailObject userConfigDetail = delegate.getAppConfigDetailByKey("userSecuritySwith"); AppConfigDetailObject ipConfigDetail = delegate.getAppConfigDetailByKey("ipSecuritySwitch"); if ("on".equals(userConfigDetail.getValue())) { userSecuritySwith.setSelected(true); } if ("on".equals(ipConfigDetail.getValue())) { ipSecuritySwitch.setSelected(true); } } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); } userSecuritySwith.setLabel("用户密级"); ipSecuritySwitch.setLabel("机器密级"); contentPanel.add(userSecuritySwith); contentPanel.add(ipSecuritySwitch); return contentPanel; } private JPanel initButtonPanel() { JPanel buttonPanel = new JPanel(); JButton saveBtn = new JButton("保存"); buttonPanel.add(saveBtn); saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveSecretGrade(); } }); return buttonPanel; } private void saveSecretGrade() { boolean userSwich = userSecuritySwith.isSelected(); boolean ipSwich = ipSecuritySwitch.isSelected(); AppConfigDetailClientDelegate delegate = new AppConfigDetailClientDelegate(LogonApplication.getUserEntityObject()); AppConfigCategoryClientDelegate category = new AppConfigCategoryClientDelegate(LogonApplication.getUserEntityObject()); try { AppConfigCategoryObject[] categories = category.getAppConfigCategorys(); String secretGradeCategoryId = ""; for (int i = 0; i < categories.length; i++) { if ("系统密级配置".equals(categories[i].getName())) { secretGradeCategoryId = categories[i].getId(); break; } } if ("".equals(secretGradeCategoryId)) { AppConfigCategoryObject categoryObj = new AppConfigCategoryObject(); categoryObj.setName("系统密级配置"); categoryObj.setDesc("系统密级配置"); secretGradeCategoryId = category.saveAppConfigCategory(categoryObj); } AppConfigDetailObject userConfigDetail = delegate.getAppConfigDetailByKey("userSecuritySwith"); AppConfigDetailObject ipConfigDetail = delegate.getAppConfigDetailByKey("ipSecuritySwitch"); if (ipSwich) { if (ipConfigDetail.getId() != null && !"".equals(ipConfigDetail.getId())) { ipConfigDetail.setValue("on"); boolean res = delegate.updateAppConfigDetail(ipConfigDetail); System.out.println("ip配置修改结果-------" + res); } else { ipConfigDetail = new AppConfigDetailObject(); ipConfigDetail.setKey("ipSecuritySwitch"); ipConfigDetail.setValue("on"); ipConfigDetail.setName("机器密级停启"); ipConfigDetail.setDesc("value值为on时代表机器密级开启,值为其他或者不配置时代表不开启。"); ipConfigDetail.setCategoryId(secretGradeCategoryId); String res = delegate.saveAppConfigDetail(ipConfigDetail); System.out.println("ip配置保存结果-------" + res); } } else { if (ipConfigDetail.getId() != null && !"".equals(ipConfigDetail.getId())) { ipConfigDetail.setValue("off"); delegate.updateAppConfigDetail(ipConfigDetail); } } if (userSwich) { if (userConfigDetail.getId() != null && !"".equals(userConfigDetail.getId())) { userConfigDetail.setValue("on"); boolean res = delegate.updateAppConfigDetail(userConfigDetail); System.out.println("user配置修改结果-------" + res); } else { userConfigDetail = new AppConfigDetailObject(); userConfigDetail.setKey("userSecuritySwith"); userConfigDetail.setValue("on"); userConfigDetail.setName("用户密级停启"); userConfigDetail.setCategoryId(secretGradeCategoryId); userConfigDetail.setDesc("value值为on时代表用户密级开启,值为其他或者不配置时代表不开启。"); String res = delegate.saveAppConfigDetail(userConfigDetail); System.out.println("user配置保存结果-------" + res); } updateUserSecretGrade(); } else { if (userConfigDetail.getId() != null && !"".equals(userConfigDetail.getId())) { userConfigDetail.setValue("off"); boolean res = delegate.updateAppConfigDetail(userConfigDetail); System.out.println("user配置修改结果-------" + res); } } JOptionPane.showMessageDialog(this, "保存配置成功", "保存成功", JOptionPane.INFORMATION_MESSAGE); } catch (VCIException e) { JOptionPane.showMessageDialog(this, "保存配置失败", "保存失败", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); } catch (VCIError e) { JOptionPane.showMessageDialog(this, "保存配置失败", "保存失败", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); } } private void updateUserSecretGrade() throws VCIError { EnumItem enumItem = ServiceProvider.getOMDService().getEnumService().getEmItemByName("usersecurityenum"); EnumChild[] children = enumItem.children; int grade = 10; if (children.length > 0) { grade = Integer.parseInt(children[0].value); for (int i = 0; i < children.length; i++) { EnumChild child = children[i]; if (grade >= Integer.parseInt(child.value)) { grade = Integer.parseInt(child.value); } } } String updateSql = "update pluser set plsecretgrade = '" + grade + "' " + "where plsecretgrade is null"; ClientBusinessObjectOperation cboo = new ClientBusinessObjectOperation(); cboo.executeUpdateSql(updateSql); } @Override public String getUserID() { return logonUserId; } @Override public String getRoleID() { return logonRoleId; } @Override public JPanel getModuleComponent() { return this; } @Override public String getModuleName() { return moduleName; } @Override public String getIconName() { return iconName; } @Override public String getModuleShowInfo() { return moduleShowInfo; } }