package 固定资产管理系统;
import java.awt.*;
import java.util.Calendar;
import javax.swing.*;
import java.sql.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Dialogreturn extends JDialog {
ConnectDataBase cdb=new ConnectDataBase();
Calendar cal=Calendar.getInstance();
JPanel panel1 = new JPanel();
JLabel lblastid = new JLabel();
JLabel lblastname = new JLabel();
JTextField txtastname = new JTextField();
JLabel lblcatename = new JLabel();
JTextField txtcatename = new JTextField();
JLabel lblsubcatename = new JLabel();
JTextField txtsubcatename = new JTextField();
JLabel lblemp = new JLabel();
JLabel lblreturndate = new JLabel();
JLabel lblreturnoperator = new JLabel();
JTextField txtreturndate = new JTextField();
JButton btnreturn = new JButton();
JComboBox cmbastid = new JComboBox();
JButton btnup = new JButton();
JButton btndown = new JButton();
JLabel lbllenddate = new JLabel();
JTextField txtlenddate = new JTextField();
JTextField txtemp = new JTextField();
JTextField txtretoperator = new JTextField();
public Dialogreturn(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public Dialogreturn() {
this(new Frame(), "Dialoglend", false);
}
private void jbInit() throws Exception {
panel1.setLayout(null);
lblastid.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblastid.setText("资产编号 :");
lblastid.setBounds(new Rectangle(25, 25, 70, 25));
lblastname.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblastname.setText("资产名称 :");
lblastname.setBounds(new Rectangle(216, 25, 70, 25));
cmbastid.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
cmbastid.setBounds(new Rectangle(90, 25, 110, 25));
cmbastid.addItemListener(new Dialogreturn_cmbastid_itemAdapter(this));
cmbastid.addItem("请选择资产编号");
for (int i = 0; i < cdb.getAstreturnid().size(); i++) {
cmbastid.addItem(cdb.getAstreturnid().get(i));
}
txtastname.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtastname.setEditable(true);
txtastname.setText("");
txtastname.setBounds(new Rectangle(280, 25, 110, 23));
lblcatename.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblcatename.setText("大类名称 :");
lblcatename.setBounds(new Rectangle(25, 75, 70, 25));
txtcatename.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtcatename.setEditable(true);
txtcatename.setText("");
txtcatename.setBounds(new Rectangle(90, 75, 110, 23));
lblsubcatename.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblsubcatename.setText("小类名称 :");
lblsubcatename.setBounds(new Rectangle(215, 75, 70, 23));
txtsubcatename.setText("");
txtsubcatename.setBounds(new Rectangle(280, 75, 110, 23));
txtsubcatename.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtsubcatename.setEditable(true);
lblemp.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblemp.setText(" 领用人 :");
lblemp.setBounds(new Rectangle(25, 125, 70, 23));
lblreturndate.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblreturndate.setText("归还日期 :");
lblreturndate.setBounds(new Rectangle(25, 175, 80, 23));
lblreturnoperator.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lblreturnoperator.setText("归还操作员:");
lblreturnoperator.setBounds(new Rectangle(210, 175, 80, 23));
java.sql.Date dd=new Date(cal.getTimeInMillis());
txtreturndate.setText(String.valueOf(dd));
txtreturndate.setBounds(new Rectangle(90, 175, 110, 23));
txtreturndate.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtreturndate.setEditable(false);
this.setTitle("归还信息");
btnreturn.setBounds(new Rectangle(290, 235, 80, 23));
btnreturn.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btnreturn.setText("归还");
btnreturn.addActionListener(new Dialogreturn_btnreturn_actionAdapter(this));
btnup.setBounds(new Rectangle(120, 235, 80, 23));
btnup.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btnup.setText("上一条");
btnup.addActionListener(new Dialogreturn_btnup_actionAdapter(this));
btndown.setBounds(new Rectangle(205, 235, 80, 23));
btndown.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btndown.setText("下一条");
btndown.addActionListener(new Dialogreturn_btndown_actionAdapter(this));
lbllenddate.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
lbllenddate.setText("领用日期 :");
lbllenddate.setBounds(new Rectangle(215, 125, 80, 23));
txtlenddate.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtlenddate.setEditable(true);
txtlenddate.setText("");
txtlenddate.setBounds(new Rectangle(280, 125, 110, 23));
txtemp.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
txtemp.setEditable(true);
txtemp.setText("");
txtemp.setBounds(new Rectangle(90, 125, 110, 23));
txtretoperator.setEditable(false);
txtretoperator.setBounds(new Rectangle(280, 175, 110, 23));
getContentPane().add(panel1);
panel1.add(lblastid);
panel1.add(lblcatename);
panel1.add(txtcatename);
panel1.add(lblemp);
panel1.add(btnreturn);
panel1.add(cmbastid);
panel1.add(btnup);
panel1.add(btndown);
panel1.add(lblreturndate);
panel1.add(txtreturndate);
panel1.add(txtemp);
panel1.add(txtastname);
panel1.add(txtsubcatename);
panel1.add(txtlenddate);
panel1.add(lblreturnoperator);
panel1.add(lbllenddate);
panel1.add(lblsubcatename);
panel1.add(lblastname);
panel1.add(txtretoperator);
}
public void cmbastid_itemStateChanged(ItemEvent e) {
if(cmbastid.getSelectedItem().equals("请选择资产编号")){
txtastname.setText("");
txtcatename.setText("");
txtsubcatename.setText("");
txtemp.setText("");
txtlenddate.setText("");
}
else{
txtastname.setText(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(0).toString());
txtcatename.setText(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(1).toString());
txtsubcatename.setText(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(2).toString());
txtemp.setText(cdb.getreturninfo(String.valueOf(cmbastid.
getSelectedItem())).get(1).toString());
txtlenddate.setText(cdb.getreturninfo(String.valueOf(cmbastid.
getSelectedItem())).get(2).toString());
}
}
public void btnup_actionPerformed(ActionEvent e) {
if(cmbastid.getSelectedIndex()!=0){
cmbastid.setSelectedIndex(cmbastid.getSelectedIndex()-1);
}
}
public void btndown_actionPerformed(ActionEvent e) {
if(cmbastid.getSelectedIndex() cmbastid.setSelectedIndex(cmbastid.getSelectedIndex() + 1);
}
}
public void btnreturn_actionPerformed(ActionEvent e) {
if(txtastname.getText().equals("")){
JOptionPane.showMessageDialog(this,"请选择资产编号","错误",
JOptionPane.ERROR_MESSAGE);
}
else if(JOptionPane.showConfirmDialog(this,"确定要归还资产吗?","归还信息",0)==0){
if(txtastname.getText().equals(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(0)) &&
txtcatename.getText().equals(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(1)) &&
txtsubcatename.getText().equals(cdb.getAstlendinfo(String.valueOf(cmbastid.
getSelectedItem())).get(2)) &&
txtemp.getText().equals(cdb.getreturninfo(String.valueOf(cmbastid.
getSelectedItem())).get(1)) &&
txtlenddate.getText().equals(cdb.getreturninfo(String.valueOf(cmbastid.
getSelectedItem())).get(2))){
cdb.updatereturn(String.valueOf(cmbastid.getSelectedItem()),
txtreturndate.getText(),
String.valueOf(txtretoperator.getText()));
JOptionPane.showMessageDialog(this, "归还资产已经完成!", "成功归还",
JOptionPane.INFORMATION_MESSAGE);
cmbastid.removeItem(cmbastid.getSelectedItem());
}
else
JOptionPane.showMessageDialog(this, "归还的资产信息不正确!", "错误",
JOptionPane.ERROR_MESSAGE);
}
}
}
class Dialogreturn_btnreturn_actionAdapter implements ActionListener {
private Dialogreturn adaptee;
Dialogreturn_btnreturn_actionAdapter(Dialogreturn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnreturn_actionPerformed(e);
}
}
class Dialogreturn_btndown_actionAdapter implements ActionListener {
private Dialogreturn adaptee;
Dialogreturn_btndown_actionAdapter(Dialogreturn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btndown_actionPerformed(e);
}
}
class Dialogreturn_btnup_actionAdapter implements ActionListener {
private Dialogreturn adaptee;
Dialogreturn_btnup_actionAdapter(Dialogreturn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnup_actionPerformed(e);
}
}
class Dialogreturn_cmbastid_itemAdapter implements ItemListener {
private Dialogreturn adaptee;
Dialogreturn_cmbastid_itemAdapter(Dialogreturn adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.cmbastid_itemStateChanged(e);
}
}