package com.jz.sm.framework.control.action.org;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import com.jz.sm.framework.model.dao.impl.IOrgTypeDAO;
import com.jz.sm.framework.model.dao.impl.OrgTypeDAOImpl;
import com.jz.sm.framework.model.entity.OrgType;
public class OrgTypeModifyAction implements FunctionAction, ActionListener {
private JTabbedPane content = null;
private JPanel bodyPanel = null;
private JPanel helpPanel = null;
private JTable bodyTable = null;
private JScrollPane bodyScroll = null;
private DefaultTableModel bodyTableModle = null;
private String bodyTableColums[] = {"机构类别代号","部门名称","部门描述"};
private String[][] bodyTableRows = null;
private String[][] getTableData() {
IOrgTypeDAO orgTypeDAO = new OrgTypeDAOImpl();
List<OrgType> list = orgTypeDAO.findByLike(new OrgType());
String[][] data = new String[list.size()][3];
for (int i = 0; i < list.size(); i++) {
OrgType orgType = list.get(i);
data[i][0] = orgType.getOrgTypeId();
data[i][1] = orgType.getOrgTypeName();
data[i][2] = orgType.getOrgTypeMemo();
}
return data;
}
private void createBodyPanel() {
//生成bodyPanel
this.bodyPanel = new JPanel();
this.bodyPanel.setLayout(new BorderLayout());
//生成table加入bodyPanel
this.bodyTableRows = this.getTableData();
this.bodyTableModle = new DefaultTableModel(this.bodyTableRows, this.bodyTableColums);
this.bodyTable = new JTable();
this.bodyTable.setModel(this.bodyTableModle);
this.bodyScroll = new JScrollPane();
this.bodyScroll.getViewport().add(this.bodyTable);
this.bodyPanel.add(this.bodyScroll, BorderLayout.CENTER);
//生成button加入bodyPanel
JPanel buttonJPanel = new JPanel();
JButton modifyButton = new JButton("修改");
modifyButton.setActionCommand("modify");
modifyButton.addActionListener(this);
JButton refreshButton = new JButton("刷新");
refreshButton.setActionCommand("refresh");
refreshButton.addActionListener(this);
buttonJPanel.add(modifyButton);
buttonJPanel.add(refreshButton);
this.bodyPanel.add(buttonJPanel, BorderLayout.SOUTH);
}
private void createHelpPanel() {
this.helpPanel = new JPanel();
}
@Override
public void myPaint(JPanel workSpace) {
workSpace.removeAll();
workSpace.repaint();
workSpace.setLayout(new BorderLayout());
this.content = new JTabbedPane();
this.createBodyPanel();
this.content.add("修改操作", this.bodyPanel);
this.createHelpPanel();
this.content.add("修改说明", this.helpPanel);
workSpace.add(this.content, BorderLayout.CENTER);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("modify")) {
int selectCmount = this.bodyTable.getSelectedRowCount();
if(selectCmount == 1) {
String orgTypeId = this.bodyTable.getValueAt(this.bodyTable.getSelectedRow(), 0).toString();
new OrgTypeModifyDialog(this, orgTypeId);
} else {
JOptionPane.showMessageDialog(null, "请选择一条要修改的数据!");
}
}else if(e.getActionCommand().equals("refresh")) {
this.refreshBodyTable();
}
}
private void refreshBodyTable() {
this.bodyPanel.removeAll();
this.bodyTableRows = this.getTableData();
this.bodyTableModle = new DefaultTableModel(this.bodyTableRows, this.bodyTableColums);
this.bodyTable.setModel(this.bodyTableModle);
}
public class OrgTypeModifyDialog extends JDialog implements ActionListener {
private OrgTypeModifyAction orgTypeModifyAction = null;
private OrgType orgType = null;
private JLabel orgTypeIdLabel = null;
private JTextField orgTypeIdField = null;
private JLabel orgTypeNameLabel = null;
private JTextField orgTypeNameField = null;
private JLabel orgTypeMemoLabel = null;
private JScrollPane orgTypeMemoScroll = null;
private JTextArea orgTypeMemoField = null;
private JPanel buttonJPanel = null;
private JButton addOrgType = null;
private JButton clearOrgType = null;
private OrgType getorOrgType(String orgTypeId) {
OrgType orgType = null;
IOrgTypeDAO orgTypeDAO = new OrgTypeDAOImpl();
orgType = orgTypeDAO.findById(orgTypeId);
return orgType;
}
////////////////////////////////////////////////////////////////////////////////////////////////
private void init() {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - 600) / 2);
int y = (int) ((dimension.getHeight() - 550) / 2);
this.setBounds(x, y, 600, 550);
Container container = this.getContentPane();
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
this.orgTypeIdLabel = new JLabel("机构类别代号");
container.add(this.orgTypeIdLabel, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
this.orgTypeIdField = new JTextField(20);
this.orgTypeIdField.setEditable(false);
this.orgTypeIdField.setText(this.orgType.getOrgTypeId());
container.add(this.orgTypeIdField, gbc);
//机构类别名称
gbc.gridx = 0;
gbc.gridy = 1;
this.orgTypeNameLabel = new JLabel("机构类别名称");
container.add(this.orgTypeNameLabel, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
this.orgTypeNameField = new JTextField(20);
this.orgTypeNameField.setText(this.orgType.getOrgTypeName());
container.add(this.orgTypeNameField, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
this.orgTypeMemoLabel = new JLabel("机构类别备注:");
container.add(this.orgTypeMemoLabel, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
this.orgTypeMemoField = new JTextArea(8, 40);
this.orgTypeMemoField.setText(this.orgType.getOrgTypeMemo());
this.orgTypeMemoScroll = new JScrollPane();
this.orgTypeMemoScroll.getViewport().add(this.orgTypeMemoField);
container.add(this.orgTypeMemoScroll, gbc);
this.buttonJPanel = new JPanel();
this.buttonJPanel.setLayout(new FlowLayout());
this.addOrgType = new JButton("保存");
this.addOrgType.setActionCommand("save");
this.addOrgType.addActionListener(this);
this.clearOrgType = new JButton("还原");
this.clearOrgType.setActionCommand("fade");
this.clearOrgType.addActionListener(this);
this.buttonJPanel.add(this.addOrgType);
this.buttonJPanel.add(this.clearOrgType);
gbc.gridx = 0;
gbc.gridy = 3;
container.add(this.buttonJPanel, gbc);
this.setVisible(true);
}
public OrgTypeModifyDialog() {
}
public OrgTypeModifyDialog(OrgTypeModifyAction orgTypeModifyAction,
String orgTypeId) {
this.orgTypeModifyAction = orgTypeModifyAction;
this.orgType = this.getorOrgType(orgTypeId);
this.init();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("save")) {
OrgType orgType = new OrgType();
orgType.setOrgTypeId(this.orgTypeIdField.getText());
orgType.setOrgTypeName(this.orgTypeNameField.getText());
orgType.setOrgTypeMemo(this.orgTypeMemoField.getText());
IOrgTypeDAO orgTypeDAO = new OrgTypeDAOImpl();
if(orgTypeDAO.modify(orgType)) {
JOptionPane.showMessageDialog(this, "修改部门类别成功!");
} else {
JOptionPane.showMessageDialog(this, "修改部门类别失败,请检查数据是否正确");
}
} else if(e.getAction
学校管理系统-java代码
1星 需积分: 18 170 浏览量
2015-09-30
18:42:22
上传
评论 4
收藏 336KB ZIP 举报
aduxiaoyan
- 粉丝: 0
- 资源: 4
最新资源
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
- Rankings & Leaderboards 排名和排行榜Unity游戏开发插件资源unitypackage
- Semantic Color Palette 语义调色板Unity游戏开发插件资源unitypackage
- Low Poly Nature:Lush and Diverse Environments低聚自然郁郁Unity低多边形模型资源
- voc数据集是什么-我们如何使用voc数据集
- Edgar Pro-Procedural Level Generator程序关卡生成器Unity开发插件unitypackage
- 宝藏软件m3u8下载器\m3u8DL-CLI
- 三次样条插值的介绍-什么是三次样条插值原理
- http的一些相关介绍-对于我们来说什么是http
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈