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

📄 allocate_medicine.java~42~

📁 使用Java语言开发的数据库课程设计——医药管理信息系统。
💻 JAVA~42~
📖 第 1 页 / 共 2 页
字号:
        {
            JOptionPane.showMessageDialog(null,
                                          "SQLException:" + ex.getMessage(),
                                          "警告!",
                                          JOptionPane.WARNING_MESSAGE);
        }
    }

    public void DB_Update(String sql)
    {
        try
        {
            Connection con = DriverManager.getConnection(conURL, Username, Password);
            Statement s = con.createStatement();
            s.executeUpdate(sql);
            s.close();
            con.close();
        }
        catch (SQLException ex)
        {
            JOptionPane.showMessageDialog(null, "SQLException:" + ex.getMessage(),
                                          "警告!", JOptionPane.WARNING_MESSAGE);
        }
    }

    public void jButton5_actionPerformed(ActionEvent e)
    {
        if(jTextField1.getText().equals("")||jTextField2.getText().equals("")
           ||jTextField3.getText().equals("")||jTextField4.getText().equals("")
           ||jTextField5.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null,"  请输入还没填入的数据 ","系统提示!",
                     JOptionPane.WARNING_MESSAGE);
        }
        else
        {
            try
            {
                Connection con = DriverManager.getConnection(conURL, Username,
                        Password);
                Statement s = con.createStatement(ResultSet.
                                                  TYPE_SCROLL_INSENSITIVE,
                                                  ResultSet.CONCUR_UPDATABLE);
                ResultSet rs = s.executeQuery(
                        "select 药品编号,药品名称 from Medicine_Data where 药品编号 ='"
                        + jTextField2.getText() + "'");
                if(rs.next()==false)
                {
                    JOptionPane.showMessageDialog(null,"资料库中没有编号为 '"+jTextField2.getText()+" ' 的药品"+'\n'
                                                  +"请先检查所要索取药品的资料","系统提示",JOptionPane.WARNING_MESSAGE);
                }
                else
                {
                    if(jTextField5.getText().equals("0"))
                        JOptionPane.showMessageDialog(null,
                                    "  对不起,既然需求量为 0 ,此次不作记录 ", "系统提示!",
                                    JOptionPane.WARNING_MESSAGE);
                    else
                    {
                        try
                        {
                            Connection con2 = DriverManager.getConnection(
                                    conURL,
                                    Username,
                                    Password);
                            Statement s2 = con2.createStatement();
                            String get_kucun =
                                    "select * from Medicine_Data where 药品编号='" +
                                    jTextField2.getText() + "'";
                            ResultSet rs2 = s2.executeQuery(get_kucun);
                            rs2.next();
                            kucun = rs2.getInt("库存量");
                            if (kucun < Integer.parseInt(jTextField5.getText()))
                            {
                                JOptionPane.showMessageDialog(null,
                                        "  对不起,库存量只有 " + String.valueOf(kucun)
                                        + " 不能答应请求 ", "系统提示!",
                                        JOptionPane.WARNING_MESSAGE);
                                rs2.close();
                                s2.close();
                            }
                            else
                            { //更新药品分配表  Medicine_Allocation
                                String sql =
                                        "insert into Medicine_Allocation values('"
                                        + jTextField1.getText() + "','" +
                                        jTextField2.getText() + "','"
                                        + jTextField3.getText() + "','" +
                                        jComboBox1.getSelectedItem().toString() +
                                        "','"
                                        + jTextField4.getText() + "'," +
                                        jTextField5.getText() + ",'" +
                                        jTextField6.getText() + "')";
                                DB_Update(sql);
                                data = new Vector();
                                data.addElement(jTextField1.getText());
                                data.addElement(jTextField2.getText());
                                data.addElement(jTextField3.getText());
                                data.addElement(jComboBox1.getSelectedItem().
                                                toString());
                                data.addElement(jTextField4.getText());
                                data.addElement(jTextField5.getText());
                                data.addElement(jTextField6.getText());
                                tableModel1.addRow(data);
                                jTable1.setModel(tableModel1);
                                JOptionPane.showMessageDialog(null,
                                        " 已经将这次取药的记录到数据库中 ", "系统提示!",
                                        JOptionPane.WARNING_MESSAGE);

                                //取药后,对库存量的更新
                                kucun = kucun -
                                        Integer.parseInt(jTextField5.getText());
                                String Reset_kucun =
                                        "update Medicine_Data set 库存量=" +
                                        String.valueOf(kucun)
                                        + "where 药品编号='" + jTextField2.getText() +
                                        "'";
                                DB_Update(Reset_kucun);
                                JOptionPane.showMessageDialog(null,
                                        " 库存量更新成功 ! 现有量: " +
                                        String.valueOf(kucun), "系统提示!",
                                         JOptionPane.WARNING_MESSAGE);
                            }
                            rs2.close();
                            s2.close();
                        }
                        catch (SQLException ex)
                        {
                            /*JOptionPane.showMessageDialog(null,
                             "SQLException:" + ex.getMessage(),
                                                  "警告!",
                             JOptionPane.WARNING_MESSAGE);*/
                            System.out.println(ex.getMessage());
                        }
                    }
                }
                s.close();
                con.close();
            }
            catch(SQLException ex)
            {
                JOptionPane.showMessageDialog(null,
                                              "SQLException:" + ex.getMessage(),
                                              "警告4444444!",
                                              JOptionPane.WARNING_MESSAGE);
            }
        }
    }

    public void jButton6_actionPerformed(ActionEvent e)
    {
        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");
        jTextField5.setText("");
        jTextField6.setText("");
    }

    public void jButton1_actionPerformed(ActionEvent e)
    {
        init_table();
        Order = "select * from Medicine_Allocation order by 流水号";
        add_table_data(Order);
    }

    public void jButton2_actionPerformed(ActionEvent e)
    {
        init_table();
        Order = "select * from Medicine_Allocation order by 供应科室";
        add_table_data(Order);
    }

    public void jButton3_actionPerformed(ActionEvent e)
    {
        init_table();
        Order = "select * from Medicine_Allocation order by 医生名称";
        add_table_data(Order);
    }

    public void jButton4_actionPerformed(ActionEvent e)
    {
        init_table();
        Order = "select * from Medicine_Allocation order by 开单日期";
        add_table_data(Order);
    }
}


class Allocate_Medicine_jButton4_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton4_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class Allocate_Medicine_jButton3_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton3_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class Allocate_Medicine_jButton2_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton2_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class Allocate_Medicine_jButton1_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton1_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class Allocate_Medicine_jButton6_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton6_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class Allocate_Medicine_jButton5_actionAdapter implements ActionListener {
    private Allocate_Medicine adaptee;
    Allocate_Medicine_jButton5_actionAdapter(Allocate_Medicine adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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