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

📄 add_medicine.java~39~

📁 在个一个诊所系统,实现数据的查询和删除等的操作.
💻 JAVA~39~
字号:
package clinique;

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.Rectangle;
import com.borland.dbswing.JdbTable;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.dataset.Column;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import javax.swing.BorderFactory;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class add_medicine extends JPanel {
    public add_medicine() {
        try {
            jbInit();
            connect();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void connect()
    {
        try {
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
 } catch (ClassNotFoundException ce) {
     System.out.println(ce);
 }
 try {
     String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
     Connection con = DriverManager.getConnection(url,"sa","");
     Statement s = con.createStatement();

//     rs.close();
//     s.close();
//     con.close();
 } catch (SQLException ce) {
     System.out.println(ce);
 }

    }
    private void jbInit() throws Exception {
        this.setLayout(null);
        jScrollPane1.setBorder(BorderFactory.createEtchedBorder());
        jScrollPane1.setBounds(new Rectangle(9, 8, 641, 211));
        database1.setConnection(new ConnectionDescriptor(
                "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique",
                "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
        queryDataSet1.setQuery(new QueryDescriptor(database1,
                "select * from medicine", null, true, Load.ALL));
        jdbTable1.setDataSet(queryDataSet1);
        jdbTable1.setEditable(false);
        column1.setColumnName("name");
        column1.setDataType(com.borland.dx.dataset.Variant.STRING);
        column1.setPrecision(50);
        column1.setTableName("medicine");
        column1.setWidth(14);
        column1.setServerColumnName("NAME");
        column1.setSqlType(1);
        column2.setColumnName("factory");
        column2.setDataType(com.borland.dx.dataset.Variant.STRING);
        column2.setPrecision(50);
        column2.setTableName("medicine");
        column2.setWidth(14);
        column2.setServerColumnName("FACTORY");
        column2.setSqlType(1);
        column3.setColumnName("price");
        column3.setDataType(com.borland.dx.dataset.Variant.BIGDECIMAL);
        column3.setPrecision(19);
        column3.setScale(4);
        column3.setTableName("medicine");
        column3.setWidth(14);
        column3.setServerColumnName("PRICE");
        column3.setSqlType(3);
        jBadd.setBounds(new Rectangle(193, 350, 92, 23));
        jBadd.setText("添加药品");
        jBadd.addActionListener(new add_madicine_jBadd_actionAdapter(this));
        jLabel1.setText("药品名称:");
        jLabel1.setBounds(new Rectangle(24, 29, 70, 15));
        jLabel2.setText("药品厂家:");
        jLabel2.setBounds(new Rectangle(325, 30, 70, 15));
        jLabel3.setText("药品单价:");
        jLabel3.setBounds(new Rectangle(22, 68, 65, 15));
        mad_name.setBounds(new Rectangle(99, 25, 130, 20));
        mad_factory.setBounds(new Rectangle(404, 27, 139, 20));
        mad_price.setBounds(new Rectangle(99, 65, 130, 20));
        this.setBackground(SystemColor.control);
        jBexit.setBounds(new Rectangle(373, 350, 81, 23));
        jBexit.setText("取消");
        jBexit.addActionListener(new add_medicine_jBexit_actionAdapter(this));
        column4.setColumnName("medicine_id");
        column4.setDataType(com.borland.dx.dataset.Variant.INT);
        column4.setRowId(true);
        column4.setTableName("medicine");
        column4.setWidth(14);
        column4.setServerColumnName("MEDICINE_ID");
        column4.setSqlType(4);
        jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel4.setText("药品信息添加");
        jLabel4.setBounds(new Rectangle(34, 21, 117, 19));
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(64, 47, 659, 387));
        jPanel1.setLayout(null);
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setBounds(new Rectangle(8, 234, 641, 102));
        jPanel2.setLayout(null);
        jLabel5.setText("药品数量:");
        jLabel5.setBounds(new Rectangle(325, 68, 71, 15));
        jTextField1.setBounds(new Rectangle(404, 65, 139, 20));
        jPanel2.add(jLabel1);
        jPanel2.add(mad_name);
        jPanel2.add(mad_factory);
        jPanel2.add(jLabel2);
        jPanel2.add(mad_price);
        jPanel2.add(jLabel3);
        jPanel2.add(jLabel5);
        jPanel2.add(jTextField1);
        jPanel1.add(jBexit);
        jPanel1.add(jBadd);
        jPanel1.add(jScrollPane1);
        jPanel1.add(jPanel2);
        jScrollPane1.getViewport().add(jdbTable1);
        this.add(jLabel4);
        this.add(jPanel1);
        queryDataSet1.setColumns(new Column[] {column4, column1, column2,
                                 column3});
    }



    JScrollPane jScrollPane1 = new JScrollPane();
    JdbTable jdbTable1 = new JdbTable();
    Database database1 = new Database();
    QueryDataSet queryDataSet1 = new QueryDataSet();
    Column column1 = new Column();
    Column column2 = new Column();
    Column column3 = new Column();
    JButton jBadd = new JButton();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JTextField mad_name = new JTextField();
    JTextField mad_factory = new JTextField();
    JTextField mad_price = new JTextField();
    JButton jBexit = new JButton();
    Column column4 = new Column();
    JLabel jLabel4 = new JLabel();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JLabel jLabel5 = new JLabel();
    JTextField jTextField1 = new JTextField();
    public void jBadd_actionPerformed(ActionEvent e) {
      /*  String name;
        String factory;
        String price;
        name=mad_name.getText();
        factory=mad_factory.getText();
        price=mad_price.getText();
        String sqlStr;
        sqlStr="inset into madicine(name,factory,price) vlaues(\'name\',\'factory\',\'price\')";
        ResultSet rs = s.executeQuery(sqlStr);*/
      if(mad_name.getText().length()==0)
          {
              mad_name.requestFocus();
              JOptionPane.showMessageDialog(null,"     请输入药品名称!");
          }
      else if(mad_factory.getText().length()==0)
      {
          mad_factory.requestFocus();
          JOptionPane.showMessageDialog(null,"     请输入药品的厂家名称!");
      }
      else if(mad_price.getText().length()==0)
      {
          mad_price.requestFocus();
          JOptionPane.showMessageDialog(null,"     请输入药品的单价!");
      }
    //  else if(!mad_price.getText().equals(""))
   //   {
   //
    //  }
      else
      {
          insert_add();
      }
    }
private void insert_add()
    {
        try {
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
 } catch (ClassNotFoundException ce) {
     System.out.println(ce);
 }
 try {
     String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
     Connection con = DriverManager.getConnection(url,"sa","");
     String sqlStr;
     sqlStr="insert into medicine(name,factory,price) values(\'"+mad_name.getText()+"\',\'"+mad_factory.getText()+"\',"+mad_price.getText()+")";
     Statement s = con.createStatement();
     s.executeUpdate(sqlStr);
     JOptionPane.showMessageDialog(null,"数据添加成功!");
     mad_name.setText("");
     mad_factory.setText("");
     mad_price.setText("");
     queryDataSet1.refresh();
     s.close();
     con.close();
 } catch (SQLException ce) {
     System.out.println(ce);
 }
 }

    private boolean check_price()
    {
        String s;
       // s=
       return true;
    }

    public void jBexit_actionPerformed(ActionEvent e) {
        mad_name.setText("");
        mad_factory.setText("");
        mad_price.setText("");
    }

    public void jBreturn_actionPerformed(ActionEvent e) {
        this.setVisible(false);

        main_frame m=new main_frame();
        m.setVisible(true);
        //m.remove(m.getContentPane());
        //m.setVisible(true);
    }

}


class add_medicine_jBexit_actionAdapter implements ActionListener {
    private add_medicine adaptee;
    add_medicine_jBexit_actionAdapter(add_medicine adaptee) {
        this.adaptee = adaptee;
    }

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


class add_madicine_jBadd_actionAdapter implements ActionListener {
    private add_medicine adaptee;
    add_madicine_jBadd_actionAdapter(add_medicine adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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