📄 lendpanel.java
字号:
package stage_project;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.JTableHeader;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class LendPanel extends JPanel {
public LendPanel() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
//时间显示
TimeClass tc = new TimeClass();
String time = tc.getTime();
private void jbInit() throws Exception {
this.setLayout(null);
setSize(new Dimension(960, 600));
jLabel1.setText("资产编号:");
jLabel1.setBounds(new Rectangle(240, 160, 60, 30));
jLabel2.setText("样 式:");
jLabel2.setBounds(new Rectangle(240, 220, 60, 30));
jLabel3.setText("借 用 人:");
jLabel3.setBounds(new Rectangle(240, 280, 60, 30));
jLabel4.setText("归还日期:");
jLabel4.setBounds(new Rectangle(240, 340, 60, 30));
jLabel5.setText("操 作 人:");
jLabel5.setBounds(new Rectangle(240, 400, 60, 30));
jLabel6.setText("资产名称:");
jLabel6.setBounds(new Rectangle(470, 160, 60, 30));
jLabel7.setText("价 格:");
jLabel7.setBounds(new Rectangle(470, 220, 60, 30));
jLabel8.setText("借用日期:");
jLabel8.setBounds(new Rectangle(470, 280, 60, 30));
jLabel9.setText("是否归还:");
jLabel9.setBounds(new Rectangle(470, 340, 60, 30));
jLabel10.setText("备 注:");
jLabel10.setBounds(new Rectangle(470, 400, 60, 30));
btnLend.setBounds(new Rectangle(290, 480, 70, 25));
btnLend.setText("借 用");
btnLend.addActionListener(new LendPanel_btnLend_actionAdapter(this));
btnReturn.setBounds(new Rectangle(405, 480, 70, 25));
btnReturn.setText("归 还");
btnReturn.addActionListener(new LendPanel_btnReturn_actionAdapter(this));
btnSel.setBounds(new Rectangle(520, 480, 70, 25));
btnSel.setText("查 询");
btnSel.addActionListener(new LendPanel_btnSel_actionAdapter(this));
txtAssertId.setText("");
txtAssertId.setBounds(new Rectangle(315, 160, 120, 30));
txtType.setText("");
txtType.setBounds(new Rectangle(315, 220, 120, 30));
txtAssertName.setText("");
txtAssertName.setBounds(new Rectangle(550, 160, 120, 30));
txtPrice.setText("");
txtPrice.setBounds(new Rectangle(550, 220, 120, 30));
txtLendDate.setText("");
txtLendDate.setBounds(new Rectangle(550, 280, 120, 30));
txtReturnDate.setText("");
txtReturnDate.setBounds(new Rectangle(315, 340, 120, 30));
txtOperator.setText("");
txtOperator.setBounds(new Rectangle(315, 400, 120, 30));
txtRemark.setText("");
txtRemark.setBounds(new Rectangle(550, 400, 120, 30));
cboLendMan.setBounds(new Rectangle(315, 280, 120, 30));
cboReturnYorN.setBounds(new Rectangle(550, 340, 120, 30));
lblTime.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
lblTime.setHorizontalAlignment(SwingConstants.CENTER);
lblTime.setBounds(new Rectangle(757, 45, 162, 50));
DebarkationDialog dd= new DebarkationDialog();
String operator = dd.name;
txtOperator.setText(operator);
lblBeijing.setIcon(img);
lblBeijing.setBounds(new Rectangle(0, 0, 960, 600));
this.add(txtReturnDate);
this.add(cboLendMan);
this.add(btnLend);
this.add(txtOperator);
this.add(btnReturn);
this.add(btnSel);
this.add(jLabel10);
this.add(jLabel9);
this.add(jLabel8);
this.add(jLabel7);
this.add(txtType);
this.add(txtAssertId);
this.add(jLabel6);
this.add(jLabel1);
this.add(jLabel5);
this.add(jLabel4);
this.add(jLabel3);
this.add(jLabel2);
this.add(txtRemark);
this.add(txtLendDate);
this.add(txtAssertName);
this.add(txtPrice);
this.add(cboReturnYorN);
this.add(lblTime);
this.add(lblBeijing);
String sqllendman = "select ename from employee ";
ArrayList arr1 = new ArrayList();
arr1 = db.getId(sqllendman);
for (int i = 0; i < arr1.size(); i++) {
cboLendMan.addItem(arr1.get(i));
}
//是否归还
cboReturnYorN.addItem("借用");
cboReturnYorN.addItem("归还");
lblTime.setText(time);
}
ImageIcon img = new ImageIcon("xiubei.gif");
JLabel lblBeijing = new JLabel(img);
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JButton btnLend = new JButton();
JButton btnReturn = new JButton();
JButton btnSel = new JButton();
JTextField txtAssertId = new JTextField();
JTextField txtType = new JTextField();
JTextField txtAssertName = new JTextField();
JTextField txtPrice = new JTextField();
JTextField txtLendDate = new JTextField();
JTextField txtReturnDate = new JTextField();
JTextField txtOperator = new JTextField();
JTextField txtRemark = new JTextField();
JComboBox cboLendMan = new JComboBox();
JComboBox cboReturnYorN = new JComboBox();
DBAccess db = new DBAccess();
JLabel jLabel12 = new JLabel();
JLabel lblTime = new JLabel();
//借用事件
public void btnLend_actionPerformed(ActionEvent e) {
String assertid = txtAssertId.getText();
String assertname = txtAssertName.getText();
String type = txtType.getText();
String price = txtPrice.getText();
String lenddate = txtLendDate.getText();
String operator = txtOperator.getText();
String remarks = txtRemark.getText();
txtReturnDate.setText("");
String returntime = txtReturnDate.getText();
String lendrorn = "借用";
//资产编号不能为空
if (assertid.equals("")) {
JOptionPane.showMessageDialog(this, "资产编号不能为空 ");
return;
}
//资产编号必须为数字
for (int i = 0; i < assertid.length(); i++) {
char mci = assertid.charAt(i);
if (!Character.isDigit(mci)) {
JOptionPane.showMessageDialog(this, "资产编号必须为数字 ");
return;
}
}
//资产编号是否存在
String sql1 = "select * from asset where assetid = '" + assertid +
"'";
boolean b1 = db.jiancha(sql1);
if (!b1) {
JOptionPane.showMessageDialog(this,
"添加" + "\n" + assertid +
"资产编号不存在,请重新选择资产编号");
return;
}
//资产名称不能为空
if (assertname.equals("")) {
JOptionPane.showMessageDialog(this, "资产名称不能为空 ");
return;
}
//资产价格不能为空
if (price.equals("")) {
JOptionPane.showMessageDialog(this, "资产价格不能为空 ");
return;
}
String name = cboLendMan.getSelectedItem().toString();
String sql2 = "select empno from employee where ename = '"+name+"'";
ArrayList arr = db.chaxun(sql2,1);
String empon = arr.get(0).toString();
String sql = "insert into lend (assetid,empno,usedate,retdate,isreturn,operator,remarks ) values('"+assertid+
"','"+empon+"','"+time+"','"+returntime+"','"+"借用"+"','"+operator+"','"+remarks+"')";
int num = db.doUpdate(sql);
if (num == 1) {
JOptionPane.showMessageDialog(this, "固定资产借用成功 ");
} else {
JOptionPane.showMessageDialog(this, "固定资产借用失败 " + "\n " + "请重新借用");
}
}
//查询事件 查询借用归还信息
public void btnSel_actionPerformed(ActionEvent e) {
String assertid = txtAssertId.getText();
String assertname = txtAssertName.getText();
String type = txtType.getText();
String price = txtPrice.getText();
String lenddate = txtLendDate.getText();
String operator = txtOperator.getText();
String remarks = txtRemark.getText();
String returntime = txtReturnDate.getText();
//资产编号不能为空
if (assertid.equals("")) {
JOptionPane.showMessageDialog(this, "资产编号不能为空 ");
return;
}
//资产编号必须为数字
for (int i = 0; i < assertid.length(); i++) {
char mci = assertid.charAt(i);
if (!Character.isDigit(mci)) {
JOptionPane.showMessageDialog(this, "资产编号必须为数字 ");
return;
}
}
//资产编号是否存在
String sql1 = "select * from asset where assetid = '" + assertid +
"'";
boolean b1 = db.jiancha(sql1);
if (!b1) {
JOptionPane.showMessageDialog(this,"资产编号不存在,请重新选择资产编号");
return;
}
String sql = "select * from lend where assetid = '" + assertid +"'";
ArrayList arr = db.chaxun(sql,8);
// System.out.println(sql);-----------------------------测试
if (arr.size()<1){
String sql3 = "select asset_name,model,price from asset where assetid = '" + assertid + "'";
ArrayList arr3 = db.chaxun(sql3, 3);
txtAssertName.setText(arr3.get(0).toString());
txtType.setText(arr3.get(1).toString());
txtPrice.setText(arr3.get(2).toString());
} else {
String sql2 =
"select asset_name, model ,price from asset where assetid = '" +
assertid +
"'";
ArrayList arr1 = db.chaxun(sql2, 3);
String sql3 = "select ename from employee where empno = '" + arr.get(2).toString() +
"'";
ArrayList arr2 = db.chaxun(sql3, 1);
cboLendMan.setSelectedItem(arr2.get(0));
txtAssertName.setText(arr1.get(0).toString());
txtPrice.setText(arr1.get(2).toString());
txtType.setText(arr1.get(1).toString());
txtLendDate.setText(arr.get(3).toString());
txtReturnDate.setText(arr.get(4).toString());
cboReturnYorN.setSelectedItem(arr.get(5).toString());
txtOperator.setText(arr.get(6).toString());
if(arr.get(7)==null){
remarks = "";
}else{
txtRemark.setText(remarks);
}
}
}
//归还事件处理
public void btnReturn_actionPerformed(ActionEvent e) {
String assertid = txtAssertId.getText();
//资产编号是否存在
String sql1 = "select * from asset where assetid = '" + assertid +
"'";
boolean b1 = db.jiancha(sql1);
if (!b1) {
JOptionPane.showMessageDialog(this,
"编号" + "\n" + assertid +
"资产不存在,请重新选择资产编号");
return;
}
//资产编号不能为空
if (assertid.equals("")) {
JOptionPane.showMessageDialog(this, "资产编号不能为空 ");
return;
}
//资产编号必须为数字
for (int i = 0; i < assertid.length(); i++) {
char mci = assertid.charAt(i);
if (!Character.isDigit(mci)) {
JOptionPane.showMessageDialog(this, "资产编号必须为数字 ");
return;
}
}
//执行SQL语句
String sql = "update lend set retdate = '" + time + "',isreturn = '" +
"归还" + "' where assetid = '" + assertid +
"'";
int num = -1;
num = db.doUpdate(sql);
if (num == 1) {
JOptionPane.showMessageDialog(this, "归还成功!!");
} else {
JOptionPane.showMessageDialog(this, "归还失败!!");
}
}
}
class LendPanel_btnReturn_actionAdapter implements ActionListener {
private LendPanel adaptee;
LendPanel_btnReturn_actionAdapter(LendPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnReturn_actionPerformed(e);
}
}
class LendPanel_btnSel_actionAdapter implements ActionListener {
private LendPanel adaptee;
LendPanel_btnSel_actionAdapter(LendPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSel_actionPerformed(e);
}
}
class LendPanel_btnLend_actionAdapter implements ActionListener {
private LendPanel adaptee;
LendPanel_btnLend_actionAdapter(LendPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnLend_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -