⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixassertpanel.java

📁 固定资产管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        sortid = arr.get(2).toString();

        String sql3 = "insert into asset(assetid, asset_name, cateid, subcateid, model, price,purchase_date, status, useby, remarks) values('" +
                      assertId + "','" + assertName +
                      "','" +
                      maincateid + "','" +
                      sortid + "','" +
                      type + "','" + p +
                      "','" + buyDate + "','" + status +
                      "','" + buyer + "','" +
                      remark + "')";
        //System.out.println(sql3); --------------------------------测试语句
        int num = db.doUpdate(sql3);
        if (num == 1) {
            JOptionPane.showMessageDialog(this, "固定资产添加成功 ");
        } else {
            JOptionPane.showMessageDialog(this, "固定资产添加失败 " + "\n " + "请重新添加 ");
        }
    }

    //查询事件 得到要修改和删除的 固定资产信息
    public void btnSel_actionPerformed(ActionEvent e) {
        //文本信息
        String assertId = txtAssertId.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 sql = "select * from asset where assetid  = '" + assertId + "'";
        ArrayList arr = db.chaxun(sql, 10);
        arr = db.chaxun(sql, 10);
        if (arr.size() < 1) {
            JOptionPane.showMessageDialog(this, "未找到,请确认输入是否正确!");
            return;
        } else {
            String assertName = arr.get(1).toString(); //资产名称
            String maincatename = null; //主类名称
            String sortname = null; //子类名称
            String type = arr.get(4).toString(); //样式
            String price = arr.get(5).toString(); //价格
            float p = 0;
            String buyDate = arr.get(6).toString(); //购入日期
            String buyer = arr.get(8).toString(); //购入人
            String   remark ="";
            if(arr.get(9)==null){
                remark ="";
            }else{
                  remark = arr.get(9).toString(); //备注
            }

//---------------------------------------------------------------------
            //执行SQL语句
            String sql2 = "select * from category where cateid = '" +
                          arr.get(2).toString() +
                          "'and subcateid='" + arr.get(3).toString() + "'";
            ArrayList arr2 = db.chaxun(sql2, 4);
            maincatename = arr2.get(1).toString();
            sortname = arr2.get(3).toString();
            //        System.out.println(arr2.size());-----------------------测试语句
//----------------------输出查询结果-------------------------------------------

            txtAssertName.setText(assertName);
            cboMainId.setSelectedItem(arr2.get(1).toString());
            cboZiLeiBianHao.setSelectedItem(arr2.get(3).toString());
            txtType.setText(type);
            txtPrice.setText(price);
            txtBuyDate.setText(buyDate);
            cboZhuangTai.setSelectedItem(arr.get(7).toString()); //状态
            txtBuyer.setText(buyer);
            txtRemark.setText(remark);
        }

    }

    //修改事件 修改固定资产信息
    public void btnMod_actionPerformed(ActionEvent e) {
        //文本信息
        String assertId = txtAssertId.getText(); //资产编号
        String assertName = txtAssertName.getText(); //资产名称
        String maincatename = cboMainId.getSelectedItem().toString(); //主类名称
        String sortname = cboZiLeiBianHao.getSelectedItem().toString(); //子类名称
        String maincateid = null; //主类编号
        String sortid = null; //子类编号
        String status = cboZhuangTai.getSelectedItem().toString(); //状态
        String type = txtType.getText(); //样式
        String price = txtPrice.getText(); //价格
        float p = 0;
        String buyDate = txtBuyDate.getText(); //购入日期
        String buyer = txtBuyer.getText(); //购入人
        String remark = txtRemark.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;
            }
        }
        //资产名称不能为空
        if (assertName.equals("")) {
            JOptionPane.showMessageDialog(this, "资产名称不能为空 ");
            return;
        }
        //资产价格不能为空
        if (price.equals("")) {
            JOptionPane.showMessageDialog(this, "资产价格不能为空 ");
            return;
        } else {
            p = Float.parseFloat(price);
        }
        //资产购入日期不能为空
        if (buyDate.equals("")) {
            JOptionPane.showMessageDialog(this, "资产购入日期不能为空 ");
            return;
        }
        //执行SQL语句
        String sql2 = "select * from category where catename = '" +
                      maincatename +
                      "'and subcatename='" + sortname + "'";
        ArrayList arr = db.chaxun(sql2, 4);
        //   System.out.println(arr.size());----------------------------------测试
        maincateid = arr.get(0).toString();
        sortid = arr.get(2).toString();

        String sql3 = "update  asset set asset_name = '" + assertName +
                      "', cateid = '" +
                      maincateid + "' ,subcateid = '" + sortid + "',model = '" +
                      type + "', price = '" + p +
                      "',purchase_date = '" + buyDate + "', status='" + status +
                      "', useby='" + buyer + "', remarks='" +
                      remark + "' where  assetid= '" + assertId + "'";

        int num = -1;
        num = db.doUpdate(sql3);
        if (num == 1) {
            JOptionPane.showMessageDialog(this, "修改成功!!");
        } else {
            JOptionPane.showMessageDialog(this, "修改失败!!");
        }
    }

    //删除事件 删除固定资产信息
    public void btnDel_actionPerformed(ActionEvent e) {
        String assertId = txtAssertId.getText(); //资产编号
        String sql = "delete from asset  where assetid = '" + assertId +
                     "'";
        int num = -1;
        num = db.doUpdate(sql);
        if (num == 1) {
            JOptionPane.showMessageDialog(this, "删除成功!!");
        } else {
            JOptionPane.showMessageDialog(this, "删除失败!!");
        }

    }
//下拉列表值改变事件处理
    public void cboMainId_itemStateChanged(ItemEvent e) {
        //往下拉列表中添加数据
        cboZiLeiBianHao.removeAllItems();
        String xuanze = cboMainId.getSelectedItem().toString();
        String sqlsortid = "select subcatename from category where catename='" +
                           xuanze + "'";
        ArrayList arr2 = new ArrayList();
        DBAccess db = new DBAccess();
        arr2 = db.getId(sqlsortid);
        for (int i = 0; i < arr2.size(); i++) {
            cboZiLeiBianHao.addItem(arr2.get(i));
        }
    }


    class FixAssertPanel_btnDel_actionAdapter implements ActionListener {
        private FixAssertPanel adaptee;
        FixAssertPanel_btnDel_actionAdapter(FixAssertPanel adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.btnDel_actionPerformed(e);
        }
    }


    class FixAssertPanel_btnMod_actionAdapter implements ActionListener {
        private FixAssertPanel adaptee;
        FixAssertPanel_btnMod_actionAdapter(FixAssertPanel adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.btnMod_actionPerformed(e);
        }
    }


    class FixAssertPanel_btnSel_actionAdapter implements ActionListener {
        private FixAssertPanel adaptee;
        FixAssertPanel_btnSel_actionAdapter(FixAssertPanel adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.btnSel_actionPerformed(e);
        }
    }


    class FixAssertPanel_jButton1_actionAdapter implements ActionListener {
        private FixAssertPanel adaptee;
        FixAssertPanel_jButton1_actionAdapter(FixAssertPanel adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.jButton1_actionPerformed(e);
        }
    }
}


class FixAssertPanel_cboMainId_itemAdapter implements ItemListener {
    private FixAssertPanel adaptee;
    FixAssertPanel_cboMainId_itemAdapter(FixAssertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void itemStateChanged(ItemEvent e) {
        adaptee.cboMainId_itemStateChanged(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -