Medicine.java
来源:互联网 发布:java编译命令是什么 编辑:程序博客网 时间:2024/05/15 07:55
package yaopin;
import javax.swing.JPanel;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import model.MedicineDAO;
import model.MedicineDTO;
public class Medicine implements ActionListener
{
private static final long serialVersionUID = 1L;
private JPanel jSubPanel = null;
private JLabel jLabelID,jLabelName,jLabelSpellCode,jLabelTypeCode,jLabelUsage,jLabelMemo,jLabelMDDose,jLabelIngredient,jLabelMDUnit,jLabelMDFunction,jLabelSpecContent;
private JTextField jTextID,jTextName,jTextSpellCode,jTextMDDose,jTextMDUnit,jTextSpecContent,jTextIngredient;
private JComboBox jCmdTypeCode;
private JTextField jTextMDFunction, jTextUsage, jTextMemo;
private JButton jBtnAdd, jBtnUpdate, jBtnDelete, jBtnSearch, jBtnCancel;
private DefaultTableModel tableModel;
private MedicineDAO medicineDAO = new MedicineDAO();
private MedicineDTO medicineDTO = new MedicineDTO();
public DefaultTableModel getTableModel()
{
if (tableModel == null)
{
tableModel=new DefaultTableModel(); // 与控件名要一致。
String[] columnNames = {"药品编码", "药品名称", "药品拼音码", "药品类别", "规格含量", "药品单位", "药品剂型", "药品成份","功能与主治","用法与用量","备注"};
for(String column : columnNames)
{
tableModel.addColumn(column);
}
for(MedicineDTO user : medicineDAO.fillMedicine())
{
tableModel.addRow(user.toArray());
}
}
return tableModel;
}
public JPanel getJSubPanel()
{
if (jSubPanel == null)
{
jLabelID = new JLabel("药品编码");
jLabelID.setBounds(new Rectangle(90, 40, 68, 22));
jTextID = new JTextField();
jTextID.setName("药品编码");
jTextID.setBounds(new Rectangle(160, 40, 200, 25));
jLabelName = new JLabel("药品名称");
jLabelName.setBounds(new Rectangle(440, 40, 68, 22));
jTextName = new JTextField();
jTextName.setName("药品名称");
jTextName.setBounds(new Rectangle(510, 40, 200, 25));
jLabelSpellCode = new JLabel("药品拼音码");
jLabelSpellCode.setBounds(new Rectangle(90, 72, 68, 22));
jTextSpellCode = new JTextField();
jTextSpellCode.setName("药品拼音码");
jTextSpellCode.setBounds(new Rectangle(160, 72, 200, 25));
jLabelTypeCode = new JLabel("药品类别");
jLabelTypeCode.setBounds(new Rectangle(440, 72, 68, 22));
jCmdTypeCode = new JComboBox();
for(String user : medicineDAO.getTypeCode())
{
jCmdTypeCode.addItem(user);
}
jCmdTypeCode.setName("药品类别");
jCmdTypeCode.setBounds(new Rectangle(510, 72, 199, 25));
jLabelSpecContent = new JLabel("规格含量");
jLabelSpecContent.setBounds(new Rectangle(90, 104, 68, 22));
jTextSpecContent = new JTextField();
jTextSpecContent.setName("规格含量");
jTextSpecContent.setBounds(new Rectangle(160, 104, 200, 25));
jLabelMDUnit = new JLabel("药品单位");
jLabelMDUnit.setBounds(new Rectangle(440, 104, 68, 22));
jTextMDUnit = new JTextField();
jTextMDUnit.setName("药品单位");
jTextMDUnit.setBounds(new Rectangle(510, 104, 200, 25));
jLabelMDDose = new JLabel("药品剂型");
jLabelMDDose.setBounds(new Rectangle(90, 136, 68, 22));
jTextMDDose = new JTextField();
jTextMDDose.setName("药品剂型");
jTextMDDose.setBounds(new Rectangle(160, 136, 200, 25));
jLabelIngredient = new JLabel("药品成份");
jLabelIngredient.setBounds(new Rectangle(440, 136, 68, 22));
jTextIngredient = new JTextField();
jTextIngredient.setName("药品成份");
jTextIngredient.setBounds(new Rectangle(510, 136, 200, 25));
jLabelMDFunction = new JLabel("功能与主治");
jLabelMDFunction.setBounds(new Rectangle(90, 168, 68, 22));
jTextMDFunction = new JTextField();
jTextMDFunction.setName("功能与主治");
jTextMDFunction.setBounds(new Rectangle(160, 168, 200, 25));
jLabelUsage = new JLabel("用法与用量");
jLabelUsage.setBounds(new Rectangle(440, 168, 68, 22));
jTextUsage = new JTextField();
jTextUsage.setName("用法与用量");
jTextUsage.setBounds(new Rectangle(510, 168, 200, 25));
jLabelMemo = new JLabel("备 注");
jLabelMemo.setBounds(new Rectangle(90, 200, 68, 22));
jTextMemo = new JTextField();
jTextMemo.setName("备注");
jTextMemo.setBounds(new Rectangle(160, 200, 550, 25));
jBtnAdd = new JButton("添加");
jBtnAdd.setBounds(new Rectangle(100, 260, 75, 23));
jBtnAdd.addActionListener(this);
jBtnUpdate = new JButton("修改");
jBtnUpdate.setBounds(new Rectangle(210, 260, 75, 23));
jBtnUpdate.addActionListener(this);
jBtnDelete = new JButton("删除");
jBtnDelete.setBounds(new Rectangle(320, 260, 75, 23));
jBtnDelete.addActionListener(this);
jBtnSearch = new JButton("查询");
jBtnSearch.setBounds(new Rectangle(500, 260, 75, 23));
jBtnSearch.addActionListener(this);
jBtnCancel = new JButton("取消");
jBtnCancel.setBounds(new Rectangle(610, 260, 75, 23));
jBtnCancel.addActionListener(this);
jSubPanel = new JPanel(null);
jSubPanel.add(jLabelID, null);
jSubPanel.add(jTextID, null);
jSubPanel.add(jLabelName, null);
jSubPanel.add(jTextName, null);
jSubPanel.add(jTextSpellCode, null);
jSubPanel.add(jCmdTypeCode, null);
jSubPanel.add(jLabelSpellCode, null);
jSubPanel.add(jLabelTypeCode, null);
jSubPanel.add(jTextMDUnit, null);
jSubPanel.add(jLabelMDDose, null);
jSubPanel.add(jTextSpecContent, null);
jSubPanel.add(jLabelIngredient, null);
jSubPanel.add(jTextIngredient, null);
jSubPanel.add(jLabelMDUnit, null);
jSubPanel.add(jTextMDDose, null);
jSubPanel.add(jLabelMDFunction, null);
jSubPanel.add(jLabelSpecContent, null);
jSubPanel.add(jTextUsage, null);
jSubPanel.add(jLabelUsage, null);
jSubPanel.add(jLabelMemo, null);
jSubPanel.add(jTextMemo, null);
jSubPanel.add(jTextMDFunction, null);
jSubPanel.add(jBtnAdd, null);
jSubPanel.add(jBtnUpdate, null);
jSubPanel.add(jBtnDelete, null);
jSubPanel.add(jBtnSearch, null);
jSubPanel.add(jBtnCancel, null);
}
return jSubPanel;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(jBtnSearch))
{
while(tableModel.getRowCount() > 0)
{
tableModel.removeRow(0); // 先清空所有数据
}
medicineDTO = new MedicineDTO();
medicineDTO.setMdCode(jTextID.getText());
medicineDTO.setMdName(jTextName.getText());
medicineDTO.setSpellCode(jTextSpellCode.getText());
medicineDTO.setTypeCode(jCmdTypeCode.getSelectedItem().toString());
medicineDAO.setMedicineDTO(medicineDTO);
for(MedicineDTO user : medicineDAO.searchMedicine())
{
tableModel.addRow(user.toArray());
}
}
else if(e.getSource().equals(jBtnAdd))
{
if (jSubPanel.getName() != null)
{
JOptionPane.showMessageDialog(jSubPanel,"供应商编号“" +jTextID.getText()+ "”已存在!");
return;
}
this.userInfo();
if(medicineDAO.addMedicine())
{
tableModel.addRow(medicineDTO.toArray());
this.clearText();
}
else
JOptionPane.showMessageDialog(jSubPanel,"供应商编号“" +jTextID.getText()+ "”添加失败!");
}
else if(e.getSource().equals(jBtnUpdate))
{
if (jSubPanel.getName() == null)
{
JOptionPane.showMessageDialog(jSubPanel,"请选择要修改的行");
return;
}
this.userInfo();
if(medicineDAO.updateMedicine())
{
int rowIndex = Integer.parseInt(jSubPanel.getName());
tableModel.removeRow(rowIndex);
tableModel.insertRow(rowIndex, medicineDTO.toArray());
this.clearText();
}
else
JOptionPane.showMessageDialog(jSubPanel,"供应商编号“" +jTextID.getText()+ "”修改失败!");
}
else if(e.getSource().equals(jBtnDelete))
{
if (jSubPanel.getName() == null)
{
JOptionPane.showMessageDialog(jSubPanel,"请选择要删除的行");
return;
}
if(JOptionPane.showConfirmDialog(jSubPanel, "确实要删除员工编号“" + jTextID.getText() + "”吗?", "系统提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0)
{
medicineDTO.setMdCode(jTextID.getText());
medicineDAO.setMedicineDTO(medicineDTO);
if(medicineDAO.deleteMedicine())
{
tableModel.removeRow(Integer.parseInt(jSubPanel.getName()));
this.clearText();
}
else
JOptionPane.showMessageDialog(jSubPanel,"供应商编号“" +jTextID.getText()+ "”删除失败!");
}
}
else
this.clearText();
}
private void userInfo()
{
medicineDTO.setMdCode(jTextID.getText());
medicineDTO.setMdName(jTextName.getText());
medicineDTO.setSpellCode(jTextSpellCode.getText());
medicineDTO.setTypeCode(jCmdTypeCode.getSelectedItem().toString());
medicineDTO.setSpecContent(jTextSpecContent.getText());
medicineDTO.setMdUnit(jTextMDUnit.getText());
medicineDTO.setMdDose(jTextMDDose.getText());
medicineDTO.setIngredient(jTextIngredient.getText());
medicineDTO.setMdFunction(jTextMDFunction.getText());
medicineDTO.setUsage(jTextUsage.getText());
medicineDTO.setMemo(jTextMemo.getText());
medicineDAO.setMedicineDTO(medicineDTO);
}
private void clearText()
{
for(Component cpt : jSubPanel.getComponents())
{
if(cpt instanceof JTextField) //JAVA(instanceof) == .NET (is)
((JTextField)cpt).setText(null); // 清空文本框
}
jSubPanel.setName(null);
jTextID.setEditable(true);
jTextID.requestFocusInWindow(); // 设置焦点
}
}
- Medicine.java
- 基本药物 essential medicine
- ACdream P1003 Medicine
- ZOJ3812--We need Medicine
- Huatuo's Medicine
- Huatuo's Medicine 【水题】
- Huatuo's Medicine HDU
- HDU5551-Huatuo's Medicine
- Moving is the best medicine.
- Medicine (01多维背包)
- 【ZOJ】3812 We Need Medicine
- ZOJ 3812 We Need Medicine
- zoj 3812 We Need Medicine
- UESTC 1226 Huatuo's Medicine
- L - Huatuo's Medicine【ccpc】
- hdu5551 水题 Huatuo's Medicine
- 2015 CCPC Huatuo's Medicine
- hdu 5551/Huatuo's Medicine
- Notepad Find
- Notepad Font
- 各大银行网上转账手续一览表
- Login.java
- Main.java
- Medicine.java
- MedicineType.java
- Provider.java
- VC6.0程序的另一种调试方案(release 调试)
- Worker.java
- MedicineDAO.java
- MedicineDTO.java
- MedicineTypeDAO.java
- MedicineTypeDTO.java